From eb5d02900d3f0359c50b350f51a6aa24ddf8a8c4 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Thu, 21 Feb 2013 11:03:53 +0100 Subject: [PATCH] Add tests for wfParseUrl() Follows-up Ife07d6e2 (a7c103a). Change-Id: Ie32cf604959829904fb8661347edbbd94091d84b --- .../GlobalFunctions/wfParseUrlTest.php | 143 ++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 tests/phpunit/includes/GlobalFunctions/wfParseUrlTest.php diff --git a/tests/phpunit/includes/GlobalFunctions/wfParseUrlTest.php b/tests/phpunit/includes/GlobalFunctions/wfParseUrlTest.php new file mode 100644 index 0000000000..841a1b126e --- /dev/null +++ b/tests/phpunit/includes/GlobalFunctions/wfParseUrlTest.php @@ -0,0 +1,143 @@ +setMwGlobals( 'wgUrlProtocols', array( + '//', 'http://', 'file://', 'mailto:', + ) ); + } + + /** @dataProvider provideURLs */ + public function testWfParseUrl( $url, $parts ) { + $partsDump = var_export( $parts, true ); + $this->assertEquals( + $parts, + wfParseUrl( $url ), + "Testing $url parses to $partsDump" + ); + } + + /** + * Provider of URLs for testing wfParseUrl() + * + * @return array + */ + public static function provideURLs() { + return array( + array( + '//example.org', + array( + 'scheme' => '', + 'delimiter' => '//', + 'host' => 'example.org', + ) + ), + array( + 'http://example.org', + array( + 'scheme' => 'http', + 'delimiter' => '://', + 'host' => 'example.org', + ) + ), + array( + 'http://id:key@example.org:123/path?foo=bar#baz', + array( + 'scheme' => 'http', + 'delimiter' => '://', + 'user' => 'id', + 'pass' => 'key', + 'host' => 'example.org', + 'port' => 123, + 'path' => '/path', + 'query' => 'foo=bar', + 'fragment' => 'baz', + ) + ), + array( + 'file://example.org/etc/php.ini', + array( + 'scheme' => 'file', + 'delimiter' => '://', + 'host' => 'example.org', + 'path' => '/etc/php.ini', + ) + ), + array( + 'file:///etc/php.ini', + array( + 'scheme' => 'file', + 'delimiter' => '://', + 'host' => '', + 'path' => '/etc/php.ini', + ) + ), + array( + 'file:///c:/', + array( + 'scheme' => 'file', + 'delimiter' => '://', + 'host' => '', + 'path' => '/c:/', + ) + ), + array( + 'mailto:id@example.org', + array( + 'scheme' => 'mailto', + 'delimiter' => ':', + 'host' => 'id@example.org', + 'path' => '', + ) + ), + array( + 'mailto:id@example.org?subject=Foo', + array( + 'scheme' => 'mailto', + 'delimiter' => ':', + 'host' => 'id@example.org', + 'path' => '', + 'query' => 'subject=Foo', + ) + ), + array( + 'mailto:?subject=Foo', + array( + 'scheme' => 'mailto', + 'delimiter' => ':', + 'host' => '', + 'path' => '', + 'query' => 'subject=Foo', + ) + ), + array( + 'invalid://test/', + false + ), + ); + } +} -- 2.20.1