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
27 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
29 class SiteListTest
extends MediaWikiTestCase
{
32 * Returns instances of SiteList implementing objects.
35 public function siteListProvider() {
36 $sitesArrays = $this->siteArrayProvider();
40 foreach ( $sitesArrays as $sitesArray ) {
41 $listInstances[] = new SiteList( $sitesArray[0] );
44 return $this->arrayWrap( $listInstances );
48 * Returns arrays with instances of Site implementing objects.
51 public function siteArrayProvider() {
52 $sites = TestSites
::getSites();
56 $siteArrays[] = $sites;
58 $siteArrays[] = [ array_shift( $sites ) ];
60 $siteArrays[] = [ array_shift( $sites ), array_shift( $sites ) ];
62 return $this->arrayWrap( $siteArrays );
66 * @dataProvider siteListProvider
67 * @param SiteList $sites
68 * @covers SiteList::isEmpty
70 public function testIsEmpty( SiteList
$sites ) {
71 $this->assertEquals( count( $sites ) === 0, $sites->isEmpty() );
75 * @dataProvider siteListProvider
76 * @param SiteList $sites
77 * @covers SiteList::getSite
79 public function testGetSiteByGlobalId( SiteList
$sites ) {
83 foreach ( $sites as $site ) {
84 $this->assertEquals( $site, $sites->getSite( $site->getGlobalId() ) );
87 $this->assertTrue( true );
91 * @dataProvider siteListProvider
92 * @param SiteList $sites
93 * @covers SiteList::getSiteByInternalId
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
111 * @covers SiteList::getSiteByNavigationId
113 public function testGetSiteByNavigationId( $sites ) {
117 foreach ( $sites as $site ) {
118 $ids = $site->getNavigationIds();
119 foreach ( $ids as $navId ) {
120 $this->assertEquals( $site, $sites->getSiteByNavigationId( $navId ) );
124 $this->assertTrue( true );
128 * @dataProvider siteListProvider
129 * @param SiteList $sites
130 * @covers SiteList::hasSite
132 public function testHasGlobalId( $sites ) {
133 $this->assertFalse( $sites->hasSite( 'non-existing-global-id' ) );
134 $this->assertFalse( $sites->hasInternalId( 720101010 ) );
136 if ( !$sites->isEmpty() ) {
140 foreach ( $sites as $site ) {
141 $this->assertTrue( $sites->hasSite( $site->getGlobalId() ) );
147 * @dataProvider siteListProvider
148 * @param SiteList $sites
149 * @covers SiteList::hasInternalId
151 public function testHasInternallId( $sites ) {
155 foreach ( $sites as $site ) {
156 if ( is_int( $site->getInternalId() ) ) {
157 $this->assertTrue( $site, $sites->hasInternalId( $site->getInternalId() ) );
161 $this->assertFalse( $sites->hasInternalId( -1 ) );
165 * @dataProvider siteListProvider
166 * @param SiteList $sites
167 * @covers SiteList::hasNavigationId
169 public function testHasNavigationId( $sites ) {
173 foreach ( $sites as $site ) {
174 $ids = $site->getNavigationIds();
175 foreach ( $ids as $navId ) {
176 $this->assertTrue( $sites->hasNavigationId( $navId ) );
180 $this->assertFalse( $sites->hasNavigationId( 'non-existing-navigation-id' ) );
184 * @dataProvider siteListProvider
185 * @param SiteList $sites
186 * @covers SiteList::getGlobalIdentifiers
188 public function testGetGlobalIdentifiers( SiteList
$sites ) {
189 $identifiers = $sites->getGlobalIdentifiers();
191 $this->assertTrue( is_array( $identifiers ) );
198 foreach ( $sites as $site ) {
199 $expected[] = $site->getGlobalId();
202 $this->assertArrayEquals( $expected, $identifiers );
206 * @dataProvider siteListProvider
210 * @param SiteList $list
211 * @covers SiteList::getSerializationData
212 * @covers SiteList::unserialize
214 public function testSerialization( SiteList
$list ) {
215 $serialization = serialize( $list );
217 * @var SiteList $copy
219 $copy = unserialize( $serialization );
221 $this->assertArrayEquals( $list->getGlobalIdentifiers(), $copy->getGlobalIdentifiers() );
226 foreach ( $list as $site ) {
227 $this->assertTrue( $copy->hasInternalId( $site->getInternalId() ) );
229 foreach ( $site->getNavigationIds() as $navId ) {
231 $copy->hasNavigationId( $navId ),
232 'unserialized data expects nav id ' . $navId . ' for site ' . $site->getGlobalId()