/** * Test to ensure that event data is being stored correctly. */ public function test_course_module_instance_list_viewed_viewed() { global $USER; // Not much can be tested here as the event is only triggered on a page load, // let's just check that the event contains the expected basic information. $this->setAdminUser(); $params = array('context' => context_course::instance($this->course->id)); $event = \mod_choice\event\course_module_instance_list_viewed::create($params); $sink = $this->redirectEvents(); $event->trigger(); $events = $sink->get_events(); $event = reset($events); $this->assertInstanceOf('\\mod_choice\\event\\course_module_instance_list_viewed', $event); $this->assertEquals($USER->id, $event->userid); $this->assertEquals(context_course::instance($this->course->id), $event->get_context()); $expected = array($this->course->id, 'choice', 'view all', 'index.php?id=' . $this->course->id, ''); $this->assertEventLegacyLogData($expected, $event); $this->assertEventContextNotUsed($event); }
<?php require_once "../../config.php"; require_once "lib.php"; $id = required_param('id', PARAM_INT); // course $PAGE->set_url('/mod/choice/index.php', array('id' => $id)); if (!($course = $DB->get_record('course', array('id' => $id)))) { print_error('invalidcourseid'); } require_course_login($course); $PAGE->set_pagelayout('incourse'); $eventdata = array('context' => context_course::instance($id)); $event = \mod_choice\event\course_module_instance_list_viewed::create($eventdata); $event->add_record_snapshot('course', $course); $event->trigger(); $strchoice = get_string("modulename", "choice"); $strchoices = get_string("modulenameplural", "choice"); $PAGE->set_title($strchoices); $PAGE->set_heading($course->fullname); $PAGE->navbar->add($strchoices); echo $OUTPUT->header(); if (!($choices = get_all_instances_in_course("choice", $course))) { notice(get_string('thereareno', 'moodle', $strchoices), "../../course/view.php?id={$course->id}"); } $usesections = course_format_uses_sections($course->format); $sql = "SELECT cha.*\n FROM {choice} ch, {choice_answers} cha\n WHERE cha.choiceid = ch.id AND\n ch.course = ? AND cha.userid = ?"; $answers = array(); if (isloggedin() and !isguestuser() and $allanswers = $DB->get_records_sql($sql, array($course->id, $USER->id))) { foreach ($allanswers as $aa) { $answers[$aa->choiceid] = $aa;