Merge "Improve Database related documentation a bit"
[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 * @covers ::wfParseUrl
25 */
26 class WfParseUrlTest extends MediaWikiTestCase {
27 protected function setUp() {
28 parent::setUp();
29
30 $this->setMwGlobals( 'wgUrlProtocols', array(
31 '//',
32 'http://',
33 'https://',
34 'file://',
35 'mailto:',
36 ) );
37 }
38
39 /**
40 * @dataProvider provideURLs
41 */
42 public function testWfParseUrl( $url, $parts ) {
43 $this->assertEquals(
44 $parts,
45 wfParseUrl( $url )
46 );
47 }
48
49 /**
50 * Provider of URLs for testing wfParseUrl()
51 *
52 * @return array
53 */
54 public static function provideURLs() {
55 return array(
56 array(
57 '//example.org',
58 array(
59 'scheme' => '',
60 'delimiter' => '//',
61 'host' => 'example.org',
62 )
63 ),
64 array(
65 'http://example.org',
66 array(
67 'scheme' => 'http',
68 'delimiter' => '://',
69 'host' => 'example.org',
70 )
71 ),
72 array(
73 'https://example.org',
74 array(
75 'scheme' => 'https',
76 'delimiter' => '://',
77 'host' => 'example.org',
78 )
79 ),
80 array(
81 'http://id:key@example.org:123/path?foo=bar#baz',
82 array(
83 'scheme' => 'http',
84 'delimiter' => '://',
85 'user' => 'id',
86 'pass' => 'key',
87 'host' => 'example.org',
88 'port' => 123,
89 'path' => '/path',
90 'query' => 'foo=bar',
91 'fragment' => 'baz',
92 )
93 ),
94 array(
95 'file://example.org/etc/php.ini',
96 array(
97 'scheme' => 'file',
98 'delimiter' => '://',
99 'host' => 'example.org',
100 'path' => '/etc/php.ini',
101 )
102 ),
103 array(
104 'file:///etc/php.ini',
105 array(
106 'scheme' => 'file',
107 'delimiter' => '://',
108 'host' => '',
109 'path' => '/etc/php.ini',
110 )
111 ),
112 array(
113 'file:///c:/',
114 array(
115 'scheme' => 'file',
116 'delimiter' => '://',
117 'host' => '',
118 'path' => '/c:/',
119 )
120 ),
121 array(
122 'mailto:id@example.org',
123 array(
124 'scheme' => 'mailto',
125 'delimiter' => ':',
126 'host' => 'id@example.org',
127 'path' => '',
128 )
129 ),
130 array(
131 'mailto:id@example.org?subject=Foo',
132 array(
133 'scheme' => 'mailto',
134 'delimiter' => ':',
135 'host' => 'id@example.org',
136 'path' => '',
137 'query' => 'subject=Foo',
138 )
139 ),
140 array(
141 'mailto:?subject=Foo',
142 array(
143 'scheme' => 'mailto',
144 'delimiter' => ':',
145 'host' => '',
146 'path' => '',
147 'query' => 'subject=Foo',
148 )
149 ),
150 array(
151 'invalid://test/',
152 false
153 ),
154 );
155 }
156 }