*/
protected $byGlobalId = array();
+ /**
+ * Navigational site identifiers alias inter-language prefixes
+ * pointing to their sites offset value.
+ *
+ * @since 1.23
+ *
+ * @var array of string
+ */
+ protected $byNavigationId = array();
+
/**
* @see GenericArrayObject::getObjectType
*
$this->byGlobalId[$site->getGlobalId()] = $index;
$this->byInternalId[$site->getInternalId()] = $index;
+ $ids = $site->getNavigationIds();
+ foreach ( $ids as $navId ) {
+ $this->byNavigationId[$navId] = $index;
+ }
+
return true;
}
unset( $this->byGlobalId[$site->getGlobalId()] );
unset( $this->byInternalId[$site->getInternalId()] );
+
+ $ids = $site->getNavigationIds();
+ foreach ( $ids as $navId ) {
+ unset( $this->byNavigationId[$navId] );
+ }
}
parent::offsetUnset( $index );
$this->offsetUnset( $this->byInternalId[$id] );
}
+ /**
+ * Returns if the list contains the site with the provided navigational site id.
+ *
+ * @param string $id
+ *
+ * @return boolean
+ */
+ public function hasNavigationId( $id ) {
+ return array_key_exists( $id, $this->byNavigationId );
+ }
+
+ /**
+ * Returns the Site with the provided navigational site id.
+ * The site needs to exist, so if not sure, call has first.
+ *
+ * @since 1.23
+ *
+ * @param string $id
+ *
+ * @return Site
+ */
+ public function getSiteByNavigationId( $id ) {
+ return $this->offsetGet( $this->byNavigationId[$id] );
+ }
+
+ /**
+ * Removes the site with the specified navigational site id.
+ * The site needs to exist, so if not sure, call has first.
+ *
+ * @since 1.23
+ *
+ * @param string $id
+ */
+ public function removeSiteByNavigationId( $id ) {
+ $this->offsetUnset( $this->byNavigationId[$id] );
+ }
+
/**
* Sets a site in the list. If the site was not there,
* it will be added. If it was, it will be updated.
* @covers SiteList::getSite
*/
public function testGetSiteByGlobalId( SiteList $sites ) {
- if ( $sites->isEmpty() ) {
- $this->assertTrue( true );
- } else {
- /**
- * @var Site $site
- */
- foreach ( $sites as $site ) {
- $this->assertEquals( $site, $sites->getSite( $site->getGlobalId() ) );
- }
+ /**
+ * @var Site $site
+ */
+ foreach ( $sites as $site ) {
+ $this->assertEquals( $site, $sites->getSite( $site->getGlobalId() ) );
}
+
+ $this->assertTrue( true );
}
/**
$this->assertTrue( true );
}
+ /**
+ * @dataProvider siteListProvider
+ * @param SiteList $sites
+ * @covers SiteList::getSiteByNavigationId
+ */
+ public function testGetSiteByNavigationId( $sites ) {
+ /**
+ * @var Site $site
+ */
+ foreach ( $sites as $site ) {
+ $ids = $site->getNavigationIds();
+ foreach ( $ids as $navId ) {
+ $this->assertEquals( $site, $sites->getSiteByNavigationId( $navId ) );
+ }
+ }
+
+ $this->assertTrue( true );
+ }
+
/**
* @dataProvider siteListProvider
* @param SiteList $sites
$this->assertFalse( $sites->hasInternalId( -1 ) );
}
+ /**
+ * @dataProvider siteListProvider
+ * @param SiteList $sites
+ * @covers SiteList::hasNavigationId
+ */
+ public function testHasNavigationId( $sites ) {
+ /**
+ * @var Site $site
+ */
+ foreach ( $sites as $site ) {
+ $ids = $site->getNavigationIds();
+ foreach ( $ids as $navId ) {
+ $this->assertTrue( $sites->hasNavigationId( $navId ) );
+ }
+ }
+
+ $this->assertFalse( $sites->hasNavigationId( 'non-existing-navigation-id' ) );
+ }
+
/**
* @dataProvider siteListProvider
* @param SiteList $sites