Merge "Update docs/hooks.txt for ShowSearchHitTitle"
[mediawiki.git] / tests / phpunit / includes / site / HashSiteStoreTest.php
blob6269fd39dc24337d91daccb296c8ca507cf379d6
1 <?php
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.
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.
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
19 * @file
20 * @since 1.25
22 * @ingroup Site
23 * @group Site
25 * @author Katie Filbert < aude.wiki@gmail.com >
27 class HashSiteStoreTest extends MediaWikiTestCase {
29 /**
30 * @covers HashSiteStore::getSites
32 public function testGetSites() {
33 $expectedSites = [];
35 foreach ( TestSites::getSites() as $testSite ) {
36 $siteId = $testSite->getGlobalId();
37 $expectedSites[$siteId] = $testSite;
40 $siteStore = new HashSiteStore( $expectedSites );
42 $this->assertEquals( new SiteList( $expectedSites ), $siteStore->getSites() );
45 /**
46 * @covers HashSiteStore::saveSite
47 * @covers HashSiteStore::getSite
49 public function testSaveSite() {
50 $store = new HashSiteStore();
52 $site = new Site();
53 $site->setGlobalId( 'dewiki' );
55 $this->assertCount( 0, $store->getSites(), '0 sites in store' );
57 $store->saveSite( $site );
59 $this->assertCount( 1, $store->getSites(), 'Store has 1 sites' );
60 $this->assertEquals( $site, $store->getSite( 'dewiki' ), 'Store has dewiki' );
63 /**
64 * @covers HashSiteStore::saveSites
66 public function testSaveSites() {
67 $store = new HashSiteStore();
69 $sites = [];
71 $site = new Site();
72 $site->setGlobalId( 'enwiki' );
73 $site->setLanguageCode( 'en' );
74 $sites[] = $site;
76 $site = new MediaWikiSite();
77 $site->setGlobalId( 'eswiki' );
78 $site->setLanguageCode( 'es' );
79 $sites[] = $site;
81 $this->assertCount( 0, $store->getSites(), '0 sites in store' );
83 $store->saveSites( $sites );
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' );
90 /**
91 * @covers HashSiteStore::clear
93 public function testClear() {
94 $store = new HashSiteStore();
96 $site = new Site();
97 $site->setGlobalId( 'arwiki' );
98 $store->saveSite( $site );
100 $this->assertCount( 1, $store->getSites(), '1 site in store' );
102 $store->clear();
103 $this->assertCount( 0, $store->getSites(), '0 sites in store' );