Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added SiteList::offsetUnset test

Change-Id: Id57c3a4e3cfca7b7cc90bd1fdda906f08f3d165e
  • Loading branch information...
commit a13db9c3ad39d27d2149eb0e076d8a84b6b9a771 1 parent 63ad58a
@JeroenDeDauw authored
Showing with 43 additions and 0 deletions.
  1. +21 −0 lib/includes/SiteList.php
  2. +22 −0 lib/tests/phpunit/SiteListTest.php
View
21 lib/includes/SiteList.php
@@ -197,13 +197,34 @@ public function getLocalIdentifiers() {
}
/**
+ * Returns the names of the groups represented in this
+ * list of sites.
+ *
+ * @since 0.1
+ *
* @return array
*/
public function getGroupNames() {
+ $this->cleanDeadGroups();
return array_keys( $this->groups );
}
/**
+ * Removes the groups without any associated sites
+ * from the groups field.
+ *
+ * @since 0.1
+ */
+ protected function cleanDeadGroups() {
+ $this->groups = array_filter(
+ $this->groups,
+ function( array $groupPointers ) {
+ return $groupPointers !== array();
+ }
+ );
+ }
+
+ /**
* Returns a Sites containing only the sites of the specified group.
*
* @since 0.1
View
22 lib/tests/phpunit/SiteListTest.php
@@ -21,6 +21,28 @@
*/
class SiteListTest extends \MediaWikiTestCase {
+ public function testUnset() {
+ $sites = Sites::singleton()->getAllSites();
+
+ if ( !$sites->isEmpty() ) {
+ $offset = $sites->getIterator()->key();
+ $count = $sites->count();
+ $sites->offsetUnset( $offset );
+ $this->assertEquals( $count - 1, $sites->count() );
+ }
+
+ if ( !$sites->isEmpty() ) {
+ $offset = $sites->getIterator()->key();
+ $count = $sites->count();
+ unset( $sites[$offset] );
+ $this->assertEquals( $count - 1, $sites->count() );
+ }
+
+ $exception = null;
+ try { $sites->offsetUnset( 'sdfsedtgsrdysftu' ); } catch ( \Exception $exception ){}
+ $this->assertInstanceOf( '\Exception', $exception );
+ }
+
public function siteArrayProvider() {
$sites = Sites::singleton()->getAllSites()->getArrayCopy();
Please sign in to comment.
Something went wrong with that request. Please try again.