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