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