test: coverage recording now needs to be explicit
[mediawiki.git] / tests / phpunit / includes / GlobalFunctions / wfParseUrlTest.php
blob841a1b126e61a81a8129debc7001889f8f184f2a
1 <?php
2 /**
3 * Tests for wfParseUrl()
5 * Copyright © 2013 Alexandre Emsenhuber
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.
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.
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
22 * @file
25 class WfParseUrlTest extends MediaWikiTestCase {
26 protected function setUp() {
27 parent::setUp();
29 $this->setMwGlobals( 'wgUrlProtocols', array(
30 '//', 'http://', 'file://', 'mailto:',
31 ) );
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"
44 /**
45 * Provider of URLs for testing wfParseUrl()
47 * @return array
49 public static function provideURLs() {
50 return array(
51 array(
52 '//example.org',
53 array(
54 'scheme' => '',
55 'delimiter' => '//',
56 'host' => 'example.org',
59 array(
60 'http://example.org',
61 array(
62 'scheme' => 'http',
63 'delimiter' => '://',
64 'host' => 'example.org',
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',
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',
90 array(
91 'file:///etc/php.ini',
92 array(
93 'scheme' => 'file',
94 'delimiter' => '://',
95 'host' => '',
96 'path' => '/etc/php.ini',
99 array(
100 'file:///c:/',
101 array(
102 'scheme' => 'file',
103 'delimiter' => '://',
104 'host' => '',
105 'path' => '/c:/',
108 array(
109 'mailto:id@example.org',
110 array(
111 'scheme' => 'mailto',
112 'delimiter' => ':',
113 'host' => 'id@example.org',
114 'path' => '',
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',
127 array(
128 'mailto:?subject=Foo',
129 array(
130 'scheme' => 'mailto',
131 'delimiter' => ':',
132 'host' => '',
133 'path' => '',
134 'query' => 'subject=Foo',
137 array(
138 'invalid://test/',
139 false