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 }
SiteListTest\testIsEmpty
testIsEmpty(SiteList $sites)
siteListProvider
Definition: SiteListTest.php:72
MediaWikiTestCase\assertArrayEquals
assertArrayEquals(array $expected, array $actual, $ordered=false, $named=false)
Assert that two arrays are equal.
Definition: MediaWikiTestCase.php:1771
SiteListTest\testGetGlobalIdentifiers
testGetGlobalIdentifiers(SiteList $sites)
siteListProvider
Definition: SiteListTest.php:190
SiteListTest
Definition: SiteListTest.php:31
TestSites\getSites
static getSites()
Definition: TestSites.php:36
unserialize
unserialize( $serialized)
Definition: ApiMessage.php:192
SiteListTest\testSerialization
testSerialization(SiteList $list)
siteListProvider
Definition: SiteListTest.php:216
serialize
serialize()
Definition: ApiMessage.php:184
SiteListTest\testGetSiteByInternalId
testGetSiteByInternalId( $sites)
siteListProvider
Definition: SiteListTest.php:97
SiteListTest\testGetSiteByNavigationId
testGetSiteByNavigationId( $sites)
siteListProvider
Definition: SiteListTest.php:115
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:37
MediaWikiTestCase
Definition: MediaWikiTestCase.php:17
SiteList
Definition: SiteList.php:29
MediaWikiTestCase\arrayWrap
arrayWrap(array $elements)
Utility method taking an array of elements and wrapping each element in its own array.
Definition: MediaWikiTestCase.php:1750
SiteList\isEmpty
isEmpty()
Returns if the list contains no sites.
Definition: SiteList.php:177
SiteListTest\testHasInternallId
testHasInternallId( $sites)
siteListProvider
Definition: SiteListTest.php:153
SiteListTest\siteListProvider
siteListProvider()
Returns instances of SiteList implementing objects.
Definition: SiteListTest.php:37
SiteListTest\testHasGlobalId
testHasGlobalId( $sites)
siteListProvider
Definition: SiteListTest.php:134
SiteListTest\testGetSiteByGlobalId
testGetSiteByGlobalId(SiteList $sites)
siteListProvider
Definition: SiteListTest.php:81
SiteList\getGlobalIdentifiers
getGlobalIdentifiers()
Returns all the global site identifiers.
Definition: SiteList.php:129
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:22
SiteList\getSite
getSite( $globalSiteId)
Returns the Site with the provided global site identifier.
Definition: SiteList.php:154
SiteListTest\testHasNavigationId
testHasNavigationId( $sites)
siteListProvider
Definition: SiteListTest.php:171
SiteListTest\siteArrayProvider
siteArrayProvider()
Returns arrays with instances of Site implementing objects.
Definition: SiteListTest.php:53