2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Unit tests for some mod URL lib stuff.
22 * @copyright 2011 petr Skoda
23 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
27 defined('MOODLE_INTERNAL') || die();
29 require_once($CFG->dirroot . '/mod/url/locallib.php');
33 * @copyright 2011 petr Skoda
35 class url_lib_test extends UnitTestCase {
37 public function test_url_appears_valid_url() {
39 $this->assertTrue(url_appears_valid_url('http://example'));
40 $this->assertTrue(url_appears_valid_url('http://www.example.com'));
41 $this->assertTrue(url_appears_valid_url('http://www.exa-mple2.com'));
42 $this->assertTrue(url_appears_valid_url('http://www.example.com/~nobody/index.html'));
43 $this->assertTrue(url_appears_valid_url('http://www.example.com#hmm'));
44 $this->assertTrue(url_appears_valid_url('http://www.example.com/#hmm'));
45 $this->assertTrue(url_appears_valid_url('http://www.example.com/žlutý koníček/lala.txt'));
46 $this->assertTrue(url_appears_valid_url('http://www.example.com/žlutý koníček/lala.txt#hmmmm'));
47 $this->assertTrue(url_appears_valid_url('http://www.example.com/index.php?xx=yy&zz=aa'));
48 $this->assertTrue(url_appears_valid_url('https://user:password@www.example.com/žlutý koníček/lala.txt'));
49 $this->assertTrue(url_appears_valid_url('ftp://user:password@www.example.com/žlutý koníček/lala.txt'));
51 $this->assertFalse(url_appears_valid_url('http:example.com'));
52 $this->assertFalse(url_appears_valid_url('http:/example.com'));
53 $this->assertFalse(url_appears_valid_url('http://'));
54 $this->assertFalse(url_appears_valid_url('http://www.exa mple.com'));
55 $this->assertFalse(url_appears_valid_url('http://www.examplé.com'));
56 $this->assertFalse(url_appears_valid_url('http://@www.example.com'));
57 $this->assertFalse(url_appears_valid_url('http://user:@www.example.com'));
59 $this->assertTrue(url_appears_valid_url('lalala://@:@/'));