MediaWiki  master
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 }
static getSites()
Definition: TestSites.php:36
getGlobalIdentifiers()
Returns all the global site identifiers.
Definition: SiteList.php:129
serialize()
siteListProvider()
Returns instances of SiteList implementing objects.
assertArrayEquals(array $expected, array $actual, $ordered=false, $named=false)
Assert that two arrays are equal.
siteArrayProvider()
Returns arrays with instances of Site implementing objects.
arrayWrap(array $elements)
Utility method taking an array of elements and wrapping each element in its own array.
testSerialization(SiteList $list)
siteListProvider
unserialize( $serialized)
testGetGlobalIdentifiers(SiteList $sites)
siteListProvider
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:9
isEmpty()
Returns if the list contains no sites.
Definition: SiteList.php:177
testIsEmpty(SiteList $sites)
siteListProvider
testGetSiteByGlobalId(SiteList $sites)
siteListProvider
testHasGlobalId( $sites)
siteListProvider
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:35
testHasInternallId( $sites)
siteListProvider
testGetSiteByNavigationId( $sites)
siteListProvider
testHasNavigationId( $sites)
siteListProvider
getSite( $globalSiteId)
Returns the Site with the provided global site identifier.
Definition: SiteList.php:154
testGetSiteByInternalId( $sites)
siteListProvider