/** * Test imscp_view * @return void */ public function test_imscp_view() { global $CFG; $CFG->enablecompletion = 1; $this->resetAfterTest(); $this->setAdminUser(); // Setup test data. $course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1)); $imscp = $this->getDataGenerator()->create_module('imscp', array('course' => $course->id), array('completion' => 2, 'completionview' => 1)); $context = context_module::instance($imscp->cmid); $cm = get_coursemodule_from_instance('imscp', $imscp->id); // Trigger and capture the event. $sink = $this->redirectEvents(); imscp_view($imscp, $course, $cm, $context); $events = $sink->get_events(); // 2 additional events thanks to completion. $this->assertCount(3, $events); $event = array_shift($events); // Checking that the event contains the expected values. $this->assertInstanceOf('\\mod_imscp\\event\\course_module_viewed', $event); $this->assertEquals($context, $event->get_context()); $moodleurl = new \moodle_url('/mod/imscp/view.php', array('id' => $cm->id)); $this->assertEquals($moodleurl, $event->get_url()); $this->assertEventContextNotUsed($event); $this->assertNotEmpty($event->get_name()); // Check completion status. $completion = new completion_info($course); $completiondata = $completion->get_data($cm); $this->assertEquals(1, $completiondata->completionstate); }
/** * Simulate the imscp/view.php web interface page: trigger events, completion, etc... * * @param int $imscpid the imscp instance id * @return array of warnings and status result * @since Moodle 3.0 * @throws moodle_exception */ public static function view_imscp($imscpid) { global $DB, $CFG; require_once($CFG->dirroot . "/mod/imscp/lib.php"); $params = self::validate_parameters(self::view_imscp_parameters(), array( 'imscpid' => $imscpid )); $warnings = array(); // Request and permission validation. $imscp = $DB->get_record('imscp', array('id' => $params['imscpid']), '*', MUST_EXIST); list($course, $cm) = get_course_and_cm_from_instance($imscp, 'imscp'); $context = context_module::instance($cm->id); self::validate_context($context); require_capability('mod/imscp:view', $context); // Call the imscp/lib API. imscp_view($imscp, $course, $cm, $context); $result = array(); $result['status'] = true; $result['warnings'] = $warnings; return $result; }
$i = optional_param('i', 0, PARAM_INT); // IMS CP instance id. if ($i) { // Two ways to specify the module. $imscp = $DB->get_record('imscp', array('id' => $i), '*', MUST_EXIST); $cm = get_coursemodule_from_instance('imscp', $imscp->id, $imscp->course, false, MUST_EXIST); } else { $cm = get_coursemodule_from_id('imscp', $id, 0, false, MUST_EXIST); $imscp = $DB->get_record('imscp', array('id' => $cm->instance), '*', MUST_EXIST); } $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); require_course_login($course, true, $cm); $context = context_module::instance($cm->id); require_capability('mod/imscp:view', $context); // Completion and trigger events. imscp_view($imscp, $course, $cm, $context); $PAGE->set_url('/mod/imscp/view.php', array('id' => $cm->id)); $PAGE->requires->js('/mod/imscp/dummyapi.js', true); $PAGE->requires->string_for_js('navigation', 'imscp'); $PAGE->requires->string_for_js('toc', 'imscp'); $PAGE->requires->string_for_js('hide', 'moodle'); $PAGE->requires->string_for_js('show', 'moodle'); // TODO: find some better way to disable blocks and minimise footer - pagetype just for this does not seem like a good solution. // $PAGE->set_pagelayout('maxcontent'); ? $PAGE->set_title($course->shortname . ': ' . $imscp->name); $PAGE->set_heading($course->fullname); $PAGE->set_activity_record($imscp); // Verify imsmanifest was parsed properly. if (!$imscp->structure) { redirect(course_get_url($course->id, $cm->section), get_string('deploymenterror', 'imscp')); }