4 * Tests for the SiteList implementing classes.
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 * @licence GNU GPL v2+
30 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
32 class SiteListTest
extends MediaWikiTestCase
{
35 * Returns instances of SiteList implementing objects.
38 public function siteListProvider() {
39 $sitesArrays = $this->siteArrayProvider();
41 $listInstances = array();
43 foreach ( $sitesArrays as $sitesArray ) {
44 $listInstances[] = new SiteArray( $sitesArray[0] );
47 return $this->arrayWrap( $listInstances );
51 * Returns arrays with instances of Site implementing objects.
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 );
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 ) {
81 if ( $sites->isEmpty() ) {
82 $this->assertTrue( true );
88 foreach ( $sites as $site ) {
89 $this->assertEquals( $site, $sites->getSite( $site->getGlobalId() ) );
95 * @dataProvider siteListProvider
96 * @param SiteList $sites
98 public function testGetSiteByInternalId( $sites ) {
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
115 public function testHasGlobalId( $sites ) {
116 $this->assertFalse( $sites->hasSite( 'non-existing-global-id' ) );
117 $this->assertFalse( $sites->hasInternalId( 72010101010 ) );
119 if ( !$sites->isEmpty() ) {
123 foreach ( $sites as $site ) {
124 $this->assertTrue( $sites->hasSite( $site->getGlobalId() ) );
130 * @dataProvider siteListProvider
131 * @param SiteList $sites
133 public function testHasInternallId( $sites ) {
137 foreach ( $sites as $site ) {
138 if ( is_integer( $site->getInternalId() ) ) {
139 $this->assertTrue( $site, $sites->hasInternalId( $site->getInternalId() ) );
143 $this->assertFalse( $sites->hasInternalId( -1 ) );
147 * @dataProvider siteListProvider
148 * @param SiteList $sites
150 public function testGetGlobalIdentifiers( SiteList
$sites ) {
151 $identifiers = $sites->getGlobalIdentifiers();
153 $this->assertTrue( is_array( $identifiers ) );
160 foreach ( $sites as $site ) {
161 $expected[] = $site->getGlobalId();
164 $this->assertArrayEquals( $expected, $identifiers );