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