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
;
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
33 * @author Katie Filbert < aude.wiki@gmail.com >
35 class HashSiteStoreTest
extends MediaWikiIntegrationTestCase
{
38 * @covers \MediaWiki\Site\HashSiteStore::getSites
40 public function testGetSites() {
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() );
54 * @covers \MediaWiki\Site\HashSiteStore::saveSite
55 * @covers \MediaWiki\Site\HashSiteStore::getSite
57 public function testSaveSite() {
58 $store = new HashSiteStore();
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' );
72 * @covers \MediaWiki\Site\HashSiteStore::saveSites
74 public function testSaveSites() {
75 $store = new HashSiteStore();
80 $site->setGlobalId( 'enwiki' );
81 $site->setLanguageCode( 'en' );
84 $site = new MediaWikiSite();
85 $site->setGlobalId( 'eswiki' );
86 $site->setLanguageCode( 'es' );
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' );
99 * @covers \MediaWiki\Site\HashSiteStore::clear
101 public function testClear() {
102 $store = new HashSiteStore();
105 $site->setGlobalId( 'arwiki' );
106 $store->saveSite( $site );
108 $this->assertCount( 1, $store->getSites(), '1 site in store' );
111 $this->assertCount( 0, $store->getSites(), '0 sites in store' );