MediaWiki  1.27.2
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_integer( $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_integer( $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 }
static getSites()
Definition: TestSites.php:38
getGlobalIdentifiers()
Returns all the global site identifiers.
Definition: SiteList.php:129
siteListProvider()
Returns instances of SiteList implementing objects.
assertArrayEquals(array $expected, array $actual, $ordered=false, $named=false)
Assert that two arrays are equal.
testHasNavigationId($sites)
siteListProvider
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.
unserialize($serialized)
Definition: ApiMessage.php:102
testSerialization(SiteList $list)
siteListProvider
testHasInternallId($sites)
siteListProvider
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
getSite($globalSiteId)
Returns the Site with the provided global site identifier.
Definition: SiteList.php:154
testIsEmpty(SiteList $sites)
siteListProvider
testGetSiteByGlobalId(SiteList $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
testGetSiteByNavigationId($sites)
siteListProvider
serialize()
Definition: ApiMessage.php:94
testHasGlobalId($sites)
siteListProvider
testGetSiteByInternalId($sites)
siteListProvider