X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/tests/phpunit/includes/site/MediaWikiSiteTest.php diff --git a/tests/phpunit/includes/site/MediaWikiSiteTest.php b/tests/phpunit/includes/site/MediaWikiSiteTest.php new file mode 100644 index 00000000..b3679799 --- /dev/null +++ b/tests/phpunit/includes/site/MediaWikiSiteTest.php @@ -0,0 +1,108 @@ + + */ +class MediaWikiSiteTest extends SiteTest { + + public function testNormalizePageTitle() { + $this->setMwGlobals( [ + 'wgCapitalLinks' => true, + ] ); + + $site = new MediaWikiSite(); + $site->setGlobalId( 'enwiki' ); + + // NOTE: this does not actually call out to the enwiki site to perform the normalization, + // but uses a local Title object to do so. This is hardcoded on SiteLink::normalizePageTitle + // for the case that MW_PHPUNIT_TEST is set. + $this->assertEquals( 'Foo', $site->normalizePageName( ' foo ' ) ); + } + + public function fileUrlProvider() { + return [ + // url, filepath, path arg, expected + [ 'https://en.wikipedia.org', '/w/$1', 'api.php', 'https://en.wikipedia.org/w/api.php' ], + [ 'https://en.wikipedia.org', '/w/', 'api.php', 'https://en.wikipedia.org/w/' ], + [ + 'https://en.wikipedia.org', + '/foo/page.php?name=$1', + 'api.php', + 'https://en.wikipedia.org/foo/page.php?name=api.php' + ], + [ + 'https://en.wikipedia.org', + '/w/$1', + '', + 'https://en.wikipedia.org/w/' + ], + [ + 'https://en.wikipedia.org', + '/w/$1', + 'foo/bar/api.php', + 'https://en.wikipedia.org/w/foo/bar/api.php' + ], + ]; + } + + /** + * @dataProvider fileUrlProvider + * @covers MediaWikiSite::getFileUrl + */ + public function testGetFileUrl( $url, $filePath, $pathArgument, $expected ) { + $site = new MediaWikiSite(); + $site->setFilePath( $url . $filePath ); + + $this->assertEquals( $expected, $site->getFileUrl( $pathArgument ) ); + } + + public static function provideGetPageUrl() { + return [ + // path, page, expected substring + [ 'http://acme.test/wiki/$1', 'Berlin', '/wiki/Berlin' ], + [ 'http://acme.test/wiki/', 'Berlin', '/wiki/' ], + [ 'http://acme.test/w/index.php?title=$1', 'Berlin', '/w/index.php?title=Berlin' ], + [ 'http://acme.test/wiki/$1', '', '/wiki/' ], + [ 'http://acme.test/wiki/$1', 'Berlin/sub page', '/wiki/Berlin/sub_page' ], + [ 'http://acme.test/wiki/$1', 'Cork (city) ', '/Cork_(city)' ], + [ 'http://acme.test/wiki/$1', 'M&M', '/wiki/M%26M' ], + ]; + } + + /** + * @dataProvider provideGetPageUrl + * @covers MediaWikiSite::getPageUrl + */ + public function testGetPageUrl( $path, $page, $expected ) { + $site = new MediaWikiSite(); + $site->setLinkPath( $path ); + + $this->assertContains( $path, $site->getPageUrl() ); + $this->assertContains( $expected, $site->getPageUrl( $page ) ); + } +}