[ 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 some mod URL lib stuff. 19 * 20 * @package mod_url 21 * @category phpunit 22 * @copyright 2012 Petr Skoda {@link http://skodak.org} 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 29 /** 30 * mod_url tests 31 * 32 * @package mod_url 33 * @category phpunit 34 * @copyright 2011 Petr Skoda {@link http://skodak.org} 35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 36 */ 37 class mod_url_lib_testcase extends advanced_testcase { 38 39 /** 40 * Prepares things before this test case is initialised 41 * @return void 42 */ 43 public static function setUpBeforeClass() { 44 global $CFG; 45 require_once($CFG->dirroot . '/mod/url/lib.php'); 46 require_once($CFG->dirroot . '/mod/url/locallib.php'); 47 } 48 49 /** 50 * Tests the url_appears_valid_url function 51 * @return void 52 */ 53 public function test_url_appears_valid_url() { 54 $this->assertTrue(url_appears_valid_url('http://example')); 55 $this->assertTrue(url_appears_valid_url('http://www.example.com')); 56 $this->assertTrue(url_appears_valid_url('http://www.exa-mple2.com')); 57 $this->assertTrue(url_appears_valid_url('http://www.example.com/~nobody/index.html')); 58 $this->assertTrue(url_appears_valid_url('http://www.example.com#hmm')); 59 $this->assertTrue(url_appears_valid_url('http://www.example.com/#hmm')); 60 $this->assertTrue(url_appears_valid_url('http://www.example.com/žlutý koníček/lala.txt')); 61 $this->assertTrue(url_appears_valid_url('http://www.example.com/žlutý koníček/lala.txt#hmmmm')); 62 $this->assertTrue(url_appears_valid_url('http://www.example.com/index.php?xx=yy&zz=aa')); 63 $this->assertTrue(url_appears_valid_url('https://user:password@www.example.com/žlutý koníček/lala.txt')); 64 $this->assertTrue(url_appears_valid_url('ftp://user:password@www.example.com/žlutý koníček/lala.txt')); 65 66 $this->assertFalse(url_appears_valid_url('http:example.com')); 67 $this->assertFalse(url_appears_valid_url('http:/example.com')); 68 $this->assertFalse(url_appears_valid_url('http://')); 69 $this->assertFalse(url_appears_valid_url('http://www.exa mple.com')); 70 $this->assertFalse(url_appears_valid_url('http://www.examplé.com')); 71 $this->assertFalse(url_appears_valid_url('http://@www.example.com')); 72 $this->assertFalse(url_appears_valid_url('http://user:@www.example.com')); 73 74 $this->assertTrue(url_appears_valid_url('lalala://@:@/')); 75 } 76 77 /** 78 * Test url_view 79 * @return void 80 */ 81 public function test_url_view() { 82 global $CFG; 83 84 $CFG->enablecompletion = 1; 85 $this->resetAfterTest(); 86 87 // Setup test data. 88 $course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1)); 89 $url = $this->getDataGenerator()->create_module('url', array('course' => $course->id), 90 array('completion' => 2, 'completionview' => 1)); 91 $context = context_module::instance($url->cmid); 92 $cm = get_coursemodule_from_instance('url', $url->id); 93 94 // Trigger and capture the event. 95 $sink = $this->redirectEvents(); 96 97 $this->setAdminUser(); 98 url_view($url, $course, $cm, $context); 99 100 $events = $sink->get_events(); 101 // 2 additional events thanks to completion. 102 $this->assertCount(3, $events); 103 $event = array_shift($events); 104 105 // Checking that the event contains the expected values. 106 $this->assertInstanceOf('\mod_url\event\course_module_viewed', $event); 107 $this->assertEquals($context, $event->get_context()); 108 $url = new \moodle_url('/mod/url/view.php', array('id' => $cm->id)); 109 $this->assertEquals($url, $event->get_url()); 110 $this->assertEventContextNotUsed($event); 111 $this->assertNotEmpty($event->get_name()); 112 113 // Check completion status. 114 $completion = new completion_info($course); 115 $completiondata = $completion->get_data($cm); 116 $this->assertEquals(1, $completiondata->completionstate); 117 118 } 119 }
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 |