2011-11-15 17:38:20 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
2014-07-18 19:35:43 +00:00
|
|
|
* @group GlobalFunctions
|
2013-10-24 09:53:24 +00:00
|
|
|
* @covers ::wfAssembleUrl
|
2011-11-15 17:38:20 +00:00
|
|
|
*/
|
2013-02-21 23:58:19 +00:00
|
|
|
class WfAssembleUrlTest extends MediaWikiTestCase {
|
2013-10-24 09:53:24 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provideURLParts
|
|
|
|
|
*/
|
2011-11-15 17:38:20 +00:00
|
|
|
public function testWfAssembleUrl( $parts, $output ) {
|
|
|
|
|
$partsDump = print_r( $parts, true );
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
$output,
|
|
|
|
|
wfAssembleUrl( $parts ),
|
|
|
|
|
"Testing $partsDump assembles to $output"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Provider of URL parts for testing wfAssembleUrl()
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2012-10-08 10:56:20 +00:00
|
|
|
public static function provideURLParts() {
|
2016-02-17 09:09:32 +00:00
|
|
|
$schemes = [
|
|
|
|
|
'' => [],
|
|
|
|
|
'//' => [
|
2011-11-15 17:38:20 +00:00
|
|
|
'delimiter' => '//',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'http://' => [
|
2011-11-15 17:38:20 +00:00
|
|
|
'scheme' => 'http',
|
|
|
|
|
'delimiter' => '://',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
];
|
2011-11-15 17:38:20 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$hosts = [
|
|
|
|
|
'' => [],
|
|
|
|
|
'example.com' => [
|
2011-11-15 17:38:20 +00:00
|
|
|
'host' => 'example.com',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'example.com:123' => [
|
2011-11-15 17:38:20 +00:00
|
|
|
'host' => 'example.com',
|
|
|
|
|
'port' => 123,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'id@example.com' => [
|
2011-11-15 17:38:20 +00:00
|
|
|
'user' => 'id',
|
|
|
|
|
'host' => 'example.com',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'id@example.com:123' => [
|
2011-11-15 17:38:20 +00:00
|
|
|
'user' => 'id',
|
|
|
|
|
'host' => 'example.com',
|
|
|
|
|
'port' => 123,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'id:key@example.com' => [
|
2011-11-15 17:38:20 +00:00
|
|
|
'user' => 'id',
|
|
|
|
|
'pass' => 'key',
|
|
|
|
|
'host' => 'example.com',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'id:key@example.com:123' => [
|
2011-11-15 17:38:20 +00:00
|
|
|
'user' => 'id',
|
|
|
|
|
'pass' => 'key',
|
|
|
|
|
'host' => 'example.com',
|
|
|
|
|
'port' => 123,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
];
|
2011-11-15 17:38:20 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$cases = [];
|
2011-11-15 17:38:20 +00:00
|
|
|
foreach ( $schemes as $scheme => $schemeParts ) {
|
|
|
|
|
foreach ( $hosts as $host => $hostParts ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
foreach ( [ '', '/path' ] as $path ) {
|
|
|
|
|
foreach ( [ '', 'query' ] as $query ) {
|
|
|
|
|
foreach ( [ '', 'fragment' ] as $fragment ) {
|
2011-11-15 17:38:20 +00:00
|
|
|
$parts = array_merge(
|
|
|
|
|
$schemeParts,
|
|
|
|
|
$hostParts
|
|
|
|
|
);
|
|
|
|
|
$url = $scheme .
|
|
|
|
|
$host .
|
|
|
|
|
$path;
|
|
|
|
|
|
|
|
|
|
if ( $path ) {
|
|
|
|
|
$parts['path'] = $path;
|
|
|
|
|
}
|
|
|
|
|
if ( $query ) {
|
|
|
|
|
$parts['query'] = $query;
|
|
|
|
|
$url .= '?' . $query;
|
|
|
|
|
}
|
2013-02-14 11:22:13 +00:00
|
|
|
if ( $fragment ) {
|
2011-11-15 17:38:20 +00:00
|
|
|
$parts['fragment'] = $fragment;
|
|
|
|
|
$url .= '#' . $fragment;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$cases[] = [
|
2011-11-15 17:38:20 +00:00
|
|
|
$parts,
|
|
|
|
|
$url,
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2011-11-15 17:38:20 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$complexURL = 'http://id:key@example.org:321' .
|
|
|
|
|
'/over/there?name=ferret&foo=bar#nose';
|
2016-02-17 09:09:32 +00:00
|
|
|
$cases[] = [
|
2011-11-15 17:38:20 +00:00
|
|
|
wfParseUrl( $complexURL ),
|
|
|
|
|
$complexURL,
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2011-11-15 17:38:20 +00:00
|
|
|
|
|
|
|
|
return $cases;
|
|
|
|
|
}
|
|
|
|
|
}
|