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