/** * Test the edit page viewed event. * * There is no external API for updating a quiz, so the unit test will simply * create and trigger the event and ensure the event data is returned as expected. */ public function test_edit_page_viewed() { $this->resetAfterTest(); $this->setAdminUser(); $course = $this->getDataGenerator()->create_course(); $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id)); $params = array('courseid' => $course->id, 'context' => context_module::instance($quiz->cmid), 'other' => array('quizid' => $quiz->id)); $event = \mod_quiz\event\edit_page_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\\edit_page_viewed', $event); $this->assertEquals(context_module::instance($quiz->cmid), $event->get_context()); $expected = array($course->id, 'quiz', 'editquestions', 'view.php?id=' . $quiz->cmid, $quiz->id, $quiz->cmid); $this->assertEventLegacyLogData($expected, $event); $this->assertEventContextNotUsed($event); }
// this page otherwise they would go in question_edit_setup. $scrollpos = optional_param('scrollpos', '', PARAM_INT); list($thispageurl, $contexts, $cmid, $cm, $quiz, $pagevars) = question_edit_setup('editq', '/mod/quiz/edit.php', true); $defaultcategoryobj = question_make_default_categories($contexts->all()); $defaultcategory = $defaultcategoryobj->id . ',' . $defaultcategoryobj->contextid; $quizhasattempts = quiz_has_attempts($quiz->id); $PAGE->set_url($thispageurl); // Get the course object and related bits. $course = $DB->get_record('course', array('id' => $quiz->course), '*', MUST_EXIST); $quizobj = new quiz($quiz, $cm, $course); $structure = $quizobj->get_structure(); // You need mod/quiz:manage in addition to question capabilities to access this page. require_capability('mod/quiz:manage', $contexts->lowest()); // Log this visit. $params = array('courseid' => $course->id, 'context' => $contexts->lowest(), 'other' => array('quizid' => $quiz->id)); $event = \mod_quiz\event\edit_page_viewed::create($params); $event->trigger(); // Process commands ============================================================. // Get the list of question ids had their check-boxes ticked. $selectedslots = array(); $params = (array) data_submitted(); foreach ($params as $key => $value) { if (preg_match('!^s([0-9]+)$!', $key, $matches)) { $selectedslots[] = $matches[1]; } } $afteractionurl = new moodle_url($thispageurl); if ($scrollpos) { $afteractionurl->param('scrollpos', $scrollpos); } if (optional_param('repaginate', false, PARAM_BOOL) && confirm_sesskey()) {