Commit 028cbda0 authored by jun's avatar jun
Browse files

Merge branch 'MDL-75048-master' of https://github.com/jleyva/moodle

parents 3af7eee0 a3201673
...@@ -547,8 +547,9 @@ class quiz { ...@@ -547,8 +547,9 @@ class quiz {
if (!isset($qcategories[$questiondata->category])) { if (!isset($qcategories[$questiondata->category])) {
$qcategories[$questiondata->category] = false; $qcategories[$questiondata->category] = false;
} }
if ($questiondata->includingsubcategories) { if (!empty($questiondata->filtercondition)) {
$qcategories[$questiondata->category] = true; $filtercondition = json_decode($questiondata->filtercondition);
$qcategories[$questiondata->category] = !empty($filtercondition->includingsubcategories);
} }
} else { } else {
if (!in_array($questiondata->qtype, $questiontypes)) { if (!in_array($questiondata->qtype, $questiontypes)) {
......
...@@ -1960,4 +1960,55 @@ class external_test extends externallib_advanced_testcase { ...@@ -1960,4 +1960,55 @@ class external_test extends externallib_advanced_testcase {
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
} }
/**
* Test get_quiz_required_qtypes for quiz with random questions
*/
public function test_get_quiz_required_qtypes_random() {
$this->setAdminUser();
// Create a new quiz.
$quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz');
$quiz = $quizgenerator->create_instance(['course' => $this->course->id]);
// Create some questions.
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
$cat = $questiongenerator->create_question_category();
$anothercat = $questiongenerator->create_question_category();
$question = $questiongenerator->create_question('numerical', null, ['category' => $cat->id]);
$question = $questiongenerator->create_question('shortanswer', null, ['category' => $cat->id]);
$question = $questiongenerator->create_question('truefalse', null, ['category' => $cat->id]);
// Question in a different category.
$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->setUser($this->student);
$result = mod_quiz_external::get_quiz_required_qtypes($quiz->id);
$result = \external_api::clean_returnvalue(mod_quiz_external::get_quiz_required_qtypes_returns(), $result);
$expected = ['numerical', 'shortanswer', 'truefalse'];
ksort($result['questiontypes']);
$this->assertEquals($expected, $result['questiontypes']);
// 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->setUser($this->student);
$result = mod_quiz_external::get_quiz_required_qtypes($quiz->id);
$result = \external_api::clean_returnvalue(mod_quiz_external::get_quiz_required_qtypes_returns(), $result);
// The new question from the new category is returned as a potential random question for the quiz.
$expected = ['essay', 'numerical', 'shortanswer', 'truefalse'];
ksort($result['questiontypes']);
$this->assertEquals($expected, $result['questiontypes']);
}
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment