MDL-45803 mod_quiz: removed usage of the function quiz_fire_attempt_started_event
authorMark Nelson <markn@moodle.com>
Mon, 9 Jun 2014 22:58:14 +0000 (15:58 -0700)
committerMark Nelson <markn@moodle.com>
Wed, 11 Jun 2014 20:53:03 +0000 (13:53 -0700)
mod/quiz/tests/events_test.php

index 6c70949..4ea32ec 100644 (file)
@@ -190,39 +190,7 @@ class mod_quiz_events_testcase extends advanced_testcase {
     }
 
     public function test_attempt_started() {
-        global $USER;
-
         list($quizobj, $quba, $attempt) = $this->prepare_quiz_data();
-        $attemptobj = quiz_attempt::create($attempt->id);
-
-        // Catch the event.
-        $sink = $this->redirectEvents();
-        quiz_fire_attempt_started_event($attempt, $quizobj);
-        $events = $sink->get_events();
-        $sink->close();
-
-        // Legacy event data.
-        $legacydata = new stdClass();
-        $legacydata->component = 'mod_quiz';
-        $legacydata->attemptid = $attempt->id;
-        $legacydata->timestart = $attempt->timestart;
-        $legacydata->timestamp = $attempt->timestart;
-        $legacydata->userid = $attempt->userid;
-        $legacydata->quizid = $quizobj->get_quizid();
-        $legacydata->cmid = $quizobj->get_cmid();
-        $legacydata->courseid = $quizobj->get_courseid();
-
-        // Validate the event.
-        $this->assertCount(1, $events);
-        $event = $events[0];
-        $this->assertInstanceOf('\mod_quiz\event\attempt_started', $event);
-        $this->assertEquals('quiz_attempts', $event->objecttable);
-        $this->assertEquals($attempt->id, $event->objectid);
-        $this->assertEquals($attempt->userid, $event->relateduserid);
-        $this->assertEquals($quizobj->get_context(), $event->get_context());
-        $this->assertEquals('quiz_attempt_started', $event->get_legacy_eventname());
-        $this->assertEventLegacyData($legacydata, $event);
-        $this->assertEventContextNotUsed($event);
 
         // Create another attempt.
         $attempt = quiz_create_attempt($quizobj, 1, false, time(), false, 2);
@@ -235,10 +203,28 @@ class mod_quiz_events_testcase extends advanced_testcase {
 
         // Check that the event data is valid.
         $this->assertInstanceOf('\mod_quiz\event\attempt_started', $event);
+        $this->assertEquals('quiz_attempts', $event->objecttable);
+        $this->assertEquals($attempt->id, $event->objectid);
+        $this->assertEquals($attempt->userid, $event->relateduserid);
+        $this->assertEquals($quizobj->get_context(), $event->get_context());
+        $this->assertEquals('quiz_attempt_started', $event->get_legacy_eventname());
         $this->assertEquals(context_module::instance($quizobj->get_cmid()), $event->get_context());
+        // Check legacy log data.
         $expected = array($quizobj->get_courseid(), 'quiz', 'attempt', 'review.php?attempt=' . $attempt->id,
             $quizobj->get_quizid(), $quizobj->get_cmid());
         $this->assertEventLegacyLogData($expected, $event);
+        // Check legacy event data.
+        $legacydata = new stdClass();
+        $legacydata->component = 'mod_quiz';
+        $legacydata->attemptid = $attempt->id;
+        $legacydata->timestart = $attempt->timestart;
+        $legacydata->timestamp = $attempt->timestart;
+        $legacydata->userid = $attempt->userid;
+        $legacydata->quizid = $quizobj->get_quizid();
+        $legacydata->cmid = $quizobj->get_cmid();
+        $legacydata->courseid = $quizobj->get_courseid();
+        $this->assertEventLegacyData($legacydata, $event);
+        $this->assertEventContextNotUsed($event);
     }
 
     /**