2011-07-13 01:54:40 +00:00
|
|
|
<?php
|
2011-10-11 18:30:50 +00:00
|
|
|
/**
|
2014-07-18 19:35:43 +00:00
|
|
|
* @group GlobalFunctions
|
2013-10-24 09:53:24 +00:00
|
|
|
* @covers ::wfExpandUrl
|
2011-07-13 01:54:40 +00:00
|
|
|
*/
|
2013-02-21 23:58:19 +00:00
|
|
|
class WfExpandUrlTest extends MediaWikiTestCase {
|
2013-10-24 09:53:24 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provideExpandableUrls
|
|
|
|
|
*/
|
2014-04-24 09:47:06 +00:00
|
|
|
public function testWfExpandUrl( $fullUrl, $shortUrl, $defaultProto,
|
|
|
|
|
$server, $canServer, $httpsMode, $message
|
|
|
|
|
) {
|
2013-08-21 05:35:40 +00:00
|
|
|
// Fake $wgServer, $wgCanonicalServer and $wgRequest->getProtocol()
|
2013-03-21 19:35:44 +00:00
|
|
|
$this->setMwGlobals( array(
|
|
|
|
|
'wgServer' => $server,
|
|
|
|
|
'wgCanonicalServer' => $canServer,
|
2013-08-21 05:35:40 +00:00
|
|
|
'wgRequest' => new FauxRequest( array(), false, null, $httpsMode ? 'https' : 'http' )
|
2013-03-21 19:35:44 +00:00
|
|
|
) );
|
2011-11-25 00:15:27 +00:00
|
|
|
|
2011-07-27 08:21:40 +00:00
|
|
|
$this->assertEquals( $fullUrl, wfExpandUrl( $shortUrl, $defaultProto ), $message );
|
2011-07-13 01:54:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Provider of URL examples for testing wfExpandUrl()
|
2011-07-24 21:36:04 +00:00
|
|
|
*
|
|
|
|
|
* @return array
|
2011-07-13 01:54:40 +00:00
|
|
|
*/
|
2012-10-08 10:56:20 +00:00
|
|
|
public static function provideExpandableUrls() {
|
2011-07-27 08:21:40 +00:00
|
|
|
$modes = array( 'http', 'https' );
|
2012-09-28 23:35:16 +00:00
|
|
|
$servers = array(
|
|
|
|
|
'http' => 'http://example.com',
|
|
|
|
|
'https' => 'https://example.com',
|
|
|
|
|
'protocol-relative' => '//example.com'
|
|
|
|
|
);
|
|
|
|
|
$defaultProtos = array(
|
|
|
|
|
'http' => PROTO_HTTP,
|
|
|
|
|
'https' => PROTO_HTTPS,
|
|
|
|
|
'protocol-relative' => PROTO_RELATIVE,
|
|
|
|
|
'current' => PROTO_CURRENT,
|
|
|
|
|
'canonical' => PROTO_CANONICAL
|
|
|
|
|
);
|
2011-11-25 00:15:27 +00:00
|
|
|
|
2011-07-27 08:21:40 +00:00
|
|
|
$retval = array();
|
|
|
|
|
foreach ( $modes as $mode ) {
|
|
|
|
|
$httpsMode = $mode == 'https';
|
|
|
|
|
foreach ( $servers as $serverDesc => $server ) {
|
2013-02-14 11:22:13 +00:00
|
|
|
foreach ( $modes as $canServerMode ) {
|
2011-08-19 15:25:50 +00:00
|
|
|
$canServer = "$canServerMode://example2.com";
|
|
|
|
|
foreach ( $defaultProtos as $protoDesc => $defaultProto ) {
|
2012-09-28 23:35:16 +00:00
|
|
|
$retval[] = array(
|
|
|
|
|
'http://example.com', 'http://example.com',
|
|
|
|
|
$defaultProto, $server, $canServer, $httpsMode,
|
2014-04-24 09:47:06 +00:00
|
|
|
"Testing fully qualified http URLs (no need to expand) "
|
|
|
|
|
. "(defaultProto: $protoDesc , wgServer: $server, "
|
|
|
|
|
. "wgCanonicalServer: $canServer, current request protocol: $mode )"
|
2012-09-28 23:35:16 +00:00
|
|
|
);
|
|
|
|
|
$retval[] = array(
|
|
|
|
|
'https://example.com', 'https://example.com',
|
|
|
|
|
$defaultProto, $server, $canServer, $httpsMode,
|
2014-04-24 09:47:06 +00:00
|
|
|
"Testing fully qualified https URLs (no need to expand) "
|
|
|
|
|
. "(defaultProto: $protoDesc , wgServer: $server, "
|
|
|
|
|
. "wgCanonicalServer: $canServer, current request protocol: $mode )"
|
2012-09-28 23:35:16 +00:00
|
|
|
);
|
2011-08-19 15:25:50 +00:00
|
|
|
# Would be nice to support this, see fixme on wfExpandUrl()
|
2012-09-28 23:35:16 +00:00
|
|
|
$retval[] = array(
|
|
|
|
|
"wiki/FooBar", 'wiki/FooBar',
|
|
|
|
|
$defaultProto, $server, $canServer, $httpsMode,
|
2014-04-24 09:47:06 +00:00
|
|
|
"Test non-expandable relative URLs (defaultProto: $protoDesc, "
|
|
|
|
|
. "wgServer: $server, wgCanonicalServer: $canServer, "
|
|
|
|
|
. "current request protocol: $mode )"
|
2012-09-28 23:35:16 +00:00
|
|
|
);
|
2011-11-25 00:15:27 +00:00
|
|
|
|
2011-08-19 15:25:50 +00:00
|
|
|
// Determine expected protocol
|
|
|
|
|
if ( $protoDesc == 'protocol-relative' ) {
|
|
|
|
|
$p = '';
|
2011-11-25 00:15:27 +00:00
|
|
|
} elseif ( $protoDesc == 'current' ) {
|
2011-08-19 15:25:50 +00:00
|
|
|
$p = "$mode:";
|
2011-11-25 00:15:27 +00:00
|
|
|
} elseif ( $protoDesc == 'canonical' ) {
|
2011-08-19 15:25:50 +00:00
|
|
|
$p = "$canServerMode:";
|
|
|
|
|
} else {
|
|
|
|
|
$p = $protoDesc . ':';
|
|
|
|
|
}
|
|
|
|
|
// Determine expected server name
|
|
|
|
|
if ( $protoDesc == 'canonical' ) {
|
|
|
|
|
$srv = $canServer;
|
2011-11-25 00:15:27 +00:00
|
|
|
} elseif ( $serverDesc == 'protocol-relative' ) {
|
2011-08-19 15:25:50 +00:00
|
|
|
$srv = $p . $server;
|
|
|
|
|
} else {
|
|
|
|
|
$srv = $server;
|
|
|
|
|
}
|
2011-11-25 00:15:27 +00:00
|
|
|
|
2012-09-28 23:35:16 +00:00
|
|
|
$retval[] = array(
|
|
|
|
|
"$p//wikipedia.org", '//wikipedia.org',
|
|
|
|
|
$defaultProto, $server, $canServer, $httpsMode,
|
2014-04-24 09:47:06 +00:00
|
|
|
"Test protocol-relative URL (defaultProto: $protoDesc, "
|
|
|
|
|
. "wgServer: $server, wgCanonicalServer: $canServer, "
|
|
|
|
|
. "current request protocol: $mode )"
|
2012-09-28 23:35:16 +00:00
|
|
|
);
|
|
|
|
|
$retval[] = array(
|
2014-04-24 09:47:06 +00:00
|
|
|
"$srv/wiki/FooBar",
|
|
|
|
|
'/wiki/FooBar',
|
|
|
|
|
$defaultProto,
|
|
|
|
|
$server,
|
|
|
|
|
$canServer,
|
|
|
|
|
$httpsMode,
|
|
|
|
|
"Testing expanding URL beginning with / (defaultProto: $protoDesc, "
|
|
|
|
|
. "wgServer: $server, wgCanonicalServer: $canServer, "
|
|
|
|
|
. "current request protocol: $mode )"
|
2012-09-28 23:35:16 +00:00
|
|
|
);
|
2011-07-27 08:21:40 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-04-26 12:00:22 +00:00
|
|
|
|
2011-07-27 08:21:40 +00:00
|
|
|
return $retval;
|
2011-07-13 01:54:40 +00:00
|
|
|
}
|
|
|
|
|
}
|