} if (!($cm = get_coursemodule_from_instance("quora", $quora->id, $course->id))) { print_error('invalidcoursemodule'); } require_login($course, false, $cm); $returnto = quora_go_back_to($returnpage . '?id=' . $course->id . '&f=' . $quora->id); if (!quora_tp_can_track_quoras($quora)) { redirect($returnto); } $info = new stdClass(); $info->name = fullname($USER); $info->quora = format_string($quora->name); $eventparams = array('context' => context_module::instance($cm->id), 'relateduserid' => $USER->id, 'other' => array('quoraid' => $quora->id)); if (quora_tp_is_tracked($quora)) { if (quora_tp_stop_tracking($quora->id)) { $event = \mod_quora\event\readtracking_disabled::create($eventparams); $event->trigger(); redirect($returnto, get_string("nownottracking", "quora", $info), 1); } else { print_error('cannottrack', '', get_local_referer(false)); } } else { // subscribe if (quora_tp_start_tracking($quora->id)) { $event = \mod_quora\event\readtracking_enabled::create($eventparams); $event->trigger(); redirect($returnto, get_string("nowtracking", "quora", $info), 1); } else { print_error('cannottrack', '', get_local_referer(false)); } }
/** * Test the readtracking_enabled event. */ public function test_readtracking_enabled() { // Setup test data. $user = $this->getDataGenerator()->create_user(); $course = $this->getDataGenerator()->create_course(); $quora = $this->getDataGenerator()->create_module('quora', array('course' => $course->id)); $context = context_module::instance($quora->cmid); $params = array('context' => $context, 'other' => array('quoraid' => $quora->id), 'relateduserid' => $user->id); $event = \mod_quora\event\readtracking_enabled::create($params); // Trigger and capture the event. $sink = $this->redirectEvents(); $event->trigger(); $events = $sink->get_events(); $this->assertCount(1, $events); $event = reset($events); // Checking that the event contains the expected values. $this->assertInstanceOf('\\mod_quora\\event\\readtracking_enabled', $event); $this->assertEquals($context, $event->get_context()); $expected = array($course->id, 'quora', 'start tracking', "view.php?f={$quora->id}", $quora->id, $quora->cmid); $this->assertEventLegacyLogData($expected, $event); $url = new \moodle_url('/mod/quora/view.php', array('f' => $quora->id)); $this->assertEquals($url, $event->get_url()); $this->assertEventContextNotUsed($event); $this->assertNotEmpty($event->get_name()); }