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 { $params['other']['groupid'] = $fromform->groupid; $event = \mod_quiz\event\group_override_created::create($params); }
/** * Test the group override updated event. * * There is no external API for updating a group override, so the unit test will simply * create and trigger the event and ensure the event data is returned as expected. */ public function test_group_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, 'context' => context_module::instance($quiz->cmid), 'other' => array('quizid' => $quiz->id, 'groupid' => 2)); $event = \mod_quiz\event\group_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\\group_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); }