-
-
- {{> core/overlay_loading}}
+
diff --git a/mod/quiz/templates/update_filter_condition_form.mustache b/mod/quiz/templates/update_filter_condition_form.mustache
new file mode 100644
index 00000000000..efe499605bb
--- /dev/null
+++ b/mod/quiz/templates/update_filter_condition_form.mustache
@@ -0,0 +1,43 @@
+{{!
+ This file is part of Moodle - http://moodle.org/
+
+ Moodle is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Moodle is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Moodle. If not, see
.
+}}
+{{!
+ @template mod_quiz/update_filter_condition_form
+
+ From to add random questions.
+
+ Example context (json):
+ {
+ "questionbank": "
Question bank HTML goes here
",
+ "returnurl": "https://example.com",
+ "cmid": "1234",
+ "slotid": "5678"
+ }
+}}
+
+
+
+ {{{questionbank}}}
+
+
+
+
+
+
diff --git a/mod/quiz/tests/attempt_walkthrough_from_csv_test.php b/mod/quiz/tests/attempt_walkthrough_from_csv_test.php
index 86a801d442c..4cb2e15304b 100644
--- a/mod/quiz/tests/attempt_walkthrough_from_csv_test.php
+++ b/mod/quiz/tests/attempt_walkthrough_from_csv_test.php
@@ -23,6 +23,7 @@ defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
+require_once($CFG->dirroot . '/mod/quiz/tests/quiz_question_helper_test_trait.php');
/**
* Quiz attempt walk through using data from csv file.
@@ -35,6 +36,8 @@ require_once($CFG->dirroot . '/mod/quiz/locallib.php');
*/
class attempt_walkthrough_from_csv_test extends \advanced_testcase {
+ use \quiz_question_helper_test_trait;
+
/**
* @var string[] names of the files which contain the test data.
*/
@@ -134,7 +137,7 @@ class attempt_walkthrough_from_csv_test extends \advanced_testcase {
if ($slotquestion['type'] !== 'random') {
quiz_add_quiz_question($slotquestion['id'], $this->quiz, 0, $slotquestion['mark']);
} else {
- quiz_add_random_questions($this->quiz, 0, $slotquestion['catid'], 1, 0);
+ $this->add_random_questions($this->quiz->id, 0, $slotquestion['catid'], 1);
$this->randqids[$slotno] = $qidsbycat[$slotquestion['catid']];
}
}
diff --git a/mod/quiz/tests/attempt_walkthrough_test.php b/mod/quiz/tests/attempt_walkthrough_test.php
index c2a294f33ff..21a2c557260 100644
--- a/mod/quiz/tests/attempt_walkthrough_test.php
+++ b/mod/quiz/tests/attempt_walkthrough_test.php
@@ -24,6 +24,7 @@ defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
+require_once($CFG->dirroot . '/mod/quiz/tests/quiz_question_helper_test_trait.php');
/**
* Quiz attempt walk through.
@@ -37,6 +38,8 @@ require_once($CFG->dirroot . '/mod/quiz/locallib.php');
*/
class attempt_walkthrough_test extends \advanced_testcase {
+ use \quiz_question_helper_test_trait;
+
/**
* Create a quiz with questions and walk through a quiz attempt.
*/
@@ -288,7 +291,7 @@ class attempt_walkthrough_test extends \advanced_testcase {
$numq = $questiongenerator->create_question('numerical', null, ['category' => $cat->id]);
// Add random question to the quiz.
- quiz_add_random_questions($quiz, 0, $cat->id, 1, false);
+ $this->add_random_questions($quiz->id, 0, $cat->id, 1);
// Make another category.
$cat2 = $questiongenerator->create_question_category();
diff --git a/mod/quiz/tests/behat/behat_mod_quiz.php b/mod/quiz/tests/behat/behat_mod_quiz.php
index e249c07e26c..ed65cd9aa4e 100644
--- a/mod/quiz/tests/behat/behat_mod_quiz.php
+++ b/mod/quiz/tests/behat/behat_mod_quiz.php
@@ -276,7 +276,18 @@ class behat_mod_quiz extends behat_question_base {
} else {
$includingsubcategories = clean_param($questiondata['includingsubcategories'], PARAM_BOOL);
}
- quiz_add_random_questions($quiz, $page, $question->category, 1, $includingsubcategories);
+
+ $filter = [
+ 'category' => [
+ 'jointype' => \qbank_managecategories\category_condition::JOINTYPE_DEFAULT,
+ 'values' => [$question->category],
+ 'filteroptions' => ['includesubcategories' => $includingsubcategories],
+ ],
+ ];
+ $filtercondition['filter'] = $filter;
+ $settings = quiz_settings::create($quiz->id);
+ $structure = \mod_quiz\structure::create_for_quiz($settings);
+ $structure->add_random_questions($page, 1, $filtercondition);
} else {
// Add the question.
quiz_add_quiz_question($question->id, $quiz, $page, $maxmark);
diff --git a/mod/quiz/tests/behat/editing_add.feature b/mod/quiz/tests/behat/editing_add.feature
index 7fca18fe8bf..639ba3bebb8 100644
--- a/mod/quiz/tests/behat/editing_add.feature
+++ b/mod/quiz/tests/behat/editing_add.feature
@@ -117,7 +117,6 @@ Feature: Edit quiz page - adding things
And I select "Questions" from the "Question bank tertiary navigation" singleselect
And I should see "Question bank"
- And I should see "Select a category"
# Create the Essay 01 question.
When I press "Create a new question ..."
@@ -131,8 +130,6 @@ Feature: Edit quiz page - adding things
And I should see "Essay 01"
# Create the Essay 02 question.
- And I should see "Select a category"
- And I set the field "Select a category:" to "Subcat 1"
When I press "Create a new question ..."
And I set the field "item_qtype_essay" to "1"
And I click on "Add" "button" in the "Choose a question type to add" "dialogue"
@@ -144,7 +141,6 @@ Feature: Edit quiz page - adding things
And I should see "Essay 02"
# Create the Essay 03 question.
- And I set the field "Select a category" to "Default for C1"
And I wait until the page is ready
When I press "Create a new question ..."
And I set the field "item_qtype_essay" to "1"
@@ -201,8 +197,6 @@ Feature: Edit quiz page - adding things
# Add Esay 02 from question bank.
And I open the "Page 1" add to quiz menu
And I follow "from question bank"
- And I should see "Select a category"
- And I set the field "Select a category" to "Subcat 1"
And I click on "Add to quiz" "link" in the "Essay 02" "table_row"
And I should see "Essay 03" on quiz page "1"
And I should see "Essay 01" on quiz page "1"
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 7630ad2e845..a4140863be7 100644
--- a/mod/quiz/tests/behat/editing_add_from_question_bank.feature
+++ b/mod/quiz/tests/behat/editing_add_from_question_bank.feature
@@ -40,8 +40,7 @@ Feature: Adding questions to a quiz from the question bank
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"
- And I set the field "Filter by tags..." to "foo"
- And I press the enter key
+ When I apply question bank filter "Tag" with value "foo"
And I should see "question 01 name" in the "categoryquestions" "table"
And I should not see "question 02 name" in the "categoryquestions" "table"
@@ -76,9 +75,8 @@ Feature: Adding questions to a quiz from the question bank
Then I should see "question 21 name" in the "categoryquestions" "table"
And I should see "question 22 name" in the "categoryquestions" "table"
And I should not see "question 01 name" in the "categoryquestions" "table"
- And I click on "Show all 22" "link" in the ".question-showall-text" "css_element"
+ And I click on "1" "link" in the ".pagination" "css_element"
And I should see "question 01 name" in the "categoryquestions" "table"
- And I should see "question 22 name" in the "categoryquestions" "table"
Scenario: Questions are added in the right place with multiple sections
Given the following "questions" exist:
diff --git a/mod/quiz/tests/behat/editing_add_random.feature b/mod/quiz/tests/behat/editing_add_random.feature
index 17113976a2a..856db6e3c4c 100644
--- a/mod/quiz/tests/behat/editing_add_random.feature
+++ b/mod/quiz/tests/behat/editing_add_random.feature
@@ -43,7 +43,9 @@ 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 open the autocomplete suggestions list
+ And I add question bank filter "Tag"
+ And I click on "Tag" "field"
+ And I press the down key
Then "foo" "autocomplete_suggestions" should exist
And "bar" "autocomplete_suggestions" should exist
@@ -51,21 +53,16 @@ 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 set the field "Category" to "Top for Course 1"
- And I wait until the page is ready
- And I open the autocomplete suggestions list
- And I click on "foo" item in the autocomplete list
- Then I should see "question 1 name"
- And I should see "question 3 name"
- And I should not see "question 2 name"
- And I should not see "question 4 name"
- And I set the field "Category" to "Questions Category 1"
+ And I apply question bank filter "Category" with value "Questions Category 1"
+ And I apply question bank filter "Tag" with value "foo"
+ And I click on "Apply filters" "button"
And I wait until the page is ready
And I should see "question 1 name"
And I should not see "question 3 name"
And I should not see "question 2 name"
And I should not see "question 4 name"
- And I click on "Include questions from subcategories too" "checkbox"
+ And I set the field "Also show questions from subcategories" to "1"
+ And I click on "Apply filters" "button"
And I wait until the page is ready
And I should see "question 1 name"
And I should see "question 3 name"
@@ -76,10 +73,11 @@ 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 set the field "Tags" to "foo"
+ And I apply question bank filter "Tag" with value "foo"
+ And I select "1" from the "randomcount" singleselect
And I press "Add random question"
- And I should see "Random (Questions Category 1, tags: foo)" on quiz page "1"
- And I click on "(See questions)" "link"
+ And I should see "Random question based on filter condition with tags: foo" on quiz page "1"
+ When I click on "Configure question" "link" in the "Random question based on filter condition with tags: foo" "list_item"
Then I should see "Questions Category 1"
And I should see "foo"
And I should see "question 1 name"
@@ -101,8 +99,8 @@ Feature: Adding random questions to a quiz based on category and tags
And I follow "New category"
And I set the following fields to these values:
| Name | New Random category |
- | Parent category | Top for Quiz 1 |
+ | Parent category | Default for Quiz 1 |
And I press "Create category and add random question"
- And I should see "Random (New Random category)" on quiz page "1"
- And I click on "(See questions)" "link"
- Then I should see "Top for Quiz 1"
+ And I should see "Random question based on filter condition" on quiz page "1"
+ And I click on "Configure question" "link" in the "Random question based on filter condition" "list_item"
+ Then I should see "New Random category"
diff --git a/mod/quiz/tests/behat/editing_edit_random.feature b/mod/quiz/tests/behat/editing_edit_random.feature
index d853b4ee0de..df05f8344a6 100644
--- a/mod/quiz/tests/behat/editing_edit_random.feature
+++ b/mod/quiz/tests/behat/editing_edit_random.feature
@@ -38,18 +38,17 @@ Feature: Editing random questions already in a quiz based on category and tags
And I follow "a random question"
# 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 set the field "Tags" to "easy"
+ 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 set the field "Tags" to "hard"
+ And I apply question bank filter "Tag" with value "hard"
And I press "Add random question"
And I follow "Add page break"
- When I click on "Configure question" "link" in the "Random (Questions Category 1, tags: easy)" "list_item"
- And I click on "easy" "autocomplete_selection"
- And I set the field "Tags" to "essay"
- And I press "Save changes"
- Then I should see "Random (Questions Category 1, tags: essay)" on quiz page "1"
- And I should see "Random (Questions Category 1, tags: hard)" on quiz page "2"
- And I click on "Configure question" "link" in the "Questions Category 1, tags: hard" "list_item"
+ When I click on "Configure question" "link" in the "Random question based on filter condition with tags: easy" "list_item"
+ And I apply question bank filter "Tag" with value "essay"
+ And I press "Update filter conditions"
+ Then I should see "Random question based on filter condition with tags: essay" on quiz page "1"
+ And I should see "Random question based on filter condition with tags: hard" on quiz page "2"
+ And I click on "Configure question" "link" in the "Random question based on filter condition with tags: hard" "list_item"
And "hard" "autocomplete_selection" should be visible
diff --git a/mod/quiz/tests/behat/editing_remove_multiple_questions.feature b/mod/quiz/tests/behat/editing_remove_multiple_questions.feature
index 1e7ff95ad03..5aa2fa6adb9 100644
--- a/mod/quiz/tests/behat/editing_remove_multiple_questions.feature
+++ b/mod/quiz/tests/behat/editing_remove_multiple_questions.feature
@@ -261,11 +261,9 @@ Feature: Edit quiz page - remove multiple questions
And I click on "selectquestion-2" "checkbox"
And I click on "Delete selected" "button"
And I click on "Yes" "button" in the "Confirm" "dialogue"
- # To make sure question is deleted completely.
- And I reload the page
- Then I should see "Random (Test questions)" on quiz page "1"
- And I should not see "Random (Test questions)" on quiz page "2"
- And I should not see "Random (Test questions)" on quiz page "3"
+ Then I should see "Random question based on filter condition" on quiz page "1"
+ And I should not see "Random question based on filter condition" on quiz page "2"
+ And I should not see "Random question based on filter condition" on quiz page "3"
And I should see "Total of marks: 1.00"
And I should see "Questions: 1"
@@ -284,16 +282,15 @@ Feature: Edit quiz page - remove multiple questions
# Delete all questions in page. Page contains multiple questions.
When I open the "last" add to quiz menu
And I follow "a random question"
- And I set the field "Number of random questions" to "3"
+ And I click on "menurandomcount" "select"
+ And I click on "3" "option"
And I press "Add random question"
And I click on "Select multiple items" "button"
And I press "Select all"
And I click on "Delete selected" "button"
And I click on "Yes" "button" in the "Confirm" "dialogue"
- # To make sure question is deleted completely.
- And I reload the page
- Then I should not see "Random (Test questions)" on quiz page "1"
- And I should not see "Random (Test questions)" on quiz page "2"
- And I should not see "Random (Test questions)" on quiz page "3"
+ Then I should not see "Random question based on filter condition" on quiz page "1"
+ And I should not see "Random question based on filter condition" on quiz page "2"
+ And I should not see "Random question based on filter condition" on quiz page "3"
And I should see "Total of marks: 0.00"
And I should see "Questions: 0"
diff --git a/mod/quiz/tests/behat/random_question.feature b/mod/quiz/tests/behat/random_question.feature
index a6f3562640d..15a7e047b68 100644
--- a/mod/quiz/tests/behat/random_question.feature
+++ b/mod/quiz/tests/behat/random_question.feature
@@ -33,23 +33,24 @@ Feature: Moving a question to another category should not affect random question
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 set the field "Category" to "Used category"
+ And I apply question bank filter "Category" with value "Used category"
And I press "Add random question"
- And I should see "Random (Used category)" on quiz page "1"
- And I click on "(See questions)" "link"
+ And I should see "Random question based on filter condition" on quiz page "1"
+ And I click on "Configure question" "link" in the "Random question based on filter condition" "list_item"
And I should see "Used category"
+ And I am on "Course 1" course homepage
+ And I navigate to "Question bank" in current page administration
+ And I apply question bank filter "Category" with value "Used category"
And I click on "Test question to be moved" "checkbox" in the "Test question to be moved" "table_row"
And I click on "With selected" "button"
And I click on question bulk action "move"
And I set the field "Question category" to "Subcategory"
And I press "Move to"
Then I should see "Test question to be moved"
- And the field "Select a category" matches value " Subcategory (1)"
- And the "Select a category" select box should contain "Used category"
- And the "Select a category" select box should not contain "Used category (1)"
+ And I should see "Subcategory (1)"
And I am on the "Quiz 1" "mod_quiz > Edit" page
- And I should see "Random (Used category)" on quiz page "1"
- And I click on "(See questions)" "link"
+ And I should see "Random question based on filter condition" on quiz page "1"
+ And I click on "Configure question" "link" in the "Random question based on filter condition" "list_item"
And I should see "Used category"
@javascript
@@ -57,9 +58,9 @@ Feature: Moving a question to another category should not affect random question
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 set the field "Category" to "Used category"
+ And I apply question bank filter "Category" with value "Used category"
And I press "Add random question"
- And I should see "Random (Used category)" on quiz page "1"
+ And I should see "Random question based on filter condition" on quiz page "1"
And I am on the "Course 1" "core_question > course question categories" page
And I click on "Edit this category" "link" in the "Used category" "list_item"
And I set the following fields to these values:
@@ -69,4 +70,4 @@ Feature: Moving a question to another category should not affect random question
Then I should see "Used category new"
And I should see "I was edited" in the "Used category new" "list_item"
And I am on the "Quiz 1" "mod_quiz > Edit" page
- And I should see "Random (Used category new)" on quiz page "1"
+ And I should see "Random question based on filter condition" on quiz page "1"
diff --git a/mod/quiz/tests/external/external_test.php b/mod/quiz/tests/external/external_test.php
index 9fc37410f38..d3796d5fbf7 100644
--- a/mod/quiz/tests/external/external_test.php
+++ b/mod/quiz/tests/external/external_test.php
@@ -41,6 +41,7 @@ defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
+require_once($CFG->dirroot . '/mod/quiz/tests/quiz_question_helper_test_trait.php');
/**
* Silly class to access mod_quiz_external internal methods.
@@ -86,6 +87,8 @@ class testable_mod_quiz_external extends mod_quiz_external {
*/
class external_test extends externallib_advanced_testcase {
+ use \quiz_question_helper_test_trait;
+
/** @var \stdClass course record. */
protected $course;
@@ -1898,7 +1901,7 @@ class external_test extends externallib_advanced_testcase {
$question = $questiongenerator->create_question('truefalse', null, ['category' => $cat->id]);
$question = $questiongenerator->create_question('essay', null, ['category' => $cat->id]);
- quiz_add_random_questions($quiz, 0, $cat->id, 1, false);
+ $this->add_random_questions($quiz->id, 0, $cat->id, 1);
$quizobj = quiz_settings::create($quiz->id, $this->student->id);
@@ -2024,8 +2027,8 @@ class external_test extends externallib_advanced_testcase {
$question = $questiongenerator->create_question('essay', null, ['category' => $anothercat->id]);
// Add a couple of random questions from the same category.
- quiz_add_random_questions($quiz, 0, $cat->id, 1, false);
- quiz_add_random_questions($quiz, 0, $cat->id, 1, false);
+ $this->add_random_questions($quiz->id, 0, $cat->id, 1);
+ $this->add_random_questions($quiz->id, 0, $cat->id, 1);
$this->setUser($this->student);
@@ -2039,7 +2042,7 @@ class external_test extends externallib_advanced_testcase {
// Add more questions to the quiz, this time from the other category.
$this->setAdminUser();
- quiz_add_random_questions($quiz, 0, $anothercat->id, 1, false);
+ $this->add_random_questions($quiz->id, 0, $anothercat->id, 1);
$this->setUser($this->student);
$result = mod_quiz_external::get_quiz_required_qtypes($quiz->id);
diff --git a/mod/quiz/tests/lib_test.php b/mod/quiz/tests/lib_test.php
index 53b598a0b0d..7a8bf421408 100644
--- a/mod/quiz/tests/lib_test.php
+++ b/mod/quiz/tests/lib_test.php
@@ -31,12 +31,15 @@ defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/mod/quiz/lib.php');
+require_once($CFG->dirroot . '/mod/quiz/tests/quiz_question_helper_test_trait.php');
/**
* @copyright 2008 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
class lib_test extends \advanced_testcase {
+ use \quiz_question_helper_test_trait;
+
public function test_quiz_has_grades() {
$quiz = new \stdClass();
$quiz->grade = '100.0000';
@@ -109,7 +112,7 @@ class lib_test extends \advanced_testcase {
$standardq = $questiongenerator->create_question('shortanswer', null, ['category' => $cat->id]);
quiz_add_quiz_question($standardq->id, $quiz);
- quiz_add_random_questions($quiz, 0, $cat->id, 1, false);
+ $this->add_random_questions($quiz->id, 0, $cat->id, 1);
// Get the random question.
$randomq = $DB->get_record('question', ['qtype' => 'random']);
diff --git a/mod/quiz/tests/local_structure_slot_random_test.php b/mod/quiz/tests/local_structure_slot_random_test.php
index 6c4c11eecac..3a29b7e5757 100644
--- a/mod/quiz/tests/local_structure_slot_random_test.php
+++ b/mod/quiz/tests/local_structure_slot_random_test.php
@@ -16,8 +16,14 @@
namespace mod_quiz;
+defined('MOODLE_INTERNAL') || die();
+
use mod_quiz\question\bank\qbank_helper;
+global $CFG;
+require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
+require_once($CFG->dirroot . '/mod/quiz/tests/quiz_question_helper_test_trait.php');
+
/**
* Class mod_quiz_local_structure_slot_random_test
* Class for tests related to the {@link \mod_quiz\local\structure\slot_random} class.
@@ -26,8 +32,12 @@ use mod_quiz\question\bank\qbank_helper;
* @category test
* @copyright 2018 Shamim Rezaie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @covers \mod_quiz\local\structure\slot_random
*/
class local_structure_slot_random_test extends \advanced_testcase {
+
+ use \quiz_question_helper_test_trait;
+
/**
* Constructor test.
*/
@@ -57,8 +67,7 @@ class local_structure_slot_random_test extends \advanced_testcase {
// Set the filter conditions.
$filtercondition = new \stdClass();
- $filtercondition->questioncategoryid = $category->id;
- $filtercondition->includingsubcategories = 1;
+ $filtercondition->filters = \question_filter_test_helper::create_filters([$category->id], true);
// Slot data.
$randomslotdata = new \stdClass();
@@ -69,7 +78,7 @@ class local_structure_slot_random_test extends \advanced_testcase {
// Insert the random question to the quiz.
$randomslot = new \mod_quiz\local\structure\slot_random($randomslotdata);
- $randomslot->set_filter_condition($filtercondition);
+ $randomslot->set_filter_condition(json_encode($filtercondition));
$rc = new \ReflectionClass('\mod_quiz\local\structure\slot_random');
$rcp = $rc->getProperty('filtercondition');
@@ -77,8 +86,8 @@ class local_structure_slot_random_test extends \advanced_testcase {
$record = json_decode($rcp->getValue($randomslot));
$this->assertEquals($quiz->id, $randomslot->get_quiz()->id);
- $this->assertEquals($category->id, $record->questioncategoryid);
- $this->assertEquals(1, $record->includingsubcategories);
+ $this->assertEquals($category->id, $record->filters->category->values[0]);
+ $this->assertTrue($record->filters->category->filteroptions->includesubcategories);
$rcp = $rc->getProperty('record');
$rcp->setAccessible(true);
@@ -100,12 +109,11 @@ class local_structure_slot_random_test extends \advanced_testcase {
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
$category = $questiongenerator->create_question_category();
- quiz_add_random_questions($quiz, 0, $category->id, 1, false);
+ $this->add_random_questions($quiz->id, 0, $category->id, 1);
// Set the filter conditions.
$filtercondition = new \stdClass();
- $filtercondition->questioncategoryid = $category->id;
- $filtercondition->includingsubcategories = 1;
+ $filtercondition->filters = \question_filter_test_helper::create_filters([$category->id], 1);
// Slot data.
$randomslotdata = new \stdClass();
@@ -115,7 +123,7 @@ class local_structure_slot_random_test extends \advanced_testcase {
$randomslotdata->questionscontextid = $category->contextid;
$randomslot = new \mod_quiz\local\structure\slot_random($randomslotdata);
- $randomslot->set_filter_condition($filtercondition);
+ $randomslot->set_filter_condition(json_encode($filtercondition));
// The create_instance had injected an additional cmid propery to the quiz. Let's remove that.
unset($quiz->cmid);
@@ -137,12 +145,11 @@ class local_structure_slot_random_test extends \advanced_testcase {
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
$category = $questiongenerator->create_question_category();
- quiz_add_random_questions($quiz, 0, $category->id, 1, false);
+ $this->add_random_questions($quiz->id, 0, $category->id, 1);
// Set the filter conditions.
$filtercondition = new \stdClass();
- $filtercondition->questioncategoryid = $category->id;
- $filtercondition->includingsubcategories = 1;
+ $filtercondition->filters = \question_filter_test_helper::create_filters([$category->id], 1);
// Slot data.
$randomslotdata = new \stdClass();
@@ -152,7 +159,7 @@ class local_structure_slot_random_test extends \advanced_testcase {
$randomslotdata->questionscontextid = $category->contextid;
$randomslot = new \mod_quiz\local\structure\slot_random($randomslotdata);
- $randomslot->set_filter_condition($filtercondition);
+ $randomslot->set_filter_condition(json_encode($filtercondition));
// The create_instance had injected an additional cmid propery to the quiz. Let's remove that.
unset($quiz->cmid);
@@ -178,7 +185,7 @@ class local_structure_slot_random_test extends \advanced_testcase {
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
$category = $questiongenerator->create_question_category();
- quiz_add_random_questions($quiz, 0, $category->id, 1, false);
+ $this->add_random_questions($quiz->id, 0, $category->id, 1);
// Slot data.
$randomslotdata = new \stdClass();
@@ -203,147 +210,24 @@ class local_structure_slot_random_test extends \advanced_testcase {
return [$randomslot, $tags];
}
- public function test_set_tags() {
+ public function test_set_tags_filter() {
$this->resetAfterTest();
$this->setAdminUser();
list($randomslot, $tags) = $this->setup_for_test_tags(['foo', 'bar']);
+
+ $qtagids = [$tags['foo']->id, $tags['bar']->id];
$filtercondition = new \stdClass();
- $randomslot->set_tags([$tags['foo'], $tags['bar']]);
- $randomslot->set_filter_condition($filtercondition);
+ $filtercondition->filters = \question_filter_test_helper::create_filters([], 0, $qtagids);
+ $randomslot->set_filter_condition(json_encode($filtercondition));
$rc = new \ReflectionClass('\mod_quiz\local\structure\slot_random');
$rcp = $rc->getProperty('filtercondition');
$rcp->setAccessible(true);
$tagspropery = $rcp->getValue($randomslot);
- $this->assertEquals([
- $tags['foo']->id => $tags['foo'],
- $tags['bar']->id => $tags['bar'],
- ], (array)json_decode($tagspropery)->tags);
- }
-
- public function test_set_tags_twice() {
- $this->resetAfterTest();
- $this->setAdminUser();
-
- list($randomslot, $tags) = $this->setup_for_test_tags(['foo', 'bar', 'baz']);
-
- // Set tags for the first time.
- $filtercondition = new \stdClass();
- $randomslot->set_tags([$tags['foo'], $tags['bar']]);
- // Now set the tags again.
- $randomslot->set_tags([$tags['baz']]);
- $randomslot->set_filter_condition($filtercondition);
-
- $rc = new \ReflectionClass('\mod_quiz\local\structure\slot_random');
- $rcp = $rc->getProperty('filtercondition');
- $rcp->setAccessible(true);
- $tagspropery = $rcp->getValue($randomslot);
-
- $this->assertEquals([
- $tags['baz']->id => $tags['baz'],
- ], (array)json_decode($tagspropery)->tags);
- }
-
- public function test_set_tags_duplicates() {
- $this->resetAfterTest();
- $this->setAdminUser();
-
- list($randomslot, $tags) = $this->setup_for_test_tags(['foo', 'bar', 'baz']);
- $filtercondition = new \stdClass();
- $randomslot->set_tags([$tags['foo'], $tags['bar'], $tags['foo']]);
- $randomslot->set_filter_condition($filtercondition);
-
- $rc = new \ReflectionClass('\mod_quiz\local\structure\slot_random');
- $rcp = $rc->getProperty('filtercondition');
- $rcp->setAccessible(true);
- $tagspropery = $rcp->getValue($randomslot);
-
- $this->assertEquals([
- $tags['foo']->id => $tags['foo'],
- $tags['bar']->id => $tags['bar'],
- ], (array)json_decode($tagspropery)->tags);
- }
-
- public function test_set_tags_by_id() {
- $this->resetAfterTest();
- $this->setAdminUser();
-
- list($randomslot, $tags) = $this->setup_for_test_tags(['foo', 'bar', 'baz']);
- $filtercondition = new \stdClass();
- $randomslot->set_tags_by_id([$tags['foo']->id, $tags['bar']->id]);
- $randomslot->set_filter_condition($filtercondition);
-
- $rc = new \ReflectionClass('\mod_quiz\local\structure\slot_random');
- $rcp = $rc->getProperty('tags');
- $rcp->setAccessible(true);
- $tagspropery = $rcp->getValue($randomslot);
-
- // The set_tags_by_id function only retrieves id and name fields of the tag object.
- $this->assertCount(2, $tagspropery);
- $this->assertArrayHasKey($tags['foo']->id, $tagspropery);
- $this->assertArrayHasKey($tags['bar']->id, $tagspropery);
- $this->assertEquals(
- (object)['id' => $tags['foo']->id, 'name' => $tags['foo']->name],
- $tagspropery[$tags['foo']->id]->to_object()
- );
- $this->assertEquals(
- (object)['id' => $tags['bar']->id, 'name' => $tags['bar']->name],
- $tagspropery[$tags['bar']->id]->to_object()
- );
- }
-
- public function test_set_tags_by_id_twice() {
- $this->resetAfterTest();
- $this->setAdminUser();
-
- list($randomslot, $tags) = $this->setup_for_test_tags(['foo', 'bar', 'baz']);
-
- // Set tags for the first time.
- $randomslot->set_tags_by_id([$tags['foo']->id, $tags['bar']->id]);
- // Now set the tags again.
- $randomslot->set_tags_by_id([$tags['baz']->id]);
-
- $rc = new \ReflectionClass('\mod_quiz\local\structure\slot_random');
- $rcp = $rc->getProperty('tags');
- $rcp->setAccessible(true);
- $tagspropery = $rcp->getValue($randomslot);
-
- // The set_tags_by_id function only retrieves id and name fields of the tag object.
- $this->assertCount(1, $tagspropery);
- $this->assertArrayHasKey($tags['baz']->id, $tagspropery);
- $this->assertEquals(
- (object)['id' => $tags['baz']->id, 'name' => $tags['baz']->name],
- $tagspropery[$tags['baz']->id]->to_object()
- );
- }
-
- public function test_set_tags_by_id_duplicates() {
- $this->resetAfterTest();
- $this->setAdminUser();
-
- list($randomslot, $tags) = $this->setup_for_test_tags(['foo', 'bar', 'baz']);
-
- $randomslot->set_tags_by_id([$tags['foo']->id, $tags['bar']->id], $tags['foo']->id);
-
- $rc = new \ReflectionClass('\mod_quiz\local\structure\slot_random');
- $rcp = $rc->getProperty('tags');
- $rcp->setAccessible(true);
- $tagspropery = $rcp->getValue($randomslot);
-
- // The set_tags_by_id function only retrieves id and name fields of the tag object.
- $this->assertCount(2, $tagspropery);
- $this->assertArrayHasKey($tags['foo']->id, $tagspropery);
- $this->assertArrayHasKey($tags['bar']->id, $tagspropery);
- $this->assertEquals(
- (object)['id' => $tags['foo']->id, 'name' => $tags['foo']->name],
- $tagspropery[$tags['foo']->id]->to_object()
- );
- $this->assertEquals(
- (object)['id' => $tags['bar']->id, 'name' => $tags['bar']->name],
- $tagspropery[$tags['bar']->id]->to_object()
- );
+ $this->assertEquals([$tags['foo']->id, $tags['bar']->id],
+ (array)json_decode($tagspropery)->filters->qtagids->values);
}
public function test_insert() {
@@ -389,8 +273,7 @@ class local_structure_slot_random_test extends \advanced_testcase {
// Set the filter conditions.
$filtercondition = new \stdClass();
- $filtercondition->questioncategoryid = $category->id;
- $filtercondition->includingsubcategories = 1;
+ $filtercondition->filter = \question_filter_test_helper::create_filters([$category->id], true, [$footag->id, $bartag->id]);
// Slot data.
$randomslotdata = new \stdClass();
@@ -401,26 +284,26 @@ class local_structure_slot_random_test extends \advanced_testcase {
// Insert the random question to the quiz.
$randomslot = new \mod_quiz\local\structure\slot_random($randomslotdata);
- $randomslot->set_tags([$footag, $bartag]);
- $randomslot->set_filter_condition($filtercondition);
+ $randomslot->set_filter_condition(json_encode($filtercondition));
$randomslot->insert(1); // Put the question on the first page of the quiz.
$slots = qbank_helper::get_question_structure($quiz->id, $quizcontext);
$quizslot = reset($slots);
- $this->assertEquals($category->id, $quizslot->category);
- $this->assertEquals(1, $quizslot->randomrecurse);
- $this->assertEquals(1, $quizslot->maxmark);
- $tagspropery = $quizslot->randomtags;
+ $filter = $quizslot->filtercondition['filter'];
- $this->assertCount(2, $tagspropery);
+ $this->assertEquals($category->id, $filter['category']['values'][0]);
+ $this->assertTrue($filter['category']['filteroptions']['includesubcategories']);
+ $this->assertEquals(1, $quizslot->maxmark);
+
+ $this->assertCount(2, $filter['qtagids']['values']);
$this->assertEqualsCanonicalizing(
[
- ['tagid' => $footag->id, 'tagname' => $footag->name],
- ['tagid' => $bartag->id, 'tagname' => $bartag->name]
+ ['tagid' => $footag->id],
+ ['tagid' => $bartag->id]
],
- array_map(function($slottag) {
- return ['tagid' => $slottag->id, 'tagname' => $slottag->name];
- }, $tagspropery));
+ array_map(function($tagid) {
+ return ['tagid' => $tagid];
+ }, $filter['qtagids']['values']));
}
}
diff --git a/mod/quiz/tests/locallib_test.php b/mod/quiz/tests/locallib_test.php
index 83b368da141..9a79fab38d9 100644
--- a/mod/quiz/tests/locallib_test.php
+++ b/mod/quiz/tests/locallib_test.php
@@ -31,7 +31,7 @@ defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
-
+require_once($CFG->dirroot . '/mod/quiz/tests/quiz_question_helper_test_trait.php');
/**
* Unit tests for (some of) mod/quiz/locallib.php.
@@ -41,6 +41,8 @@ require_once($CFG->dirroot . '/mod/quiz/locallib.php');
*/
class locallib_test extends \advanced_testcase {
+ use \quiz_question_helper_test_trait;
+
public function test_quiz_rescale_grade() {
$quiz = new \stdClass();
$quiz->decimalpoints = 2;
@@ -523,7 +525,7 @@ class locallib_test extends \advanced_testcase {
$tagids[] = $tagobjects[$tagname]->id;
}
}
- quiz_add_random_questions($quiz, 0, $cat->id, 1, false, $tagids);
+ $this->add_random_questions($quiz->id, 0, $cat->id, 1);
}
return [$quiz, $tagobjects];
diff --git a/mod/quiz/tests/quiz_question_bank_view_test.php b/mod/quiz/tests/quiz_question_bank_view_test.php
index bcefd39deeb..dff013c9526 100644
--- a/mod/quiz/tests/quiz_question_bank_view_test.php
+++ b/mod/quiz/tests/quiz_question_bank_view_test.php
@@ -49,7 +49,8 @@ class quiz_question_bank_view_test extends \advanced_testcase {
// Create a question in the default category.
$contexts = new question_edit_contexts($context);
- $cat = question_make_default_categories($contexts->all());
+ question_make_default_categories($contexts->all());
+ $cat = question_get_default_category($context->id);
$questiondata = $questiongenerator->create_question('numerical', null,
['name' => 'Example question', 'category' => $cat->id]);
@@ -58,17 +59,19 @@ class quiz_question_bank_view_test extends \advanced_testcase {
$cache->delete($questiondata->id);
// Generate the view.
- $view = new custom_view($contexts, new \moodle_url('/'), $course, $cm, $quiz);
- ob_start();
- $pagevars = [
+ $params = [
'qpage' => 0,
'qperpage' => 20,
'cat' => $cat->id . ',' . $context->id,
'recurse' => false,
'showhidden' => false,
- 'qbshowtext' => false
+ 'qbshowtext' => false,
+ 'tabname' => 'editq'
];
- $view->display($pagevars, 'editq');
+ $extraparams = ['cmid' => $cm->id];
+ $view = new custom_view($contexts, new \moodle_url('/'), $course, $cm, $params, $extraparams);
+ ob_start();
+ $view->display();
$html = ob_get_clean();
// Verify the output includes the expected question.
diff --git a/mod/quiz/tests/quiz_question_helper_test_trait.php b/mod/quiz/tests/quiz_question_helper_test_trait.php
index 174ab2adc31..198c41e9968 100644
--- a/mod/quiz/tests/quiz_question_helper_test_trait.php
+++ b/mod/quiz/tests/quiz_question_helper_test_trait.php
@@ -92,7 +92,7 @@ trait quiz_question_helper_test_trait {
$cat = $questiongenerator->create_question_category($override);
$questiongenerator->create_question('truefalse', null, ['category' => $cat->id]);
$questiongenerator->create_question('essay', null, ['category' => $cat->id]);
- quiz_add_random_questions($quiz, 0, $cat->id, 1, false);
+ $this->add_random_questions($quiz->id, 0, $cat->id, 1);
}
/**
@@ -180,4 +180,28 @@ trait quiz_question_helper_test_trait {
protected function duplicate_quiz($course, $quiz): ?\cm_info {
return duplicate_module($course, get_fast_modinfo($course)->get_cm($quiz->cmid));
}
+
+ /**
+ * Add random questions to a quiz, with a filter condition based on a category ID.
+ *
+ * @param int $quizid The quiz to add the questions to.
+ * @param int $page The page number to add the questions to.
+ * @param int $categoryid The category ID to use for the filter condition.
+ * @param int $number The number of questions to add.
+ * @return void
+ */
+ protected function add_random_questions(int $quizid, int $page, int $categoryid, int $number): void {
+ $settings = quiz_settings::create($quizid);
+ $structure = \mod_quiz\structure::create_for_quiz($settings);
+ $filtercondition = [
+ 'filter' => [
+ 'category' => [
+ 'jointype' => \qbank_managecategories\category_condition::JOINTYPE_DEFAULT,
+ 'values' => [$categoryid],
+ 'filteroptions' => ['includesubcategories' => false],
+ ],
+ ],
+ ];
+ $structure->add_random_questions($page, $number, $filtercondition);
+ }
}
diff --git a/mod/quiz/tests/quiz_question_restore_test.php b/mod/quiz/tests/quiz_question_restore_test.php
index afc77a713ce..1086016c217 100644
--- a/mod/quiz/tests/quiz_question_restore_test.php
+++ b/mod/quiz/tests/quiz_question_restore_test.php
@@ -470,7 +470,7 @@ class quiz_question_restore_test extends \advanced_testcase {
quiz_add_quiz_question($saq->id, $quiz, 1, 3);
quiz_add_quiz_question($numq->id, $quiz, 2, 2);
quiz_add_quiz_question($matchq->id, $quiz, 3, 1);
- quiz_add_random_questions($quiz, 3, $randomcat->id, 2, false);
+ $this->add_random_questions($quiz->id, 3, $randomcat->id, 2);
$quizobj = quiz_settings::create($quiz->id, $user1->id);
$originalstructure = \mod_quiz\structure::create_for_quiz($quizobj);
diff --git a/mod/quiz/tests/structure_test.php b/mod/quiz/tests/structure_test.php
index 759dbba4667..6e198469889 100644
--- a/mod/quiz/tests/structure_test.php
+++ b/mod/quiz/tests/structure_test.php
@@ -16,6 +16,11 @@
namespace mod_quiz;
+defined('MOODLE_INTERNAL') || die();
+
+global $CFG;
+require_once($CFG->dirroot . '/mod/quiz/tests/quiz_question_helper_test_trait.php');
+
/**
* Unit tests for quiz events.
*
@@ -26,6 +31,8 @@ namespace mod_quiz;
*/
class structure_test extends \advanced_testcase {
+ use \quiz_question_helper_test_trait;
+
/**
* Create a course with an empty quiz.
* @return array with three elements quiz, cm and course.
@@ -691,7 +698,7 @@ class structure_test extends \advanced_testcase {
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
$cat = $questiongenerator->create_question_category();
- quiz_add_random_questions($quizobj->get_quiz(), 1, $cat->id, 1, false);
+ $this->add_random_questions($quizobj->get_quizid(), 1, $cat->id, 1);
$structure = structure::create_for_quiz($quizobj);
$sql = 'SELECT qsr.*
FROM {question_set_references} qsr
diff --git a/question/bank/managecategories/tests/helper_test.php b/question/bank/managecategories/tests/helper_test.php
index 6dd8e861954..a5c746a046a 100644
--- a/question/bank/managecategories/tests/helper_test.php
+++ b/question/bank/managecategories/tests/helper_test.php
@@ -16,9 +16,14 @@
namespace qbank_managecategories;
+defined('MOODLE_INTERNAL') || die();
+
use moodle_url;
use core_question\local\bank\question_edit_contexts;
+global $CFG;
+require_once($CFG->dirroot . '/mod/quiz/tests/quiz_question_helper_test_trait.php');
+
/**
* Unit tests for helper class.
*
@@ -30,6 +35,8 @@ use core_question\local\bank\question_edit_contexts;
*/
class helper_test extends \advanced_testcase {
+ use \quiz_question_helper_test_trait;
+
/**
* @var \context_module module context.
*/
@@ -97,7 +104,7 @@ class helper_test extends \advanced_testcase {
quiz_add_quiz_question($q2b->id, $this->quiz);
// Adding a new random question does not add a new question, adds a question_set_references record.
- quiz_add_random_questions($this->quiz, 0, $qcat2->id, 1, false);
+ $this->add_random_questions($this->quiz->id, 0, $qcat2->id, 1);
// We added one random question to the quiz and we expect the quiz to have only one random question.
$q2d = $DB->get_record_sql("SELECT qsr.*
diff --git a/question/bank/statistics/tests/helper_test.php b/question/bank/statistics/tests/helper_test.php
index 671c896d5e7..8b77b3f2cb7 100644
--- a/question/bank/statistics/tests/helper_test.php
+++ b/question/bank/statistics/tests/helper_test.php
@@ -16,11 +16,16 @@
namespace qbank_statistics;
+defined('MOODLE_INTERNAL') || die();
+
use core_question\statistics\questions\all_calculated_for_qubaid_condition;
use mod_quiz\quiz_attempt;
use mod_quiz\quiz_settings;
use question_engine;
+global $CFG;
+require_once($CFG->dirroot . '/mod/quiz/tests/quiz_question_helper_test_trait.php');
+
/**
* Tests for question statistics.
*
@@ -31,6 +36,8 @@ use question_engine;
*/
class helper_test extends \advanced_testcase {
+ use \quiz_question_helper_test_trait;
+
/**
* Test quizzes that contain a specified question.
*
@@ -100,7 +107,7 @@ class helper_test extends \advanced_testcase {
$this->assertEquals((object) ['component' => 'mod_quiz', 'contextid' => $quiz2context->id], $q2places[0]);
// Add a random question to quiz3.
- quiz_add_random_questions($quiz3, 0, $cat->id, 1, false);
+ $this->add_random_questions($quiz3->id, 0, $cat->id, 1);
$this->submit_quiz($quiz3, [1 => ['answer' => 'willbewrong']]);
// Quiz 3 will now be in one of these arrays.
diff --git a/question/bank/usage/tests/helper_test.php b/question/bank/usage/tests/helper_test.php
index 77cef5fdd0f..efab696af7c 100644
--- a/question/bank/usage/tests/helper_test.php
+++ b/question/bank/usage/tests/helper_test.php
@@ -16,8 +16,13 @@
namespace qbank_usage;
+defined('MOODLE_INTERNAL') || die();
+
use mod_quiz\quiz_attempt;
+global $CFG;
+require_once($CFG->dirroot . '/mod/quiz/tests/quiz_question_helper_test_trait.php');
+
/**
* Helper test.
*
@@ -29,6 +34,8 @@ use mod_quiz\quiz_attempt;
*/
class helper_test extends \advanced_testcase {
+ use \quiz_question_helper_test_trait;
+
/**
* @var \stdClass $quiz
*/
@@ -133,7 +140,7 @@ class helper_test extends \advanced_testcase {
$this->setAdminUser();
$cat = $this->questiongenerator->create_question_category();
$question = $this->questiongenerator->create_question('shortanswer', null, ['category' => $cat->id]);
- quiz_add_random_questions($this->quiz, 1, $cat->id, 1, false);
+ $this->add_random_questions($this->quiz->id, 1, $cat->id, 1);
$qdef = \question_bank::load_question($question->id);
$count = helper::get_question_entry_usage_count($qdef);
@@ -226,7 +233,7 @@ class helper_test extends \advanced_testcase {
$this->setAdminUser();
$cat = $this->questiongenerator->create_question_category();
$question = $this->questiongenerator->create_question('shortanswer', null, ['category' => $cat->id]);
- quiz_add_random_questions($this->quiz, 1, $cat->id, 1, false);
+ $this->add_random_questions($this->quiz->id, 1, $cat->id, 1);
$this->attempt_quiz();
diff --git a/question/editlib.php b/question/editlib.php
index beb6f4809df..fec2787f91a 100644
--- a/question/editlib.php
+++ b/question/editlib.php
@@ -270,7 +270,10 @@ function question_build_edit_resources($edittab, $baseurl, $params,
}
if (!empty($params['filter'])) {
- $cleanparams['filter'] = json_decode($params['filter'], true);
+ if (!is_array($params['filter'])) {
+ $params['filter'] = json_decode($params['filter'], true);
+ }
+ $cleanparams['filter'] = $params['filter'];
}
$cmid = $cleanparams['cmid'];
diff --git a/question/tests/local/statistics/statistics_bulk_loader_test.php b/question/tests/local/statistics/statistics_bulk_loader_test.php
index 2ce29c378b1..14c14321dba 100644
--- a/question/tests/local/statistics/statistics_bulk_loader_test.php
+++ b/question/tests/local/statistics/statistics_bulk_loader_test.php
@@ -16,6 +16,8 @@
namespace core_question\local\statistics;
+defined('MOODLE_INTERNAL') || die();
+
use advanced_testcase;
use context;
use context_module;
@@ -27,6 +29,9 @@ use mod_quiz\quiz_settings;
use question_engine;
use ReflectionMethod;
+global $CFG;
+require_once($CFG->dirroot . '/mod/quiz/tests/quiz_question_helper_test_trait.php');
+
/**
* Tests for question statistics.
*
@@ -37,6 +42,8 @@ use ReflectionMethod;
*/
class statistics_bulk_loader_test extends advanced_testcase {
+ use \quiz_question_helper_test_trait;
+
/** @var float Delta used when comparing statistics values out-of 1. */
protected const DELTA = 0.00005;
@@ -111,7 +118,7 @@ class statistics_bulk_loader_test extends advanced_testcase {
$this->assertEquals((object) ['component' => 'mod_quiz', 'contextid' => $quiz2context->id], $q2places[0]);
// Add a random question to quiz3.
- quiz_add_random_questions($quiz3, 0, $cat->id, 1, false);
+ $this->add_random_questions($quiz3->id, 0, $cat->id, 1, false);
$this->submit_quiz($quiz3, [1 => ['answer' => 'willbewrong']]);
// Quiz 3 will now be in one of these arrays.
diff --git a/question/tests/random_question_loader_test.php b/question/tests/random_question_loader_test.php
index 1f9da267412..13cc9dec3aa 100644
--- a/question/tests/random_question_loader_test.php
+++ b/question/tests/random_question_loader_test.php
@@ -25,6 +25,7 @@ defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
+require_once($CFG->dirroot . '/mod/quiz/tests/quiz_question_helper_test_trait.php');
/**
* Tests for the {@see \core_question\local\bank\random_question_loader} class.
@@ -35,6 +36,8 @@ require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
*/
class random_question_loader_test extends \advanced_testcase {
+ use \quiz_question_helper_test_trait;
+
public function test_empty_category_gives_null() {
$this->resetAfterTest();
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
@@ -104,7 +107,7 @@ class random_question_loader_test extends \advanced_testcase {
$cat = $generator->create_question_category();
$course = $this->getDataGenerator()->create_course();
$quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course]);
- quiz_add_random_questions($quiz, 1, $cat->id, 1);
+ $this->add_random_questions($quiz->id, 1, $cat->id, 1);
$loader = new \core_question\local\bank\random_question_loader(new qubaid_list([]));
$filters = question_filter_test_helper::create_filters([$cat->id]);