Merge "cleanup action=tokens"
[lhc/web/wiklou.git] / tests / phpunit / includes / GlobalFunctions / wfParseUrlTest.php
1 <?php
2 /**
3 * Tests for wfParseUrl()
4 *
5 * Copyright © 2013 Alexandre Emsenhuber
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
21 *
22 * @file
23 */
24
25 class WfParseUrlTest extends MediaWikiTestCase {
26 protected function setUp() {
27 parent::setUp();
28
29 $this->setMwGlobals( 'wgUrlProtocols', array(
30 '//', 'http://', 'file://', 'mailto:',
31 ) );
32 }
33
34 /** @dataProvider provideURLs */
35 public function testWfParseUrl( $url, $parts ) {
36 $partsDump = var_export( $parts, true );
37 $this->assertEquals(
38 $parts,
39 wfParseUrl( $url ),
40 "Testing $url parses to $partsDump"
41 );
42 }
43
44 /**
45 * Provider of URLs for testing wfParseUrl()
46 *
47 * @return array
48 */
49 public static function provideURLs() {
50 return array(
51 array(
52 '//example.org',
53 array(
54 'scheme' => '',
55 'delimiter' => '//',
56 'host' => 'example.org',
57 )
58 ),
59 array(
60 'http://example.org',
61 array(
62 'scheme' => 'http',
63 'delimiter' => '://',
64 'host' => 'example.org',
65 )
66 ),
67 array(
68 'http://id:key@example.org:123/path?foo=bar#baz',
69 array(
70 'scheme' => 'http',
71 'delimiter' => '://',
72 'user' => 'id',
73 'pass' => 'key',
74 'host' => 'example.org',
75 'port' => 123,
76 'path' => '/path',
77 'query' => 'foo=bar',
78 'fragment' => 'baz',
79 )
80 ),
81 array(
82 'file://example.org/etc/php.ini',
83 array(
84 'scheme' => 'file',
85 'delimiter' => '://',
86 'host' => 'example.org',
87 'path' => '/etc/php.ini',
88 )
89 ),
90 array(
91 'file:///etc/php.ini',
92 array(
93 'scheme' => 'file',
94 'delimiter' => '://',
95 'host' => '',
96 'path' => '/etc/php.ini',
97 )
98 ),
99 array(
100 'file:///c:/',
101 array(
102 'scheme' => 'file',
103 'delimiter' => '://',
104 'host' => '',
105 'path' => '/c:/',
106 )
107 ),
108 array(
109 'mailto:id@example.org',
110 array(
111 'scheme' => 'mailto',
112 'delimiter' => ':',
113 'host' => 'id@example.org',
114 'path' => '',
115 )
116 ),
117 array(
118 'mailto:id@example.org?subject=Foo',
119 array(
120 'scheme' => 'mailto',
121 'delimiter' => ':',
122 'host' => 'id@example.org',
123 'path' => '',
124 'query' => 'subject=Foo',
125 )
126 ),
127 array(
128 'mailto:?subject=Foo',
129 array(
130 'scheme' => 'mailto',
131 'delimiter' => ':',
132 'host' => '',
133 'path' => '',
134 'query' => 'subject=Foo',
135 )
136 ),
137 array(
138 'invalid://test/',
139 false
140 ),
141 );
142 }
143 }