MediaWiki
REL1_23
|
00001 <?php 00005 class WfExpandUrlTest extends MediaWikiTestCase { 00009 public function testWfExpandUrl( $fullUrl, $shortUrl, $defaultProto, $server, $canServer, $httpsMode, $message ) { 00010 // Fake $wgServer, $wgCanonicalServer and $wgRequest->getProtocol() 00011 $this->setMwGlobals( array( 00012 'wgServer' => $server, 00013 'wgCanonicalServer' => $canServer, 00014 'wgRequest' => new FauxRequest( array(), false, null, $httpsMode ? 'https' : 'http' ) 00015 ) ); 00016 00017 $this->assertEquals( $fullUrl, wfExpandUrl( $shortUrl, $defaultProto ), $message ); 00018 } 00019 00025 public static function provideExpandableUrls() { 00026 $modes = array( 'http', 'https' ); 00027 $servers = array( 00028 'http' => 'http://example.com', 00029 'https' => 'https://example.com', 00030 'protocol-relative' => '//example.com' 00031 ); 00032 $defaultProtos = array( 00033 'http' => PROTO_HTTP, 00034 'https' => PROTO_HTTPS, 00035 'protocol-relative' => PROTO_RELATIVE, 00036 'current' => PROTO_CURRENT, 00037 'canonical' => PROTO_CANONICAL 00038 ); 00039 00040 $retval = array(); 00041 foreach ( $modes as $mode ) { 00042 $httpsMode = $mode == 'https'; 00043 foreach ( $servers as $serverDesc => $server ) { 00044 foreach ( $modes as $canServerMode ) { 00045 $canServer = "$canServerMode://example2.com"; 00046 foreach ( $defaultProtos as $protoDesc => $defaultProto ) { 00047 $retval[] = array( 00048 'http://example.com', 'http://example.com', 00049 $defaultProto, $server, $canServer, $httpsMode, 00050 "Testing fully qualified http URLs (no need to expand) ' . 00051 '(defaultProto: $protoDesc , wgServer: $server, wgCanonicalServer: $canServer, current request protocol: $mode )" 00052 ); 00053 $retval[] = array( 00054 'https://example.com', 'https://example.com', 00055 $defaultProto, $server, $canServer, $httpsMode, 00056 "Testing fully qualified https URLs (no need to expand) ' . 00057 '(defaultProto: $protoDesc , wgServer: $server, wgCanonicalServer: $canServer, current request protocol: $mode )" 00058 ); 00059 # Would be nice to support this, see fixme on wfExpandUrl() 00060 $retval[] = array( 00061 "wiki/FooBar", 'wiki/FooBar', 00062 $defaultProto, $server, $canServer, $httpsMode, 00063 "Test non-expandable relative URLs ' . 00064 '(defaultProto: $protoDesc , wgServer: $server, wgCanonicalServer: $canServer, current request protocol: $mode )" 00065 ); 00066 00067 // Determine expected protocol 00068 if ( $protoDesc == 'protocol-relative' ) { 00069 $p = ''; 00070 } elseif ( $protoDesc == 'current' ) { 00071 $p = "$mode:"; 00072 } elseif ( $protoDesc == 'canonical' ) { 00073 $p = "$canServerMode:"; 00074 } else { 00075 $p = $protoDesc . ':'; 00076 } 00077 // Determine expected server name 00078 if ( $protoDesc == 'canonical' ) { 00079 $srv = $canServer; 00080 } elseif ( $serverDesc == 'protocol-relative' ) { 00081 $srv = $p . $server; 00082 } else { 00083 $srv = $server; 00084 } 00085 00086 $retval[] = array( 00087 "$p//wikipedia.org", '//wikipedia.org', 00088 $defaultProto, $server, $canServer, $httpsMode, 00089 "Test protocol-relative URL ' . 00090 '(defaultProto: $protoDesc, wgServer: $server, wgCanonicalServer: $canServer, current request protocol: $mode )" 00091 ); 00092 $retval[] = array( 00093 "$srv/wiki/FooBar", '/wiki/FooBar', 00094 $defaultProto, $server, $canServer, $httpsMode, 00095 "Testing expanding URL beginning with / ' . 00096 '(defaultProto: $protoDesc , wgServer: $server, wgCanonicalServer: $canServer, current request protocol: $mode )" 00097 ); 00098 } 00099 } 00100 } 00101 } 00102 00103 return $retval; 00104 } 00105 }