3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
21 namespace MediaWiki\Tests\Site
;
23 use MediaWiki\Site\Site
;
24 use MediaWiki\Site\SiteList
;
25 use MediaWikiIntegrationTestCase
;
28 * @covers \MediaWiki\Site\SiteList
30 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
32 class SiteListTest
extends MediaWikiIntegrationTestCase
{
35 * Returns instances of SiteList implementing objects.
38 public function siteListProvider() {
39 $sitesArrays = $this->siteArrayProvider();
43 foreach ( $sitesArrays as $sitesArray ) {
44 $listInstances[] = new SiteList( $sitesArray[0] );
47 return $this->arrayWrap( $listInstances );
51 * Returns arrays with instances of Site implementing objects.
54 public function siteArrayProvider() {
55 $sites = TestSites
::getSites();
59 $siteArrays[] = $sites;
61 $siteArrays[] = [ array_shift( $sites ) ];
63 $siteArrays[] = [ array_shift( $sites ), array_shift( $sites ) ];
65 return $this->arrayWrap( $siteArrays );
69 * @dataProvider siteListProvider
70 * @param SiteList $sites
72 public function testIsEmpty( SiteList
$sites ) {
73 $this->assertEquals( count( $sites ) === 0, $sites->isEmpty() );
77 * @dataProvider siteListProvider
78 * @param SiteList $sites
80 public function testGetSiteByGlobalId( SiteList
$sites ) {
84 foreach ( $sites as $site ) {
85 $this->assertEquals( $site, $sites->getSite( $site->getGlobalId() ) );
88 $this->assertTrue( true );
92 * @dataProvider siteListProvider
93 * @param SiteList $sites
95 public function testGetSiteByInternalId( $sites ) {
99 foreach ( $sites as $site ) {
100 if ( is_int( $site->getInternalId() ) ) {
101 $this->assertEquals( $site, $sites->getSiteByInternalId( $site->getInternalId() ) );
105 $this->assertTrue( true );
109 * @dataProvider siteListProvider
110 * @param SiteList $sites
112 public function testGetSiteByNavigationId( $sites ) {
116 foreach ( $sites as $site ) {
117 $ids = $site->getNavigationIds();
118 foreach ( $ids as $navId ) {
119 $this->assertEquals( $site, $sites->getSiteByNavigationId( $navId ) );
123 $this->assertTrue( true );
127 * @dataProvider siteListProvider
128 * @param SiteList $sites
130 public function testHasGlobalId( $sites ) {
131 $this->assertFalse( $sites->hasSite( 'non-existing-global-id' ) );
132 $this->assertFalse( $sites->hasInternalId( 720101010 ) );
134 if ( !$sites->isEmpty() ) {
138 foreach ( $sites as $site ) {
139 $this->assertTrue( $sites->hasSite( $site->getGlobalId() ) );
145 * @dataProvider siteListProvider
146 * @param SiteList $sites
148 public function testHasInternallId( $sites ) {
152 foreach ( $sites as $site ) {
153 if ( is_int( $site->getInternalId() ) ) {
154 $this->assertTrue( $site, $sites->hasInternalId( $site->getInternalId() ) );
158 $this->assertFalse( $sites->hasInternalId( -1 ) );
162 * @dataProvider siteListProvider
163 * @param SiteList $sites
165 public function testHasNavigationId( $sites ) {
169 foreach ( $sites as $site ) {
170 $ids = $site->getNavigationIds();
171 foreach ( $ids as $navId ) {
172 $this->assertTrue( $sites->hasNavigationId( $navId ) );
176 $this->assertFalse( $sites->hasNavigationId( 'non-existing-navigation-id' ) );
180 * @dataProvider siteListProvider
181 * @param SiteList $sites
183 public function testGetGlobalIdentifiers( SiteList
$sites ) {
184 $identifiers = $sites->getGlobalIdentifiers();
186 $this->assertIsArray( $identifiers );
193 foreach ( $sites as $site ) {
194 $expected[] = $site->getGlobalId();
197 $this->assertArrayEquals( $expected, $identifiers );
201 * @dataProvider siteListProvider
202 * @param SiteList $list
204 public function testSerialization( SiteList
$list ) {
205 $serialization = serialize( $list );
207 * @var SiteList $copy
209 $copy = unserialize( $serialization );
211 $this->assertArrayEquals( $list->getGlobalIdentifiers(), $copy->getGlobalIdentifiers() );
216 foreach ( $list as $site ) {
217 $this->assertTrue( $copy->hasInternalId( $site->getInternalId() ) );
219 foreach ( $site->getNavigationIds() as $navId ) {
221 $copy->hasNavigationId( $navId ),
222 'unserialized data expects nav id ' . $navId . ' for site ' . $site->getGlobalId()