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
29 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
31 class SiteListTest
extends MediaWikiTestCase
{
34 * Returns instances of SiteList implementing objects.
37 public function siteListProvider() {
38 $sitesArrays = $this->siteArrayProvider();
42 foreach ( $sitesArrays as $sitesArray ) {
43 $listInstances[] = new SiteList( $sitesArray[0] );
46 return $this->arrayWrap( $listInstances );
50 * Returns arrays with instances of Site implementing objects.
53 public function siteArrayProvider() {
54 $sites = TestSites
::getSites();
58 $siteArrays[] = $sites;
60 $siteArrays[] = [ array_shift( $sites ) ];
62 $siteArrays[] = [ array_shift( $sites ), array_shift( $sites ) ];
64 return $this->arrayWrap( $siteArrays );
68 * @dataProvider siteListProvider
69 * @param SiteList $sites
70 * @covers SiteList::isEmpty
72 public function testIsEmpty( SiteList
$sites ) {
73 $this->assertEquals( count( $sites ) === 0, $sites->isEmpty() );
77 * @dataProvider siteListProvider
78 * @param SiteList $sites
79 * @covers SiteList::getSite
81 public function testGetSiteByGlobalId( SiteList
$sites ) {
85 foreach ( $sites as $site ) {
86 $this->assertEquals( $site, $sites->getSite( $site->getGlobalId() ) );
89 $this->assertTrue( true );
93 * @dataProvider siteListProvider
94 * @param SiteList $sites
95 * @covers SiteList::getSiteByInternalId
97 public function testGetSiteByInternalId( $sites ) {
101 foreach ( $sites as $site ) {
102 if ( is_integer( $site->getInternalId() ) ) {
103 $this->assertEquals( $site, $sites->getSiteByInternalId( $site->getInternalId() ) );
107 $this->assertTrue( true );
111 * @dataProvider siteListProvider
112 * @param SiteList $sites
113 * @covers SiteList::getSiteByNavigationId
115 public function testGetSiteByNavigationId( $sites ) {
119 foreach ( $sites as $site ) {
120 $ids = $site->getNavigationIds();
121 foreach ( $ids as $navId ) {
122 $this->assertEquals( $site, $sites->getSiteByNavigationId( $navId ) );
126 $this->assertTrue( true );
130 * @dataProvider siteListProvider
131 * @param SiteList $sites
132 * @covers SiteList::hasSite
134 public function testHasGlobalId( $sites ) {
135 $this->assertFalse( $sites->hasSite( 'non-existing-global-id' ) );
136 $this->assertFalse( $sites->hasInternalId( 720101010 ) );
138 if ( !$sites->isEmpty() ) {
142 foreach ( $sites as $site ) {
143 $this->assertTrue( $sites->hasSite( $site->getGlobalId() ) );
149 * @dataProvider siteListProvider
150 * @param SiteList $sites
151 * @covers SiteList::hasInternalId
153 public function testHasInternallId( $sites ) {
157 foreach ( $sites as $site ) {
158 if ( is_integer( $site->getInternalId() ) ) {
159 $this->assertTrue( $site, $sites->hasInternalId( $site->getInternalId() ) );
163 $this->assertFalse( $sites->hasInternalId( -1 ) );
167 * @dataProvider siteListProvider
168 * @param SiteList $sites
169 * @covers SiteList::hasNavigationId
171 public function testHasNavigationId( $sites ) {
175 foreach ( $sites as $site ) {
176 $ids = $site->getNavigationIds();
177 foreach ( $ids as $navId ) {
178 $this->assertTrue( $sites->hasNavigationId( $navId ) );
182 $this->assertFalse( $sites->hasNavigationId( 'non-existing-navigation-id' ) );
186 * @dataProvider siteListProvider
187 * @param SiteList $sites
188 * @covers SiteList::getGlobalIdentifiers
190 public function testGetGlobalIdentifiers( SiteList
$sites ) {
191 $identifiers = $sites->getGlobalIdentifiers();
193 $this->assertTrue( is_array( $identifiers ) );
200 foreach ( $sites as $site ) {
201 $expected[] = $site->getGlobalId();
204 $this->assertArrayEquals( $expected, $identifiers );
208 * @dataProvider siteListProvider
212 * @param SiteList $list
213 * @covers SiteList::getSerializationData
214 * @covers SiteList::unserialize
216 public function testSerialization( SiteList
$list ) {
217 $serialization = serialize( $list );
219 * @var SiteList $copy
221 $copy = unserialize( $serialization );
223 $this->assertArrayEquals( $list->getGlobalIdentifiers(), $copy->getGlobalIdentifiers() );
228 foreach ( $list as $site ) {
229 $this->assertTrue( $copy->hasInternalId( $site->getInternalId() ) );
231 foreach ( $site->getNavigationIds() as $navId ) {
233 $copy->hasNavigationId( $navId ),
234 'unserialized data expects nav id ' . $navId . ' for site ' . $site->getGlobalId()