public function testGivenIdInExceptionList_hasEntityThrowsException()
 {
     $lookup = new InMemoryEntityLookup();
     $lookup->addException(new EntityLookupException(new ItemId('Q1')));
     $lookup->hasEntity(new ItemId('Q2'));
     $this->setExpectedException('Wikibase\\DataModel\\Services\\Lookup\\EntityLookupException');
     $lookup->hasEntity(new ItemId('Q1'));
 }
 /**
  * @return EntityLookup
  */
 private function newEntityLookup()
 {
     $lookup = new InMemoryEntityLookup();
     foreach ($this->propertiesAndTypes as $propertyId => $dataTypeId) {
         $property = Property::newFromType($dataTypeId);
         $property->setId(new PropertyId($propertyId));
         $lookup->addEntity($property);
     }
     return $lookup;
 }
 public function addReferences(MicroData $microData, $item, $sourceUrl)
 {
     // Only cache entity lookup stuff per item we are adding references for!
     // (but can be used for multiple sourceURLs!!
     if (!$item->getId()->equals($this->lastEntityId)) {
         $this->inMemoryEntityLookup = new InMemoryEntityLookup();
     }
     $referenceCounter = 0;
     foreach ($this->callbackMap as $propertyIdString => $valueGetterFunction) {
         $values = $valueGetterFunction($microData);
         $statements = $item->getStatements()->getByPropertyId(new PropertyId($propertyIdString));
         foreach ($values as $value) {
             foreach ($statements->getIterator() as &$statement) {
                 $mainSnak = $statement->getMainSnak();
                 if (!$mainSnak instanceof PropertyValueSnak) {
                     continue;
                     // Ignore some and no value statements
                 }
                 /** @var EntityIdValue $valueEntityIdValue */
                 $valueEntityIdValue = $mainSnak->getDataValue();
                 /** @var ItemId $valueItemId */
                 $valueItemId = $valueEntityIdValue->getEntityId();
                 if ($this->inMemoryEntityLookup->hasEntity($valueItemId)) {
                     $valueItem = $this->inMemoryEntityLookup->getEntity($valueItemId);
                 } else {
                     $valueItem = $this->wikibaseFactory->newItemLookup()->getItemForId($valueItemId);
                     $this->inMemoryEntityLookup->addEntity($valueItem);
                 }
                 if (!in_array(strtolower($value), DataModelUtils::getMainTermsAsLowerCaseStrings($valueItem->getFingerprint()))) {
                     continue;
                     // Ignore things that don't appear to have the correct value
                 }
                 if (DataModelUtils::statementHasReferenceForUrlWithSameDomain($statement, $sourceUrl)) {
                     continue;
                     // Ignore statements that already have this URL domain as a ref
                 }
                 // Add the new reference!
                 $newReference = DataModelUtils::getReferenceForUrl($sourceUrl);
                 try {
                     $this->wikibaseFactory->newReferenceSetter()->set($newReference, $statement, null, new EditInfo(urldecode($sourceUrl), EditInfo::NOTMINOR, EditInfo::BOT));
                     //NOTE: keep our in memory item copy up to date (yay such reference passing)
                     $statement->addNewReference($newReference->getSnaks());
                     $referenceCounter++;
                 } catch (UsageException $e) {
                     //Ignore
                 }
             }
         }
     }
     return $referenceCounter;
 }
 /**
  * @return EntityLookup
  */
 private function getEntityLookup()
 {
     $entityLookup = new InMemoryEntityLookup();
     $entityLookup->addException(new EntityLookupException(new ItemId('Q503')));
     $item = new Item(new ItemId('Q116'));
     $item->setLabel('en', 'New York City');
     $item->setLabel('es', 'Nueva York');
     $item->setDescription('de', 'Metropole an der Ostküste der Vereinigten Staaten');
     $item->setDescription('en', 'largest city in New York and the United States of America');
     $entityLookup->addEntity($item);
     $item = new Item(new ItemId('Q117'));
     $item->setLabel('de', 'Berlin');
     $entityLookup->addEntity($item);
     return $entityLookup;
 }