MediaWiki
REL1_19
|
00001 <?php 00006 class wfAssembleUrl extends MediaWikiTestCase { 00008 public function testWfAssembleUrl( $parts, $output ) { 00009 $partsDump = print_r( $parts, true ); 00010 $this->assertEquals( 00011 $output, 00012 wfAssembleUrl( $parts ), 00013 "Testing $partsDump assembles to $output" 00014 ); 00015 } 00016 00022 public function provideURLParts() { 00023 $schemes = array( 00024 '' => array(), 00025 '//' => array( 00026 'delimiter' => '//', 00027 ), 00028 'http://' => array( 00029 'scheme' => 'http', 00030 'delimiter' => '://', 00031 ), 00032 ); 00033 00034 $hosts = array( 00035 '' => array(), 00036 'example.com' => array( 00037 'host' => 'example.com', 00038 ), 00039 'example.com:123' => array( 00040 'host' => 'example.com', 00041 'port' => 123, 00042 ), 00043 '[email protected]' => array( 00044 'user' => 'id', 00045 'host' => 'example.com', 00046 ), 00047 '[email protected]:123' => array( 00048 'user' => 'id', 00049 'host' => 'example.com', 00050 'port' => 123, 00051 ), 00052 'id:[email protected]' => array( 00053 'user' => 'id', 00054 'pass' => 'key', 00055 'host' => 'example.com', 00056 ), 00057 'id:[email protected]:123' => array( 00058 'user' => 'id', 00059 'pass' => 'key', 00060 'host' => 'example.com', 00061 'port' => 123, 00062 ), 00063 ); 00064 00065 $cases = array(); 00066 foreach ( $schemes as $scheme => $schemeParts ) { 00067 foreach ( $hosts as $host => $hostParts ) { 00068 foreach ( array( '', '/path' ) as $path ) { 00069 foreach ( array( '', 'query' ) as $query ) { 00070 foreach ( array( '', 'fragment' ) as $fragment ) { 00071 $parts = array_merge( 00072 $schemeParts, 00073 $hostParts 00074 ); 00075 $url = $scheme . 00076 $host . 00077 $path; 00078 00079 if ( $path ) { 00080 $parts['path'] = $path; 00081 } 00082 if ( $query ) { 00083 $parts['query'] = $query; 00084 $url .= '?' . $query; 00085 } 00086 if( $fragment ) { 00087 $parts['fragment'] = $fragment; 00088 $url .= '#' . $fragment; 00089 } 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 }