/** * Transforms the entity usages from $pageEntityUsages according to the relevant * aspects defined by calling setRelevantAspects(). A new PageEntityUsages * containing the filtered usage list is returned. * * @see getFilteredUsages() * * @param PageEntityUsages $pageEntityUsages * * @return PageEntityUsages */ public function transformPageEntityUsages(PageEntityUsages $pageEntityUsages) { $entityIds = $pageEntityUsages->getEntityIds(); $transformedPageEntityUsages = new PageEntityUsages($pageEntityUsages->getPageId(), array()); foreach ($entityIds as $id) { $aspects = $pageEntityUsages->getUsageAspectKeys($id); $usages = $this->getFilteredUsages($id, $aspects); $transformedPageEntityUsages->addUsages($usages); } return $transformedPageEntityUsages; }
public function testGetters() { $q7 = new ItemId('Q7'); $q11 = new ItemId('Q11'); $usages = array(new EntityUsage($q7, EntityUsage::ALL_USAGE), new EntityUsage($q11, EntityUsage::LABEL_USAGE, 'de'), new EntityUsage($q11, EntityUsage::LABEL_USAGE, 'en'), new EntityUsage($q11, EntityUsage::TITLE_USAGE)); $pageUsages = new PageEntityUsages(6, $usages); $this->assertEquals(6, $pageUsages->getPageId()); $expectedAspects = array(EntityUsage::LABEL_USAGE, EntityUsage::TITLE_USAGE, EntityUsage::ALL_USAGE); $expectedAspectKeys = array(EntityUsage::LABEL_USAGE . '.de', EntityUsage::LABEL_USAGE . '.en', EntityUsage::TITLE_USAGE, EntityUsage::ALL_USAGE); $expectedAspectKeysQ11 = array(EntityUsage::LABEL_USAGE . '.de', EntityUsage::LABEL_USAGE . '.en', EntityUsage::TITLE_USAGE); $this->assertEquals($expectedAspects, $pageUsages->getAspects(), 'getAspects'); $this->assertEquals($expectedAspectKeys, $pageUsages->getAspectKeys(), 'getAspectKeys'); $this->assertEquals(array('Q11' => $q11, 'Q7' => $q7), $pageUsages->getEntityIds(), 'getEntityIds'); $this->assertEquals(array('Q11#L.de', 'Q11#L.en', 'Q11#T', 'Q7#X'), array_keys($pageUsages->getUsages()), 'getUsagesCallback'); $this->assertEquals($expectedAspectKeysQ11, $pageUsages->getUsageAspectKeys($q11), 'getUsageAspects'); }