MDL-81114 question: fix coding style in random_question_loader_test

This commit is contained in:
Tim Hunt 2024-03-08 17:11:59 +00:00
parent 38a3310c92
commit f0d92f492c

View file

@ -16,6 +16,11 @@
namespace core_question; namespace core_question;
use core_question\local\bank\condition;
use core_question\local\bank\question_version_status;
use core_question\local\bank\random_question_loader;
use core_question_generator;
use mod_quiz\quiz_settings;
use qubaid_list; use qubaid_list;
use question_bank; use question_bank;
use question_engine; use question_engine;
@ -33,17 +38,18 @@ require_once($CFG->dirroot . '/mod/quiz/tests/quiz_question_helper_test_trait.ph
* @package core_question * @package core_question
* @copyright 2015 The Open University * @copyright 2015 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \random_question_loader
*/ */
class random_question_loader_test extends \advanced_testcase { final class random_question_loader_test extends \advanced_testcase {
use \quiz_question_helper_test_trait; use \quiz_question_helper_test_trait;
public function test_empty_category_gives_null() { public function test_empty_category_gives_null(): void {
$this->resetAfterTest(); $this->resetAfterTest();
$generator = $this->getDataGenerator()->get_plugin_generator('core_question'); $generator = $this->getDataGenerator()->get_plugin_generator('core_question');
$cat = $generator->create_question_category(); $cat = $generator->create_question_category();
$loader = new \core_question\local\bank\random_question_loader(new qubaid_list([])); $loader = new random_question_loader(new qubaid_list([]));
$filters = question_filter_test_helper::create_filters([$cat->id]); $filters = question_filter_test_helper::create_filters([$cat->id]);
$this->assertNull($loader->get_next_filtered_question_id($filters)); $this->assertNull($loader->get_next_filtered_question_id($filters));
@ -52,26 +58,26 @@ class random_question_loader_test extends \advanced_testcase {
$this->assertNull($loader->get_next_filtered_question_id($filters)); $this->assertNull($loader->get_next_filtered_question_id($filters));
} }
public function test_unknown_category_behaves_like_empty() { public function test_unknown_category_behaves_like_empty(): void {
// It is up the caller to make sure the category id is valid. // It is up the caller to make sure the category id is valid.
$loader = new \core_question\local\bank\random_question_loader(new qubaid_list([])); $loader = new random_question_loader(new qubaid_list([]));
$filters = question_filter_test_helper::create_filters([-1], 1); $filters = question_filter_test_helper::create_filters([-1], 1);
$this->assertNull($loader->get_next_filtered_question_id($filters)); $this->assertNull($loader->get_next_filtered_question_id($filters));
} }
public function test_descriptions_not_returned() { public function test_descriptions_not_returned(): void {
$this->resetAfterTest(); $this->resetAfterTest();
$generator = $this->getDataGenerator()->get_plugin_generator('core_question'); $generator = $this->getDataGenerator()->get_plugin_generator('core_question');
$cat = $generator->create_question_category(); $cat = $generator->create_question_category();
$info = $generator->create_question('description', null, ['category' => $cat->id]); $info = $generator->create_question('description', null, ['category' => $cat->id]);
$loader = new \core_question\local\bank\random_question_loader(new qubaid_list([])); $loader = new random_question_loader(new qubaid_list([]));
$filters = question_filter_test_helper::create_filters([$cat->id]); $filters = question_filter_test_helper::create_filters([$cat->id]);
$this->assertNull($loader->get_next_filtered_question_id($filters)); $this->assertNull($loader->get_next_filtered_question_id($filters));
} }
public function test_hidden_questions_not_returned() { public function test_hidden_questions_not_returned(): void {
global $DB; global $DB;
$this->resetAfterTest(); $this->resetAfterTest();
$generator = $this->getDataGenerator()->get_plugin_generator('core_question'); $generator = $this->getDataGenerator()->get_plugin_generator('core_question');
@ -80,26 +86,26 @@ class random_question_loader_test extends \advanced_testcase {
$question1 = $generator->create_question('shortanswer', null, ['category' => $cat->id]); $question1 = $generator->create_question('shortanswer', null, ['category' => $cat->id]);
$DB->set_field('question_versions', 'status', $DB->set_field('question_versions', 'status',
\core_question\local\bank\question_version_status::QUESTION_STATUS_HIDDEN, ['questionid' => $question1->id]); \core_question\local\bank\question_version_status::QUESTION_STATUS_HIDDEN, ['questionid' => $question1->id]);
$loader = new \core_question\local\bank\random_question_loader(new qubaid_list([])); $loader = new random_question_loader(new qubaid_list([]));
$filters = question_filter_test_helper::create_filters([$cat->id]); $filters = question_filter_test_helper::create_filters([$cat->id]);
$this->assertNull($loader->get_next_filtered_question_id($filters)); $this->assertNull($loader->get_next_filtered_question_id($filters));
} }
public function test_cloze_subquestions_not_returned() { public function test_cloze_subquestions_not_returned(): void {
$this->resetAfterTest(); $this->resetAfterTest();
$generator = $this->getDataGenerator()->get_plugin_generator('core_question'); $generator = $this->getDataGenerator()->get_plugin_generator('core_question');
$cat = $generator->create_question_category(); $cat = $generator->create_question_category();
$question1 = $generator->create_question('multianswer', null, ['category' => $cat->id]); $question1 = $generator->create_question('multianswer', null, ['category' => $cat->id]);
$loader = new \core_question\local\bank\random_question_loader(new qubaid_list([])); $loader = new random_question_loader(new qubaid_list([]));
$filters = question_filter_test_helper::create_filters([$cat->id]); $filters = question_filter_test_helper::create_filters([$cat->id]);
$this->assertEquals($question1->id, $loader->get_next_filtered_question_id($filters)); $this->assertEquals($question1->id, $loader->get_next_filtered_question_id($filters));
$this->assertNull($loader->get_next_filtered_question_id($filters)); $this->assertNull($loader->get_next_filtered_question_id($filters));
} }
public function test_random_questions_not_returned() { public function test_random_questions_not_returned(): void {
$this->resetAfterTest(); $this->resetAfterTest();
$this->setAdminUser(); $this->setAdminUser();
$generator = $this->getDataGenerator()->get_plugin_generator('core_question'); $generator = $this->getDataGenerator()->get_plugin_generator('core_question');
@ -108,19 +114,19 @@ class random_question_loader_test extends \advanced_testcase {
$course = $this->getDataGenerator()->create_course(); $course = $this->getDataGenerator()->create_course();
$quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course]); $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course]);
$this->add_random_questions($quiz->id, 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([])); $loader = new random_question_loader(new qubaid_list([]));
$filters = question_filter_test_helper::create_filters([$cat->id]); $filters = question_filter_test_helper::create_filters([$cat->id]);
$this->assertNull($loader->get_next_filtered_question_id($filters)); $this->assertNull($loader->get_next_filtered_question_id($filters));
} }
public function test_one_question_category_returns_that_q_then_null() { public function test_one_question_category_returns_that_q_then_null(): void {
$this->resetAfterTest(); $this->resetAfterTest();
$generator = $this->getDataGenerator()->get_plugin_generator('core_question'); $generator = $this->getDataGenerator()->get_plugin_generator('core_question');
$cat = $generator->create_question_category(); $cat = $generator->create_question_category();
$question1 = $generator->create_question('shortanswer', null, ['category' => $cat->id]); $question1 = $generator->create_question('shortanswer', null, ['category' => $cat->id]);
$loader = new \core_question\local\bank\random_question_loader(new qubaid_list([])); $loader = new random_question_loader(new qubaid_list([]));
$filters = question_filter_test_helper::create_filters([$cat->id], 1); $filters = question_filter_test_helper::create_filters([$cat->id], 1);
$this->assertEquals($question1->id, $loader->get_next_filtered_question_id($filters)); $this->assertEquals($question1->id, $loader->get_next_filtered_question_id($filters));
@ -129,14 +135,14 @@ class random_question_loader_test extends \advanced_testcase {
$this->assertNull($loader->get_next_filtered_question_id($filters)); $this->assertNull($loader->get_next_filtered_question_id($filters));
} }
public function test_two_question_category_returns_both_then_null() { public function test_two_question_category_returns_both_then_null(): void {
$this->resetAfterTest(); $this->resetAfterTest();
$generator = $this->getDataGenerator()->get_plugin_generator('core_question'); $generator = $this->getDataGenerator()->get_plugin_generator('core_question');
$cat = $generator->create_question_category(); $cat = $generator->create_question_category();
$question1 = $generator->create_question('shortanswer', null, ['category' => $cat->id]); $question1 = $generator->create_question('shortanswer', null, ['category' => $cat->id]);
$question2 = $generator->create_question('shortanswer', null, ['category' => $cat->id]); $question2 = $generator->create_question('shortanswer', null, ['category' => $cat->id]);
$loader = new \core_question\local\bank\random_question_loader(new qubaid_list([])); $loader = new random_question_loader(new qubaid_list([]));
$questionids = []; $questionids = [];
$filters = question_filter_test_helper::create_filters([$cat->id]); $filters = question_filter_test_helper::create_filters([$cat->id]);
@ -149,7 +155,7 @@ class random_question_loader_test extends \advanced_testcase {
$this->assertNull($loader->get_next_filtered_question_id($filters)); $this->assertNull($loader->get_next_filtered_question_id($filters));
} }
public function test_nested_categories() { public function test_nested_categories(): void {
$this->resetAfterTest(); $this->resetAfterTest();
$generator = $this->getDataGenerator()->get_plugin_generator('core_question'); $generator = $this->getDataGenerator()->get_plugin_generator('core_question');
@ -157,7 +163,7 @@ class random_question_loader_test extends \advanced_testcase {
$cat2 = $generator->create_question_category(['parent' => $cat1->id]); $cat2 = $generator->create_question_category(['parent' => $cat1->id]);
$question1 = $generator->create_question('shortanswer', null, ['category' => $cat1->id]); $question1 = $generator->create_question('shortanswer', null, ['category' => $cat1->id]);
$question2 = $generator->create_question('shortanswer', null, ['category' => $cat2->id]); $question2 = $generator->create_question('shortanswer', null, ['category' => $cat2->id]);
$loader = new \core_question\local\bank\random_question_loader(new qubaid_list([])); $loader = new random_question_loader(new qubaid_list([]));
$filters = question_filter_test_helper::create_filters([$cat2->id], 1); $filters = question_filter_test_helper::create_filters([$cat2->id], 1);
$this->assertEquals($question2->id, $loader->get_next_filtered_question_id($filters)); $this->assertEquals($question2->id, $loader->get_next_filtered_question_id($filters));
@ -168,22 +174,22 @@ class random_question_loader_test extends \advanced_testcase {
$this->assertNull($loader->get_next_filtered_question_id($filters)); $this->assertNull($loader->get_next_filtered_question_id($filters));
} }
public function test_used_question_not_returned_until_later() { public function test_used_question_not_returned_until_later(): void {
$this->resetAfterTest(); $this->resetAfterTest();
$generator = $this->getDataGenerator()->get_plugin_generator('core_question'); $generator = $this->getDataGenerator()->get_plugin_generator('core_question');
$cat = $generator->create_question_category(); $cat = $generator->create_question_category();
$question1 = $generator->create_question('shortanswer', null, ['category' => $cat->id]); $question1 = $generator->create_question('shortanswer', null, ['category' => $cat->id]);
$question2 = $generator->create_question('shortanswer', null, ['category' => $cat->id]); $question2 = $generator->create_question('shortanswer', null, ['category' => $cat->id]);
$loader = new \core_question\local\bank\random_question_loader(new qubaid_list([]), $loader = new random_question_loader(new qubaid_list([]),
array($question2->id => 2)); [$question2->id => 2]);
$filters = question_filter_test_helper::create_filters([$cat->id]); $filters = question_filter_test_helper::create_filters([$cat->id]);
$this->assertEquals($question1->id, $loader->get_next_filtered_question_id($filters)); $this->assertEquals($question1->id, $loader->get_next_filtered_question_id($filters));
$this->assertNull($loader->get_next_filtered_question_id($filters)); $this->assertNull($loader->get_next_filtered_question_id($filters));
} }
public function test_previously_used_question_not_returned_until_later() { public function test_previously_used_question_not_returned_until_later(): void {
$this->resetAfterTest(); $this->resetAfterTest();
$generator = $this->getDataGenerator()->get_plugin_generator('core_question'); $generator = $this->getDataGenerator()->get_plugin_generator('core_question');
@ -198,7 +204,7 @@ class random_question_loader_test extends \advanced_testcase {
$quba->start_all_questions(); $quba->start_all_questions();
question_engine::save_questions_usage_by_activity($quba); question_engine::save_questions_usage_by_activity($quba);
$loader = new \core_question\local\bank\random_question_loader(new qubaid_list(array($quba->get_id()))); $loader = new random_question_loader(new qubaid_list([$quba->get_id()]));
$filters = question_filter_test_helper::create_filters([$cat->id]); $filters = question_filter_test_helper::create_filters([$cat->id]);
$this->assertEquals($question1->id, $loader->get_next_filtered_question_id($filters)); $this->assertEquals($question1->id, $loader->get_next_filtered_question_id($filters));
@ -206,12 +212,12 @@ class random_question_loader_test extends \advanced_testcase {
$this->assertNull($loader->get_next_filtered_question_id($filters)); $this->assertNull($loader->get_next_filtered_question_id($filters));
} }
public function test_empty_category_does_not_have_question_available() { public function test_empty_category_does_not_have_question_available(): void {
$this->resetAfterTest(); $this->resetAfterTest();
$generator = $this->getDataGenerator()->get_plugin_generator('core_question'); $generator = $this->getDataGenerator()->get_plugin_generator('core_question');
$cat = $generator->create_question_category(); $cat = $generator->create_question_category();
$loader = new \core_question\local\bank\random_question_loader(new qubaid_list(array())); $loader = new random_question_loader(new qubaid_list([]));
$filters = question_filter_test_helper::create_filters([$cat->id]); $filters = question_filter_test_helper::create_filters([$cat->id]);
$this->assertFalse($loader->is_filtered_question_available($filters, 1)); $this->assertFalse($loader->is_filtered_question_available($filters, 1));
@ -219,13 +225,13 @@ class random_question_loader_test extends \advanced_testcase {
$this->assertFalse($loader->is_filtered_question_available($filters, 1)); $this->assertFalse($loader->is_filtered_question_available($filters, 1));
} }
public function test_descriptions_not_available() { public function test_descriptions_not_available(): void {
$this->resetAfterTest(); $this->resetAfterTest();
$generator = $this->getDataGenerator()->get_plugin_generator('core_question'); $generator = $this->getDataGenerator()->get_plugin_generator('core_question');
$cat = $generator->create_question_category(); $cat = $generator->create_question_category();
$info = $generator->create_question('description', null, array('category' => $cat->id)); $info = $generator->create_question('description', null, ['category' => $cat->id]);
$loader = new \core_question\local\bank\random_question_loader(new qubaid_list(array())); $loader = new random_question_loader(new qubaid_list([]));
$filters = question_filter_test_helper::create_filters([$cat->id]); $filters = question_filter_test_helper::create_filters([$cat->id]);
$this->assertFalse($loader->is_filtered_question_available($filters, $info->id)); $this->assertFalse($loader->is_filtered_question_available($filters, $info->id));
@ -233,13 +239,13 @@ class random_question_loader_test extends \advanced_testcase {
$this->assertFalse($loader->is_filtered_question_available($filters, $info->id)); $this->assertFalse($loader->is_filtered_question_available($filters, $info->id));
} }
public function test_existing_question_is_available_but_then_marked_used() { public function test_existing_question_is_available_but_then_marked_used(): void {
$this->resetAfterTest(); $this->resetAfterTest();
$generator = $this->getDataGenerator()->get_plugin_generator('core_question'); $generator = $this->getDataGenerator()->get_plugin_generator('core_question');
$cat = $generator->create_question_category(); $cat = $generator->create_question_category();
$question1 = $generator->create_question('shortanswer', null, array('category' => $cat->id)); $question1 = $generator->create_question('shortanswer', null, ['category' => $cat->id]);
$loader = new \core_question\local\bank\random_question_loader(new qubaid_list(array())); $loader = new random_question_loader(new qubaid_list([]));
$filters = question_filter_test_helper::create_filters([$cat->id]); $filters = question_filter_test_helper::create_filters([$cat->id]);
$this->assertTrue($loader->is_filtered_question_available($filters, $question1->id)); $this->assertTrue($loader->is_filtered_question_available($filters, $question1->id));
@ -250,8 +256,10 @@ class random_question_loader_test extends \advanced_testcase {
/** /**
* Data provider for the get_questions test. * Data provider for the get_questions test.
*
* @return array testcases.
*/ */
public function get_questions_test_cases() { public static function get_questions_test_cases(): array {
return [ return [
'empty category' => [ 'empty category' => [
'categoryindex' => 'emptycat', 'categoryindex' => 'emptycat',
@ -334,7 +342,7 @@ class random_question_loader_test extends \advanced_testcase {
$includesubcategories, $includesubcategories,
$usetagnames, $usetagnames,
$expectedquestionindexes $expectedquestionindexes
) { ): void {
$this->resetAfterTest(); $this->resetAfterTest();
$categories = []; $categories = [];
@ -350,22 +358,22 @@ class random_question_loader_test extends \advanced_testcase {
$generator = $this->getDataGenerator()->get_plugin_generator('core_question'); $generator = $this->getDataGenerator()->get_plugin_generator('core_question');
// First category and questions. // First category and questions.
list($category, $categoryquestions) = $this->create_category_and_questions(2, ['cat1', 'foo']); [$category, $categoryquestions] = $this->create_category_and_questions(2, ['cat1', 'foo']);
$categories['cat1'] = $category; $categories['cat1'] = $category;
$questions['cat1q1'] = $categoryquestions[0]; $questions['cat1q1'] = $categoryquestions[0];
$questions['cat1q2'] = $categoryquestions[1]; $questions['cat1q2'] = $categoryquestions[1];
// Second category and questions. // Second category and questions.
list($category, $categoryquestions) = $this->create_category_and_questions(2, ['cat2', 'foo']); [$category, $categoryquestions] = $this->create_category_and_questions(2, ['cat2', 'foo']);
$categories['cat2'] = $category; $categories['cat2'] = $category;
$questions['cat2q1'] = $categoryquestions[0]; $questions['cat2q1'] = $categoryquestions[0];
$questions['cat2q2'] = $categoryquestions[1]; $questions['cat2q2'] = $categoryquestions[1];
// Sub category and questions. // Sub category and questions.
list($category, $categoryquestions) = $this->create_category_and_questions(2, ['subcat', 'foo'], $categories['cat1']); [$category, $categoryquestions] = $this->create_category_and_questions(2, ['subcat', 'foo'], $categories['cat1']);
$categories['subcat'] = $category; $categories['subcat'] = $category;
$questions['subcatq1'] = $categoryquestions[0]; $questions['subcatq1'] = $categoryquestions[0];
$questions['subcatq2'] = $categoryquestions[1]; $questions['subcatq2'] = $categoryquestions[1];
// Empty category. // Empty category.
list($category, $categoryquestions) = $this->create_category_and_questions(0); [$category, $categoryquestions] = $this->create_category_and_questions(0);
$categories['emptycat'] = $category; $categories['emptycat'] = $category;
// Generate the arguments for the get_questions function. // Generate the arguments for the get_questions function.
@ -374,7 +382,7 @@ class random_question_loader_test extends \advanced_testcase {
return $tags[$tagname]->id; return $tags[$tagname]->id;
}, $usetagnames); }, $usetagnames);
$loader = new \core_question\local\bank\random_question_loader(new qubaid_list([])); $loader = new random_question_loader(new qubaid_list([]));
$filters = question_filter_test_helper::create_filters([$category->id], $includesubcategories, $tagids); $filters = question_filter_test_helper::create_filters([$category->id], $includesubcategories, $tagids);
$result = $loader->get_filtered_questions($filters); $result = $loader->get_filtered_questions($filters);
// Generate the expected question set. // Generate the expected question set.
@ -393,15 +401,15 @@ class random_question_loader_test extends \advanced_testcase {
/** /**
* get_questions should allow limiting and offsetting of the result set. * get_questions should allow limiting and offsetting of the result set.
*/ */
public function test_get_questions_with_limit_and_offset() { public function test_get_questions_with_limit_and_offset(): void {
$this->resetAfterTest(); $this->resetAfterTest();
$numberofquestions = 5; $numberofquestions = 5;
$includesubcategories = false; $includesubcategories = false;
$tagids = []; $tagids = [];
$limit = 1; $limit = 1;
$offset = 0; $offset = 0;
$loader = new \core_question\local\bank\random_question_loader(new qubaid_list([])); $loader = new random_question_loader(new qubaid_list([]));
list($category, $questions) = $this->create_category_and_questions($numberofquestions); [$category, $questions] = $this->create_category_and_questions($numberofquestions);
// Add questionid as key to find them easily later. // Add questionid as key to find them easily later.
$questionsbyid = []; $questionsbyid = [];
@ -428,15 +436,15 @@ class random_question_loader_test extends \advanced_testcase {
* get_questions should allow retrieving questions with only a subset of * get_questions should allow retrieving questions with only a subset of
* fields populated. * fields populated.
*/ */
public function test_get_questions_with_restricted_fields() { public function test_get_questions_with_restricted_fields(): void {
$this->resetAfterTest(); $this->resetAfterTest();
$includesubcategories = false; $includesubcategories = false;
$tagids = []; $tagids = [];
$limit = 10; $limit = 10;
$offset = 0; $offset = 0;
$fields = ['id', 'name']; $fields = ['id', 'name'];
$loader = new \core_question\local\bank\random_question_loader(new qubaid_list([])); $loader = new random_question_loader(new qubaid_list([]));
list($category, $questions) = $this->create_category_and_questions(1); [$category, $questions] = $this->create_category_and_questions(1);
$filters = question_filter_test_helper::create_filters([$category->id], $includesubcategories, $tagids); $filters = question_filter_test_helper::create_filters([$category->id], $includesubcategories, $tagids);
$result = $loader->get_filtered_questions( $result = $loader->get_filtered_questions(
@ -458,8 +466,10 @@ class random_question_loader_test extends \advanced_testcase {
/** /**
* Data provider for the count_questions test. * Data provider for the count_questions test.
*
* @return array testcases.
*/ */
public function count_questions_test_cases() { public static function count_questions_test_cases(): array {
return [ return [
'empty category' => [ 'empty category' => [
'categoryindex' => 'emptycat', 'categoryindex' => 'emptycat',
@ -542,7 +552,7 @@ class random_question_loader_test extends \advanced_testcase {
$includesubcategories, $includesubcategories,
$usetagnames, $usetagnames,
$expectedcount $expectedcount
) { ): void {
$this->resetAfterTest(); $this->resetAfterTest();
$categories = []; $categories = [];
@ -558,22 +568,22 @@ class random_question_loader_test extends \advanced_testcase {
$generator = $this->getDataGenerator()->get_plugin_generator('core_question'); $generator = $this->getDataGenerator()->get_plugin_generator('core_question');
// First category and questions. // First category and questions.
list($category, $categoryquestions) = $this->create_category_and_questions(2, ['cat1', 'foo']); [$category, $categoryquestions] = $this->create_category_and_questions(2, ['cat1', 'foo']);
$categories['cat1'] = $category; $categories['cat1'] = $category;
$questions['cat1q1'] = $categoryquestions[0]; $questions['cat1q1'] = $categoryquestions[0];
$questions['cat1q2'] = $categoryquestions[1]; $questions['cat1q2'] = $categoryquestions[1];
// Second category and questions. // Second category and questions.
list($category, $categoryquestions) = $this->create_category_and_questions(2, ['cat2', 'foo']); [$category, $categoryquestions] = $this->create_category_and_questions(2, ['cat2', 'foo']);
$categories['cat2'] = $category; $categories['cat2'] = $category;
$questions['cat2q1'] = $categoryquestions[0]; $questions['cat2q1'] = $categoryquestions[0];
$questions['cat2q2'] = $categoryquestions[1]; $questions['cat2q2'] = $categoryquestions[1];
// Sub category and questions. // Sub category and questions.
list($category, $categoryquestions) = $this->create_category_and_questions(2, ['subcat', 'foo'], $categories['cat1']); [$category, $categoryquestions] = $this->create_category_and_questions(2, ['subcat', 'foo'], $categories['cat1']);
$categories['subcat'] = $category; $categories['subcat'] = $category;
$questions['subcatq1'] = $categoryquestions[0]; $questions['subcatq1'] = $categoryquestions[0];
$questions['subcatq2'] = $categoryquestions[1]; $questions['subcatq2'] = $categoryquestions[1];
// Empty category. // Empty category.
list($category, $categoryquestions) = $this->create_category_and_questions(0); [$category, $categoryquestions] = $this->create_category_and_questions(0);
$categories['emptycat'] = $category; $categories['emptycat'] = $category;
// Generate the arguments for the get_questions function. // Generate the arguments for the get_questions function.
@ -583,7 +593,7 @@ class random_question_loader_test extends \advanced_testcase {
}, $usetagnames); }, $usetagnames);
$filters = question_filter_test_helper::create_filters([$category->id], $includesubcategories, $tagids); $filters = question_filter_test_helper::create_filters([$category->id], $includesubcategories, $tagids);
$loader = new \core_question\local\bank\random_question_loader(new qubaid_list([])); $loader = new random_question_loader(new qubaid_list([]));
$result = $loader->count_filtered_questions($filters); $result = $loader->count_filtered_questions($filters);
// Ensure the result matches what was expected. // Ensure the result matches what was expected.
@ -599,7 +609,7 @@ class random_question_loader_test extends \advanced_testcase {
* @param stdClass|null $parentcategory The category to set as the parent of the created category. * @param stdClass|null $parentcategory The category to set as the parent of the created category.
* @return array The category and questions. * @return array The category and questions.
*/ */
protected function create_category_and_questions($questioncount, $tagnames = [], $parentcategory = null) { protected function create_category_and_questions($questioncount, $tagnames = [], $parentcategory = null): array {
$generator = $this->getDataGenerator()->get_plugin_generator('core_question'); $generator = $this->getDataGenerator()->get_plugin_generator('core_question');
if ($parentcategory) { if ($parentcategory) {