X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fsite%2FDBSiteStoreTest.php;h=32dd7f282cef7063854781d545754d0539953a98;hb=91d40b872f960d2b53a4d9dd2a8b77f953f6ff41;hp=673ba54d6380184e6a72579b959d17daaccfbcbf;hpb=3368cccde53732c1278f51632e69b9865c4ee6ba;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/site/DBSiteStoreTest.php b/tests/phpunit/includes/site/DBSiteStoreTest.php index 673ba54d63..32dd7f282c 100644 --- a/tests/phpunit/includes/site/DBSiteStoreTest.php +++ b/tests/phpunit/includes/site/DBSiteStoreTest.php @@ -31,6 +31,15 @@ */ class DBSiteStoreTest extends MediaWikiTestCase { + /** + * @return DBSiteStore + */ + private function newDBSiteStore() { + // NOTE: Use the real DB load balancer for now. Eventually, the test framework should + // provide a LoadBalancer that is safe to use in unit tests. + return new DBSiteStore( wfGetLB() ); + } + /** * @covers DBSiteStore::getSites */ @@ -38,7 +47,7 @@ class DBSiteStoreTest extends MediaWikiTestCase { $expectedSites = TestSites::getSites(); TestSites::insertIntoDb(); - $store = new DBSiteStore(); + $store = $this->newDBSiteStore(); $sites = $store->getSites(); @@ -62,9 +71,9 @@ class DBSiteStoreTest extends MediaWikiTestCase { * @covers DBSiteStore::saveSites */ public function testSaveSites() { - $store = new DBSiteStore(); + $store = $this->newDBSiteStore(); - $sites = array(); + $sites = []; $site = new Site(); $site->setGlobalId( 'ertrywuutr' ); @@ -95,8 +104,8 @@ class DBSiteStoreTest extends MediaWikiTestCase { * @covers DBSiteStore::reset */ public function testReset() { - $store1 = new DBSiteStore(); - $store2 = new DBSiteStore(); + $store1 = $this->newDBSiteStore(); + $store2 = $this->newDBSiteStore(); // initialize internal cache $this->assertGreaterThan( 0, $store1->getSites()->count() ); @@ -121,7 +130,7 @@ class DBSiteStoreTest extends MediaWikiTestCase { * @covers DBSiteStore::clear */ public function testClear() { - $store = new DBSiteStore(); + $store = $this->newDBSiteStore(); $this->assertTrue( $store->clear() ); $site = $store->getSite( 'enwiki' ); @@ -130,4 +139,28 @@ class DBSiteStoreTest extends MediaWikiTestCase { $sites = $store->getSites(); $this->assertEquals( 0, $sites->count() ); } + + /** + * @covers DBSiteStore::getSites + */ + public function testGetSitesDefaultOrder() { + $store = $this->newDBSiteStore(); + $siteB = new Site(); + $siteB->setGlobalId( 'B' ); + $siteA = new Site(); + $siteA->setGlobalId( 'A' ); + $store->saveSites( [ $siteB, $siteA ] ); + + $sites = $store->getSites(); + $siteIdentifiers = []; + /** @var Site $site */ + foreach ( $sites as $site ) { + $siteIdentifiers[] = $site->getGlobalId(); + } + $this->assertSame( [ 'A', 'B' ], $siteIdentifiers ); + + // Note: SiteList::getGlobalIdentifiers uses an other internal state. Iteration must be + // tested separately. + $this->assertSame( [ 'A', 'B' ], $sites->getGlobalIdentifiers() ); + } }