/** * Test the stats report viewed event. * * It's not possible to use the moodle API to simulate the viewing of stats report, so here we * simply create the event and trigger it. */ public function test_report_viewed() { $user = $this->getDataGenerator()->create_user(); $course = $this->getDataGenerator()->create_course(); $context = context_course::instance($course->id); // Trigger event for stats report viewed. $event = \report_stats\event\report_viewed::create(array('context' => $context, 'relateduserid' => $user->id, 'other' => array('report' => 0, 'time' => 0, 'mode' => 1))); // Trigger and capture the event. $sink = $this->redirectEvents(); $event->trigger(); $events = $sink->get_events(); $event = reset($events); $this->assertInstanceOf('\\report_stats\\event\\report_viewed', $event); $this->assertEquals($context, $event->get_context()); $expected = array($course->id, "course", "report stats", "report/stats/index.php?course={$course->id}", $course->id); $this->assertEventLegacyLogData($expected, $event); $this->assertEventContextNotUsed($event); }
} if (!($course = $DB->get_record("course", array("id" => $courseid)))) { print_error("invalidcourseid"); } if (!empty($userid)) { $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST); } else { $user = null; } require_login($course); $context = context_course::instance($course->id); require_capability('report/stats:view', $context); $PAGE->set_url(new moodle_url('/report/stats/index.php', array('course' => $course->id, 'report' => $report, 'time' => $time, 'mode' => $mode, 'userid' => $userid))); navigation_node::override_active_url(new moodle_url('/report/stats/index.php', array('course' => $course->id))); // Trigger a content view event. $event = \report_stats\event\report_viewed::create(array('context' => $context, 'relateduserid' => $userid, 'other' => array('report' => $report, 'time' => $time, 'mode' => $mode))); $event->trigger(); stats_check_uptodate($course->id); if ($course->id == SITEID) { admin_externalpage_setup('reportstats', '', null, '', array('pagelayout' => 'report')); echo $OUTPUT->header(); } else { $strreports = get_string("reports"); $strstats = get_string('stats'); $PAGE->set_title("{$course->shortname}: {$strstats}"); $PAGE->set_heading($course->fullname); $PAGE->set_pagelayout('report'); $PAGE->set_headingmenu(report_stats_mode_menu($course, $mode, $time, "{$CFG->wwwroot}/report/stats/index.php")); echo $OUTPUT->header(); } report_stats_report($course, $report, $mode, $user, $roleid, $time);