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