3 * @covers ::wfExpandUrl
5 class WfExpandUrlTest
extends MediaWikiTestCase
{
7 * @dataProvider provideExpandableUrls
9 public function testWfExpandUrl( $fullUrl, $shortUrl, $defaultProto, $server, $canServer, $httpsMode, $message ) {
10 // Fake $wgServer and $wgCanonicalServer
11 $this->setMwGlobals( array(
12 'wgServer' => $server,
13 'wgCanonicalServer' => $canServer,
16 // Fake $_SERVER['HTTPS'] if needed
18 $_SERVER['HTTPS'] = 'on';
20 unset( $_SERVER['HTTPS'] );
23 $this->assertEquals( $fullUrl, wfExpandUrl( $shortUrl, $defaultProto ), $message );
27 * Provider of URL examples for testing wfExpandUrl()
31 public static function provideExpandableUrls() {
32 $modes = array( 'http', 'https' );
34 'http' => 'http://example.com',
35 'https' => 'https://example.com',
36 'protocol-relative' => '//example.com'
38 $defaultProtos = array(
40 'https' => PROTO_HTTPS
,
41 'protocol-relative' => PROTO_RELATIVE
,
42 'current' => PROTO_CURRENT
,
43 'canonical' => PROTO_CANONICAL
47 foreach ( $modes as $mode ) {
48 $httpsMode = $mode == 'https';
49 foreach ( $servers as $serverDesc => $server ) {
50 foreach ( $modes as $canServerMode ) {
51 $canServer = "$canServerMode://example2.com";
52 foreach ( $defaultProtos as $protoDesc => $defaultProto ) {
54 'http://example.com', 'http://example.com',
55 $defaultProto, $server, $canServer, $httpsMode,
56 "Testing fully qualified http URLs (no need to expand) ' .
57 '(defaultProto: $protoDesc , wgServer: $server, wgCanonicalServer: $canServer, current request protocol: $mode )"
60 'https://example.com', 'https://example.com',
61 $defaultProto, $server, $canServer, $httpsMode,
62 "Testing fully qualified https URLs (no need to expand) ' .
63 '(defaultProto: $protoDesc , wgServer: $server, wgCanonicalServer: $canServer, current request protocol: $mode )"
65 # Would be nice to support this, see fixme on wfExpandUrl()
67 "wiki/FooBar", 'wiki/FooBar',
68 $defaultProto, $server, $canServer, $httpsMode,
69 "Test non-expandable relative URLs ' .
70 '(defaultProto: $protoDesc , wgServer: $server, wgCanonicalServer: $canServer, 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 ' .
96 '(defaultProto: $protoDesc, wgServer: $server, wgCanonicalServer: $canServer, current request protocol: $mode )"
99 "$srv/wiki/FooBar", '/wiki/FooBar',
100 $defaultProto, $server, $canServer, $httpsMode,
101 "Testing expanding URL beginning with / ' .
102 '(defaultProto: $protoDesc , wgServer: $server, wgCanonicalServer: $canServer, current request protocol: $mode )"