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