[ 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_page lib 19 * 20 * @package mod_page 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_page lib 32 * 33 * @package mod_page 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_page_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/page/lib.php'); 48 } 49 50 /** 51 * Test page_view 52 * @return void 53 */ 54 public function test_page_view() { 55 global $CFG; 56 57 $CFG->enablecompletion = 1; 58 $this->resetAfterTest(); 59 60 // Setup test data. 61 $course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1)); 62 $page = $this->getDataGenerator()->create_module('page', array('course' => $course->id), 63 array('completion' => 2, 'completionview' => 1)); 64 $context = context_module::instance($page->cmid); 65 $cm = get_coursemodule_from_instance('page', $page->id); 66 67 // Trigger and capture the event. 68 $sink = $this->redirectEvents(); 69 70 $this->setAdminUser(); 71 page_view($page, $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_page\event\course_module_viewed', $event); 80 $this->assertEquals($context, $event->get_context()); 81 $moodleurl = new \moodle_url('/mod/page/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 }
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 |