MediaWiki
REL1_24
|
00001 <?php 00027 class WfParseUrlTest extends MediaWikiTestCase { 00028 protected function setUp() { 00029 parent::setUp(); 00030 00031 $this->setMwGlobals( 'wgUrlProtocols', array( 00032 '//', 00033 'http://', 00034 'https://', 00035 'file://', 00036 'mailto:', 00037 ) ); 00038 } 00039 00043 public function testWfParseUrl( $url, $parts ) { 00044 $this->assertEquals( 00045 $parts, 00046 wfParseUrl( $url ) 00047 ); 00048 } 00049 00055 public static function provideURLs() { 00056 return array( 00057 array( 00058 '//example.org', 00059 array( 00060 'scheme' => '', 00061 'delimiter' => '//', 00062 'host' => 'example.org', 00063 ) 00064 ), 00065 array( 00066 'http://example.org', 00067 array( 00068 'scheme' => 'http', 00069 'delimiter' => '://', 00070 'host' => 'example.org', 00071 ) 00072 ), 00073 array( 00074 'https://example.org', 00075 array( 00076 'scheme' => 'https', 00077 'delimiter' => '://', 00078 'host' => 'example.org', 00079 ) 00080 ), 00081 array( 00082 'http://id:[email protected]:123/path?foo=bar#baz', 00083 array( 00084 'scheme' => 'http', 00085 'delimiter' => '://', 00086 'user' => 'id', 00087 'pass' => 'key', 00088 'host' => 'example.org', 00089 'port' => 123, 00090 'path' => '/path', 00091 'query' => 'foo=bar', 00092 'fragment' => 'baz', 00093 ) 00094 ), 00095 array( 00096 'file://example.org/etc/php.ini', 00097 array( 00098 'scheme' => 'file', 00099 'delimiter' => '://', 00100 'host' => 'example.org', 00101 'path' => '/etc/php.ini', 00102 ) 00103 ), 00104 array( 00105 'file:///etc/php.ini', 00106 array( 00107 'scheme' => 'file', 00108 'delimiter' => '://', 00109 'host' => '', 00110 'path' => '/etc/php.ini', 00111 ) 00112 ), 00113 array( 00114 'file:///c:/', 00115 array( 00116 'scheme' => 'file', 00117 'delimiter' => '://', 00118 'host' => '', 00119 'path' => '/c:/', 00120 ) 00121 ), 00122 array( 00123 'mailto:[email protected]', 00124 array( 00125 'scheme' => 'mailto', 00126 'delimiter' => ':', 00127 'host' => '[email protected]', 00128 'path' => '', 00129 ) 00130 ), 00131 array( 00132 'mailto:[email protected]?subject=Foo', 00133 array( 00134 'scheme' => 'mailto', 00135 'delimiter' => ':', 00136 'host' => '[email protected]', 00137 'path' => '', 00138 'query' => 'subject=Foo', 00139 ) 00140 ), 00141 array( 00142 'mailto:?subject=Foo', 00143 array( 00144 'scheme' => 'mailto', 00145 'delimiter' => ':', 00146 'host' => '', 00147 'path' => '', 00148 'query' => 'subject=Foo', 00149 ) 00150 ), 00151 array( 00152 'invalid://test/', 00153 false 00154 ), 00155 ); 00156 } 00157 }