3 * @group GlobalFunctions
4 * @covers ::wfExpandUrl
6 class WfExpandUrlTest
extends MediaWikiTestCase
{
8 * @dataProvider provideExpandableUrls
10 public function testWfExpandUrl( $fullUrl, $shortUrl, $defaultProto,
11 $server, $canServer, $httpsMode, $message
13 // Fake $wgServer, $wgCanonicalServer and $wgRequest->getProtocol()
14 $this->setMwGlobals( array(
15 'wgServer' => $server,
16 'wgCanonicalServer' => $canServer,
17 'wgRequest' => new FauxRequest( array(), false, null, $httpsMode ?
'https' : 'http' )
20 $this->assertEquals( $fullUrl, wfExpandUrl( $shortUrl, $defaultProto ), $message );
24 * Provider of URL examples for testing wfExpandUrl()
28 public static function provideExpandableUrls() {
29 $modes = array( 'http', 'https' );
31 'http' => 'http://example.com',
32 'https' => 'https://example.com',
33 'protocol-relative' => '//example.com'
35 $defaultProtos = array(
37 'https' => PROTO_HTTPS
,
38 'protocol-relative' => PROTO_RELATIVE
,
39 'current' => PROTO_CURRENT
,
40 'canonical' => PROTO_CANONICAL
44 foreach ( $modes as $mode ) {
45 $httpsMode = $mode == 'https';
46 foreach ( $servers as $serverDesc => $server ) {
47 foreach ( $modes as $canServerMode ) {
48 $canServer = "$canServerMode://example2.com";
49 foreach ( $defaultProtos as $protoDesc => $defaultProto ) {
51 'http://example.com', 'http://example.com',
52 $defaultProto, $server, $canServer, $httpsMode,
53 "Testing fully qualified http URLs (no need to expand) "
54 . "(defaultProto: $protoDesc , wgServer: $server, "
55 . "wgCanonicalServer: $canServer, current request protocol: $mode )"
58 'https://example.com', 'https://example.com',
59 $defaultProto, $server, $canServer, $httpsMode,
60 "Testing fully qualified https URLs (no need to expand) "
61 . "(defaultProto: $protoDesc , wgServer: $server, "
62 . "wgCanonicalServer: $canServer, current request protocol: $mode )"
64 # Would be nice to support this, see fixme on wfExpandUrl()
66 "wiki/FooBar", 'wiki/FooBar',
67 $defaultProto, $server, $canServer, $httpsMode,
68 "Test non-expandable relative URLs (defaultProto: $protoDesc, "
69 . "wgServer: $server, wgCanonicalServer: $canServer, "
70 . "current request protocol: $mode )"
73 // Determine expected protocol
74 if ( $protoDesc == 'protocol-relative' ) {
76 } elseif ( $protoDesc == 'current' ) {
78 } elseif ( $protoDesc == 'canonical' ) {
79 $p = "$canServerMode:";
81 $p = $protoDesc . ':';
83 // Determine expected server name
84 if ( $protoDesc == 'canonical' ) {
86 } elseif ( $serverDesc == 'protocol-relative' ) {
93 "$p//wikipedia.org", '//wikipedia.org',
94 $defaultProto, $server, $canServer, $httpsMode,
95 "Test protocol-relative URL (defaultProto: $protoDesc, "
96 . "wgServer: $server, wgCanonicalServer: $canServer, "
97 . "current request protocol: $mode )"
106 "Testing expanding URL beginning with / (defaultProto: $protoDesc, "
107 . "wgServer: $server, wgCanonicalServer: $canServer, "
108 . "current request protocol: $mode )"