require_login($course, false, $cm); if (empty($chat->studentlogs) && !has_capability('mod/chat:readlog', $context)) { notice(get_string('nopermissiontoseethechatlog', 'chat')); } $params = array( 'context' => $context, 'objectid' => $chat->id, 'other' => array( 'start' => $start, 'end' => $end ) ); $event = \mod_chat\event\sessions_viewed::create($params); $event->add_record_snapshot('chat', $chat); $event->trigger(); $strchats = get_string('modulenameplural', 'chat'); $strchat = get_string('modulename', 'chat'); $strchatreport = get_string('chatreport', 'chat'); $strseesession = get_string('seesession', 'chat'); $strdeletesession = get_string('deletesession', 'chat'); $navlinks = array(); $canexportsess = has_capability('mod/chat:exportsession', $context); // Print a session if one has been specified.
public function test_sessions_viewed() { global $USER; $this->resetAfterTest(); // 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(); $course = $this->getDataGenerator()->create_course(); $chat = $this->getDataGenerator()->create_module('chat', array('course' => $course->id)); $params = array( 'context' => context_module::instance($chat->cmid), 'objectid' => $chat->id, 'other' => array( 'start' => 1234, 'end' => 5678 ) ); $event = \mod_chat\event\sessions_viewed::create($params); $event->add_record_snapshot('chat', $chat); $sink = $this->redirectEvents(); $event->trigger(); $events = $sink->get_events(); $event = reset($events); $this->assertInstanceOf('\mod_chat\event\sessions_viewed', $event); $this->assertEquals($USER->id, $event->userid); $this->assertEquals(context_module::instance($chat->cmid), $event->get_context()); $this->assertEquals(1234, $event->other['start']); $this->assertEquals(5678, $event->other['end']); $this->assertEquals($chat->id, $event->objectid); $this->assertEquals($chat, $event->get_record_snapshot('chat', $chat->id)); $expected = array($course->id, 'chat', 'report', "report.php?id=$chat->cmid", $chat->id, $chat->cmid); $this->assertEventLegacyLogData($expected, $event); $this->assertEventContextNotUsed($event); }