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