X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FWikiMapTest.php;h=1fb8affa39626ec726a73c7903289f327d55ab5d;hb=51945dbca3594;hp=53e0b10b880419a084aa7c904a2cf6dd28447fbe;hpb=f638ac8b9a832abb728f016e50129b9c928bf097;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/WikiMapTest.php b/tests/phpunit/includes/WikiMapTest.php index 53e0b10b88..1fb8affa39 100644 --- a/tests/phpunit/includes/WikiMapTest.php +++ b/tests/phpunit/includes/WikiMapTest.php @@ -235,6 +235,18 @@ class WikiMapTest extends MediaWikiLangTestCase { $this->assertEquals( $wiki, WikiMap::getWikiFromUrl( $url ) ); } + public function provideGetWikiIdFromDomain() { + return [ + [ 'db-prefix', 'db-prefix' ], + [ wfWikiID(), wfWikiID() ], + [ new DatabaseDomain( 'db-dash', null, 'prefix' ), 'db-dash-prefix' ], + [ wfWikiID(), wfWikiID() ], + [ new DatabaseDomain( 'db-dash', null, 'prefix' ), 'db-dash-prefix' ], + [ new DatabaseDomain( 'db', 'mediawiki', 'prefix' ), 'db-prefix' ], // schema ignored + [ new DatabaseDomain( 'db', 'custom', 'prefix' ), 'db-custom-prefix' ], + ]; + } + /** * @dataProvider provideGetWikiIdFromDomain * @covers WikiMap::getWikiIdFromDomain() @@ -243,11 +255,53 @@ class WikiMapTest extends MediaWikiLangTestCase { $this->assertEquals( $wikiId, WikiMap::getWikiIdFromDomain( $domain ) ); } - public function provideGetWikiIdFromDomain() { + /** + * @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-prefix', 'db-prefix' ], - [ wfWikiID(), wfWikiID() ], - [ new DatabaseDomain( 'db-dash', null, 'prefix' ), 'db-dash-prefix' ] + [ 'db', 'db', null, '' ], + [ 'db-schema-','db', 'schema', '' ], + [ 'db','db', 'mediawiki', '' ], // common b/c case + [ 'db-prefix', 'db', null, 'prefix' ], + [ 'db-schema-prefix', 'db', 'schema', 'prefix' ], + [ 'db-prefix', 'db', 'mediawiki', 'prefix' ], // common b/c case + // Bad hyphen cases (best effort support) + [ 'db-stuff', 'db-stuff', null, '' ], + [ 'db-stuff-prefix', 'db-stuff', null, 'prefix' ], + [ 'db-stuff-schema-', 'db-stuff', 'schema', '' ], + [ 'db-stuff-schema-prefix', 'db-stuff', 'schema', 'prefix' ], + [ 'db-stuff-prefix', 'db-stuff', 'mediawiki', 'prefix' ] // common b/c case ]; } + + /** + * @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" ); + } }