protected function makeEntity(EntityId $id, array $statements = array())
 {
     $item = new Item($id);
     $item->setLabel('en', "label:{$id}");
     $item->setDescription('en', "description:{$id}");
     $item->setStatements(new StatementList($statements));
     return $item;
 }
Example #2
0
 private function patchItem(Item $item, EntityDiff $patch)
 {
     $this->fingerprintPatcher->patchFingerprint($item->getFingerprint(), $patch);
     if ($patch instanceof ItemDiff) {
         $item->setSiteLinkList($this->siteLinkListPatcher->getPatchedSiteLinkList($item->getSiteLinkList(), $patch->getSiteLinkDiff()));
     }
     $item->setStatements($this->statementListPatcher->getPatchedStatementList($item->getStatements(), $patch->getClaimsDiff()));
 }
Example #3
0
 private function setStatementListFromSerialization(array $serialization, Item $item)
 {
     if (!array_key_exists('claims', $serialization)) {
         return;
     }
     $statements = $this->statementListDeserializer->deserialize($serialization['claims']);
     $item->setStatements($statements);
 }
 /**
  * @return array 1=>from 2=>to 3=>expectedFrom 4=>expectedTo
  */
 public function provideData()
 {
     $testCases = array();
     $itemWithEnLabel = new Item();
     $itemWithEnLabel->getFingerprint()->setLabel('en', 'foo');
     $testCases['labelMerge'] = array($itemWithEnLabel->copy(), new Item(), new Item(), $itemWithEnLabel->copy());
     $testCases['identicalLabelMerge'] = array($itemWithEnLabel->copy(), $itemWithEnLabel->copy(), new Item(), $itemWithEnLabel->copy());
     $itemWithEnBarLabel = new Item();
     $itemWithEnBarLabel->getFingerprint()->setLabel('en', 'bar');
     $itemWithLabelAndAlias = new Item();
     $itemWithLabelAndAlias->getFingerprint()->setLabel('en', 'bar');
     $itemWithLabelAndAlias->getFingerprint()->setAliasGroup('en', array('foo'));
     $testCases['labelAsAliasMerge'] = array($itemWithEnLabel->copy(), $itemWithEnBarLabel->copy(), new Item(), $itemWithLabelAndAlias->copy());
     $itemWithDescription = new Item();
     $itemWithDescription->getFingerprint()->setDescription('en', 'foo');
     $testCases['descriptionMerge'] = array($itemWithDescription->copy(), new Item(), new Item(), $itemWithDescription->copy());
     $testCases['identicalDescriptionMerge'] = array($itemWithDescription->copy(), $itemWithDescription->copy(), new Item(), $itemWithDescription->copy());
     $itemWithBarDescription = new Item();
     $itemWithBarDescription->getFingerprint()->setDescription('en', 'bar');
     $testCases['ignoreConflictDescriptionMerge'] = array($itemWithDescription->copy(), $itemWithBarDescription->copy(), $itemWithDescription->copy(), $itemWithBarDescription->copy(), array('description'));
     $itemWithFooBarAliases = new Item();
     $itemWithFooBarAliases->getFingerprint()->setAliasGroup('en', array('foo', 'bar'));
     $testCases['aliasMerge'] = array($itemWithFooBarAliases->copy(), new Item(), new Item(), $itemWithFooBarAliases->copy());
     $itemWithFooBarBazAliases = new Item();
     $itemWithFooBarBazAliases->getFingerprint()->setAliasGroup('en', array('foo', 'bar', 'baz'));
     $testCases['duplicateAliasMerge'] = array($itemWithFooBarAliases->copy(), $itemWithFooBarBazAliases->copy(), new Item(), $itemWithFooBarBazAliases->copy());
     $itemWithLink = new Item();
     $itemWithLink->getSiteLinkList()->addNewSiteLink('enwiki', 'foo');
     $testCases['linkMerge'] = array($itemWithLink->copy(), new Item(), new Item(), $itemWithLink->copy());
     $testCases['sameLinkLinkMerge'] = array($itemWithLink->copy(), $itemWithLink->copy(), new Item(), $itemWithLink->copy());
     $itemWithBarLink = new Item();
     $itemWithBarLink->getSiteLinkList()->addNewSiteLink('enwiki', 'bar');
     $testCases['ignoreConflictLinkMerge'] = array($itemWithLink->copy(), $itemWithBarLink->copy(), $itemWithLink->copy(), $itemWithBarLink->copy(), array('sitelink'));
     $statement = new Statement(new PropertyNoValueSnak(new PropertyId('P56')));
     $statement->setGuid('Q111$D8404CDA-25E4-4334-AF13-A390BCD9C556');
     $itemWithStatement = new Item();
     $itemWithStatement->getStatements()->addStatement($statement);
     $testCases['statementMerge'] = array($itemWithStatement->copy(), new Item(), new Item(), $itemWithStatement->copy());
     $qualifiedStatement = new Statement(new PropertyNoValueSnak(new PropertyId('P56')), new SnakList(array(new PropertyNoValueSnak(new PropertyId('P56')))));
     $qualifiedStatement->setGuid('Q111$D8404CDA-25E4-4334-AF13-A390BCD9C556');
     $itemWithQualifiedStatement = new Item();
     $itemWithQualifiedStatement->getStatements()->addStatement($qualifiedStatement);
     $testCases['statementWithQualifierMerge'] = array($itemWithQualifiedStatement->copy(), new Item(), new Item(), $itemWithQualifiedStatement->copy());
     $anotherQualifiedStatement = new Statement(new PropertyNoValueSnak(new PropertyId('P88')), new SnakList(array(new PropertyNoValueSnak(new PropertyId('P88')))));
     $anotherQualifiedStatement->setGuid('Q111$D8404CDA-25E4-4334-AF88-A3290BCD9C0F');
     $selfReferencingStatement = new Statement(new PropertyValueSnak(new PropertyId('P42'), new EntityIdValue(new ItemId('Q111'))));
     $selfReferencingStatement->setGuid('Q111$D74D43D7-BD8F-4240-A058-24C5171ABBFA');
     $bigItem = new Item();
     $bigItem->setId(111);
     $bigItem->getFingerprint()->setLabel('en', 'foo');
     $bigItem->getFingerprint()->setLabel('pt', 'ptfoo');
     $bigItem->getFingerprint()->setDescription('en', 'foo');
     $bigItem->getFingerprint()->setDescription('pl', 'pldesc');
     $bigItem->getFingerprint()->setAliasGroup('en', array('foo', 'bar'));
     $bigItem->getFingerprint()->setAliasGroup('de', array('defoo', 'debar'));
     $bigItem->getSiteLinkList()->addNewSiteLink('dewiki', 'foo');
     $bigItem->getStatements()->addStatement($anotherQualifiedStatement);
     $bigItem->getStatements()->addStatement($selfReferencingStatement);
     $testCases['itemMerge'] = array($bigItem->copy(), new Item(), new Item(), $bigItem->copy());
     $referencingStatement = new Statement(new PropertyValueSnak(new PropertyId('P42'), new EntityIdValue(new ItemId('Q222'))));
     $referencingStatement->setGuid('Q111$949A4D27-0EBC-46A7-BF5F-AA2DD33C0443');
     $bigItem->getSiteLinkList()->addNewSiteLink('nlwiki', 'bar');
     $bigItem->getStatements()->addStatement($referencingStatement);
     $smallerItem = new Item();
     $smallerItem->setId(222);
     $smallerItem->getFingerprint()->setLabel('en', 'toLabel');
     $smallerItem->getFingerprint()->setDescription('pl', 'toDescription');
     $smallerItem->getSiteLinkList()->addNewSiteLink('nlwiki', 'toLink');
     $smallerMergedItem = new Item();
     $smallerMergedItem->setId(222);
     $smallerMergedItem->getFingerprint()->setDescription('pl', 'pldesc');
     $smallerMergedItem->getSiteLinkList()->addNewSiteLink('nlwiki', 'bar');
     $bigMergedItem = new Item();
     $bigMergedItem->setId(111);
     $bigMergedItem->getFingerprint()->setLabel('en', 'toLabel');
     $bigMergedItem->getFingerprint()->setLabel('pt', 'ptfoo');
     $bigMergedItem->getFingerprint()->setDescription('en', 'foo');
     $bigMergedItem->getFingerprint()->setDescription('pl', 'toDescription');
     $bigMergedItem->getFingerprint()->setAliasGroup('en', array('foo', 'bar'));
     $bigMergedItem->getFingerprint()->setAliasGroup('de', array('defoo', 'debar'));
     $bigMergedItem->getSiteLinkList()->addNewSiteLink('dewiki', 'foo');
     $bigMergedItem->getSiteLinkList()->addNewSiteLink('nlwiki', 'toLink');
     $bigMergedItem->setStatements(new StatementList($anotherQualifiedStatement, $selfReferencingStatement, $referencingStatement));
     $testCases['ignoreConflictItemMerge'] = array($bigItem->copy(), $smallerItem->copy(), $smallerMergedItem->copy(), $bigMergedItem->copy(), array('description', 'sitelink', 'statement'));
     return $testCases;
 }
 /**
  * @param ItemId $id
  * @param string[] $labels
  * @param Statement[]|null $statements
  * @param SiteLink[]|null $siteLinks
  *
  * @return Item
  */
 private function createTestItem(ItemId $id, array $labels, array $statements = null, array $siteLinks = null)
 {
     $item = new Item($id);
     $item->getFingerprint()->setDescription('de', 'Description of ' . $id->getSerialization());
     foreach ($labels as $lang => $label) {
         $item->setLabel($lang, $label);
     }
     if ($statements !== null) {
         $item->setStatements(new StatementList($statements));
     }
     if ($siteLinks !== null) {
         $item->setSiteLinkList(new SiteLinkList($siteLinks));
     }
     $this->siteLinkLookup->putEntity($item);
     return $item;
 }
Example #6
0
 public function testSetStatements()
 {
     $item = new Item();
     $item->getStatements()->addNewStatement(new PropertyNoValueSnak(42));
     $item->setStatements(new StatementList());
     $this->assertTrue($item->getStatements()->isEmpty());
 }
 public function testNewFromUpdate_excludeStatementsInDiffs()
 {
     $factory = $this->getEntityChangeFactory();
     $item = new Item(new ItemId('Q3'));
     $statementList = new StatementList(array(new Statement(new PropertyNoValueSnak(9000))));
     $item->setStatements($statementList);
     $updatedItem = new Item(new ItemId('Q3'));
     $statementList = new StatementList(array(new Statement(new PropertyNoValueSnak(10))));
     $updatedItem->setStatements($statementList);
     $change = $factory->newFromUpdate(EntityChange::UPDATE, $item, $updatedItem);
     $this->assertTrue($change->getDiff()->isEmpty(), 'Diff excludes statement changes and is empty');
 }