public function test_view_resources_list() { $this->resetAfterTest(); $course = self::getDataGenerator()->create_course(); $coursecontext = context_course::instance($course->id); $event = \core\event\course_resources_list_viewed::create(array('context' => context_course::instance($course->id))); $event->set_legacy_logdata(array('book', 'page', 'resource')); $sink = $this->redirectEvents(); $event->trigger(); $events = $sink->get_events(); $sink->close(); // Validate the event. $event = $events[0]; $this->assertInstanceOf('\\core\\event\\course_resources_list_viewed', $event); $this->assertEquals(null, $event->objecttable); $this->assertEquals(null, $event->objectid); $this->assertEquals($course->id, $event->courseid); $this->assertEquals($coursecontext->id, $event->contextid); $expectedlegacydata = array(array($course->id, "book", "view all", 'index.php?id=' . $course->id, ''), array($course->id, "page", "view all", 'index.php?id=' . $course->id, ''), array($course->id, "resource", "view all", 'index.php?id=' . $course->id, '')); $this->assertEventLegacyLogData($expectedlegacydata, $event); $this->assertEventContextNotUsed($event); }
$allmodules = $DB->get_records('modules', array('visible' => 1)); $availableresources = array(); foreach ($allmodules as $key => $module) { $modname = $module->name; $libfile = "{$CFG->dirroot}/mod/{$modname}/lib.php"; if (!file_exists($libfile)) { continue; } $archetype = plugin_supports('mod', $modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER); if ($archetype != MOD_ARCHETYPE_RESOURCE) { continue; } $availableresources[] = $modname; } // Triger view event. $event = \core\event\course_resources_list_viewed::create(array('context' => context_course::instance($course->id))); $event->set_legacy_logdata($availableresources); $event->add_record_snapshot('course', $course); $event->trigger(); $strresources = get_string('resources'); $strname = get_string('name'); $strintro = get_string('moduleintro'); $strlastmodified = get_string('lastmodified'); $PAGE->set_url('/course/resources.php', array('id' => $course->id)); $PAGE->set_title($course->shortname . ': ' . $strresources); $PAGE->set_heading($course->fullname); $PAGE->navbar->add($strresources); echo $OUTPUT->header(); $modinfo = get_fast_modinfo($course); $usesections = course_format_uses_sections($course->format); $cms = array();