MediaWiki  REL1_22
MediaWikiSiteTest.php
Go to the documentation of this file.
00001 <?php
00002 
00032 class MediaWikiSiteTest extends SiteTest {
00033 
00034     public function testNormalizePageTitle() {
00035         $site = new MediaWikiSite();
00036         $site->setGlobalId( 'enwiki' );
00037 
00038         //NOTE: this does not actually call out to the enwiki site to perform the normalization,
00039         //      but uses a local Title object to do so. This is hardcoded on SiteLink::normalizePageTitle
00040         //      for the case that MW_PHPUNIT_TEST is set.
00041         $this->assertEquals( 'Foo', $site->normalizePageName( ' foo ' ) );
00042     }
00043 
00044     public function fileUrlProvider() {
00045         return array(
00046             // url, filepath, path arg, expected
00047             array( 'https://en.wikipedia.org', '/w/$1', 'api.php', 'https://en.wikipedia.org/w/api.php' ),
00048             array( 'https://en.wikipedia.org', '/w/', 'api.php', 'https://en.wikipedia.org/w/' ),
00049             array( 'https://en.wikipedia.org', '/foo/page.php?name=$1', 'api.php', 'https://en.wikipedia.org/foo/page.php?name=api.php' ),
00050             array( 'https://en.wikipedia.org', '/w/$1', '', 'https://en.wikipedia.org/w/' ),
00051             array( 'https://en.wikipedia.org', '/w/$1', 'foo/bar/api.php', 'https://en.wikipedia.org/w/foo/bar/api.php' ),
00052         );
00053     }
00054 
00059     public function testGetFileUrl( $url, $filePath, $pathArgument, $expected ) {
00060         $site = new MediaWikiSite();
00061         $site->setFilePath( $url . $filePath );
00062 
00063         $this->assertEquals( $expected, $site->getFileUrl( $pathArgument ) );
00064     }
00065 
00066     public static function provideGetPageUrl() {
00067         return array(
00068             // path, page, expected substring
00069             array( 'http://acme.test/wiki/$1', 'Berlin', '/wiki/Berlin' ),
00070             array( 'http://acme.test/wiki/', 'Berlin', '/wiki/' ),
00071             array( 'http://acme.test/w/index.php?title=$1', 'Berlin', '/w/index.php?title=Berlin' ),
00072             array( 'http://acme.test/wiki/$1', '', '/wiki/' ),
00073             array( 'http://acme.test/wiki/$1', 'Berlin/sub page', '/wiki/Berlin/sub_page' ),
00074             array( 'http://acme.test/wiki/$1', 'Cork (city)   ', '/Cork_(city)' ),
00075             array( 'http://acme.test/wiki/$1', 'M&M', '/wiki/M%26M' ),
00076         );
00077     }
00078 
00083     public function testGetPageUrl( $path, $page, $expected ) {
00084         $site = new MediaWikiSite();
00085         $site->setLinkPath( $path );
00086 
00087         $this->assertContains( $path, $site->getPageUrl() );
00088         $this->assertContains( $expected, $site->getPageUrl( $page ) );
00089     }
00090 }