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