MDL-31857 phpunit: PHPDoc and typo fixes during integration
[moodle.git] / mod / url / tests / lib_test.php
CommitLineData
5bd40408
PS
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
26defined('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 */
37class mod_url_lib_testcase extends basic_testcase {
38
7aea08e1
SH
39 /**
40 * Prepares things before this test case is initialised
41 * @return void
42 */
5bd40408
PS
43 public static function setUpBeforeClass() {
44 global $CFG;
45 require_once($CFG->dirroot . '/mod/url/locallib.php');
46 }
47
7aea08e1
SH
48 /**
49 * Tests the url_appears_valid_url function
50 * @return void
51 */
5bd40408
PS
52 public function test_url_appears_valid_url() {
53 $this->assertTrue(url_appears_valid_url('http://example'));
54 $this->assertTrue(url_appears_valid_url('http://www.example.com'));
55 $this->assertTrue(url_appears_valid_url('http://www.exa-mple2.com'));
56 $this->assertTrue(url_appears_valid_url('http://www.example.com/~nobody/index.html'));
57 $this->assertTrue(url_appears_valid_url('http://www.example.com#hmm'));
58 $this->assertTrue(url_appears_valid_url('http://www.example.com/#hmm'));
59 $this->assertTrue(url_appears_valid_url('http://www.example.com/žlutý koníček/lala.txt'));
60 $this->assertTrue(url_appears_valid_url('http://www.example.com/žlutý koníček/lala.txt#hmmmm'));
61 $this->assertTrue(url_appears_valid_url('http://www.example.com/index.php?xx=yy&zz=aa'));
62 $this->assertTrue(url_appears_valid_url('https://user:password@www.example.com/žlutý koníček/lala.txt'));
63 $this->assertTrue(url_appears_valid_url('ftp://user:password@www.example.com/žlutý koníček/lala.txt'));
64
65 $this->assertFalse(url_appears_valid_url('http:example.com'));
66 $this->assertFalse(url_appears_valid_url('http:/example.com'));
67 $this->assertFalse(url_appears_valid_url('http://'));
68 $this->assertFalse(url_appears_valid_url('http://www.exa mple.com'));
69 $this->assertFalse(url_appears_valid_url('http://www.examplé.com'));
70 $this->assertFalse(url_appears_valid_url('http://@www.example.com'));
71 $this->assertFalse(url_appears_valid_url('http://user:@www.example.com'));
72
73 $this->assertTrue(url_appears_valid_url('lalala://@:@/'));
74 }
75}