public function testGetUnusedEntities()
 {
     $q3 = new ItemId('Q3');
     $q4 = new ItemId('Q4');
     $q6 = new ItemId('Q6');
     $u3i = new EntityUsage($q3, EntityUsage::SITELINK_USAGE);
     $u3l = new EntityUsage($q3, EntityUsage::LABEL_USAGE, 'de');
     $u4l = new EntityUsage($q4, EntityUsage::LABEL_USAGE, 'de');
     $usages = array($u3i, $u3l, $u4l);
     $this->putUsages(23, $usages, '20150102030405');
     Assert::assertEmpty($this->lookup->getUnusedEntities(array($q4)), 'Q4 should not be unused');
     $unused = $this->lookup->getUnusedEntities(array($q4, $q6));
     Assert::assertCount(1, $unused);
     Assert::assertEquals($q6, reset($unused), 'Q6 shouold be unused');
 }
 /**
  * Removes stale usage information for the given page, and removes
  * any subscriptions that have become unnecessary.
  *
  * @param int $pageId The ID of the page the entities are used on.
  * @param string $lastUpdatedBefore timestamp. Entries older than this timestamp will be removed.
  *
  * @see UsageTracker::trackUsedEntities
  *
  * @throws InvalidArgumentException
  */
 public function pruneUsagesForPage($pageId, $lastUpdatedBefore = '00000000000000')
 {
     if (!is_int($pageId)) {
         throw new InvalidArgumentException('$pageId must be an int!');
     }
     if (!is_string($lastUpdatedBefore) || $lastUpdatedBefore === '') {
         throw new InvalidArgumentException('$lastUpdatedBefore must be a timestamp string!');
     }
     $prunedUsages = $this->usageTracker->pruneStaleUsages($pageId, $lastUpdatedBefore);
     $prunedEntityIds = $this->getEntityIds($prunedUsages);
     $unusedIds = $this->usageLookup->getUnusedEntities($prunedEntityIds);
     if (!empty($unusedIds)) {
         // Unsubscribe from anything that was pruned and is otherwise unused.
         $this->subscriptionManager->unsubscribe($this->clientId, $unusedIds);
     }
 }