diff --git a/course/modlib.php b/course/modlib.php index 5d431f3b8cb..abb3eb05648 100644 --- a/course/modlib.php +++ b/course/modlib.php @@ -433,6 +433,11 @@ function edit_module_post_actions($moduleinfo, $course) { } } + if (plugin_supports('mod', $moduleinfo->modulename, FEATURE_USES_QUESTIONS) && empty($moduleinfo->skipdefaultcategory)) { + // Create the default question category. + question_get_default_category($modcontext->id, true); + } + return $moduleinfo; } diff --git a/lib/tests/questionlib_test.php b/lib/tests/questionlib_test.php index fdedc8ce57e..0cf6524be0a 100644 --- a/lib/tests/questionlib_test.php +++ b/lib/tests/questionlib_test.php @@ -171,10 +171,8 @@ final class questionlib_test extends \advanced_testcase { $context2 = \context_module::instance($modqbank2->cmid); /** @var \core_question_generator $questiongenerator */ $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); - $questioncat1 = $questiongenerator->create_question_category(['contextid' => - $context1->id]); - $questioncat2 = $questiongenerator->create_question_category(['contextid' => - $context2->id]); + $questioncat1 = question_get_default_category($context1->id); + $questioncat2 = question_get_default_category($context2->id); $question1 = $questiongenerator->create_question('shortanswer', null, ['category' => $questioncat1->id]); $question2 = $questiongenerator->create_question('shortanswer', null, ['category' => $questioncat1->id]); $question3 = $questiongenerator->create_question('shortanswer', null, ['category' => $questioncat2->id]); @@ -209,7 +207,7 @@ final class questionlib_test extends \advanced_testcase { // Create some question categories and questions in this course. $modcontext = \context_module::instance($modqbank3->cmid); - $questioncat = $questiongenerator->create_question_category(['contextid' => $modcontext->id]); + $questioncat = question_get_default_category($modcontext->id); $question1 = $questiongenerator->create_question('shortanswer', null, ['category' => $questioncat->id]); $question2 = $questiongenerator->create_question('shortanswer', null, ['category' => $questioncat->id]); @@ -1217,7 +1215,7 @@ final class questionlib_test extends \advanced_testcase { $context = $this->create_course_and_question_bank(); $top = question_get_top_category($context->id, true); - $cat1 = $questiongenerator->create_question_category(['parent' => $top->id]); + $cat1 = question_get_default_category($context->id); $sub11 = $questiongenerator->create_question_category(['parent' => $cat1->id]); $sub12 = $questiongenerator->create_question_category(['parent' => $cat1->id]); $cat2 = $questiongenerator->create_question_category(['parent' => $top->id]); @@ -1255,7 +1253,7 @@ final class questionlib_test extends \advanced_testcase { $wrongcontext = \context_module::instance($qbank2->cmid); $top = question_get_top_category($bank1context->id, true); - $cat1 = $questiongenerator->create_question_category(['parent' => $top->id]); + $cat1 = question_get_default_category($bank1context->id); $sub11 = $questiongenerator->create_question_category(['parent' => $cat1->id]); $sub12 = $questiongenerator->create_question_category(['parent' => $cat1->id]); $cat2 = $questiongenerator->create_question_category(['parent' => $top->id, 'contextid' => $wrongcontext->id]); diff --git a/mod/quiz/report/overview/tests/behat/regrading.feature b/mod/quiz/report/overview/tests/behat/regrading.feature index 0bdcd4e0fa1..96497b10897 100644 --- a/mod/quiz/report/overview/tests/behat/regrading.feature +++ b/mod/quiz/report/overview/tests/behat/regrading.feature @@ -209,6 +209,7 @@ Feature: Regrading quiz attempts using the Grades report And I should see "Overall number of students achieving grade ranges" And "Student One" row "Regrade" column of "attempts" table should not contain "Needed" And I am on the "Quiz for testing regrading" "mod_quiz > question bank" page + And I apply question bank filter "Category" with value "Test questions" And I choose "Edit question" action for "TF" in the question bank And I set the field "Correct answer" to "False" And I press "id_submitbutton" @@ -239,6 +240,7 @@ Feature: Regrading quiz attempts using the Grades report And I should see "(latest)" in the "TF" "list_item" # Create multiple question versions. And I am on the "Quiz for testing regrading" "mod_quiz > question bank" page + And I apply question bank filter "Category" with value "Test questions" And I choose "Edit question" action for "TF" in the question bank And I set the field "Correct answer" to "True" And I press "id_submitbutton" @@ -277,6 +279,7 @@ Feature: Regrading quiz attempts using the Grades report And I click on "Yes" "button" # Create multiple question versions. And I am on the "Quiz for testing regrading" "mod_quiz > question bank" page + And I apply question bank filter "Category" with value "Test questions" And I choose "Delete" action for "SA" in the question bank And I press "Delete" And I am on the "Quiz for testing regrading" "mod_quiz > edit" page @@ -286,6 +289,7 @@ Feature: Regrading quiz attempts using the Grades report And I click on "Yes" "button" in the "Confirm" "dialogue" And I click on "Add" "link" And I follow "a random question" + And I apply question bank filter "Category" with value "Test questions" And I press "Add random question" And I am on the "Quiz for testing regrading" "quiz activity" page logged in as student3 And I click on "Attempt quiz" "button" @@ -295,6 +299,7 @@ Feature: Regrading quiz attempts using the Grades report And I press "Submit all and finish" And I click on "Submit" "button" in the "Submit all your answers and finish?" "dialogue" And I am on the "Quiz for testing regrading" "mod_quiz > question bank" page logged in as teacher + And I apply question bank filter "Category" with value "Test questions" And I choose "Edit question" action for "TF" in the question bank And I set the field "Correct answer" to "False" And I press "id_submitbutton" diff --git a/mod/quiz/tests/behat/attempt_redo_questions.feature b/mod/quiz/tests/behat/attempt_redo_questions.feature index 3fa4fb48fc2..c8dac71f626 100644 --- a/mod/quiz/tests/behat/attempt_redo_questions.feature +++ b/mod/quiz/tests/behat/attempt_redo_questions.feature @@ -197,6 +197,7 @@ Feature: Allow students to redo questions in a practice quiz, without starting a And I follow "a random question" And I click on "Switch bank" "button" And I click on "Qbank 1" "link" in the "Select question bank" "dialogue" + And I apply question bank filter "Category" with value "Test questions" And I press "Add random question" And user "student" has started an attempt at quiz "Quiz 2" randomised as follows: | slot | actualquestion | diff --git a/mod/quiz/tests/behat/editing_add_from_question_bank.feature b/mod/quiz/tests/behat/editing_add_from_question_bank.feature index f14522c7663..a79bc0eee8c 100644 --- a/mod/quiz/tests/behat/editing_add_from_question_bank.feature +++ b/mod/quiz/tests/behat/editing_add_from_question_bank.feature @@ -47,6 +47,7 @@ Feature: Adding questions to a quiz from the question bank When I am on the "Quiz 1" "mod_quiz > Edit" page And I open the "last" add to quiz menu And I follow "from question bank" + And I apply question bank filter "Category" with value "Test questions" Then I should see "foo" in the "question 01 name" "table_row" And I should see "bar" in the "question 02 name" "table_row" And I should see "qidnum" in the "question 02 name" "table_row" @@ -70,6 +71,7 @@ Feature: Adding questions to a quiz from the question bank And I follow "from question bank" And I click on "Switch bank" "button" And I click on "Qbank 1 & < > \" ' &" "link" in the "Select question bank" "dialogue" + And I apply question bank filter "Category" with value "Qbank questions" Then I should see "qbanktag1" in the "question 03 name" "table_row" And I should see "qbanktag2" in the "question 04 name" "table_row" And I apply question bank filter "Tag" with value "qbanktag1" @@ -91,6 +93,7 @@ Feature: Adding questions to a quiz from the question bank When I am on the "Quiz 1" "mod_quiz > Edit" page logged in as teacher1 And I open the "last" add to quiz menu And I follow "from question bank" + And I apply question bank filter "Category" with value "Test questions" And I should see "question 01 name" in the "categoryquestions" "table" And I should see "question 02 name" in the "categoryquestions" "table" And I should not see "Feature question" in the "categoryquestions" "table" @@ -149,6 +152,7 @@ Feature: Adding questions to a quiz from the question bank And I am on the "Quiz 1" "mod_quiz > Edit" page When I open the "Page 1" add to quiz menu And I follow "from question bank" + And I apply question bank filter "Category" with value "Test questions" And I set the field with xpath "//tr[contains(normalize-space(.), 'question 03 name')]//input[@type='checkbox']" to "1" And I click on "Add selected questions to the quiz" "button" Then I should see "question 03 name" on quiz page "1" @@ -158,6 +162,7 @@ Feature: Adding questions to a quiz from the question bank Given I am on the "Quiz 1" "mod_quiz > Edit" page logged in as "teacher1" When I open the "last" add to quiz menu And I follow "from question bank" + And I apply question bank filter "Category" with value "Test questions" And I set the field with xpath "//input[@type='checkbox' and @id='qbheadercheckbox']" to "1" And I press "Add selected questions to the quiz" Then I should see "question 01 name" on quiz page "1" @@ -170,9 +175,11 @@ Feature: Adding questions to a quiz from the question bank When I open the "last" add to quiz menu And I follow "from question bank" Then I should see "Current bank: Quiz 1" + And I apply question bank filter "Category" with value "Test questions" And I should see "question 01 name" And I click on "Switch bank" "button" And I click on "Qbank 1 & < > \" ' &" "link" in the "Select question bank" "dialogue" + And I apply question bank filter "Category" with value "Qbank questions" And I should see "question 03 name" But I should not see "question 01 name" And I click on "Select" "checkbox" in the "question 03 name" "table_row" @@ -188,6 +195,7 @@ Feature: Adding questions to a quiz from the question bank And I am on the "Quiz 1" "mod_quiz > Edit" page logged in as "teacher1" When I open the "last" add to quiz menu And I follow "from question bank" + And I apply question bank filter "Category" with value "Test questions" And I click on "Sort by Question ascending" "link" Then "question 01 name" "text" should appear before "question 02 name" "text" And I click on "Sort by Question descending" "link" @@ -206,6 +214,7 @@ Feature: Adding questions to a quiz from the question bank When I set the field "Shuffle" to "1" And I open the "last" add to quiz menu And I follow "from question bank" + And I apply question bank filter "Category" with value "Test questions" Then I should see "question 01 name" Scenario: Question bank names are displayed in quiz questions @@ -236,6 +245,7 @@ Feature: Adding questions to a quiz from the question bank And I follow "from question bank" And I click on "Switch bank" "button" And I click on "Qbank 1 & < > \" ' &" "link" in the "Select question bank" "dialogue" + And I apply question bank filter "Category" with value "Qbank questions" And I click on "Select" "checkbox" in the "question 03 name" "table_row" And I click on "Add selected questions to the quiz" "button" When the following "role assigns" exist: diff --git a/mod/quiz/tests/behat/editing_add_random.feature b/mod/quiz/tests/behat/editing_add_random.feature index 139fa207764..82b8f6292fe 100644 --- a/mod/quiz/tests/behat/editing_add_random.feature +++ b/mod/quiz/tests/behat/editing_add_random.feature @@ -57,6 +57,7 @@ Feature: Adding random questions to a quiz based on category and tags Given I am on the "Quiz 1" "mod_quiz > Edit" page logged in as "teacher1" When I open the "last" add to quiz menu And I follow "a random question" + And I apply question bank filter "Category" with value "Questions Category 1" And I apply question bank filter "Tag" with value "foo" And I wait until the page is ready And I should see "question 1 name" @@ -93,6 +94,7 @@ Feature: Adding random questions to a quiz based on category and tags Given I am on the "Quiz 1" "mod_quiz > Edit" page logged in as "teacher1" And I open the "last" add to quiz menu And I follow "a random question" + And I apply question bank filter "Category" with value "Questions Category 1" And I apply question bank filter "Tag" with value "foo" And I select "1" from the "randomcount" singleselect And I press "Add random question" @@ -107,6 +109,7 @@ Feature: Adding random questions to a quiz based on category and tags And I navigate to "Questions" in current page administration And I open the "Page 1" add to quiz menu And I follow "a random question" + And I apply question bank filter "Category" with value "Questions Category 1" And I set the field "Also show questions from subcategories" to "1" And I click on "Apply filters" "button" And I apply question bank filter "Tag" with value "foo" @@ -176,12 +179,14 @@ Feature: Adding random questions to a quiz based on category and tags And I open the "last" add to quiz menu And I follow "a random question" And I should see "Current bank: Quiz 1" + And I apply question bank filter "Category" with value "Questions Category 1" And I should see "question 1 name" And I click on "Switch bank" "button" And I click on "Qbank 1" "link" in the "Select question bank" "dialogue" And I should see "Current bank: Qbank 1" - And I should see "Qbank question 1" And I should not see "question 1 name" + And I apply question bank filter "Category" with value "Qbank questions" + And I should see "Qbank question 1" When I apply question bank filter "Tag" with value "qbanktag" And I select "1" from the "randomcount" singleselect And I press "Add random question" @@ -218,6 +223,7 @@ Feature: Adding random questions to a quiz based on category and tags Given I am on the "Quiz 1" "mod_quiz > Edit" page logged in as "teacher1" And I open the "last" add to quiz menu And I follow "a random question" + And I apply question bank filter "Category" with value "Questions Category 1" And I apply question bank filter "Tag" with value "foo" And I select "1" from the "randomcount" singleselect And I press "Add random question" diff --git a/mod/quiz/tests/behat/editing_edit_random.feature b/mod/quiz/tests/behat/editing_edit_random.feature index cfe31b9ecb7..cf8c7a3209d 100644 --- a/mod/quiz/tests/behat/editing_edit_random.feature +++ b/mod/quiz/tests/behat/editing_edit_random.feature @@ -40,12 +40,14 @@ Feature: Editing random questions already in a quiz based on category and tags Given I am on the "Quiz 1" "mod_quiz > Edit" page logged in as "teacher1" And I open the "last" add to quiz menu And I follow "a random question" + And I apply question bank filter "Category" with value "Questions Category 1" # To actually reproduce MDL-68733 it would be better to set tags easy,essay here, and then below just delete one tag. # However, the state of Behat for autocomplete fields does not let us actually do that. And I apply question bank filter "Tag" with value "easy" And I press "Add random question" And I open the "Page 1" add to quiz menu And I follow "a random question" + And I apply question bank filter "Category" with value "Questions Category 1" And I apply question bank filter "Tag" with value "hard" And I press "Add random question" And I follow "Add page break" @@ -61,6 +63,7 @@ Feature: Editing random questions already in a quiz based on category and tags Given I am on the "Quiz 1" "mod_quiz > Edit" page logged in as "teacher1" And I open the "last" add to quiz menu And I follow "a random question" + And I apply question bank filter "Category" with value "Questions Category 1" And I apply question bank filter "Tag" with value "essay" And I press "Add random question" When I click on "Configure question" "link" in the "Random (Questions Category 1) based on filter condition with tags: essay" "list_item" @@ -76,6 +79,7 @@ Feature: Editing random questions already in a quiz based on category and tags Given I am on the "Quiz 1" "mod_quiz > Edit" page logged in as "teacher1" And I open the "last" add to quiz menu And I follow "a random question" + And I apply question bank filter "Category" with value "Questions Category 1" And I apply question bank filter "Tag" with value "essay" And I press "Add random question" When I click on "Configure question" "link" in the "Random (Questions Category 1) based on filter condition with tags: essay" "list_item" diff --git a/mod/quiz/tests/behat/editing_remove_multiple_questions.feature b/mod/quiz/tests/behat/editing_remove_multiple_questions.feature index 0ee5bb119dd..6cad48e12c9 100644 --- a/mod/quiz/tests/behat/editing_remove_multiple_questions.feature +++ b/mod/quiz/tests/behat/editing_remove_multiple_questions.feature @@ -254,6 +254,7 @@ Feature: Edit quiz page - remove multiple questions When I open the "last" add to quiz menu And I follow "a random question" + And I apply question bank filter "Category" with value "Test questions" And I set the field "Number of random questions" to "3" And I press "Add random question" And I click on "Select multiple items" "button" diff --git a/mod/quiz/tests/behat/editing_repaginate.feature b/mod/quiz/tests/behat/editing_repaginate.feature index 560a9f455bf..886fe32bbcb 100644 --- a/mod/quiz/tests/behat/editing_repaginate.feature +++ b/mod/quiz/tests/behat/editing_repaginate.feature @@ -19,21 +19,18 @@ Feature: Edit quiz page - pagination And the following "activities" exist: | activity | name | course | idnumber | questionsperpage | navmethod | | quiz | Quiz 1 | C1 | quiz1 | 0 | sequential | - And the following "question categories" exist: - | contextlevel | reference | name | - | Activity module | quiz1 | Quiz questions | And the following "questions" exist: - | questioncategory | qtype | name | questiontext | - | Quiz questions | truefalse | 1 | Question1 text | - | Quiz questions | truefalse | 2 | Question2 text | - | Quiz questions | truefalse | 3 | Question3 text | - | Quiz questions | truefalse | 4 | Question4 text | - | Quiz questions | truefalse | 5 | Question5 text | - | Quiz questions | truefalse | 6 | Question6 text | - | Quiz questions | truefalse | 7 | Question7 text | - | Quiz questions | truefalse | 8 | Question8 text | - | Quiz questions | truefalse | 9 | Question9 text | - | Quiz questions | truefalse | 10 | Question10 text | + | questioncategory | qtype | name | questiontext | + | Default for Quiz 1 | truefalse | 1 | Question1 text | + | Default for Quiz 1 | truefalse | 2 | Question2 text | + | Default for Quiz 1 | truefalse | 3 | Question3 text | + | Default for Quiz 1 | truefalse | 4 | Question4 text | + | Default for Quiz 1 | truefalse | 5 | Question5 text | + | Default for Quiz 1 | truefalse | 6 | Question6 text | + | Default for Quiz 1 | truefalse | 7 | Question7 text | + | Default for Quiz 1 | truefalse | 8 | Question8 text | + | Default for Quiz 1 | truefalse | 9 | Question9 text | + | Default for Quiz 1 | truefalse | 10 | Question10 text | And quiz "Quiz 1" contains the following questions: | question | page | | 1 | 1 | diff --git a/mod/quiz/tests/behat/editing_switch_bank.feature b/mod/quiz/tests/behat/editing_switch_bank.feature index 3c753f34103..47704f04e56 100644 --- a/mod/quiz/tests/behat/editing_switch_bank.feature +++ b/mod/quiz/tests/behat/editing_switch_bank.feature @@ -51,7 +51,7 @@ Feature: Switching question bank when adding questions to a quiz But "Qbank 4" "autocomplete_suggestions" should not exist And I click on "C2 - Qbank 3" item in the autocomplete list And I should see "Current bank: Qbank 3" - And I should see "Test questions 3" + And I should see "Default for Qbank 3" Scenario: Viewing question banks not in the current course show as recently accessed Given "teacher" has recently viewed the "qbank1" "qbank" question bank diff --git a/mod/quiz/tests/behat/quiz_question_versions.feature b/mod/quiz/tests/behat/quiz_question_versions.feature index c8c22e35474..0a44aa136d2 100644 --- a/mod/quiz/tests/behat/quiz_question_versions.feature +++ b/mod/quiz/tests/behat/quiz_question_versions.feature @@ -107,6 +107,7 @@ Feature: Quiz question versioning When I am on the "Quiz 1" "mod_quiz > Edit" page logged in as "teacher" And I open the "Page 1" add to quiz menu And I follow "from question bank" + And I apply question bank filter "Category" with value "Test questions" And I click on "Select" "checkbox" in the "Other question" "table_row" And I press "Add selected questions to the quiz" Then I should see "Other question" on quiz page "1" @@ -118,6 +119,7 @@ Feature: Quiz question versioning | question | page | | First question | 1 | And I am on the "Quiz 1" "mod_quiz > Question bank" page logged in as teacher + And I apply question bank filter "Category" with value "Test questions" And I set the field "question_status_dropdown" in the "First question" "table_row" to "Draft" When I am on the "Quiz 1" "mod_quiz > Edit" page Then I should see "This question is in draft status. To use it in the quiz, go to the question bank and change the status to ready." diff --git a/mod/quiz/tests/behat/random_question.feature b/mod/quiz/tests/behat/random_question.feature index 0f2ed508e78..c5c027c9954 100644 --- a/mod/quiz/tests/behat/random_question.feature +++ b/mod/quiz/tests/behat/random_question.feature @@ -21,7 +21,6 @@ Feature: Moving a question to another category should not affect random question | qbank | Qbank 1 | Question bank 1 | C1 | qbank1 | And the following "question categories" exist: | contextlevel | reference | questioncategory | name | - | Activity module | qbank1 | Top | top | | Activity module | qbank1 | top | Default for Qbank 1 | | Activity module | qbank1 | Default for Qbank 1 | Subcategory | | Activity module | qbank1 | top | Used category | diff --git a/question/bank/bulkmove/tests/behat/bulk_move.feature b/question/bank/bulkmove/tests/behat/bulk_move.feature index 428284704b3..fbd3d42a9d6 100644 --- a/question/bank/bulkmove/tests/behat/bulk_move.feature +++ b/question/bank/bulkmove/tests/behat/bulk_move.feature @@ -50,12 +50,14 @@ Feature: Use the qbank plugin manager page for bulkmove And I should see "Bulk move questions" And I click on "Disable" "link" in the "Bulk move questions" "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 1" And I click on "First question" "checkbox" And I click on "With selected" "button" Then I should not see question bulk action "move" And I navigate to "Plugins > Question bank plugins > Manage question bank plugins" in site administration And I click on "Enable" "link" in the "Bulk move questions" "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 1" And I click on "First question" "checkbox" And I click on "With selected" "button" And I should see question bulk action "move" @@ -64,6 +66,7 @@ Feature: Use the qbank plugin manager page for bulkmove Scenario: Selecting a shared question bank limits the available categories to those belonging to the selected bank. Given I log in as "teacher1" And I am on the "Test quiz" "mod_quiz > question bank" page + And I apply question bank filter "Category" with value "Test questions 1" And I click on "First question" "checkbox" And I click on "With selected" "button" And I click on "move" "button" @@ -78,8 +81,9 @@ Feature: Use the qbank plugin manager page for bulkmove Then I should not see "C3 - Question bank 3" in the ".search-banks" "css_element" And I click on "C1 - Question bank 1" item in the autocomplete list Then I should not see "Test questions 1" in the ".search-categories .form-autocomplete-selection" "css_element" - And the field "selectcategory" matches value "Test questions 2 (1)" + And the field "selectcategory" matches value "Default for Question bank 1" And I open the autocomplete suggestions list in the ".search-categories" "css_element" + And "Test questions 2 (1)" "autocomplete_suggestions" should exist And "Test questions 3" "autocomplete_suggestions" should not exist And "Test questions 4" "autocomplete_suggestions" should not exist And "Test questions 5" "autocomplete_suggestions" should exist @@ -88,6 +92,7 @@ Feature: Use the qbank plugin manager page for bulkmove Scenario: Move a question from one bank category to another. Given I log in as "teacher1" And I am on the "Test quiz" "mod_quiz > question bank" page + And I apply question bank filter "Category" with value "Test questions 1" And I click on "First question" "checkbox" And I click on "With selected" "button" And I click on "move" "button" @@ -107,6 +112,7 @@ Feature: Use the qbank plugin manager page for bulkmove | Test questions | missingtype | Question 2 | Write something | | Test questions | essay | Question 3 | frog | And I am on the "Course 1" "core_question > course question bank" page logged in as teacher1 + And I apply question bank filter "Category" with value "Test questions" # Select questions to be moved. And I click on "Question 1" "checkbox" And I click on "Question 2" "checkbox" @@ -129,6 +135,7 @@ Feature: Use the qbank plugin manager page for bulkmove @javascript Scenario: Unable to bulk move questions from history page Given I am on the "Test quiz" "mod_quiz > question bank" page logged in as "teacher1" + And I apply question bank filter "Category" with value "Test questions 1" And I choose "History" action for "First question" in the question bank And I click on "First question" "checkbox" And I click on "With selected" "button" @@ -161,6 +168,7 @@ Feature: Use the qbank plugin manager page for bulkmove | reference | qbank4 | | name | Test questions 7 | Given I am on the "Test quiz" "mod_quiz > question bank" page logged in as "teacher1" + And I apply question bank filter "Category" with value "Test questions 1" And I press "Create a new question ..." And I set the field "item_qtype_truefalse" to "1" # Manually create a new question so additional parameters are included in the URL, and we can test they are handled correctly @@ -174,14 +182,15 @@ Feature: Use the qbank plugin manager page for bulkmove And I click on "With selected" "button" And I click on "move" "button" And the field "searchbanks" matches value "C1 - Test quiz" - And the field "selectcategory" matches value "Test questions 1 (2)" + And the field "selectcategory" matches value "Default for Test quiz" And I open the autocomplete suggestions list in the ".search-banks" "css_element" And I should see "C1 - Question bank 1" in the ".search-banks .form-autocomplete-suggestions" "css_element" And I should see "C2 - Question bank 2" in the ".search-banks .form-autocomplete-suggestions" "css_element" And I should see "C4 - Question bank 4" in the ".search-banks .form-autocomplete-suggestions" "css_element" And I should not see "C3 - Question bank 3" in the ".search-banks .form-autocomplete-suggestions" "css_element" And I click on "C1 - Question bank 1" item in the autocomplete list - And the field "selectcategory" matches value "Test questions 2 (1)" + And I open the autocomplete suggestions list in the ".question_category_selector" "css_element" + And I click on "Test questions 2 (1)" item in the autocomplete list And I click on "Move questions" "button" And I should see "Are you sure you want to move these questions?" When I click on "Confirm" "button" @@ -191,6 +200,24 @@ Feature: Use the qbank plugin manager page for bulkmove And I click on "With selected" "button" And I click on "move" "button" And the field "searchbanks" matches value "C1 - Question bank 1" - And the field "selectcategory" matches value "Test questions 2 (2)" + And the field "selectcategory" matches value "Default for Question bank 1 (1)" # The moved question should be highlighted And the "class" attribute of "Seventh question" "table_row" should contain "highlight" + + @javascript + Scenario: A new question bank is available in the move dialogue immediately + Given I am on the "C1" "Course" page logged in as "teacher1" + And the following "user preferences" exist: + | user | preference | value | + | teacher1 | htmleditor | textarea | + And I navigate to "Question banks" in current page administration + And I press "Add" + And I set the field "Question bank name" to "New question bank" + And I press "Save and return to question bank list" + And I am on the "Test quiz" "mod_quiz > question bank" page + And I apply question bank filter "Category" with value "Test questions 1" + And I click on "First question" "checkbox" + And I click on "With selected" "button" + And I click on "move" "button" + And I open the autocomplete suggestions list in the ".search-banks" "css_element" + Then "New question bank" "autocomplete_suggestions" should exist diff --git a/question/bank/comment/tests/behat/question_comment.feature b/question/bank/comment/tests/behat/question_comment.feature index da8dab44cce..21a09940c4e 100644 --- a/question/bank/comment/tests/behat/question_comment.feature +++ b/question/bank/comment/tests/behat/question_comment.feature @@ -116,6 +116,7 @@ Feature: A Teacher can comment in a question Given I am on the "Test quiz" "mod_quiz > edit" page logged in as "teacher1" And I press "Add" And I follow "from question bank" + And I apply question bank filter "Category" with value "Test questions" And I click on "Select" "checkbox" in the "First question" "table_row" And I click on "Add selected questions to the quiz" "button" And I click on "Preview question" "link" @@ -126,6 +127,7 @@ Feature: A Teacher can comment in a question And I should see "Some new comment" And I switch to the main window 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 choose "Preview" action for "First question" in the question bank And I click on "Comments" "link" And I should see "Some new comment" @@ -140,9 +142,8 @@ Feature: A Teacher can comment in a question @javascript Scenario: Comments modal can change the version using dropdown - Given I log in as "teacher1" - And I am on the "Test quiz" "quiz activity" page - When I navigate to "Question bank" in current page administration + Given I am on the "Test quiz" "mod_quiz > question bank" page logged in as "teacher1" + And I apply question bank filter "Category" with value "Test questions" And I should see "First question" And I choose "Edit question" action for "First question" in the question bank And I set the field "id_name" to "Renamed question v2" diff --git a/question/bank/comment/tests/behat/question_comment_column.feature b/question/bank/comment/tests/behat/question_comment_column.feature index 243be8bd412..9aa83c4317a 100644 --- a/question/bank/comment/tests/behat/question_comment_column.feature +++ b/question/bank/comment/tests/behat/question_comment_column.feature @@ -23,8 +23,10 @@ Feature: Use the qbank plugin manager page for comment And I should see "Question comments" And I click on "Disable" "link" in the "Question comments" "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 "#categoryquestions .header.commentcount" "css_element" should not be visible And I navigate to "Plugins > Question bank plugins > Manage question bank plugins" in site administration And I click on "Enable" "link" in the "Question comments" "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 "#categoryquestions .header.commentcount" "css_element" should be visible diff --git a/question/bank/deletequestion/tests/behat/delete_question_column.feature b/question/bank/deletequestion/tests/behat/delete_question_column.feature index 7465469e948..c014d0b09d2 100644 --- a/question/bank/deletequestion/tests/behat/delete_question_column.feature +++ b/question/bank/deletequestion/tests/behat/delete_question_column.feature @@ -24,16 +24,19 @@ Feature: Use the qbank plugin manager page for deletequestion | Test questions | truefalse | Question 2 | Answer the second question | | Test questions | truefalse | Question 3 | Answer the third question | + @javascript Scenario: Enable/disable delete question column from the base view Given I log in as "admin" When I navigate to "Plugins > Question bank plugins > Manage question bank plugins" in site administration And I should see "Delete question" And I click on "Disable" "link" in the "Delete question" "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 the "Delete" action should not exist for the "Question 1" question in the question bank And I navigate to "Plugins > Question bank plugins > Manage question bank plugins" in site administration And I click on "Enable" "link" in the "Delete question" "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 the "Delete" action should exist for the "Question 1" question in the question bank @javascript @@ -43,17 +46,20 @@ Feature: Use the qbank plugin manager page for deletequestion And I should see "Delete question" And I click on "Disable" "link" in the "Delete question" "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 click on "With selected" "button" Then I should not see question bulk action "deleteselected" And I navigate to "Plugins > Question bank plugins > Manage question bank plugins" in site administration And I click on "Enable" "link" in the "Delete question" "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 click on "With selected" "button" And I should see question bulk action "deleteselected" @javascript Scenario: I should not see the deleted questions in the base view 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 click on "Question 1" "checkbox" And I click on "Question 2" "checkbox" And I click on "With selected" "button" @@ -70,6 +76,7 @@ Feature: Use the qbank plugin manager page for deletequestion | Tags | foo | And I click on "Save changes" "button" 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 apply question bank filter "Tag" with value "foo" And I click on "Question 1" "checkbox" And I click on "With selected" "button" @@ -81,6 +88,7 @@ Feature: Use the qbank plugin manager page for deletequestion @javascript Scenario: Questions can be bulk deleted from the question bank Given I am on the "Test quiz" "mod_quiz > question bank" page logged in as "teacher1" + And I apply question bank filter "Category" with value "Test questions" # Select questions to be deleted. And I click on "Question 1" "checkbox" And I click on "Question 2" "checkbox" diff --git a/question/bank/editquestion/tests/behat/filter_condition_question_status.feature b/question/bank/editquestion/tests/behat/filter_condition_question_status.feature index 8e96c030760..b8f99046fef 100644 --- a/question/bank/editquestion/tests/behat/filter_condition_question_status.feature +++ b/question/bank/editquestion/tests/behat/filter_condition_question_status.feature @@ -11,14 +11,11 @@ Feature: Filter questions by status And the following "activities" exist: | activity | name | intro | course | idnumber | | qbank | Qbank 1 | Question bank 1 | C1 | qbank1 | - And the following "question categories" exist: - | contextlevel | reference | name | - | Activity module | qbank1 | Test questions | And the following "questions" exist: - | questioncategory | qtype | name | questiontext | status | - | Test questions | truefalse | First question | Answer the first question | ready | - | Test questions | numerical | Second question | Answer the second question | draft | - | Test questions | essay | Third question | Answer the third question | ready | + | questioncategory | qtype | name | questiontext | status | + | Default for Qbank 1 | truefalse | First question | Answer the first question | ready | + | Default for Qbank 1 | numerical | Second question | Answer the second question | draft | + | Default for Qbank 1 | essay | Third question | Answer the third question | ready | Scenario: Filter by ready status Given I am on the "Qbank 1" "core_question > question bank" page logged in as "admin" diff --git a/question/bank/editquestion/tests/behat/qbank_editquestion.feature b/question/bank/editquestion/tests/behat/qbank_editquestion.feature index 13b6b939a73..e6d8d4ef626 100644 --- a/question/bank/editquestion/tests/behat/qbank_editquestion.feature +++ b/question/bank/editquestion/tests/behat/qbank_editquestion.feature @@ -9,13 +9,10 @@ Feature: Use the qbank plugin manager page for editquestion And the following "activities" exist: | activity | name | course | idnumber | | quiz | Test quiz | C1 | quiz1 | - And the following "question categories" exist: - | 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 | - | Test questions | truefalse | First question second | Answer the first question | + | questioncategory | qtype | name | questiontext | + | Default for Test quiz | truefalse | First question | Answer the first question | + | Default for Test quiz | truefalse | First question second | Answer the first question | Scenario: Enable/disable edit question columns from the base view Given I log in as "admin" diff --git a/question/bank/exporttoxml/tests/behat/export_to_xml_action.feature b/question/bank/exporttoxml/tests/behat/export_to_xml_action.feature index 9185882cfee..f5a280164d0 100644 --- a/question/bank/exporttoxml/tests/behat/export_to_xml_action.feature +++ b/question/bank/exporttoxml/tests/behat/export_to_xml_action.feature @@ -9,12 +9,9 @@ Feature: Use the qbank plugin manager page for exporttoxml And the following "activities" exist: | activity | name | course | idnumber | | quiz | Test quiz | C1 | quiz1 | - And the following "question categories" exist: - | 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 | questiontext | + | Default for Test quiz | truefalse | First question | Answer the first question | Scenario: Enable/disable exporttoxml column from the base view Given I log in as "admin" diff --git a/question/bank/history/tests/behat/question_history_action.feature b/question/bank/history/tests/behat/question_history_action.feature index 5ef7bf260ee..b80ae1b19c6 100644 --- a/question/bank/history/tests/behat/question_history_action.feature +++ b/question/bank/history/tests/behat/question_history_action.feature @@ -17,9 +17,9 @@ Feature: Use the qbank plugin manager page for question history | Activity module | qbank1 | Share questions | | Activity module | qbank2 | Share questions 2 | And the following "questions" exist: - | questioncategory | qtype | name | questiontext | - | Test questions | truefalse | First question | Answer the first question | - | Share questions | essay | Test question to be edited | Write about whatever you want | + | questioncategory | qtype | name | questiontext | + | Default for Test quiz | truefalse | First question | Answer the first question | + | Default for Qbank 1 | essay | Test question to be edited | Write about whatever you want | Scenario: Enable/disable question history column from the base view Given I log in as "admin" @@ -100,8 +100,8 @@ Feature: Use the qbank plugin manager page for question history | user | preference | value | | admin | qbank_columnsortorder_hiddencols | qbank_usage\question_last_used_column-question_last_used_column | And the following "questions" exist: - | questioncategory | qtype | name | questiontext | - | Test questions | truefalse | Second question | Answer the second question | + | questioncategory | qtype | name | questiontext | + | Default for Test quiz | truefalse | Second question | Answer the second question | When I am on the "Test quiz" "mod_quiz > question bank" page logged in as "admin" And "Last used" "qbank_columnsortorder > column header" should not exist Then I should see "First question" diff --git a/question/bank/managecategories/tests/behat/question_categories.feature b/question/bank/managecategories/tests/behat/question_categories.feature index 1604fd95404..b8a139e9b84 100644 --- a/question/bank/managecategories/tests/behat/question_categories.feature +++ b/question/bank/managecategories/tests/behat/question_categories.feature @@ -18,13 +18,11 @@ Feature: A teacher can put questions in categories in the question bank | activity | name | course | idnumber | | qbank | Qbank 1 | C1 | qbank1 | And the following "question categories" exist: - | contextlevel | reference | questioncategory | name | - | Activity module | qbank1 | Top | top | - | Activity module | qbank1 | top | Default for qbank1 | - | Activity module | qbank1 | Default for qbank1 | Subcategory & < > " ' & | - | Activity module | qbank1 | Default for qbank1 | Another subcat | - | Activity module | qbank1 | top | Used category | - | Activity module | qbank1 | top | Default & testing | + | contextlevel | reference | questioncategory | name | + | Activity module | qbank1 | Default for Qbank 1 | Subcategory & < > " ' & | + | Activity module | qbank1 | Default for Qbank 1 | Another subcat | + | Activity module | qbank1 | top | Used category | + | Activity module | qbank1 | top | Default & testing | And the following "questions" exist: | questioncategory | qtype | name | questiontext | | Used category | essay | Test question to be moved | Write about whatever you want | @@ -57,7 +55,7 @@ Feature: A teacher can put questions in categories in the question bank | Subcategory & < > " ' & | essay | Test question for renaming category | Write about whatever you want | And I open the action menu in "Subcategory & < > \" ' &" "list_item" And I choose "Edit settings" in the open action menu - And the field "parent" matches value "   Default for qbank1" + And the field "parent" matches value "   Default for Qbank 1" And I set the following fields to these values: | Name | New name | | Category info | I was edited | @@ -81,11 +79,11 @@ Feature: A teacher can put questions in categories in the question bank And I choose "Delete" in the open action menu And I click on "Delete" "button" in the "Delete" "dialogue" And I should see "The category 'Used category' contains 1 questions" - And I select "Default for qbank1" from the "Category" singleselect + And I select "Default for Qbank 1" from the "Category" singleselect And I press "Save in category" Then I should not see "Used category" And I press "Add category" - And I should see "Default for qbank1 (1)" + And I should see "Default for Qbank 1 (1)" @_file_upload Scenario: Multi answer questions with their child questions can be moved to another category when the current category is deleted @@ -107,7 +105,7 @@ Feature: A teacher can put questions in categories in the question bank Scenario: Filter questions by category and subcategories When I am on the "Qbank 1" "core_question > question bank" page - And I apply question bank filter "Category" with value "Default for qbank1" + And I apply question bank filter "Category" with value "Default for Qbank 1" Then I should not see "Question 1" When I set the field "Also show questions from subcategories" to "1" And I click on "Apply filters" "button" @@ -127,6 +125,7 @@ Feature: A teacher can put questions in categories in the question bank And I follow "from question bank" And I click on "Switch bank" "button" And I click on "Qbank 1" "link" in the "Select question bank" "dialogue" + And I apply question bank filter "Category" with value "Default for Qbank 1" When I set the field "Also show questions from subcategories" to "1" And I click on "Apply filters" "button" Then I should see "Question 1" in the "categoryquestions" "table" @@ -140,7 +139,7 @@ Feature: A teacher can put questions in categories in the question bank Scenario: Filter question by an invalid category should show validation error When I am on the "Qbank 1" "core_question > question bank" page - And I click on "Default for qbank1" "text" in the ".form-autocomplete-selection" "css_element" + And I click on "Default for Qbank 1" "text" in the ".form-autocomplete-selection" "css_element" And I click on "Apply filters" "button" Then the "Category" field validity check should return "false" And the "Category" field validation message should contain "You must select a valid category" @@ -148,7 +147,7 @@ Feature: A teacher can put questions in categories in the question bank Scenario: Correcting an invalid category should no longer show validation error When I am on the "Qbank 1" "core_question > question bank" page # First try to submit with a blank category. - And I click on "Default for qbank1" "text" in the ".form-autocomplete-selection" "css_element" + And I click on "Default for Qbank 1" "text" in the ".form-autocomplete-selection" "css_element" And I click on "Apply filters" "button" # Then apply a correct category. And I apply question bank filter "Category" with value "Used category" diff --git a/question/bank/managecategories/tests/behat/question_categories_idnumber.feature b/question/bank/managecategories/tests/behat/question_categories_idnumber.feature index b38d4e6aef9..624638d48a6 100644 --- a/question/bank/managecategories/tests/behat/question_categories_idnumber.feature +++ b/question/bank/managecategories/tests/behat/question_categories_idnumber.feature @@ -24,7 +24,6 @@ Feature: A teacher can put questions with idnumbers in categories with idnumbers # Note need to create the top category each time. When the following "question categories" exist: | contextlevel | reference | questioncategory | name | idnumber | - | Activity module | qbank1 | Top | top | | | Activity module | qbank1 | top | Used category | c1used | And I am on the "Qbank 1" "core_question > question categories" page And I press "Add category" @@ -49,7 +48,6 @@ Feature: A teacher can put questions with idnumbers in categories with idnumbers Scenario: A question category can be edited and saved without changing the idnumber When the following "question categories" exist: | contextlevel | reference | questioncategory | name | idnumber | - | Activity module | qbank1 | Top | top | | | Activity module | qbank1 | top | Used category | c1used | And I am on the "Qbank 1" "core_question > question categories" page Then I open the action menu in "Used category" "list_item" diff --git a/question/bank/managecategories/tests/external/move_category_test.php b/question/bank/managecategories/tests/external/move_category_test.php index 614caf71b55..8fb1964b369 100644 --- a/question/bank/managecategories/tests/external/move_category_test.php +++ b/question/bank/managecategories/tests/external/move_category_test.php @@ -80,10 +80,14 @@ final class move_category_test extends \qbank_managecategories\manage_category_t $this->create_course_category(); // Question categories. - $qcat1 = $this->create_question_category_for_a_qbank($qbank); + $qcat1 = question_get_default_category($context->id); $qcat2 = $this->create_question_category_for_a_qbank($qbank); $qcat3 = $this->create_question_category_for_a_qbank($qbank); + $this->assertEquals(999, $qcat1->sortorder); + $this->assertEquals(1000, $qcat2->sortorder); + $this->assertEquals(1001, $qcat3->sortorder); + // Check current order. $currentorder = $this->get_current_order($context); $expectedorder = [ @@ -111,7 +115,7 @@ final class move_category_test extends \qbank_managecategories\manage_category_t 'action' => 'put', 'fields' => (object)[ 'id' => $qcat1->id, - 'sortorder' => 3, + 'sortorder' => 1001, ], ], (object)[ @@ -119,7 +123,7 @@ final class move_category_test extends \qbank_managecategories\manage_category_t 'action' => 'put', 'fields' => (object)[ 'id' => $qcat3->id, - 'sortorder' => 4, + 'sortorder' => 1002, ], ], ]; @@ -142,7 +146,7 @@ final class move_category_test extends \qbank_managecategories\manage_category_t $this->create_course_category(); // Question categories. - $qcat1 = $this->create_question_category_for_a_qbank($qbank); + $qcat1 = question_get_default_category($context->id); $qcat2 = $this->create_question_category_for_a_qbank($qbank); $qcat3 = $this->create_question_category_for_a_qbank($qbank); @@ -211,7 +215,7 @@ final class move_category_test extends \qbank_managecategories\manage_category_t $this->create_course_category(); // Question categories. - $qcat1 = $this->create_question_category_for_a_qbank($qbank); + $qcat1 = question_get_default_category($context->id); $qcat2 = $this->create_question_category_for_a_qbank($qbank); $qcat3 = $this->create_question_category_for_a_qbank($qbank); @@ -284,7 +288,7 @@ final class move_category_test extends \qbank_managecategories\manage_category_t $this->create_course_category(); // Question categories. - $qcat1 = $this->create_question_category_for_a_qbank($qbank); + $qcat1 = question_get_default_category($context->id); $qcat2 = $this->create_question_category_for_a_qbank($qbank); $qcat3 = $this->create_question_category_for_a_qbank($qbank, ['parent' => $qcat1->id]); $qcat4 = $this->create_question_category_for_a_qbank($qbank, ['parent' => $qcat2->id]); @@ -347,7 +351,7 @@ final class move_category_test extends \qbank_managecategories\manage_category_t $this->create_course_category(); // Question categories. - $qcat1 = $this->create_question_category_for_a_qbank($qbank); + $qcat1 = question_get_default_category($context->id); $qcat2 = $this->create_question_category_for_a_qbank($qbank); $qcat3 = $this->create_question_category_for_a_qbank($qbank); $qcat4 = $this->create_question_category_for_a_qbank($qbank, ['parent' => $qcat3->id]); @@ -385,7 +389,7 @@ final class move_category_test extends \qbank_managecategories\manage_category_t 'action' => 'put', 'fields' => (object)[ 'id' => $qcat3->id, - 'sortorder' => 2, + 'sortorder' => 1000, ], ], (object)[ @@ -393,7 +397,7 @@ final class move_category_test extends \qbank_managecategories\manage_category_t 'action' => 'put', 'fields' => (object)[ 'id' => $qcat2->id, - 'sortorder' => 3, + 'sortorder' => 1001, ], ], ]; @@ -417,7 +421,7 @@ final class move_category_test extends \qbank_managecategories\manage_category_t $this->create_course_category(); // Question categories. - $qcat1 = $this->create_question_category_for_a_qbank($qbank); + $qcat1 = question_get_default_category($context->id); $qcat2 = $this->create_question_category_for_a_qbank($qbank); $qcat3 = $this->create_question_category_for_a_qbank($qbank); $qcat4 = $this->create_question_category_for_a_qbank($qbank, ['parent' => $qcat3->id]); diff --git a/question/bank/managecategories/tests/helper_test.php b/question/bank/managecategories/tests/helper_test.php index f502d0f1740..0c03a6e3d39 100644 --- a/question/bank/managecategories/tests/helper_test.php +++ b/question/bank/managecategories/tests/helper_test.php @@ -275,7 +275,8 @@ final class helper_test extends manage_category_test_base { // Create categories. $quiz = $this->create_quiz(); - $qcategory1 = $this->create_question_category_for_a_quiz($quiz); + $context = \context_module::instance($quiz->cmid); + $qcategory1 = question_get_default_category($context->id); $this->create_question_category_for_a_quiz($quiz, ['parent' => $qcategory1->id]); $this->create_question_category_for_a_quiz($quiz); @@ -307,7 +308,8 @@ final class helper_test extends manage_category_test_base { // Create categories. $quiz = $this->create_quiz(); - $qcategory1 = $this->create_question_category_for_a_quiz($quiz); + $context = \context_module::instance($quiz->cmid); + $qcategory1 = question_get_default_category($context->id); $qcategory2 = $this->create_question_category_for_a_quiz($quiz, ['parent' => $qcategory1->id]); $qcategory3 = $this->create_question_category_for_a_quiz($quiz); @@ -339,12 +341,13 @@ final class helper_test extends manage_category_test_base { global $DB; // Create quiz. $quiz = $this->quiz; - // Create category 1 and one hidden question. - $qcat = $this->create_question_category_for_a_quiz($quiz); + $context = \context_module::instance($quiz->cmid); + // Get the question category and create one hidden question. + $qcat = question_get_default_category($context->id); $q1 = $this->create_question_in_a_category('shortanswer', $qcat->id); $DB->set_field('question_versions', 'status', 'hidden', ['questionid' => $q1->id]); - $contexts = new \core_question\local\bank\question_edit_contexts(\context_module::instance($quiz->cmid)); + $contexts = new \core_question\local\bank\question_edit_contexts($context); $contexts = $contexts->having_cap('moodle/question:add'); foreach ($contexts as $context) { $contextslist[] = $context->id; diff --git a/question/bank/managecategories/tests/question_categories_test.php b/question/bank/managecategories/tests/question_categories_test.php index 8a2e64b314d..d12971ca47f 100644 --- a/question/bank/managecategories/tests/question_categories_test.php +++ b/question/bank/managecategories/tests/question_categories_test.php @@ -40,11 +40,11 @@ final class question_categories_test extends manage_category_test_base { // Create question categories for a course. $qbank = $this->create_qbank($this->create_course()); - $qcat1 = $this->create_question_category_for_a_qbank($qbank); + $context = \context_module::instance($qbank->cmid); + $qcat1 = question_get_default_category($context->id); $qcat2 = $this->create_question_category_for_a_qbank($qbank, ['parent' => $qcat1->id]); $qcat3 = $this->create_question_category_for_a_qbank($qbank); $qcat4 = $this->create_question_category_for_a_qbank($qbank, ['parent' => $qcat2->id]); - $context = \context_module::instance($qbank->cmid); // Create ordered tree. $questioncategories = new question_categories( diff --git a/question/bank/previewquestion/tests/behat/preview_question.feature b/question/bank/previewquestion/tests/behat/preview_question.feature index d1f2cdd5c57..8b118963044 100644 --- a/question/bank/previewquestion/tests/behat/preview_question.feature +++ b/question/bank/previewquestion/tests/behat/preview_question.feature @@ -17,12 +17,9 @@ Feature: A teacher can preview questions in the question bank And the following "course enrolments" exist: | user | course | role | | teacher1 | C1 | editingteacher | - And the following "question categories" exist: - | contextlevel | reference | name | - | Activity module | quiz1 | Test questions | And the following "questions" exist: - | questioncategory | qtype | name | - | Test questions | numerical | Test question to be previewed | + | questioncategory | qtype | name | + | Default for Test quiz | numerical | Test question to be previewed | And I am on the "Test quiz" "mod_quiz > question bank" page logged in as "teacher1" When I choose "Preview" action for "Test question to be previewed" in the question bank @@ -115,8 +112,8 @@ Feature: A teacher can preview questions in the question bank Scenario: The preview always uses the latest question version by default. Given the following "core_question > updated questions" exist: - | questioncategory | question | questiontext | - | Test questions | Test question to be previewed | Question version 2 | + | questioncategory | question | questiontext | + | Default for Test quiz | Test question to be previewed | Question version 2 | And I should see "Version 1 (latest)" And I expand all fieldsets And the field "Question version" matches value "Always latest" @@ -130,8 +127,8 @@ Feature: A teacher can preview questions in the question bank Scenario: Detect a newer version during always latest preview and offer to switch to the latest Given I should not see "This preview is using version 1" And the following "core_question > updated questions" exist: - | questioncategory | question | questiontext | - | Test questions | Test question to be previewed | Question version 2 | + | questioncategory | question | questiontext | + | Default for Test quiz | Test question to be previewed | Question version 2 | And I should see "Version 1 (latest)" And I set the field "Answer:" to "3.14" When I press "Submit and finish" @@ -143,8 +140,8 @@ Feature: A teacher can preview questions in the question bank Scenario: Previewing from the question history will not always show the latest version Given I press "Close preview" And the following "core_question > updated questions" exist: - | questioncategory | question | questiontext | - | Test questions | Test question to be previewed | Question version 2 | + | questioncategory | question | questiontext | + | Default for Test quiz | Test question to be previewed | Question version 2 | And I choose "History" action for "Test question to be previewed" in the question bank And I choose "Preview" action for "Test question to be previewed" in the question bank And I should see "Version 1 (of 2)" @@ -155,8 +152,8 @@ Feature: A teacher can preview questions in the question bank And I should see "Version 1 (of 2)" And I should not see "The latest version is 2." And the following "core_question > updated questions" exist: - | questioncategory | question | questiontext | - | Test questions | Test question to be previewed | Question version 3 | + | questioncategory | question | questiontext | + | Default for Test quiz | Test question to be previewed | Question version 3 | When I press "Start again" Then I should see "Version 1 (of 3)" And I should not see "Version 3 (latest)" diff --git a/question/bank/previewquestion/tests/behat/preview_question_action.feature b/question/bank/previewquestion/tests/behat/preview_question_action.feature index 02cc81fd6be..d3f23d4448b 100644 --- a/question/bank/previewquestion/tests/behat/preview_question_action.feature +++ b/question/bank/previewquestion/tests/behat/preview_question_action.feature @@ -9,12 +9,9 @@ Feature: Use the qbank plugin manager page for previewquestion And the following "activities" exist: | activity | name | course | idnumber | | quiz | Test quiz | C1 | quiz1 | - And the following "question categories" exist: - | 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 | questiontext | + | Default for Test quiz | truefalse | First question | Answer the first question | Scenario: Enable/disable previewquestion column from the base view Given I log in as "admin" diff --git a/question/bank/statistics/tests/behat/statistics_action.feature b/question/bank/statistics/tests/behat/statistics_action.feature index 59a2e0f4c30..45c20ee3b38 100644 --- a/question/bank/statistics/tests/behat/statistics_action.feature +++ b/question/bank/statistics/tests/behat/statistics_action.feature @@ -9,12 +9,9 @@ Feature: Use the qbank plugin manager page for statistics And the following "activities" exist: | activity | name | course | idnumber | | quiz | Test quiz | C1 | quiz1 | - And the following "question categories" exist: - | 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 | questiontext | + | Default for Test quiz | truefalse | First question | Answer the first question | Scenario: Enable/disable statistics columns from the base view Given I log in as "admin" diff --git a/question/bank/statistics/tests/behat/statistics_values.feature b/question/bank/statistics/tests/behat/statistics_values.feature index bce78b1a2ed..c4f7b899e7f 100644 --- a/question/bank/statistics/tests/behat/statistics_values.feature +++ b/question/bank/statistics/tests/behat/statistics_values.feature @@ -21,15 +21,12 @@ Feature: Show statistics in question bank | quiz | Quiz 1 | Quiz 1 description | C1 | quiz1 | | quiz | Quiz 2 | Quiz 2 description | C1 | quiz2 | | qbank | Qbank 1 | Question bank 1 | C1 | qbank1 | - And the following "question categories" exist: - | contextlevel | reference | name | - | Activity module | qbank1 | Test questions | And the following "questions" exist: - | questioncategory | qtype | name | questiontext | - | Test questions | truefalse | TF1 | First question | - | Test questions | truefalse | TF2 | Second question | - | Test questions | truefalse | TF3 | Third question | - | Test questions | truefalse | TF4 | Fourth question | + | questioncategory | qtype | name | questiontext | + | Default for Qbank 1 | truefalse | TF1 | First question | + | Default for Qbank 1 | truefalse | TF2 | Second question | + | Default for Qbank 1 | truefalse | TF3 | Third question | + | Default for Qbank 1 | truefalse | TF4 | Fourth question | And quiz "Quiz 1" contains the following questions: | question | page | maxmark | | TF1 | 1 | 1.0 | @@ -151,16 +148,13 @@ Feature: Show statistics in question bank And the following "activities" exist: | activity | name | course | idnumber | | quiz | Quiz 3 | C2 | quiz3 | - And the following "question categories" exist: - | contextlevel | reference | name | - | Activity module | quiz3 | Quiz questions | And the following "questions" exist: - | questioncategory | qtype | template | name | - | Quiz questions | multichoice | one_of_four | MCA | - | Quiz questions | multichoice | one_of_four | MCB | - | Quiz questions | multichoice | one_of_four | MCC | - | Quiz questions | multichoice | one_of_four | MCD | - | Quiz questions | multichoice | one_of_four | MCE | + | questioncategory | qtype | template | name | + | Default for Quiz 3 | multichoice | one_of_four | MCA | + | Default for Quiz 3 | multichoice | one_of_four | MCB | + | Default for Quiz 3 | multichoice | one_of_four | MCC | + | Default for Quiz 3 | multichoice | one_of_four | MCD | + | Default for Quiz 3 | multichoice | one_of_four | MCE | And quiz "Quiz 3" contains the following questions: | question | page | maxmark | | MCA | 1 | 1.0 | diff --git a/question/bank/tagquestion/tests/behat/tag_question_action.feature b/question/bank/tagquestion/tests/behat/tag_question_action.feature index 9ab3ea1da08..5bc742229fd 100644 --- a/question/bank/tagquestion/tests/behat/tag_question_action.feature +++ b/question/bank/tagquestion/tests/behat/tag_question_action.feature @@ -9,12 +9,9 @@ Feature: Use the qbank plugin manager page for tagquestion And the following "activities" exist: | activity | name | course | idnumber | | quiz | Test quiz | C1 | quiz1 | - And the following "question categories" exist: - | 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 | questiontext | + | Default for Test quiz | truefalse | First question | Answer the first question | Scenario: Enable/disable tagquestion column from the base view Given I log in as "admin" diff --git a/question/bank/usage/tests/behat/question_last_used_column.feature b/question/bank/usage/tests/behat/question_last_used_column.feature index 45c6706bfec..e01f212f8f2 100644 --- a/question/bank/usage/tests/behat/question_last_used_column.feature +++ b/question/bank/usage/tests/behat/question_last_used_column.feature @@ -23,9 +23,11 @@ Feature: Use the qbank plugin manager page for question last used When I click on "Disable" "link" in the "Question usage" "table_row" And I am on the "Test quiz" "quiz activity" page And I navigate to "Question bank" in current page administration + And I apply question bank filter "Category" with value "Test questions" Then I should not see "Last used" And I navigate to "Plugins > Question bank plugins > Manage question bank plugins" in site administration And I click on "Enable" "link" in the "Question usage" "table_row" And I am on the "Test quiz" "quiz activity" page And I navigate to "Question bank" in current page administration + And I apply question bank filter "Category" with value "Test questions" And I should see "Last used" diff --git a/question/bank/usage/tests/behat/question_usage_column.feature b/question/bank/usage/tests/behat/question_usage_column.feature index 2310e78d239..3fa09f3c656 100644 --- a/question/bank/usage/tests/behat/question_usage_column.feature +++ b/question/bank/usage/tests/behat/question_usage_column.feature @@ -9,12 +9,9 @@ Feature: Use the qbank plugin manager page for question usage And the following "activities" exist: | activity | name | course | idnumber | | quiz | Test quiz | C1 | quiz1 | - And the following "question categories" exist: - | 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 | questiontext | + | Default for Test quiz | truefalse | First question | Answer the first question | And I change window size to "large" Scenario: Enable/disable question usage column from the base view @@ -32,8 +29,7 @@ Feature: Use the qbank plugin manager page for question usage @javascript Scenario: Question usage modal should work without any usage data And 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 should see "Test questions" + And I should see "Default for Test quiz" And I should see "0" on the usage column When I click "0" on the usage column Then I should see "Version 1" @@ -47,8 +43,7 @@ Feature: Use the qbank plugin manager page for question usage | question | page | | First question | 1 | And 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 should see "Test questions" + And I should see "Default for Test quiz" And I should see "1" on the usage column When I click "1" on the usage column Then "Test quiz" "table_row" should exist in the "question-usage_table" "region" diff --git a/question/bank/viewcreator/tests/behat/filter_condition_creator_name.feature b/question/bank/viewcreator/tests/behat/filter_condition_creator_name.feature index 830195c3b48..7307da7060a 100644 --- a/question/bank/viewcreator/tests/behat/filter_condition_creator_name.feature +++ b/question/bank/viewcreator/tests/behat/filter_condition_creator_name.feature @@ -30,6 +30,7 @@ Feature: Filter questions by creator name | truefalse | Test questions | Second question | bb | | truefalse | Test questions | Third question | cc | And I am on the "Qbank 1" "core_question > question bank" page logged in as "admin" + And I apply question bank filter "Category" with value "Test questions" And I should see "First question" And I should see "Second question" And I should see "Third question" diff --git a/question/bank/viewcreator/tests/behat/filter_condition_modifier_name.feature b/question/bank/viewcreator/tests/behat/filter_condition_modifier_name.feature index 08b0d471a07..cddba5a4d1d 100644 --- a/question/bank/viewcreator/tests/behat/filter_condition_modifier_name.feature +++ b/question/bank/viewcreator/tests/behat/filter_condition_modifier_name.feature @@ -35,6 +35,7 @@ Feature: Filter questions by modifier name | Test questions | Second question | Second question | bb | | Test questions | Third question | Third question | cc | And I am on the "Qbank 1" "core_question > question bank" page logged in as "admin" + And I apply question bank filter "Category" with value "Test questions" And I should see "First question" And I should see "Second question" And I should see "Third question" diff --git a/question/bank/viewcreator/tests/behat/filter_condition_timemodified.feature b/question/bank/viewcreator/tests/behat/filter_condition_timemodified.feature index eabbaf26da2..d5e0d811f1d 100644 --- a/question/bank/viewcreator/tests/behat/filter_condition_timemodified.feature +++ b/question/bank/viewcreator/tests/behat/filter_condition_timemodified.feature @@ -25,6 +25,7 @@ Feature: Time modified filter condition | Test questions | Second question | Second question | ## 2024-01-10 11:00 ## | | Test questions | Third question | Third question | ## 2024-01-10 12:00 ## | Given I am on the "Qbank 1" "core_question > question bank" page logged in as "admin" + And I apply question bank filter "Category" with value "Test questions" And I should see "First question" And I should see "Second question" And I should see "Third question" diff --git a/question/bank/viewquestionname/tests/behat/filter_condition_question_idnumber.feature b/question/bank/viewquestionname/tests/behat/filter_condition_question_idnumber.feature index a0620f1a507..7328ae0ba23 100644 --- a/question/bank/viewquestionname/tests/behat/filter_condition_question_idnumber.feature +++ b/question/bank/viewquestionname/tests/behat/filter_condition_question_idnumber.feature @@ -20,6 +20,7 @@ Feature: Filter questions by idnumber | Test questions | numerical | b | Answer the second question | q_02_bc | | Test questions | essay | c | Answer the third question | Q_21_ca | And I am on the "Qbank 1" "core_question > question bank" page logged in as "admin" + And I apply question bank filter "Category" with value "Test questions" And I should see "q_01_ab" And I should see "q_02_bc" And I should see "Q_21_ca" diff --git a/question/bank/viewquestionname/tests/behat/filter_condition_question_name.feature b/question/bank/viewquestionname/tests/behat/filter_condition_question_name.feature index fa91b1270d4..36f353b1111 100644 --- a/question/bank/viewquestionname/tests/behat/filter_condition_question_name.feature +++ b/question/bank/viewquestionname/tests/behat/filter_condition_question_name.feature @@ -11,14 +11,11 @@ Feature: Filter questions by name And the following "activities" exist: | activity | name | intro | course | idnumber | | qbank | Qbank 1 | Question bank 1 | C1 | qbank1 | - And the following "question categories" exist: - | contextlevel | reference | name | - | Activity module | qbank1 | Test questions | And the following "questions" exist: | questioncategory | qtype | name | questiontext | - | Test questions | truefalse | First question | Answer the first question | - | Test questions | numerical | Second question | Answer the second question | - | Test questions | essay | Third Question | Answer the third question | + | Default for Qbank 1 | truefalse | First question | Answer the first question | + | Default for Qbank 1 | numerical | Second question | Answer the second question | + | Default for Qbank 1 | essay | Third Question | Answer the third question | And I am on the "Qbank 1" "core_question > question bank" page logged in as "admin" And I should see "First question" And I should see "Second question" diff --git a/question/bank/viewquestionname/tests/behat/view_question_name_column.feature b/question/bank/viewquestionname/tests/behat/view_question_name_column.feature index 0a6e7cc6f2f..74b0e20861e 100644 --- a/question/bank/viewquestionname/tests/behat/view_question_name_column.feature +++ b/question/bank/viewquestionname/tests/behat/view_question_name_column.feature @@ -9,12 +9,9 @@ Feature: Use the qbank plugin manager page for viewquestionname And the following "activities" exist: | activity | name | course | idnumber | | quiz | Test quiz | C1 | quiz1 | - And the following "question categories" exist: - | 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 | questiontext | + | Default for Test quiz | truefalse | First question | Answer the first question | Scenario: Enable/disable viewquestionname column from the base view Given I log in as "admin" diff --git a/question/bank/viewquestiontext/tests/behat/filter_condition_question_text.feature b/question/bank/viewquestiontext/tests/behat/filter_condition_question_text.feature index 7349dd9afa4..71994d13223 100644 --- a/question/bank/viewquestiontext/tests/behat/filter_condition_question_text.feature +++ b/question/bank/viewquestiontext/tests/behat/filter_condition_question_text.feature @@ -22,6 +22,7 @@ Feature: Filter questions by text found in the question text or general feedback | Test questions | truefalse | Question 4 | GHI | CDEZ | | Test questions | truefalse | Question 5 | IJK | GHI | And I am on the "Qbank 1" "core_question > question bank" page logged in as "admin" + And I apply question bank filter "Category" with value "Test questions" And I should see "Question 1" And I should see "Question 2" And I should see "Question 3" diff --git a/question/bank/viewquestiontext/tests/behat/view_question_text_column.feature b/question/bank/viewquestiontext/tests/behat/view_question_text_column.feature index 50ed7969cf4..dede99ce558 100644 --- a/question/bank/viewquestiontext/tests/behat/view_question_text_column.feature +++ b/question/bank/viewquestiontext/tests/behat/view_question_text_column.feature @@ -19,6 +19,7 @@ Feature: Use the qbank plugin manager page for viewquestiontext @javascript Scenario: Display of plain question text can be turned on and off When 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 set the field "Show question text in the question list?" to "text only" Then I should see "Answer the first " And ".totestforhtml" "css_element" should not exist in the "Answer the first " "table_row" @@ -28,6 +29,7 @@ Feature: Use the qbank plugin manager page for viewquestiontext @javascript Scenario: Display of full question text can be turned on and off When 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 set the field "Show question text in the question list?" to "with images" Then I should see "Answer the first " And ".totestforhtml" "css_element" should exist in the "Answer the first " "table_row" @@ -53,5 +55,6 @@ Feature: Use the qbank plugin manager page for viewquestiontext And I navigate to "Plugins > Question bank plugins > Manage question bank plugins" in site administration And I click on "Enable" "link" in the "View question text" "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" When I set the field "Show question text in the question list?" to "text only" And I should see "Answer the first " diff --git a/question/bank/viewquestiontype/tests/behat/filter_condition_question_type.feature b/question/bank/viewquestiontype/tests/behat/filter_condition_question_type.feature index bb86deb6d7c..7f0a2dd567a 100644 --- a/question/bank/viewquestiontype/tests/behat/filter_condition_question_type.feature +++ b/question/bank/viewquestiontype/tests/behat/filter_condition_question_type.feature @@ -11,31 +11,26 @@ Feature: Filter questions by type And the following "activities" exist: | activity | name | intro | course | idnumber | | qbank | Qbank 1 | Question bank 1 | C1 | qbank1 | - And the following "question categories" exist: - | contextlevel | reference | name | - | Activity module | qbank1 | Test questions | And the following "questions" exist: - | questioncategory | qtype | name | questiontext | - | Test questions | truefalse | First question | Answer the first question | - | Test questions | numerical | Second question | Answer the second question | - | Test questions | essay | Third question | Answer the third question | + | questioncategory | qtype | name | questiontext | + | Default for Qbank 1 | truefalse | First question | Answer the first question | + | Default for Qbank 1 | numerical | Second question | Answer the second question | + | Default for Qbank 1 | essay | Third question | Answer the third question | + And I am on the "Qbank 1" "core_question > question bank" page logged in as "admin" Scenario: Filter by a single type - Given I am on the "Qbank 1" "core_question > question bank" page logged in as "admin" When I apply question bank filter "Type" with value "True/False" Then I should see "First question" And I should not see "Second question" And I should not see "Third question" Scenario: Filter by multiple types - Given I am on the "Qbank 1" "core_question > question bank" page logged in as "admin" When I apply question bank filter "Type" with value "True/False, Essay" Then I should see "First question" And I should not see "Second question" And I should see "Third question" Scenario: Exclude types by filter - Given I am on the "Qbank 1" "core_question > question bank" page logged in as "admin" When I add question bank filter "Type" And I set the field "Type" to "True/False, Essay" And I set the field "Match" in the "Filter 3" "fieldset" to "None" diff --git a/question/bank/viewquestiontype/tests/behat/view_question_type_column.feature b/question/bank/viewquestiontype/tests/behat/view_question_type_column.feature index 9279c3d51da..597f162346c 100644 --- a/question/bank/viewquestiontype/tests/behat/view_question_type_column.feature +++ b/question/bank/viewquestiontype/tests/behat/view_question_type_column.feature @@ -23,8 +23,10 @@ Feature: Use the qbank plugin manager page for viewquestiontype And I should see "View question type" And I click on "Disable" "link" in the "View question type" "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 "#categoryquestions .header.qtype" "css_element" should not be visible And I navigate to "Plugins > Question bank plugins > Manage question bank plugins" in site administration And I click on "Enable" "link" in the "View question type" "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 "#categoryquestions .header.qtype" "css_element" should be visible diff --git a/question/classes/local/bank/question_bank_helper.php b/question/classes/local/bank/question_bank_helper.php index 3ef214ce0bf..daeaa857a38 100644 --- a/question/classes/local/bank/question_bank_helper.php +++ b/question/classes/local/bank/question_bank_helper.php @@ -612,6 +612,9 @@ class question_bank_helper { $data->name = $bankname; $data->type = in_array($type, self::SHARED_TYPES) ? $type : self::TYPE_STANDARD; $data->showdescription = $type === self::TYPE_STANDARD ? 0 : 1; + // Don't create the default category if this is being created by the system as part of a migration or restore, + // existing categories will be migrated to the new context. + $data->skipdefaultcategory = $type === self::TYPE_SYSTEM; $mod = add_moduleinfo($data, $course); diff --git a/question/format/aiken/tests/behat/aiken_export.feature b/question/format/aiken/tests/behat/aiken_export.feature index de78f70f9c6..f5b13e8e057 100644 --- a/question/format/aiken/tests/behat/aiken_export.feature +++ b/question/format/aiken/tests/behat/aiken_export.feature @@ -21,9 +21,9 @@ Feature: Test exporting questions using Aiken format. | contextlevel | reference | name | | Activity module | qbank1 | Test questions | And the following "questions" exist: - | questioncategory | qtype | name | template | - | Test questions | multichoice | Multi-choice-001 | two_of_four | - | Test questions | multichoice | Multi-choice-002 | one_of_four | + | questioncategory | qtype | name | template | + | Default for Qbank 1 | multichoice | Multi-choice-001 | two_of_four | + | Default for Qbank 1 | multichoice | Multi-choice-002 | one_of_four | Scenario: Aiken export When I am on the "Qbank 1" "core_question > question export" page logged in as "teacher1" diff --git a/question/tests/backup_test.php b/question/tests/backup_test.php index 49e4c48fa69..782bcc448eb 100644 --- a/question/tests/backup_test.php +++ b/question/tests/backup_test.php @@ -141,7 +141,7 @@ final class backup_test extends \advanced_testcase { $qgen = $this->getDataGenerator()->get_plugin_generator('core_question'); $qbank = $this->getDataGenerator()->create_module('qbank', ['course' => $course->id]); $context = \context_module::instance($qbank->cmid); - $qcat = $qgen->create_question_category(['contextid' => $context->id]); + $qcat = question_get_default_category($context->id); $question1 = $qgen->create_question('shortanswer', null, ['category' => $qcat->id, 'idnumber' => 'q1']); $question2 = $qgen->create_question('shortanswer', null, ['category' => $qcat->id, 'idnumber' => 'q2']); @@ -174,7 +174,7 @@ final class backup_test extends \advanced_testcase { $this->assertCount(1, $qbanks); $qbank = reset($qbanks); $qbankcontext = \context_module::instance($qbank->id); - $cats = $DB->get_records_select('question_categories' , 'parent <> 0', ['contextid' => $qbankcontext->id]); + $cats = $DB->get_records_select('question_categories', 'parent <> 0 AND contextid = ?', [$qbankcontext->id]); $this->assertCount(1, $cats); $cat = reset($cats); @@ -515,7 +515,7 @@ final class backup_test extends \advanced_testcase { ['type' => question_bank_helper::TYPE_STANDARD, 'course' => $course->id] ); $qbankcontext = \context_module::instance($qbank->cmid); - $bankqcat = $qgen->create_question_category(['contextid' => $qbankcontext->id]); + $bankqcat = question_get_default_category($qbankcontext->id); $bankquestion = $qgen->create_question('shortanswer', null, ['name' => 'bank question', 'category' => $bankqcat->id, 'idnumber' => 'bankq1'] @@ -524,7 +524,7 @@ final class backup_test extends \advanced_testcase { // Create a quiz module instance, a category for that module, and a question for that category. $quiz = self::getDataGenerator()->create_module('quiz', ['course' => $course->id]); $quizcontext = \context_module::instance($quiz->cmid); - $quizqcat = $qgen->create_question_category(['contextid' => $quizcontext->id]); + $quizqcat = question_get_default_category($quizcontext->id); $quizquestion = $qgen->create_question('shortanswer', null, ['name' => 'quiz question', 'category' => $quizqcat->id, 'idnumber' => 'quizq1'] diff --git a/question/tests/behat/bank_view.feature b/question/tests/behat/bank_view.feature index c28ab843156..7a0756db8be 100644 --- a/question/tests/behat/bank_view.feature +++ b/question/tests/behat/bank_view.feature @@ -27,9 +27,8 @@ Feature: A bank view with questions can be managed | questioncategory | qtype | name | questiontext | idnumber | | Test questions | essay | Essay test question | Write about whatever you want | qid | | Test questions | numerical | Numerical test question | Write about whatever you want | qid | - And I am on the "C1" "Course" page logged in as "teacher1" - And I navigate to "Question banks" in current page administration - And I click on "Qbank 1" "link" + And I am on the "Qbank 1" "core_question > question bank" page logged in as "teacher1" + And I apply question bank filter "Category" with value "Test questions" And I should see "Essay test question" And I should see "Numerical test question" And I choose "Delete" action for "Essay test question" in the question bank @@ -45,9 +44,8 @@ Feature: A bank view with questions can be managed | Test questions | missingtype | Unknown type question | Write about whatever you want | | Test questions | truefalse | Truefalse type question | Write about whatever you want | | Test questions | essay | Essay type question | Write about whatever you want | - And I am on the "C1" "Course" page logged in as "teacher1" - And I navigate to "Question banks" in current page administration - And I click on "Qbank 1" "link" + And I am on the "Qbank 1" "core_question > question bank" page logged in as "teacher1" + And I apply question bank filter "Category" with value "Test questions" And I should see "Unknown type question" And I should see "Truefalse type question" And I should see "Essay type question" diff --git a/question/tests/behat/delete_questions.feature b/question/tests/behat/delete_questions.feature index 26a7f921c7b..e20eaad2f24 100644 --- a/question/tests/behat/delete_questions.feature +++ b/question/tests/behat/delete_questions.feature @@ -24,6 +24,7 @@ Feature: A teacher can delete questions in the question bank | questioncategory | qtype | name | questiontext | | Test questions | essay | Test question to be deleted | Write about whatever you want | And I am on the "Qbank 1" "core_question > question bank" page logged in as "teacher1" + And I apply question bank filter "Category" with value "Test questions" @javascript Scenario: A question not used anywhere can really be deleted @@ -32,6 +33,7 @@ Feature: A teacher can delete questions in the question bank And I apply question bank filter "Show hidden questions" with value "Yes" Then I should not see "Test question to be deleted" + @javascript Scenario: Deleting a question can be cancelled When I choose "Delete" action for "Test question to be deleted" in the question bank And I press "Cancel" @@ -53,6 +55,7 @@ Feature: A teacher can delete questions in the question bank | question | page | requireprevious | | Test used question to be deleted | 1 | 0 | When I am on the "Qbank 1" "core_question > question bank" page + And I apply question bank filter "Category" with value "Test questions" And I choose "Delete" action for "Test used question to be deleted" in the question bank And I should see "This will delete the following question and all its versions:" And I should see "* Denotes questions which can't be deleted because they are in use. Instead, they will be hidden in the question bank unless you set 'Show hidden questions' to 'Yes'." @@ -77,7 +80,6 @@ Feature: A teacher can delete questions in the question bank @javascript Scenario: Delete question has multiple versions in question bank page - Given I am on the "Qbank 1" "core_question > question bank" page logged in as "teacher1" When the following "core_question > updated questions" exist: | questioncategory | question | questiontext | | Test questions | Test question to be deleted | Test question to be deleted version 2 | diff --git a/question/tests/behat/duplicate_questions.feature b/question/tests/behat/duplicate_questions.feature index eacef35d1bd..6040666a3ee 100644 --- a/question/tests/behat/duplicate_questions.feature +++ b/question/tests/behat/duplicate_questions.feature @@ -1,4 +1,4 @@ -@core @core_question +@core @core_question @javascript Feature: A teacher can duplicate questions in the question bank In order to efficiently expand my question bank As a teacher @@ -24,6 +24,7 @@ Feature: A teacher can duplicate questions in the question bank | questioncategory | qtype | name | questiontext | idnumber | | Test questions | essay | Test question to be copied | Write about whatever you want | qid | And I am on the "Qbank 1" "core_question > question bank" page logged in as "teacher" + And I apply question bank filter "Category" with value "Test questions" Scenario: Duplicating a previously created question When I choose "Duplicate" action for "Test question to be copied" in the question bank @@ -40,7 +41,6 @@ Feature: A teacher can duplicate questions in the question bank When I choose "Duplicate" action for "Test question to be copied" in the question bank Then the field "Question name" matches value "Test question to be copied (copy)" - @javascript Scenario: The duplicate operation can be cancelled When I choose "Duplicate" action for "Test question to be copied" in the question bank And I press "Cancel" diff --git a/question/tests/behat/edit_question_tags.feature b/question/tests/behat/edit_question_tags.feature index 9d09432a8ea..1dcbc05a5aa 100644 --- a/question/tests/behat/edit_question_tags.feature +++ b/question/tests/behat/edit_question_tags.feature @@ -24,6 +24,7 @@ Feature: A teacher can manage tags on questions in the question bank | questioncategory | qtype | name | questiontext | | Test questions | essay | Test question to be tagged | Write about whatever you want | And I am on the "Qbank 1" "core_question > question bank" page logged in as "teacher1" + And I apply question bank filter "Category" with value "Test questions" @javascript Scenario: Manage tags on a question diff --git a/question/tests/behat/edit_question_versioning.feature b/question/tests/behat/edit_question_versioning.feature index 0f6d94be62f..c3bf3d4dcb4 100644 --- a/question/tests/behat/edit_question_versioning.feature +++ b/question/tests/behat/edit_question_versioning.feature @@ -26,16 +26,16 @@ Feature: Questions in the question bank have versions And quiz "Quiz 1" contains the following questions: | question | page | | First question | 1 | + And I am on the "Quiz 1" "mod_quiz > question bank" page logged in as "teacher1" + And I apply question bank filter "Category" with value "Test questions" @javascript Scenario: Question version is displayed - Given I am on the "Quiz 1" "mod_quiz > question bank" page logged in as "teacher1" When I choose "Edit question" action for "First question" in the question bank Then I should see "v1 (latest)" @javascript Scenario: Question version change when question is altered - Given I am on the "Quiz 1" "mod_quiz > question bank" page logged in as "teacher1" When I choose "Edit question" action for "First question" in the question bank And I should see "v1 (latest)" When I set the field "id_name" to "Renamed question v2" diff --git a/question/tests/behat/edit_questions.feature b/question/tests/behat/edit_questions.feature index 2df7036a627..b56df3fb11c 100644 --- a/question/tests/behat/edit_questions.feature +++ b/question/tests/behat/edit_questions.feature @@ -24,6 +24,7 @@ Feature: A teacher can edit questions in the question bank | questioncategory | qtype | name | questiontext | | Test questions | essay | Test question to be edited | Write about whatever you want | And I am on the "Qbank 1" "core_question > question bank" page logged in as "teacher1" + And I apply question bank filter "Category" with value "Test questions" @javascript Scenario: Edit a previously created question @@ -68,6 +69,7 @@ Feature: A teacher can edit questions in the question bank When I am on the "Test question to be edited" "core_question > edit" page logged in as "teacher1" And I set the field "Question name" to "Edited question name" And I press "Cancel" + And I apply question bank filter "Category" with value "Test questions" Then I should see "Test question to be edited" And I should see "Admin User" @@ -76,6 +78,7 @@ Feature: A teacher can edit questions in the question bank | questioncategory | qtype | name | idnumber | | Test questions | essay | Question with idnumber | frog | When I am on the "Qbank 1" "core_question > question bank" page logged in as "teacher1" + And I apply question bank filter "Category" with value "Test questions" Then I should see "frog" in the "Question with idnumber" "table_row" When I choose "Edit question" action for "Question with idnumber" in the question bank And I set the field "ID number" to "" @@ -87,6 +90,7 @@ Feature: A teacher can edit questions in the question bank | questioncategory | qtype | name | questiontext | | Test questions | missingtype | Broken question | Write something | When I am on the "Qbank 1" "core_question > question bank" page logged in as "teacher1" + And I apply question bank filter "Category" with value "Test questions" Then the "Edit question" item should not exist in the "Edit" action menu of the "Broken question" "table_row" And the "Duplicate" item should not exist in the "Edit" action menu of the "Broken question" "table_row" And the "Preview" item should not exist in the "Edit" action menu of the "Broken question" "table_row" diff --git a/question/tests/behat/question_filter_pagination.feature b/question/tests/behat/question_filter_pagination.feature index 7bf60218558..c700a9b279a 100644 --- a/question/tests/behat/question_filter_pagination.feature +++ b/question/tests/behat/question_filter_pagination.feature @@ -1,5 +1,5 @@ @core @core_question @qbank_filter @javascript -Feature: A teacher can pagimate through question bank questions +Feature: A teacher can paginate through question bank questions In order to paginate questions As a teacher I must be able to paginate @@ -19,7 +19,7 @@ Feature: A teacher can pagimate through question bank questions | qbank | Qbank 1 | Question bank 1 | C1 | qbank1 | And the following "question categories" exist: | contextlevel | reference | questioncategory | name | - | Activity module | qbank1 | Top | Used category | + | Activity module | qbank1 | top | Used category | Given 100 "questions" exist with the following data: | questioncategory | Used category | | qtype | essay | @@ -32,6 +32,8 @@ Feature: A teacher can pagimate through question bank questions Scenario: Questions can be paginated Given I am on the "Qbank 1" "core_question > question bank" page logged in as "teacher1" When I apply question bank filter "Category" with value "Top for Qbank 1" + And I set the field "Also show questions from subcategories" to "1" + And I press "Apply filters" And I follow "Sort by Question name ascending" And I follow "Sort by Question name descending" And I should see "Tests question 1" diff --git a/question/tests/behat/select_questions.feature b/question/tests/behat/select_questions.feature index 5cded600472..a1690a85422 100644 --- a/question/tests/behat/select_questions.feature +++ b/question/tests/behat/select_questions.feature @@ -26,6 +26,7 @@ Feature: The questions in the question bank can be selected in various ways | Test questions | essay | B question 2 name | teacher1 | Question 2 text | | Test questions | numerical | C question 3 name | teacher1 | Question 3 text | And I am on the "Qbank 1" "core_question > question bank" page logged in as "teacher1" + And I apply question bank filter "Category" with value "Test questions" @javascript Scenario: The question text can be chosen all in the list of questions diff --git a/question/tests/behat/sort_questions.feature b/question/tests/behat/sort_questions.feature index 03581e2f1ce..d1773c1f36b 100644 --- a/question/tests/behat/sort_questions.feature +++ b/question/tests/behat/sort_questions.feature @@ -17,14 +17,11 @@ Feature: The questions in the question bank can be sorted in various ways And the following "activities" exist: | activity | name | intro | course | idnumber | | qbank | Qbank 1 | Question bank 1 | C1 | qbank1 | - And the following "question categories" exist: - | contextlevel | reference | name | - | Activity module | qbank1 | Test questions | And the following "questions" exist: - | questioncategory | qtype | name | user | questiontext | idnumber | - | Test questions | essay | A question 1 name | admin | Question 1 text | numidnum question bank" page logged in as "teacher1" Scenario: The questions are sorted by type by default diff --git a/question/tests/category_manager_test.php b/question/tests/category_manager_test.php index 644ebb94c6a..4d33ddcb183 100644 --- a/question/tests/category_manager_test.php +++ b/question/tests/category_manager_test.php @@ -538,7 +538,7 @@ final class category_manager_test extends \advanced_testcase { $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id]); $context = \context_module::instance($quiz->cmid); $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); - $qcategory1 = $questiongenerator->create_question_category(['contextid' => $context->id]); + $qcategory1 = question_get_default_category($context->id); // Try to delete an only child of top category having also at least one child. $this->expectException('moodle_exception'); @@ -591,15 +591,15 @@ final class category_manager_test extends \advanced_testcase { $context = \context_module::instance($quiz->cmid); $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); $topcategory = question_get_top_category($context->id, true); - $qcategory1 = $questiongenerator->create_question_category(['contextid' => $context->id]); - $this->assertEquals(1, $manager->get_max_sortorder($topcategory->id)); + $qcategory1 = question_get_default_category($context->id); + $this->assertEquals(999, $manager->get_max_sortorder($topcategory->id)); $qcategory2 = $questiongenerator->create_question_category(['contextid' => $context->id, 'parent' => $qcategory1->id]); $this->assertEquals(1, $manager->get_max_sortorder($qcategory1->id)); $questiongenerator->create_question_category(['contextid' => $context->id]); - $this->assertEquals(2, $manager->get_max_sortorder($topcategory->id)); + $this->assertEquals(1000, $manager->get_max_sortorder($topcategory->id)); $this->assertEquals(0, $manager->get_max_sortorder($qcategory2->id)); $questiongenerator->create_question_category(['contextid' => $context->id, 'parent' => $qcategory2->id]); diff --git a/question/tests/generator_test.php b/question/tests/generator_test.php index 3d2df271e40..3baeaa43954 100644 --- a/question/tests/generator_test.php +++ b/question/tests/generator_test.php @@ -41,8 +41,8 @@ final class generator_test extends \advanced_testcase { $count = $DB->count_records('question_categories'); $cat = $generator->create_question_category(); - $count += $count ? 1 : 2; // Calling $generator->create_question_category() for the first time - // creates a Top category as well. + $count += $count ? 1 : 3; // Calling $generator->create_question_category() for the first time + // creates a Top and Default category as well. $this->assertEquals($count, $DB->count_records('question_categories')); $cat = $generator->create_question_category(['name' => 'My category', 'sortorder' => 1]); diff --git a/question/tests/local/bank/question_bank_helper_test.php b/question/tests/local/bank/question_bank_helper_test.php index 78f7b69d560..d742ee8152d 100644 --- a/question/tests/local/bank/question_bank_helper_test.php +++ b/question/tests/local/bank/question_bank_helper_test.php @@ -83,7 +83,7 @@ final class question_bank_helper_test extends \advanced_testcase { $sharedmod1 = $sharedmodgen->create_instance(['course' => $course1]); $sharedmod1context = \context_module::instance($sharedmod1->cmid); - $sharedmod1qcat1 = $qgen->create_question_category(['contextid' => $sharedmod1context->id]); + $sharedmod1qcat1 = question_get_default_category($sharedmod1context->id); $sharedmod1qcat2 = $qgen->create_question_category(['contextid' => $sharedmod1context->id]); $sharedmod1qcat2child = $qgen->create_question_category([ 'contextid' => $sharedmod1context->id, @@ -92,13 +92,13 @@ final class question_bank_helper_test extends \advanced_testcase { ]); $privatemod1 = $privatemodgen->create_instance(['course' => $course1]); $privatemod1context = \context_module::instance($privatemod1->cmid); - $privatemod1qcat1 = $qgen->create_question_category(['contextid' => $privatemod1context->id]); + $privatemod1qcat1 = question_get_default_category($privatemod1context->id); role_assign($roles['editingteacher']->id, $user->id, \context_module::instance($sharedmod1->cmid)); role_assign($roles['editingteacher']->id, $user->id, \context_module::instance($privatemod1->cmid)); $sharedmod2 = $sharedmodgen->create_instance(['course' => $course2]); $sharedmod2context = \context_module::instance($sharedmod2->cmid); - $sharedmod2qcat1 = $qgen->create_question_category(['contextid' => $sharedmod2context->id]); + $sharedmod2qcat1 = question_get_default_category($sharedmod2context->id); $sharedmod2qcat2 = $qgen->create_question_category(['contextid' => $sharedmod2context->id]); $sharedmod2qcat2child = $qgen->create_question_category([ 'contextid' => $sharedmod2context->id, @@ -106,7 +106,7 @@ final class question_bank_helper_test extends \advanced_testcase { ]); $privatemod2 = $privatemodgen->create_instance(['course' => $course2]); $privatemod2context = \context_module::instance($privatemod2->cmid); - $privatemod1qcat1 = $qgen->create_question_category(['contextid' => $privatemod2context->id]); + $privatemod1qcat1 = question_get_default_category($privatemod2context->id); role_assign($roles['editingteacher']->id, $user->id, \context_module::instance($sharedmod2->cmid)); role_assign($roles['editingteacher']->id, $user->id, \context_module::instance($privatemod2->cmid)); diff --git a/question/type/missingtype/tests/behat/invalid_question_types.feature b/question/type/missingtype/tests/behat/invalid_question_types.feature index c5bf52f3413..fe7267d09fe 100644 --- a/question/type/missingtype/tests/behat/invalid_question_types.feature +++ b/question/type/missingtype/tests/behat/invalid_question_types.feature @@ -17,13 +17,10 @@ Feature: Questions with invalid types should be clear and any actions which won' And the following "activities" exist: | activity | name | intro | course | idnumber | | qbank | Qbank 1 | Question bank 1 | C1 | qbank1 | - And the following "question categories" exist: - | contextlevel | reference | name | - | Activity module | qbank1 | Test questions | And the following "questions" exist: - | questioncategory | qtype | name | user | questiontext | - | Test questions | essay | Question 1 | teacher1 | A text | - | Test questions | essay | Question 2 | teacher1 | B text | + | questioncategory | qtype | name | user | questiontext | + | Default for Qbank 1 | essay | Question 1 | teacher1 | A text | + | Default for Qbank 1 | essay | Question 2 | teacher1 | B text | And question "Question 2" is changed to simulate being of an uninstalled type Scenario: Questions of invalid types should be highlighted and labelled as invalid diff --git a/report/questioninstances/tests/behat/question_reports.feature b/report/questioninstances/tests/behat/question_reports.feature index e12b9eb6b47..da290ea3bbc 100644 --- a/report/questioninstances/tests/behat/question_reports.feature +++ b/report/questioninstances/tests/behat/question_reports.feature @@ -14,13 +14,10 @@ Feature: A Teacher can generate question instance reports And the following "activities" exist: | activity | course | name | | quiz | C1 | Test quiz Q001 | - And the following "question categories" exist: - | contextlevel | reference | name | - | Activity module | Test quiz Q001 | Test questions | And the following "questions" exist: - | questioncategory | qtype | name | - | Test questions | truefalse | TF | - | Test questions | shortanswer | SA | + | questioncategory | qtype | name | + | Default for Test quiz Q001 | truefalse | TF | + | Default for Test quiz Q001 | shortanswer | SA | And quiz "Test quiz Q001" contains the following questions: | question | page | maxmark | | TF | 1 | 5.0 |