MediaWiki  REL1_21
wfParseUrlTest.php
Go to the documentation of this file.
00001 <?php
00025 class WfParseUrlTest extends MediaWikiTestCase {
00026         protected function setUp() {
00027                 parent::setUp();
00028 
00029                 $this->setMwGlobals( 'wgUrlProtocols', array(
00030                         '//', 'http://', 'file://', 'mailto:',
00031                 ) );
00032         }
00033 
00035         public function testWfParseUrl( $url, $parts ) {
00036                 $partsDump = var_export( $parts, true );
00037                 $this->assertEquals(
00038                         $parts,
00039                         wfParseUrl( $url ),
00040                         "Testing $url parses to $partsDump"
00041                 );
00042         }
00043 
00049         public static function provideURLs() {
00050                 return array(
00051                         array(
00052                                 '//example.org',
00053                                 array(
00054                                         'scheme' => '',
00055                                         'delimiter' => '//',
00056                                         'host' => 'example.org',
00057                                 )
00058                         ),
00059                         array(
00060                                 'http://example.org',
00061                                 array(
00062                                         'scheme' => 'http',
00063                                         'delimiter' => '://',
00064                                         'host' => 'example.org',
00065                                 )
00066                         ),
00067                         array(
00068                                 'http://id:[email protected]:123/path?foo=bar#baz',
00069                                 array(
00070                                         'scheme' => 'http',
00071                                         'delimiter' => '://',
00072                                         'user' => 'id',
00073                                         'pass' => 'key',
00074                                         'host' => 'example.org',
00075                                         'port' => 123,
00076                                         'path' => '/path',
00077                                         'query' => 'foo=bar',
00078                                         'fragment' => 'baz',
00079                                 )
00080                         ),
00081                         array(
00082                                 'file://example.org/etc/php.ini',
00083                                 array(
00084                                         'scheme' => 'file',
00085                                         'delimiter' => '://',
00086                                         'host' => 'example.org',
00087                                         'path' => '/etc/php.ini',
00088                                 )
00089                         ),
00090                         array(
00091                                 'file:///etc/php.ini',
00092                                 array(
00093                                         'scheme' => 'file',
00094                                         'delimiter' => '://',
00095                                         'host' => '',
00096                                         'path' => '/etc/php.ini',
00097                                 )
00098                         ),
00099                         array(
00100                                 'file:///c:/',
00101                                 array(
00102                                         'scheme' => 'file',
00103                                         'delimiter' => '://',
00104                                         'host' => '',
00105                                         'path' => '/c:/',
00106                                 )
00107                         ),
00108                         array(
00109                                 'mailto:[email protected]',
00110                                 array(
00111                                         'scheme' => 'mailto',
00112                                         'delimiter' => ':',
00113                                         'host' => '[email protected]',
00114                                         'path' => '',
00115                                 )
00116                         ),
00117                         array(
00118                                 'mailto:[email protected]?subject=Foo',
00119                                 array(
00120                                         'scheme' => 'mailto',
00121                                         'delimiter' => ':',
00122                                         'host' => '[email protected]',
00123                                         'path' => '',
00124                                         'query' => 'subject=Foo',
00125                                 )
00126                         ),
00127                         array(
00128                                 'mailto:?subject=Foo',
00129                                 array(
00130                                         'scheme' => 'mailto',
00131                                         'delimiter' => ':',
00132                                         'host' => '',
00133                                         'path' => '',
00134                                         'query' => 'subject=Foo',
00135                                 )
00136                         ),
00137                         array(
00138                                 'invalid://test/',
00139                                 false
00140                         ),
00141                 );
00142         }
00143 }