Exemple #1
0
         }
         // Set the course module id before calling quiz_delete_override().
         $quiz->cmid = $cm->id;
         quiz_delete_override($quiz, $oldoverride->id);
     }
 }
 // Set the common parameters for one of the events we may be triggering.
 $params = array('context' => $context, 'other' => array('quizid' => $quiz->id));
 if (!empty($override->id)) {
     $fromform->id = $override->id;
     $DB->update_record('quiz_overrides', $fromform);
     // Determine which override updated event to fire.
     $params['objectid'] = $override->id;
     if (!$groupmode) {
         $params['relateduserid'] = $fromform->userid;
         $event = \mod_quiz\event\user_override_updated::create($params);
     } else {
         $params['other']['groupid'] = $fromform->groupid;
         $event = \mod_quiz\event\group_override_updated::create($params);
     }
     // Trigger the override updated event.
     $event->trigger();
 } else {
     unset($fromform->id);
     $fromform->id = $DB->insert_record('quiz_overrides', $fromform);
     // Determine which override created event to fire.
     $params['objectid'] = $fromform->id;
     if (!$groupmode) {
         $params['relateduserid'] = $fromform->userid;
         $event = \mod_quiz\event\user_override_created::create($params);
     } else {
 /**
  * Test the user override updated event.
  *
  * There is no external API for updating a user override, so the unit test will simply
  * create and trigger the event and ensure the event data is returned as expected.
  */
 public function test_user_override_updated()
 {
     $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, 'context' => context_module::instance($quiz->cmid), 'other' => array('quizid' => $quiz->id));
     $event = \mod_quiz\event\user_override_updated::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\\user_override_updated', $event);
     $this->assertEquals(context_module::instance($quiz->cmid), $event->get_context());
     $expected = array($course->id, 'quiz', 'edit override', 'overrideedit.php?id=1', $quiz->id, $quiz->cmid);
     $this->assertEventLegacyLogData($expected, $event);
     $this->assertEventContextNotUsed($event);
 }