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