MDL-66899 quiz: Adding test for regrading quiz event.

This commit is contained in:
Russell Boyatt
2020-06-09 09:50:34 +01:00
parent fad72d7177
commit 8a2d8ec472
+36
View File
@@ -749,4 +749,40 @@ class mod_quiz_events_testcase extends advanced_testcase {
$this->assertEventLegacyLogData($expected, $event);
$this->assertEventContextNotUsed($event);
}
/**
* Test the attempt regraded event.
*
* There is no external API for regrading attempts, so the unit test will simply
* create and trigger the event and ensure the event data is returned as expected.
*/
public function test_attempt_regraded() {
$this->resetAfterTest();
$this->setAdminUser();
$course = $this->getDataGenerator()->create_course();
$quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id));
$params = array(
'objectid' => 1,
'relateduserid' => 2,
'courseid' => $course->id,
'context' => context_module::instance($quiz->cmid),
'other' => array(
'quizid' => $quiz->id
)
);
$event = \mod_quiz\event\attempt_regraded::create($params);
// Trigger and capture the event.
$sink = $this->redirectEvents();
$event->trigger();
$events = $sink->get_events();
$event = reset($events);
// Check that the event data is valid.
$this->assertInstanceOf('\mod_quiz\event\attempt_regraded', $event);
$this->assertEquals(context_module::instance($quiz->cmid), $event->get_context());
$this->assertEventContextNotUsed($event);
}
}