From 6a34598550c538a9bdf66484ab895e8ade60f5cb Mon Sep 17 00:00:00 2001 From: Conn Warwicker Date: Tue, 4 Feb 2025 15:23:31 +0000 Subject: [PATCH] MDL-84341 qbank_history: Fix version ordering Previously the version ordering was done on timecreated which wasn't always correct. This now uses the version number instead. Also set the default sorting on the history page to be version. Also backports a change to the behat question generator to let us set the value of fields on updated questions in the step. --- .../history/classes/question_history_view.php | 13 ++------ .../history/classes/version_number_column.php | 5 +++ .../behat/question_version_column.feature | 33 ++++++++++++++++--- .../behat_core_question_generator.php | 6 ++-- 4 files changed, 38 insertions(+), 19 deletions(-) diff --git a/question/bank/history/classes/question_history_view.php b/question/bank/history/classes/question_history_view.php index 8da85e895a6..94f7d5d9610 100644 --- a/question/bank/history/classes/question_history_view.php +++ b/question/bank/history/classes/question_history_view.php @@ -97,18 +97,9 @@ class question_history_view extends view { return false; } - /** - * Default sort for question data. - * @return array - */ + #[\Override] protected function default_sort(): array { - $defaultsort = []; - if (class_exists('\\qbank_viewcreator\\creator_name_column')) { - $sort = 'qbank_viewcreator\creator_name_column-timecreated'; - } - $defaultsort[$sort] = 1; - - return $defaultsort; + return ['qbank_history__version_number_column' => 1]; } protected function build_query(): void { diff --git a/question/bank/history/classes/version_number_column.php b/question/bank/history/classes/version_number_column.php index a156223362c..a60abdb2e32 100644 --- a/question/bank/history/classes/version_number_column.php +++ b/question/bank/history/classes/version_number_column.php @@ -44,4 +44,9 @@ class version_number_column extends column_base { return ['pr-3']; } + #[\Override] + public function is_sortable() { + return 'qv.version'; + } + } diff --git a/question/bank/history/tests/behat/question_version_column.feature b/question/bank/history/tests/behat/question_version_column.feature index 81ddace0cb7..7c8f828463d 100644 --- a/question/bank/history/tests/behat/question_version_column.feature +++ b/question/bank/history/tests/behat/question_version_column.feature @@ -1,4 +1,4 @@ -@qbank @qbank_history +@qbank @qbank_history @javascript Feature: Use the qbank plugin manager page for version column In order to check the plugin behaviour with enable and disable @@ -10,11 +10,16 @@ Feature: Use the qbank plugin manager page for version column | activity | name | course | idnumber | | quiz | Test quiz | C1 | quiz1 | And the following "question categories" exist: - | contextlevel | reference | name | - | Course | C1 | Test questions | + | contextlevel | reference | name | + | Activity module | quiz1 | Test questions | And the following "questions" exist: - | questioncategory | qtype | name | questiontext | - | Test questions | truefalse | First question | Answer the first question | + | questioncategory | qtype | name | + | Test questions | truefalse | First Question | + And the following "core_question > updated questions" exist: + | questioncategory | question | name | + | Test questions | First Question | First Edit | + | Test questions | First Question | Edit the Second | + | Test questions | First Question | The Final Edit | Scenario: Enable/disable version column from the base view Given I log in as "admin" @@ -22,8 +27,26 @@ Feature: Use the qbank plugin manager page for version column And I should see "Question history" When I click on "Disable" "link" in the "Question history" "table_row" And I am on the "Test quiz" "mod_quiz > question bank" page + And I apply question bank filter "Category" with value "Test questions" Then I should not see "Version" in the "region-main" "region" And I navigate to "Plugins > Question bank plugins > Manage question bank plugins" in site administration And I click on "Enable" "link" in the "Question history" "table_row" And I am on the "Test quiz" "mod_quiz > question bank" page + And I apply question bank filter "Category" with value "Test questions" And I should see "Version" in the "region-main" "region" + + Scenario: Sort the question versions + Given I am on the "Test quiz" "mod_quiz > question bank" page logged in as "admin" + And I apply question bank filter "Category" with value "Test questions" + And I choose "History" action for "The Final Edit" in the question bank + Then "Edit the Second" "checkbox" should appear before "The Final Edit" "checkbox" + Then "First Edit" "checkbox" should appear before "Edit the Second" "checkbox" + Then "First Question" "checkbox" should appear before "First Edit" "checkbox" + And I follow "Sort by Version ascending" + Then "Edit the Second" "checkbox" should appear before "The Final Edit" "checkbox" + Then "First Edit" "checkbox" should appear before "Edit the Second" "checkbox" + Then "First Question" "checkbox" should appear before "First Edit" "checkbox" + And I follow "Sort by Version descending" + Then "The Final Edit" "checkbox" should appear before "Edit the Second" "checkbox" + Then "Edit the Second" "checkbox" should appear before "First Edit" "checkbox" + Then "First Edit" "checkbox" should appear before "First Question" "checkbox" diff --git a/question/tests/generator/behat_core_question_generator.php b/question/tests/generator/behat_core_question_generator.php index fca9147e04e..ed8b44dde91 100644 --- a/question/tests/generator/behat_core_question_generator.php +++ b/question/tests/generator/behat_core_question_generator.php @@ -76,10 +76,10 @@ class behat_core_question_generator extends behat_generator_base { protected function process_updated_question(array $data): void { global $DB; $question = $DB->get_record('question', ['id' => $data['id']], '*', MUST_EXIST); + $overrides = []; foreach ($data as $key => $value) { - $question->{$key} = $value; + $overrides[$key] = $value; } - - $this->datagenerator->get_plugin_generator('core_question')->update_question($question); + $this->datagenerator->get_plugin_generator('core_question')->update_question($question, null, $overrides); } }