[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Unit tests for mod_lti lib 19 * 20 * @package mod_lti 21 * @category external 22 * @copyright 2015 Juan Leyva <juan@moodle.com> 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 * @since Moodle 3.0 25 */ 26 27 defined('MOODLE_INTERNAL') || die(); 28 29 30 /** 31 * Unit tests for mod_lti lib 32 * 33 * @package mod_lti 34 * @category external 35 * @copyright 2015 Juan Leyva <juan@moodle.com> 36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 37 * @since Moodle 3.0 38 */ 39 class mod_lti_lib_testcase extends advanced_testcase { 40 41 /** 42 * Prepares things before this test case is initialised 43 * @return void 44 */ 45 public static function setUpBeforeClass() { 46 global $CFG; 47 require_once($CFG->dirroot . '/mod/lti/lib.php'); 48 } 49 50 /** 51 * Test lti_view 52 * @return void 53 */ 54 public function test_lti_view() { 55 global $CFG; 56 57 $CFG->enablecompletion = 1; 58 $this->resetAfterTest(); 59 60 $this->setAdminUser(); 61 // Setup test data. 62 $course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1)); 63 $lti = $this->getDataGenerator()->create_module('lti', array('course' => $course->id), 64 array('completion' => 2, 'completionview' => 1)); 65 $context = context_module::instance($lti->cmid); 66 $cm = get_coursemodule_from_instance('lti', $lti->id); 67 68 // Trigger and capture the event. 69 $sink = $this->redirectEvents(); 70 71 lti_view($lti, $course, $cm, $context); 72 73 $events = $sink->get_events(); 74 // 2 additional events thanks to completion. 75 $this->assertCount(3, $events); 76 $event = array_shift($events); 77 78 // Checking that the event contains the expected values. 79 $this->assertInstanceOf('\mod_lti\event\course_module_viewed', $event); 80 $this->assertEquals($context, $event->get_context()); 81 $moodleurl = new \moodle_url('/mod/lti/view.php', array('id' => $cm->id)); 82 $this->assertEquals($moodleurl, $event->get_url()); 83 $this->assertEventContextNotUsed($event); 84 $this->assertNotEmpty($event->get_name()); 85 86 // Check completion status. 87 $completion = new completion_info($course); 88 $completiondata = $completion->get_data($cm); 89 $this->assertEquals(1, $completiondata->completionstate); 90 91 } 92 93 /** 94 * Test deleting LTI instance. 95 */ 96 public function test_lti_delete_instance() { 97 $this->resetAfterTest(); 98 99 $this->setAdminUser(); 100 $course = $this->getDataGenerator()->create_course(array()); 101 $lti = $this->getDataGenerator()->create_module('lti', array('course' => $course->id)); 102 $cm = get_coursemodule_from_instance('lti', $lti->id); 103 104 // Must not throw notices. 105 course_delete_module($cm->id); 106 } 107 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |