X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FWikiMapTest.php;h=199f63857663d877db8d062429419fe1269afc3c;hb=dcd0a3d53;hp=186ffdbcc32ffed732fbb131f9e2bc93597de05b;hpb=3e88f9fa2a5a00bc1330560accf8e9d09c8be42a;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/WikiMapTest.php b/tests/phpunit/includes/WikiMapTest.php index 186ffdbcc3..199f638576 100644 --- a/tests/phpunit/includes/WikiMapTest.php +++ b/tests/phpunit/includes/WikiMapTest.php @@ -1,4 +1,5 @@ assertEquals( $wiki, WikiMap::getWikiFromUrl( $url ) ); } + + public function provideGetWikiIdFromDomain() { + return [ + [ 'db-prefix', 'db-prefix' ], + [ wfWikiID(), wfWikiID() ], + [ new DatabaseDomain( 'db-dash', null, 'prefix' ), 'db-dash-prefix' ] + ]; + } + + /** + * @dataProvider provideGetWikiIdFromDomain + * @covers WikiMap::getWikiIdFromDomain() + */ + public function testGetWikiIdFromDomain( $domain, $wikiId ) { + $this->assertEquals( $wikiId, WikiMap::getWikiIdFromDomain( $domain ) ); + } + + /** + * @covers WikiMap::isCurrentWikiDomain() + * @covers WikiMap::getCurrentWikiDomain() + */ + public function testIsCurrentWikiDomain() { + $this->assertTrue( WikiMap::isCurrentWikiDomain( wfWikiID() ) ); + + $localDomain = DatabaseDomain::newFromId( wfWikiID() ); + $domain1 = new DatabaseDomain( + $localDomain->getDatabase(), 'someschema', $localDomain->getTablePrefix() ); + $domain2 = new DatabaseDomain( + $localDomain->getDatabase(), null, $localDomain->getTablePrefix() ); + + $this->assertTrue( WikiMap::isCurrentWikiDomain( $domain1 ), 'Schema ignored' ); + $this->assertTrue( WikiMap::isCurrentWikiDomain( $domain2 ), 'Schema ignored' ); + + $this->assertTrue( WikiMap::isCurrentWikiDomain( WikiMap::getCurrentWikiDomain() ) ); + } + + public function provideIsCurrentWikiId() { + return [ + [ 'db', 'db', null, '' ], + [ 'db','db', 'schema', '' ], + [ 'db-prefix', 'db', null, 'prefix' ], + [ 'db-prefix', 'db', 'schema', 'prefix' ], + // Bad hyphen cases (best effort support) + [ 'db-stuff', 'db-stuff', null, '' ], + [ 'db-stuff-prefix', 'db-stuff', null, 'prefix' ] + ]; + } + + /** + * @dataProvider provideIsCurrentWikiId + * @covers WikiMap::isCurrentWikiId() + * @covers WikiMap::getCurrentWikiDomain() + * @covers WikiMap::getWikiIdFromDomain() + */ + public function testIsCurrentWikiId( $wikiId, $db, $schema, $prefix ) { + $this->setMwGlobals( + [ 'wgDBname' => $db, 'wgDBmwschema' => $schema, 'wgDBprefix' => $prefix ] ); + + $this->assertTrue( WikiMap::isCurrentWikiId( $wikiId ), "ID matches" ); + $this->assertNotTrue( WikiMap::isCurrentWikiId( $wikiId . '-more' ), "Bogus ID" ); + } }