Merge "Gracefully handle redirects in SpecialMyLanguage"
[lhc/web/wiklou.git] / tests / phpunit / includes / site / HashSiteStoreTest.php
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 * @licence GNU GPL v2+
26 * @author Katie Filbert < aude.wiki@gmail.com >
27 */
28 class HashSiteStoreTest extends MediaWikiTestCase {
29
30 /**
31 * @covers HashSiteStore::getSites
32 */
33 public function testGetSites() {
34 $expectedSites = array();
35
36 foreach( TestSites::getSites() as $testSite ) {
37 $siteId = $testSite->getGlobalId();
38 $expectedSites[$siteId] = $testSite;
39 }
40
41 $siteStore = new HashSiteStore( $expectedSites );
42
43 $this->assertEquals( new SiteList( $expectedSites ), $siteStore->getSites() );
44 }
45
46 /**
47 * @covers HashSiteStore::saveSite
48 * @covers HashSiteStore::getSite
49 */
50 public function testSaveSite() {
51 $store = new HashSiteStore();
52
53 $site = new Site();
54 $site->setGlobalId( 'dewiki' );
55
56 $this->assertCount( 0, $store->getSites(), '0 sites in store' );
57
58 $store->saveSite( $site );
59
60 $this->assertCount( 1, $store->getSites(), 'Store has 1 sites' );
61 $this->assertEquals( $site, $store->getSite( 'dewiki' ), 'Store has dewiki' );
62 }
63
64 /**
65 * @covers HashSiteStore::saveSites
66 */
67 public function testSaveSites() {
68 $store = new HashSiteStore();
69
70 $sites = array();
71
72 $site = new Site();
73 $site->setGlobalId( 'enwiki' );
74 $site->setLanguageCode( 'en' );
75 $sites[] = $site;
76
77 $site = new MediaWikiSite();
78 $site->setGlobalId( 'eswiki' );
79 $site->setLanguageCode( 'es' );
80 $sites[] = $site;
81
82 $this->assertCount( 0, $store->getSites(), '0 sites in store' );
83
84 $store->saveSites( $sites );
85
86 $this->assertCount( 2, $store->getSites(), 'Store has 2 sites' );
87 $this->assertTrue( $store->getSites()->hasSite( 'enwiki' ), 'Store has enwiki' );
88 $this->assertTrue( $store->getSites()->hasSite( 'eswiki' ), 'Store has eswiki' );
89 }
90
91 /**
92 * @covers HashSiteStore::clear
93 */
94 public function testClear() {
95 $store = new HashSiteStore();
96
97 $site = new Site();
98 $site->setGlobalId( 'arwiki' );
99 $store->saveSite( $site );
100
101 $this->assertCount( 1, $store->getSites(), '1 site in store' );
102
103 $store->clear();
104 $this->assertCount( 0, $store->getSites(), '0 sites in store' );
105 }
106 }