MediaWiki  REL1_22
wfAssembleUrlTest.php
Go to the documentation of this file.
00001 <?php
00005 class WfAssembleUrlTest extends MediaWikiTestCase {
00009     public function testWfAssembleUrl( $parts, $output ) {
00010         $partsDump = print_r( $parts, true );
00011         $this->assertEquals(
00012             $output,
00013             wfAssembleUrl( $parts ),
00014             "Testing $partsDump assembles to $output"
00015         );
00016     }
00017 
00023     public static function provideURLParts() {
00024         $schemes = array(
00025             '' => array(),
00026             '//' => array(
00027                 'delimiter' => '//',
00028             ),
00029             'http://' => array(
00030                 'scheme' => 'http',
00031                 'delimiter' => '://',
00032             ),
00033         );
00034 
00035         $hosts = array(
00036             '' => array(),
00037             'example.com' => array(
00038                 'host' => 'example.com',
00039             ),
00040             'example.com:123' => array(
00041                 'host' => 'example.com',
00042                 'port' => 123,
00043             ),
00044             '[email protected]' => array(
00045                 'user' => 'id',
00046                 'host' => 'example.com',
00047             ),
00048             '[email protected]:123' => array(
00049                 'user' => 'id',
00050                 'host' => 'example.com',
00051                 'port' => 123,
00052             ),
00053             'id:[email protected]' => array(
00054                 'user' => 'id',
00055                 'pass' => 'key',
00056                 'host' => 'example.com',
00057             ),
00058             'id:[email protected]:123' => array(
00059                 'user' => 'id',
00060                 'pass' => 'key',
00061                 'host' => 'example.com',
00062                 'port' => 123,
00063             ),
00064         );
00065 
00066         $cases = array();
00067         foreach ( $schemes as $scheme => $schemeParts ) {
00068             foreach ( $hosts as $host => $hostParts ) {
00069                 foreach ( array( '', '/path' ) as $path ) {
00070                     foreach ( array( '', 'query' ) as $query ) {
00071                         foreach ( array( '', 'fragment' ) as $fragment ) {
00072                             $parts = array_merge(
00073                                 $schemeParts,
00074                                 $hostParts
00075                             );
00076                             $url = $scheme .
00077                                 $host .
00078                                 $path;
00079 
00080                             if ( $path ) {
00081                                 $parts['path'] = $path;
00082                             }
00083                             if ( $query ) {
00084                                 $parts['query'] = $query;
00085                                 $url .= '?' . $query;
00086                             }
00087                             if ( $fragment ) {
00088                                 $parts['fragment'] = $fragment;
00089                                 $url .= '#' . $fragment;
00090                             }
00091 
00092                             $cases[] = array(
00093                                 $parts,
00094                                 $url,
00095                             );
00096                         }
00097                     }
00098                 }
00099             }
00100         }
00101 
00102         $complexURL = 'http://id:[email protected]:321' .
00103             '/over/there?name=ferret&foo=bar#nose';
00104         $cases[] = array(
00105             wfParseUrl( $complexURL ),
00106             $complexURL,
00107         );
00108 
00109         return $cases;
00110     }
00111 }