Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / includes / site / HashSiteStoreTest.php
blobc69ecfcc0c56194a9aa70d2309b9ac3498bf951c
1 <?php
3 namespace MediaWiki\Tests\Site;
5 use MediaWiki\Site\HashSiteStore;
6 use MediaWiki\Site\MediaWikiSite;
7 use MediaWiki\Site\Site;
8 use MediaWiki\Site\SiteList;
9 use MediaWikiIntegrationTestCase;
11 /**
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 * http://www.gnu.org/copyleft/gpl.html
27 * @file
28 * @since 1.25
30 * @ingroup Site
31 * @group Site
33 * @author Katie Filbert < aude.wiki@gmail.com >
35 class HashSiteStoreTest extends MediaWikiIntegrationTestCase {
37 /**
38 * @covers \MediaWiki\Site\HashSiteStore::getSites
40 public function testGetSites() {
41 $expectedSites = [];
43 foreach ( TestSites::getSites() as $testSite ) {
44 $siteId = $testSite->getGlobalId();
45 $expectedSites[$siteId] = $testSite;
48 $siteStore = new HashSiteStore( $expectedSites );
50 $this->assertEquals( new SiteList( $expectedSites ), $siteStore->getSites() );
53 /**
54 * @covers \MediaWiki\Site\HashSiteStore::saveSite
55 * @covers \MediaWiki\Site\HashSiteStore::getSite
57 public function testSaveSite() {
58 $store = new HashSiteStore();
60 $site = new Site();
61 $site->setGlobalId( 'dewiki' );
63 $this->assertCount( 0, $store->getSites(), '0 sites in store' );
65 $store->saveSite( $site );
67 $this->assertCount( 1, $store->getSites(), 'Store has 1 sites' );
68 $this->assertEquals( $site, $store->getSite( 'dewiki' ), 'Store has dewiki' );
71 /**
72 * @covers \MediaWiki\Site\HashSiteStore::saveSites
74 public function testSaveSites() {
75 $store = new HashSiteStore();
77 $sites = [];
79 $site = new Site();
80 $site->setGlobalId( 'enwiki' );
81 $site->setLanguageCode( 'en' );
82 $sites[] = $site;
84 $site = new MediaWikiSite();
85 $site->setGlobalId( 'eswiki' );
86 $site->setLanguageCode( 'es' );
87 $sites[] = $site;
89 $this->assertCount( 0, $store->getSites(), '0 sites in store' );
91 $store->saveSites( $sites );
93 $this->assertCount( 2, $store->getSites(), 'Store has 2 sites' );
94 $this->assertTrue( $store->getSites()->hasSite( 'enwiki' ), 'Store has enwiki' );
95 $this->assertTrue( $store->getSites()->hasSite( 'eswiki' ), 'Store has eswiki' );
98 /**
99 * @covers \MediaWiki\Site\HashSiteStore::clear
101 public function testClear() {
102 $store = new HashSiteStore();
104 $site = new Site();
105 $site->setGlobalId( 'arwiki' );
106 $store->saveSite( $site );
108 $this->assertCount( 1, $store->getSites(), '1 site in store' );
110 $store->clear();
111 $this->assertCount( 0, $store->getSites(), '0 sites in store' );