Remove messages.inc, rebuildLanguage.php, writeMessagesArray.inc
[mediawiki.git] / tests / phpunit / includes / site / SiteListTest.php
blob534ed9c905be0e057f6c8674dd98e778880aa0d1
1 <?php
3 /**
4 * Tests for the SiteList class.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
21 * @file
22 * @since 1.21
24 * @ingroup Site
25 * @ingroup Test
27 * @group Site
29 * @licence GNU GPL v2+
30 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
32 class SiteListTest extends MediaWikiTestCase {
34 /**
35 * Returns instances of SiteList implementing objects.
36 * @return array
38 public function siteListProvider() {
39 $sitesArrays = $this->siteArrayProvider();
41 $listInstances = array();
43 foreach ( $sitesArrays as $sitesArray ) {
44 $listInstances[] = new SiteList( $sitesArray[0] );
47 return $this->arrayWrap( $listInstances );
50 /**
51 * Returns arrays with instances of Site implementing objects.
52 * @return array
54 public function siteArrayProvider() {
55 $sites = TestSites::getSites();
57 $siteArrays = array();
59 $siteArrays[] = $sites;
61 $siteArrays[] = array( array_shift( $sites ) );
63 $siteArrays[] = array( array_shift( $sites ), array_shift( $sites ) );
65 return $this->arrayWrap( $siteArrays );
68 /**
69 * @dataProvider siteListProvider
70 * @param SiteList $sites
71 * @covers SiteList::isEmpty
73 public function testIsEmpty( SiteList $sites ) {
74 $this->assertEquals( count( $sites ) === 0, $sites->isEmpty() );
77 /**
78 * @dataProvider siteListProvider
79 * @param SiteList $sites
80 * @covers SiteList::getSite
82 public function testGetSiteByGlobalId( SiteList $sites ) {
83 /**
84 * @var Site $site
86 foreach ( $sites as $site ) {
87 $this->assertEquals( $site, $sites->getSite( $site->getGlobalId() ) );
90 $this->assertTrue( true );
93 /**
94 * @dataProvider siteListProvider
95 * @param SiteList $sites
96 * @covers SiteList::getSiteByInternalId
98 public function testGetSiteByInternalId( $sites ) {
99 /**
100 * @var Site $site
102 foreach ( $sites as $site ) {
103 if ( is_integer( $site->getInternalId() ) ) {
104 $this->assertEquals( $site, $sites->getSiteByInternalId( $site->getInternalId() ) );
108 $this->assertTrue( true );
112 * @dataProvider siteListProvider
113 * @param SiteList $sites
114 * @covers SiteList::getSiteByNavigationId
116 public function testGetSiteByNavigationId( $sites ) {
118 * @var Site $site
120 foreach ( $sites as $site ) {
121 $ids = $site->getNavigationIds();
122 foreach ( $ids as $navId ) {
123 $this->assertEquals( $site, $sites->getSiteByNavigationId( $navId ) );
127 $this->assertTrue( true );
131 * @dataProvider siteListProvider
132 * @param SiteList $sites
133 * @covers SiteList::hasSite
135 public function testHasGlobalId( $sites ) {
136 $this->assertFalse( $sites->hasSite( 'non-existing-global-id' ) );
137 $this->assertFalse( $sites->hasInternalId( 720101010 ) );
139 if ( !$sites->isEmpty() ) {
141 * @var Site $site
143 foreach ( $sites as $site ) {
144 $this->assertTrue( $sites->hasSite( $site->getGlobalId() ) );
150 * @dataProvider siteListProvider
151 * @param SiteList $sites
152 * @covers SiteList::hasInternalId
154 public function testHasInternallId( $sites ) {
156 * @var Site $site
158 foreach ( $sites as $site ) {
159 if ( is_integer( $site->getInternalId() ) ) {
160 $this->assertTrue( $site, $sites->hasInternalId( $site->getInternalId() ) );
164 $this->assertFalse( $sites->hasInternalId( -1 ) );
168 * @dataProvider siteListProvider
169 * @param SiteList $sites
170 * @covers SiteList::hasNavigationId
172 public function testHasNavigationId( $sites ) {
174 * @var Site $site
176 foreach ( $sites as $site ) {
177 $ids = $site->getNavigationIds();
178 foreach ( $ids as $navId ) {
179 $this->assertTrue( $sites->hasNavigationId( $navId ) );
183 $this->assertFalse( $sites->hasNavigationId( 'non-existing-navigation-id' ) );
187 * @dataProvider siteListProvider
188 * @param SiteList $sites
189 * @covers SiteList::getGlobalIdentifiers
191 public function testGetGlobalIdentifiers( SiteList $sites ) {
192 $identifiers = $sites->getGlobalIdentifiers();
194 $this->assertTrue( is_array( $identifiers ) );
196 $expected = array();
199 * @var Site $site
201 foreach ( $sites as $site ) {
202 $expected[] = $site->getGlobalId();
205 $this->assertArrayEquals( $expected, $identifiers );
209 * @dataProvider siteListProvider
211 * @since 1.21
213 * @param SiteList $list
214 * @covers SiteList::getSerializationData
215 * @covers SiteList::unserialize
217 public function testSerialization( SiteList $list ) {
218 $serialization = serialize( $list );
220 * @var SiteArray $copy
222 $copy = unserialize( $serialization );
224 $this->assertArrayEquals( $list->getGlobalIdentifiers(), $copy->getGlobalIdentifiers() );
227 * @var Site $site
229 foreach ( $list as $site ) {
230 $this->assertTrue( $copy->hasInternalId( $site->getInternalId() ) );
232 foreach ( $site->getNavigationIds() as $navId ) {
233 $this->assertTrue(
234 $copy->hasNavigationId( $navId ),
235 'unserialized data expects nav id ' . $navId . ' for site ' . $site->getGlobalId()