MediaWiki REL1_33
SiteListTest.php
Go to the documentation of this file.
1<?php
2
30
35 public function siteListProvider() {
36 $sitesArrays = $this->siteArrayProvider();
37
38 $listInstances = [];
39
40 foreach ( $sitesArrays as $sitesArray ) {
41 $listInstances[] = new SiteList( $sitesArray[0] );
42 }
43
44 return $this->arrayWrap( $listInstances );
45 }
46
51 public function siteArrayProvider() {
52 $sites = TestSites::getSites();
53
54 $siteArrays = [];
55
56 $siteArrays[] = $sites;
57
58 $siteArrays[] = [ array_shift( $sites ) ];
59
60 $siteArrays[] = [ array_shift( $sites ), array_shift( $sites ) ];
61
62 return $this->arrayWrap( $siteArrays );
63 }
64
70 public function testIsEmpty( SiteList $sites ) {
71 $this->assertEquals( count( $sites ) === 0, $sites->isEmpty() );
72 }
73
79 public function testGetSiteByGlobalId( SiteList $sites ) {
83 foreach ( $sites as $site ) {
84 $this->assertEquals( $site, $sites->getSite( $site->getGlobalId() ) );
85 }
86
87 $this->assertTrue( true );
88 }
89
95 public function testGetSiteByInternalId( $sites ) {
99 foreach ( $sites as $site ) {
100 if ( is_int( $site->getInternalId() ) ) {
101 $this->assertEquals( $site, $sites->getSiteByInternalId( $site->getInternalId() ) );
102 }
103 }
104
105 $this->assertTrue( true );
106 }
107
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 ) );
121 }
122 }
123
124 $this->assertTrue( true );
125 }
126
132 public function testHasGlobalId( $sites ) {
133 $this->assertFalse( $sites->hasSite( 'non-existing-global-id' ) );
134 $this->assertFalse( $sites->hasInternalId( 720101010 ) );
135
136 if ( !$sites->isEmpty() ) {
140 foreach ( $sites as $site ) {
141 $this->assertTrue( $sites->hasSite( $site->getGlobalId() ) );
142 }
143 }
144 }
145
151 public function testHasInternallId( $sites ) {
155 foreach ( $sites as $site ) {
156 if ( is_int( $site->getInternalId() ) ) {
157 $this->assertTrue( $site, $sites->hasInternalId( $site->getInternalId() ) );
158 }
159 }
160
161 $this->assertFalse( $sites->hasInternalId( -1 ) );
162 }
163
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 ) );
177 }
178 }
179
180 $this->assertFalse( $sites->hasNavigationId( 'non-existing-navigation-id' ) );
181 }
182
188 public function testGetGlobalIdentifiers( SiteList $sites ) {
189 $identifiers = $sites->getGlobalIdentifiers();
190
191 $this->assertTrue( is_array( $identifiers ) );
192
193 $expected = [];
194
198 foreach ( $sites as $site ) {
199 $expected[] = $site->getGlobalId();
200 }
201
202 $this->assertArrayEquals( $expected, $identifiers );
203 }
204
214 public function testSerialization( SiteList $list ) {
215 $serialization = serialize( $list );
219 $copy = unserialize( $serialization );
220
221 $this->assertArrayEquals( $list->getGlobalIdentifiers(), $copy->getGlobalIdentifiers() );
222
226 foreach ( $list as $site ) {
227 $this->assertTrue( $copy->hasInternalId( $site->getInternalId() ) );
228
229 foreach ( $site->getNavigationIds() as $navId ) {
230 $this->assertTrue(
231 $copy->hasNavigationId( $navId ),
232 'unserialized data expects nav id ' . $navId . ' for site ' . $site->getGlobalId()
233 );
234 }
235 }
236 }
237}
serialize()
unserialize( $serialized)
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
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