/**
  * @param array $serialization
  *
  * @return ReferenceList
  */
 private function getDeserialized(array $serialization)
 {
     $referenceList = new ReferenceList();
     foreach ($serialization as $referenceSerialization) {
         $referenceList->addReference($this->referenceDeserializer->deserialize($referenceSerialization));
     }
     return $referenceList;
 }
 /**
  * @since 0.4
  *
  * @param ReferenceList $references
  * @param Summary|null $summary
  *
  * @throws ChangeOpException
  */
 protected function removeReference(ReferenceList $references, Summary $summary = null)
 {
     if (!$references->hasReferenceHash($this->referenceHash)) {
         throw new ChangeOpException("Reference with hash {$this->referenceHash} does not exist");
     }
     $references->removeReferenceHash($this->referenceHash);
     $this->updateSummary($summary, 'remove');
     if ($summary !== null) {
         $summary->addAutoCommentArgs(1);
         //atomic edit, only one reference changed
     }
 }
 private function copyReferences(ReferenceList $references)
 {
     $newReferences = new ReferenceList();
     foreach ($references as $reference) {
         $newReferenceSnaks = array();
         foreach ($reference->getSnaks() as $referenceSnak) {
             $newReferenceSnaks[] = $this->copySnak($referenceSnak);
         }
         $newReferences->addReference(new Reference($newReferenceSnaks));
     }
     return $newReferences;
 }
Beispiel #4
0
 /**
  * @see Comparable::equals
  *
  * @since 0.7.4
  *
  * @param mixed $target
  *
  * @return bool
  */
 public function equals($target)
 {
     if ($this === $target) {
         return true;
     }
     return $target instanceof self && $this->guid === $target->guid && $this->rank === $target->rank && $this->mainSnak->equals($target->mainSnak) && $this->qualifiers->equals($target->qualifiers) && $this->references->equals($target->references);
 }
 /**
  * @since 0.4
  *
  * @param ReferenceList $references
  * @param Summary|null $summary
  *
  * @throws ChangeOpException
  */
 protected function setReference(ReferenceList $references, Summary $summary = null)
 {
     if (!$references->hasReferenceHash($this->referenceHash)) {
         throw new ChangeOpException("Reference with hash {$this->referenceHash} does not exist");
     }
     $currentIndex = $references->indexOf($this->reference);
     if ($this->index === null && $currentIndex !== false) {
         // Set index to current index to not have the reference removed and appended but
         // retain its position within the list of references.
         $this->index = $currentIndex;
     }
     if ($references->hasReference($this->reference) && $this->index === $currentIndex) {
         throw new ChangeOpException('The statement has already a reference with hash ' . $this->reference->getHash() . ' and index (' . $currentIndex . ') is not changed');
     }
     $references->removeReferenceHash($this->referenceHash);
     $references->addReference($this->reference, $this->index);
     $this->updateSummary($summary, 'set');
 }
 public function testFullEntityGetEntityResponse()
 {
     $item = new Item(new ItemId('Q123098'));
     //Basic
     $item->setLabel('de', 'foo-de');
     $item->setLabel('qu', 'foo-qu');
     $item->setAliases('en', array('bar', 'baz'));
     $item->setAliases('de-formal', array('bar', 'baz'));
     $item->setDescription('en', 'en-desc');
     $item->setDescription('pt', 'ptDesc');
     $item->getSiteLinkList()->addNewSiteLink('enwiki', 'Berlin', array(new ItemId('Q333')));
     $item->getSiteLinkList()->addNewSiteLink('zh_classicalwiki', 'User:Addshore', array());
     $snak = new PropertyValueSnak(65, new StringValue('snakStringValue'));
     $qualifiers = new SnakList();
     $qualifiers->addSnak(new PropertyValueSnak(65, new StringValue('string!')));
     $qualifiers->addSnak(new PropertySomeValueSnak(65));
     $references = new ReferenceList();
     $references->addNewReference(array(new PropertySomeValueSnak(65), new PropertySomeValueSnak(68)));
     $guid = 'imaguid';
     $item->getStatements()->addNewStatement($snak, $qualifiers, $references, $guid);
     $entityLookup = new MockRepository();
     $entityLookup->putEntity($item);
     $entityAccessor = $this->getEntityAccessor($entityLookup, null, 'qug');
     $expected = array('id' => 'Q123098', 'type' => 'item', 'labels' => array('de' => array('language' => 'de', 'value' => 'foo-de')), 'descriptions' => array('en' => array('language' => 'en', 'value' => 'en-desc')), 'aliases' => array('en' => array(1 => array('language' => 'en', 'value' => 'bar'), 2 => array('language' => 'en', 'value' => 'baz'))), 'claims' => array('P65' => array(1 => array('id' => 'imaguid', 'type' => 'statement', 'mainsnak' => array('snaktype' => 'value', 'property' => 'P65', 'datatype' => 'structured-cat', 'datavalue' => array('value' => 'snakStringValue', 'type' => 'string')), 'qualifiers' => array('P65' => array(1 => array('hash' => 'e95e866e7fa1c18bd06dae9b712cb99545107eb8', 'snaktype' => 'value', 'property' => 'P65', 'datavalue' => array('value' => 'string!', 'type' => 'string'), 'datatype' => 'structured-cat'), 2 => array('hash' => '210b00274bf03247a89de918f15b12142ebf9e56', 'snaktype' => 'somevalue', 'property' => 'P65', 'datatype' => 'structured-cat'))), 'rank' => 'normal', 'qualifiers-order' => array(1 => 'P65'), 'references' => array(1 => array('hash' => 'bdc5f7185904d6d3219e13b7443571dda8c4bee8', 'snaks' => array('P65' => array(1 => array('snaktype' => 'somevalue', 'property' => 'P65', 'datatype' => 'structured-cat')), 'P68' => array(1 => array('snaktype' => 'somevalue', 'property' => 'P68', 'datatype' => 'structured-cat'))), 'snaks-order' => array(1 => 'P65', 2 => 'P68')))))), 'sitelinks' => array('enwiki' => array('site' => 'enwiki', 'title' => 'Berlin', 'badges' => array(1 => 'Q333')), 'zh_classicalwiki' => array('site' => 'zh_classicalwiki', 'title' => 'User:Addshore', 'badges' => array())), 'schemaVersion' => 2);
     $this->assertEquals($expected, $entityAccessor->getEntity('Q123098'));
 }
 /**
  * @param ReferenceList $expected
  * @param ReferenceList $actual
  */
 public function assertReferenceListEquals(ReferenceList $expected, ReferenceList $actual)
 {
     $this->assertTrue($actual->equals($expected), 'The two ReferenceList are different');
 }
 /**
  * @dataProvider provideTestAddEntityRevision
  */
 public function testAddEntityRevision($addMetaData, array $expected)
 {
     $result = $this->getDefaultResult();
     $item = new Item(new ItemId('Q123098'));
     //Basic
     $item->setLabel('de', 'foo');
     $item->setLabel('zh_classical', 'Longer Label');
     $item->setAliases('en', array('bar', 'baz'));
     $item->setAliases('zh', array('????????'));
     $item->setDescription('pt', 'ptDesc');
     $item->setDescription('pl', 'Longer Description For An Item');
     $item->getSiteLinkList()->addNewSiteLink('enwiki', 'Berlin', array(new ItemId('Q333')));
     $item->getSiteLinkList()->addNewSiteLink('zh_classicalwiki', 'User:Addshore', array());
     $snak = new PropertyValueSnak(new PropertyId('P65'), new StringValue('snakStringValue'));
     $qualifiers = new SnakList();
     $qualifiers->addSnak(new PropertyValueSnak(new PropertyId('P65'), new StringValue('string!')));
     $qualifiers->addSnak(new PropertySomeValueSnak(new PropertyId('P65')));
     $references = new ReferenceList();
     $referenceSnaks = new SnakList();
     $referenceSnaks->addSnak(new PropertySomeValueSnak(new PropertyId('P65')));
     $referenceSnaks->addSnak(new PropertySomeValueSnak(new PropertyId('P68')));
     $references->addReference(new Reference($referenceSnaks));
     $guid = 'imaguid';
     $item->getStatements()->addNewStatement($snak, $qualifiers, $references, $guid);
     $entityRevision = new EntityRevision($item, 33, '20131126202923');
     $resultBuilder = $this->getResultBuilder($result, $addMetaData);
     $resultBuilder->addEntityRevision('Q1230000', $entityRevision);
     $data = $result->getResultData();
     $this->assertEquals($expected, $data);
 }
 public function testGivenNonEmptyListWithForwardedIterator_isNotEmpty()
 {
     $references = new ReferenceList();
     $references->addNewReference(new PropertyNoValueSnak(1));
     $references->next();
     $this->assertFalse($references->valid(), 'post condition');
     $this->assertFalse($references->isEmpty());
     $this->assertFalse($references->valid(), 'pre condition');
 }