From 9ab19a5420b6d6c5ce9b5af10b1a6fe67532d092 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thiemo=20M=C3=A4ttig?= Date: Thu, 16 Jul 2015 11:48:05 -0500 Subject: [PATCH] Enforce an alphabetic default order for SiteList entries Bug: T106054 Change-Id: I8bf22d99b8304d7a6f40e384e8de00a4aca9313d --- includes/site/DBSiteStore.php | 6 ++++- .../phpunit/includes/site/DBSiteStoreTest.php | 24 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/includes/site/DBSiteStore.php b/includes/site/DBSiteStore.php index f167584e70..1193bd65f6 100644 --- a/includes/site/DBSiteStore.php +++ b/includes/site/DBSiteStore.php @@ -153,7 +153,11 @@ class DBSiteStore implements SiteStore { protected function loadSites() { $this->sites = new SiteList(); - foreach ( $this->sitesTable->select() as $siteRow ) { + $siteRows = $this->sitesTable->select( null, array(), array( + 'ORDER BY' => 'site_global_key' + ) ); + + foreach ( $siteRows as $siteRow ) { $this->sites[] = $this->siteFromRow( $siteRow ); } diff --git a/tests/phpunit/includes/site/DBSiteStoreTest.php b/tests/phpunit/includes/site/DBSiteStoreTest.php index 673ba54d63..48ef5243b9 100644 --- a/tests/phpunit/includes/site/DBSiteStoreTest.php +++ b/tests/phpunit/includes/site/DBSiteStoreTest.php @@ -130,4 +130,28 @@ class DBSiteStoreTest extends MediaWikiTestCase { $sites = $store->getSites(); $this->assertEquals( 0, $sites->count() ); } + + /** + * @covers DBSiteStore::getSites + */ + public function testGetSitesDefaultOrder() { + $store = new DBSiteStore(); + $siteB = new Site(); + $siteB->setGlobalId( 'B' ); + $siteA = new Site(); + $siteA->setGlobalId( 'A' ); + $store->saveSites( array( $siteB, $siteA ) ); + + $sites = $store->getSites(); + $siteIdentifiers = array(); + /** @var Site $site */ + foreach ( $sites as $site ) { + $siteIdentifiers[] = $site->getGlobalId(); + } + $this->assertSame( array( 'A', 'B' ), $siteIdentifiers ); + + // Note: SiteList::getGlobalIdentifiers uses an other internal state. Iteration must be + // tested separately. + $this->assertSame( array( 'A', 'B' ), $sites->getGlobalIdentifiers() ); + } } -- 2.20.1