MediaWiki REL1_31
SiteListTest.php
Go to the documentation of this file.
1<?php
2
32
37 public function siteListProvider() {
38 $sitesArrays = $this->siteArrayProvider();
39
40 $listInstances = [];
41
42 foreach ( $sitesArrays as $sitesArray ) {
43 $listInstances[] = new SiteList( $sitesArray[0] );
44 }
45
46 return $this->arrayWrap( $listInstances );
47 }
48
53 public function siteArrayProvider() {
54 $sites = TestSites::getSites();
55
56 $siteArrays = [];
57
58 $siteArrays[] = $sites;
59
60 $siteArrays[] = [ array_shift( $sites ) ];
61
62 $siteArrays[] = [ array_shift( $sites ), array_shift( $sites ) ];
63
64 return $this->arrayWrap( $siteArrays );
65 }
66
72 public function testIsEmpty( SiteList $sites ) {
73 $this->assertEquals( count( $sites ) === 0, $sites->isEmpty() );
74 }
75
81 public function testGetSiteByGlobalId( SiteList $sites ) {
85 foreach ( $sites as $site ) {
86 $this->assertEquals( $site, $sites->getSite( $site->getGlobalId() ) );
87 }
88
89 $this->assertTrue( true );
90 }
91
97 public function testGetSiteByInternalId( $sites ) {
101 foreach ( $sites as $site ) {
102 if ( is_int( $site->getInternalId() ) ) {
103 $this->assertEquals( $site, $sites->getSiteByInternalId( $site->getInternalId() ) );
104 }
105 }
106
107 $this->assertTrue( true );
108 }
109
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 ) );
123 }
124 }
125
126 $this->assertTrue( true );
127 }
128
134 public function testHasGlobalId( $sites ) {
135 $this->assertFalse( $sites->hasSite( 'non-existing-global-id' ) );
136 $this->assertFalse( $sites->hasInternalId( 720101010 ) );
137
138 if ( !$sites->isEmpty() ) {
142 foreach ( $sites as $site ) {
143 $this->assertTrue( $sites->hasSite( $site->getGlobalId() ) );
144 }
145 }
146 }
147
153 public function testHasInternallId( $sites ) {
157 foreach ( $sites as $site ) {
158 if ( is_int( $site->getInternalId() ) ) {
159 $this->assertTrue( $site, $sites->hasInternalId( $site->getInternalId() ) );
160 }
161 }
162
163 $this->assertFalse( $sites->hasInternalId( -1 ) );
164 }
165
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 ) );
179 }
180 }
181
182 $this->assertFalse( $sites->hasNavigationId( 'non-existing-navigation-id' ) );
183 }
184
190 public function testGetGlobalIdentifiers( SiteList $sites ) {
191 $identifiers = $sites->getGlobalIdentifiers();
192
193 $this->assertTrue( is_array( $identifiers ) );
194
195 $expected = [];
196
200 foreach ( $sites as $site ) {
201 $expected[] = $site->getGlobalId();
202 }
203
204 $this->assertArrayEquals( $expected, $identifiers );
205 }
206
216 public function testSerialization( SiteList $list ) {
217 $serialization = serialize( $list );
221 $copy = unserialize( $serialization );
222
223 $this->assertArrayEquals( $list->getGlobalIdentifiers(), $copy->getGlobalIdentifiers() );
224
228 foreach ( $list as $site ) {
229 $this->assertTrue( $copy->hasInternalId( $site->getInternalId() ) );
230
231 foreach ( $site->getNavigationIds() as $navId ) {
232 $this->assertTrue(
233 $copy->hasNavigationId( $navId ),
234 'unserialized data expects nav id ' . $navId . ' for site ' . $site->getGlobalId()
235 );
236 }
237 }
238 }
239}
serialize()
unserialize( $serialized)
arrayWrap(array $elements)
Utility method taking an array of elements and wrapping each element in its own array.
assertArrayEquals(array $expected, array $actual, $ordered=false, $named=false)
Assert that two arrays are equal.
testSerialization(SiteList $list)
siteListProvider
testGetSiteByInternalId( $sites)
siteListProvider
siteListProvider()
Returns instances of SiteList implementing objects.
testGetGlobalIdentifiers(SiteList $sites)
siteListProvider
siteArrayProvider()
Returns arrays with instances of Site implementing objects.
testGetSiteByGlobalId(SiteList $sites)
siteListProvider
testIsEmpty(SiteList $sites)
siteListProvider
testHasInternallId( $sites)
siteListProvider
testHasNavigationId( $sites)
siteListProvider
testGetSiteByNavigationId( $sites)
siteListProvider
testHasGlobalId( $sites)
siteListProvider
isEmpty()
Returns if the list contains no sites.
Definition SiteList.php:177
getGlobalIdentifiers()
Returns all the global site identifiers.
Definition SiteList.php:129
getSite( $globalSiteId)
Returns the Site with the provided global site identifier.
Definition SiteList.php:154
static getSites()
Definition TestSites.php:36