/**
  * Test the course_module_viewed event.
  */
 public function test_course_module_viewed()
 {
     // Setup test data.
     $course = $this->getDataGenerator()->create_course();
     $anonforum = $this->getDataGenerator()->create_module('anonforum', array('course' => $course->id));
     $context = context_module::instance($anonforum->cmid);
     $params = array('context' => $context, 'objectid' => $anonforum->id);
     $event = \mod_anonforum\event\course_module_viewed::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_anonforum\\event\\course_module_viewed', $event);
     $this->assertEquals($context, $event->get_context());
     $expected = array($course->id, 'anonforum', 'view anonforum', "view.php?f={$anonforum->id}", $anonforum->id, $anonforum->cmid);
     $this->assertEventLegacyLogData($expected, $event);
     $url = new \moodle_url('/mod/anonforum/view.php', array('f' => $anonforum->id));
     $this->assertEquals($url, $event->get_url());
     $this->assertEventContextNotUsed($event);
     $this->assertNotEmpty($event->get_name());
 }
Example #2
0
if (empty($cm->visible) and !has_capability('moodle/course:viewhiddenactivities', $context)) {
    notice(get_string("activityiscurrentlyhidden"));
}
if (!has_capability('mod/anonforum:viewdiscussion', $context)) {
    notice(get_string('noviewdiscussionspermission', 'anonforum'));
}
echo $OUTPUT->heading(format_string($anonforum->name), 2);
if (!empty($anonforum->intro) && $anonforum->type != 'single' && $anonforum->type != 'teacher') {
    echo $OUTPUT->box(format_module_intro('anonforum', $anonforum, $cm->id), 'generalbox', 'intro');
}
// Find out current groups mode.
groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/anonforum/view.php?id=' . $cm->id);
// Okay, we can show the discussions. Log the anonymous forum view.
if (empty($anonforum->anonymous)) {
    $params = array('context' => $context, 'objectid' => $anonforum->id, 'anonymous' => 1);
    $event = \mod_anonforum\event\course_module_viewed::create($params);
    $event->add_record_snapshot('course', $course);
    if ($cm->id) {
        $event->add_record_snapshot('course_modules', $cm);
    } else {
        $event->add_record_snapshot('anonforum', $anonforum);
    }
    $event->trigger();
}
$SESSION->fromdiscussion = qualified_me();
// Return here if we post or set subscription etc
// Print settings and things across the top.
// If it's a simple single discussion anonymous forum, we need to print the display
// mode control.
if ($anonforum->type == 'single') {
    $discussion = null;