From: Thiemo Mättig Date: Thu, 16 Jul 2015 16:48:05 +0000 (-0500) Subject: Enforce an alphabetic default order for SiteList entries X-Git-Tag: 1.31.0-rc.0~10471^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/password.php?a=commitdiff_plain;h=9ab19a5420b6d6c5ce9b5af10b1a6fe67532d092;p=lhc%2Fweb%2Fwiklou.git Enforce an alphabetic default order for SiteList entries Bug: T106054 Change-Id: I8bf22d99b8304d7a6f40e384e8de00a4aca9313d --- 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() ); + } }