wiki.techinc.nl/tests/phpunit/includes/GlobalFunctions/wfParseUrlTest.php
addshore 959bc315f2 MediaWikiTestCase to MediaWikiIntegrationTestCase
The name change happened some time ago, and I think its
about time to start using the name name!
(Done with a find and replace)

My personal motivation for doing this is that I have started
trying out vscode as an IDE for mediawiki development, and
right now it doesn't appear to handle php aliases very well
or at all.

Change-Id: I412235d91ae26e4c1c6a62e0dbb7e7cf3c5ed4a6
2020-06-30 17:02:22 +01:00

197 lines
3.8 KiB
PHP

<?php
/**
* Copyright © 2013 Alexandre Emsenhuber
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
*/
/**
* @group GlobalFunctions
* @covers ::wfParseUrl
*/
class WfParseUrlTest extends MediaWikiIntegrationTestCase {
protected function setUp() : void {
parent::setUp();
$this->setMwGlobals( 'wgUrlProtocols', [
'//',
'http://',
'https://',
'file://',
'mailto:',
] );
}
/**
* @dataProvider provideURLs
*/
public function testWfParseUrl( $url, $parts ) {
$this->assertEquals(
$parts,
wfParseUrl( $url )
);
}
/**
* Provider of URLs for testing wfParseUrl()
*
* @return array
*/
public static function provideURLs() {
return [
[
'//example.org',
[
'scheme' => '',
'delimiter' => '//',
'host' => 'example.org',
]
],
[
'http://example.org',
[
'scheme' => 'http',
'delimiter' => '://',
'host' => 'example.org',
]
],
[
'https://example.org',
[
'scheme' => 'https',
'delimiter' => '://',
'host' => 'example.org',
]
],
[
'http://id:key@example.org:123/path?foo=bar#baz',
[
'scheme' => 'http',
'delimiter' => '://',
'user' => 'id',
'pass' => 'key',
'host' => 'example.org',
'port' => 123,
'path' => '/path',
'query' => 'foo=bar',
'fragment' => 'baz',
]
],
[
'file://example.org/etc/php.ini',
[
'scheme' => 'file',
'delimiter' => '://',
'host' => 'example.org',
'path' => '/etc/php.ini',
]
],
[
'file:///etc/php.ini',
[
'scheme' => 'file',
'delimiter' => '://',
'host' => '',
'path' => '/etc/php.ini',
]
],
[
'file:///c:/',
[
'scheme' => 'file',
'delimiter' => '://',
'host' => '',
'path' => '/c:/',
]
],
[
'mailto:id@example.org',
[
'scheme' => 'mailto',
'delimiter' => ':',
'host' => 'id@example.org',
'path' => '',
]
],
[
'mailto:id@example.org?subject=Foo',
[
'scheme' => 'mailto',
'delimiter' => ':',
'host' => 'id@example.org',
'path' => '',
'query' => 'subject=Foo',
]
],
[
'mailto:?subject=Foo',
[
'scheme' => 'mailto',
'delimiter' => ':',
'host' => '',
'path' => '',
'query' => 'subject=Foo',
]
],
[
'invalid://test/',
false
],
// T212067
[
'//evil.com?example.org/foo/bar',
[
'scheme' => '',
'delimiter' => '//',
'host' => 'evil.com',
'query' => 'example.org/foo/bar',
]
],
[
'//evil.com?example.org/foo/bar?baz#quux',
[
'scheme' => '',
'delimiter' => '//',
'host' => 'evil.com',
'query' => 'example.org/foo/bar?baz',
'fragment' => 'quux',
]
],
[
'//evil.com?example.org?baz#quux',
[
'scheme' => '',
'delimiter' => '//',
'host' => 'evil.com',
'query' => 'example.org?baz',
'fragment' => 'quux',
]
],
[
'//evil.com?example.org#quux',
[
'scheme' => '',
'delimiter' => '//',
'host' => 'evil.com',
'query' => 'example.org',
'fragment' => 'quux',
]
],
];
}
}