mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
MDL-71696 question: Fix random PHPUnit error with question order
This commit is contained in:
parent
9cc81bb7bf
commit
de83532bfa
@ -374,16 +374,10 @@ class random_question_loader_testcase extends advanced_testcase {
|
||||
$loader = new \core_question\local\bank\random_question_loader(new qubaid_list([]));
|
||||
list($category, $questions) = $this->create_category_and_questions($numberofquestions);
|
||||
|
||||
// Sort the questions by id to match the ordering of the get_questions
|
||||
// function.
|
||||
usort($questions, function($a, $b) {
|
||||
$aid = $a->id;
|
||||
$bid = $b->id;
|
||||
|
||||
if ($aid == $bid) {
|
||||
return 0;
|
||||
}
|
||||
return $aid < $bid ? -1 : 1;
|
||||
// Add questionid as key to find them easily later.
|
||||
$questionsbyid = [];
|
||||
array_walk($questions, function (&$value) use (&$questionsbyid) {
|
||||
$questionsbyid[$value->id] = $value;
|
||||
});
|
||||
|
||||
for ($i = 0; $i < $numberofquestions; $i++) {
|
||||
@ -397,7 +391,7 @@ class random_question_loader_testcase extends advanced_testcase {
|
||||
|
||||
$this->assertCount($limit, $result);
|
||||
$actual = array_shift($result);
|
||||
$expected = $questions[$i];
|
||||
$expected = $questionsbyid[$actual->id];
|
||||
$this->assertEquals($expected->id, $actual->id);
|
||||
$offset++;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user