MediaWiki  REL1_24
wfExpandUrlTest.php
Go to the documentation of this file.
00001 <?php
00006 class WfExpandUrlTest extends MediaWikiTestCase {
00010     public function testWfExpandUrl( $fullUrl, $shortUrl, $defaultProto,
00011         $server, $canServer, $httpsMode, $message
00012     ) {
00013         // Fake $wgServer, $wgCanonicalServer and $wgRequest->getProtocol()
00014         $this->setMwGlobals( array(
00015             'wgServer' => $server,
00016             'wgCanonicalServer' => $canServer,
00017             'wgRequest' => new FauxRequest( array(), false, null, $httpsMode ? 'https' : 'http' )
00018         ) );
00019 
00020         $this->assertEquals( $fullUrl, wfExpandUrl( $shortUrl, $defaultProto ), $message );
00021     }
00022 
00028     public static function provideExpandableUrls() {
00029         $modes = array( 'http', 'https' );
00030         $servers = array(
00031             'http' => 'http://example.com',
00032             'https' => 'https://example.com',
00033             'protocol-relative' => '//example.com'
00034         );
00035         $defaultProtos = array(
00036             'http' => PROTO_HTTP,
00037             'https' => PROTO_HTTPS,
00038             'protocol-relative' => PROTO_RELATIVE,
00039             'current' => PROTO_CURRENT,
00040             'canonical' => PROTO_CANONICAL
00041         );
00042 
00043         $retval = array();
00044         foreach ( $modes as $mode ) {
00045             $httpsMode = $mode == 'https';
00046             foreach ( $servers as $serverDesc => $server ) {
00047                 foreach ( $modes as $canServerMode ) {
00048                     $canServer = "$canServerMode://example2.com";
00049                     foreach ( $defaultProtos as $protoDesc => $defaultProto ) {
00050                         $retval[] = array(
00051                             'http://example.com', 'http://example.com',
00052                             $defaultProto, $server, $canServer, $httpsMode,
00053                             "Testing fully qualified http URLs (no need to expand) "
00054                                 . "(defaultProto: $protoDesc , wgServer: $server, "
00055                                 . "wgCanonicalServer: $canServer, current request protocol: $mode )"
00056                         );
00057                         $retval[] = array(
00058                             'https://example.com', 'https://example.com',
00059                             $defaultProto, $server, $canServer, $httpsMode,
00060                             "Testing fully qualified https URLs (no need to expand) "
00061                                 . "(defaultProto: $protoDesc , wgServer: $server, "
00062                                 . "wgCanonicalServer: $canServer, current request protocol: $mode )"
00063                         );
00064                         # Would be nice to support this, see fixme on wfExpandUrl()
00065                         $retval[] = array(
00066                             "wiki/FooBar", 'wiki/FooBar',
00067                             $defaultProto, $server, $canServer, $httpsMode,
00068                             "Test non-expandable relative URLs (defaultProto: $protoDesc, "
00069                                 . "wgServer: $server, wgCanonicalServer: $canServer, "
00070                                 . "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 (defaultProto: $protoDesc, "
00096                                 . "wgServer: $server, wgCanonicalServer: $canServer, "
00097                                 . "current request protocol: $mode )"
00098                         );
00099                         $retval[] = array(
00100                             "$srv/wiki/FooBar",
00101                             '/wiki/FooBar',
00102                             $defaultProto,
00103                             $server,
00104                             $canServer,
00105                             $httpsMode,
00106                             "Testing expanding URL beginning with / (defaultProto: $protoDesc, "
00107                                 . "wgServer: $server, wgCanonicalServer: $canServer, "
00108                                 . "current request protocol: $mode )"
00109                         );
00110                     }
00111                 }
00112             }
00113         }
00114 
00115         return $retval;
00116     }
00117 }