Skip to content

Commit

Permalink
MDL-80718 quiz: Apply overrides in mod_quiz_get_combined_review_options
Browse files Browse the repository at this point in the history
  • Loading branch information
dpalou committed Jan 25, 2024
1 parent 72c1d19 commit 9f09e25
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mod/quiz/classes/external.php
Expand Up @@ -636,6 +636,8 @@ public static function get_combined_review_options($quizid, $userid = 0) {
require_capability('mod/quiz:viewreports', $context);
}

// Update quiz with override information.
$quiz = quiz_update_effective_access($quiz, $params['userid']);
$attempts = quiz_get_user_attempts($quiz->id, $user->id, 'all', true);

$result = [];
Expand Down
77 changes: 77 additions & 0 deletions mod/quiz/tests/external/external_test.php
Expand Up @@ -844,6 +844,83 @@ public function test_get_combined_review_options() {
}
}

/**
* Test get_combined_review_options when the user has an override.
*
* @covers ::get_combined_review_options
* @covers ::get_combined_review_options_parameters
* @covers ::get_combined_review_options_returns
*/
public function test_get_combined_review_options_with_overrides(): void {
global $DB;

// Create a closed quiz with review marks only when quiz is closed.
list($quiz, $context, $quizobj) = $this->create_quiz_with_questions(true, true, 'deferredfeedback', false, [
'timeclose' => time() - HOURSECS,
'marksduring' => 0,
'marksimmediately' => 0,
'marksopen' => 0,
'marksclosed' => 1,
]);

// Check that the student can see the marks because the quiz is closed.
$this->setUser($this->student);

$expected = [
"someoptions" => [
["name" => "feedback", "value" => 1],
["name" => "generalfeedback", "value" => 1],
["name" => "rightanswer", "value" => 1],
["name" => "overallfeedback", "value" => 1],
["name" => "marks", "value" => 2],
],
"alloptions" => [
["name" => "feedback", "value" => 1],
["name" => "generalfeedback", "value" => 1],
["name" => "rightanswer", "value" => 1],
["name" => "overallfeedback", "value" => 1],
["name" => "marks", "value" => 2],
],
"warnings" => [],
];

$result = mod_quiz_external::get_combined_review_options($quiz->id);
$result = external_api::clean_returnvalue(mod_quiz_external::get_combined_review_options_returns(), $result);

$this->assertEquals($expected, $result);

// Add an override for the student to increase the close time.
$DB->insert_record('quiz_overrides', [
'quiz' => $quiz->id,
'userid' => $this->student->id,
'timeclose' => time() + HOURSECS,
]);

// Check that now the marks option has changed.
$expected = [
"someoptions" => [
["name" => "feedback", "value" => 1],
["name" => "generalfeedback", "value" => 1],
["name" => "rightanswer", "value" => 1],
["name" => "overallfeedback", "value" => 1],
["name" => "marks", "value" => 1],
],
"alloptions" => [
["name" => "feedback", "value" => 1],
["name" => "generalfeedback", "value" => 1],
["name" => "rightanswer", "value" => 1],
["name" => "overallfeedback", "value" => 1],
["name" => "marks", "value" => 1],
],
"warnings" => [],
];

$result = mod_quiz_external::get_combined_review_options($quiz->id);
$result = external_api::clean_returnvalue(mod_quiz_external::get_combined_review_options_returns(), $result);

$this->assertEquals($expected, $result);
}

/**
* Test start_attempt
*/
Expand Down

0 comments on commit 9f09e25

Please sign in to comment.