MDL-40063 mod_quiz: replaced 'continue attempt' add_to_log call with an event

This commit is contained in:
Mark Nelson 2013-11-21 16:18:10 -08:00
parent 8de2eb3582
commit e0114708af
4 changed files with 152 additions and 3 deletions

View file

@ -531,4 +531,42 @@ class mod_quiz_events_testcase extends advanced_testcase {
$this->assertEventLegacyLogData($expected, $event);
$this->assertEventContextNotUsed($event);
}
/**
* Test the attempt viewed event.
*
* There is no external API for continuing an attempt, so the unit test will simply
* create and trigger the event and ensure the event data is returned as expected.
*/
public function test_attempt_viewed() {
$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_viewed::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_viewed', $event);
$this->assertEquals(context_module::instance($quiz->cmid), $event->get_context());
$expected = array($course->id, 'quiz', 'continue attempt', 'review.php?attempt=1', $quiz->id, $quiz->cmid);
$this->assertEventLegacyLogData($expected, $event);
$this->assertEventContextNotUsed($event);
}
}