3 * @covers ::wfExpandUrl
5 class WfExpandUrlTest
extends MediaWikiTestCase
{
7 * @dataProvider provideExpandableUrls
9 public function testWfExpandUrl( $fullUrl, $shortUrl, $defaultProto,
10 $server, $canServer, $httpsMode, $message
12 // Fake $wgServer, $wgCanonicalServer and $wgRequest->getProtocol()
13 $this->setMwGlobals( array(
14 'wgServer' => $server,
15 'wgCanonicalServer' => $canServer,
16 'wgRequest' => new FauxRequest( array(), false, null, $httpsMode ?
'https' : 'http' )
19 $this->assertEquals( $fullUrl, wfExpandUrl( $shortUrl, $defaultProto ), $message );
23 * Provider of URL examples for testing wfExpandUrl()
27 public static function provideExpandableUrls() {
28 $modes = array( 'http', 'https' );
30 'http' => 'http://example.com',
31 'https' => 'https://example.com',
32 'protocol-relative' => '//example.com'
34 $defaultProtos = array(
36 'https' => PROTO_HTTPS
,
37 'protocol-relative' => PROTO_RELATIVE
,
38 'current' => PROTO_CURRENT
,
39 'canonical' => PROTO_CANONICAL
43 foreach ( $modes as $mode ) {
44 $httpsMode = $mode == 'https';
45 foreach ( $servers as $serverDesc => $server ) {
46 foreach ( $modes as $canServerMode ) {
47 $canServer = "$canServerMode://example2.com";
48 foreach ( $defaultProtos as $protoDesc => $defaultProto ) {
50 'http://example.com', 'http://example.com',
51 $defaultProto, $server, $canServer, $httpsMode,
52 "Testing fully qualified http URLs (no need to expand) "
53 . "(defaultProto: $protoDesc , wgServer: $server, "
54 . "wgCanonicalServer: $canServer, current request protocol: $mode )"
57 'https://example.com', 'https://example.com',
58 $defaultProto, $server, $canServer, $httpsMode,
59 "Testing fully qualified https URLs (no need to expand) "
60 . "(defaultProto: $protoDesc , wgServer: $server, "
61 . "wgCanonicalServer: $canServer, current request protocol: $mode )"
63 # Would be nice to support this, see fixme on wfExpandUrl()
65 "wiki/FooBar", 'wiki/FooBar',
66 $defaultProto, $server, $canServer, $httpsMode,
67 "Test non-expandable relative URLs (defaultProto: $protoDesc, "
68 . "wgServer: $server, wgCanonicalServer: $canServer, "
69 . "current request protocol: $mode )"
72 // Determine expected protocol
73 if ( $protoDesc == 'protocol-relative' ) {
75 } elseif ( $protoDesc == 'current' ) {
77 } elseif ( $protoDesc == 'canonical' ) {
78 $p = "$canServerMode:";
80 $p = $protoDesc . ':';
82 // Determine expected server name
83 if ( $protoDesc == 'canonical' ) {
85 } elseif ( $serverDesc == 'protocol-relative' ) {
92 "$p//wikipedia.org", '//wikipedia.org',
93 $defaultProto, $server, $canServer, $httpsMode,
94 "Test protocol-relative URL (defaultProto: $protoDesc, "
95 . "wgServer: $server, wgCanonicalServer: $canServer, "
96 . "current request protocol: $mode )"
105 "Testing expanding URL beginning with / (defaultProto: $protoDesc, "
106 . "wgServer: $server, wgCanonicalServer: $canServer, "
107 . "current request protocol: $mode )"