public function testReturnsFalseForVerboseStatementWithoutReferences()
 {
     $statement = new Statement(new PropertyValueSnak(42, new StringValue('\\o/')));
     $statement->setGuid('kittens of doom');
     $statement->setRank(Statement::RANK_PREFERRED);
     $statement->setQualifiers(new SnakList(array(new PropertyValueSnak(1, new StringValue('wee')), new PropertyValueSnak(2, new StringValue('woo')), new PropertyValueSnak(3, new StringValue('waa')))));
     $filter = new ReferencedStatementFilter();
     $this->assertFalse($filter->statementMatches($statement));
 }
 public function testQualifiersOrderSerialization()
 {
     $snakSerializerMock = $this->getMock('\\Serializers\\Serializer');
     $snakSerializerMock->expects($this->any())->method('serialize')->will($this->returnValue(array('snaktype' => 'novalue', 'property' => 'P42')));
     $snaksSerializerMock = $this->getMock('\\Serializers\\Serializer');
     $snaksSerializerMock->expects($this->any())->method('serialize')->will($this->returnValue(array()));
     $referencesSerializerMock = $this->getMock('\\Serializers\\Serializer');
     $statementSerializer = new StatementSerializer($snakSerializerMock, $snaksSerializerMock, $referencesSerializerMock);
     $statement = new Statement(new PropertyNoValueSnak(42));
     $statement->setQualifiers(new SnakList(array(new PropertyNoValueSnak(42), new PropertySomeValueSnak(24), new PropertyNoValueSnak(24))));
     $this->assertEquals(array('mainsnak' => array('snaktype' => 'novalue', 'property' => 'P42'), 'qualifiers' => array(), 'qualifiers-order' => array('P42', 'P24'), 'type' => 'statement', 'rank' => 'normal'), $statementSerializer->serialize($statement));
 }
 public function testQualifiersOrderDeserialization()
 {
     $snakDeserializerMock = $this->getMock('\\Deserializers\\Deserializer');
     $snakDeserializerMock->expects($this->any())->method('deserialize')->with($this->equalTo(array('snaktype' => 'novalue', 'property' => 'P42')))->will($this->returnValue(new PropertyNoValueSnak(42)));
     $snaksDeserializerMock = $this->getMock('\\Deserializers\\Deserializer');
     $snaksDeserializerMock->expects($this->any())->method('deserialize')->with($this->equalTo(array('P24' => array(array('snaktype' => 'novalue', 'property' => 'P24')), 'P42' => array(array('snaktype' => 'somevalue', 'property' => 'P42'), array('snaktype' => 'novalue', 'property' => 'P42')))))->will($this->returnValue(new SnakList(array(new PropertyNoValueSnak(24), new PropertySomeValueSnak(42), new PropertyNoValueSnak(42)))));
     $referencesDeserializerMock = $this->getMock('\\Deserializers\\Deserializer');
     $statementDeserializer = new StatementDeserializer($snakDeserializerMock, $snaksDeserializerMock, $referencesDeserializerMock);
     $statement = new Statement(new PropertyNoValueSnak(42));
     $statement->setQualifiers(new SnakList(array(new PropertySomeValueSnak(42), new PropertyNoValueSnak(42), new PropertyNoValueSnak(24))));
     $serialization = array('mainsnak' => array('snaktype' => 'novalue', 'property' => 'P42'), 'qualifiers' => array('P24' => array(array('snaktype' => 'novalue', 'property' => 'P24')), 'P42' => array(array('snaktype' => 'somevalue', 'property' => 'P42'), array('snaktype' => 'novalue', 'property' => 'P42'))), 'qualifiers-order' => array('P42', 'P24'), 'type' => 'claim');
     $this->assertEquals($statement->getHash(), $statementDeserializer->deserialize($serialization)->getHash());
 }
 public function provideValidateClaimSnaks()
 {
     $p1 = new PropertyId('p1');
     // numeric
     $p2 = new PropertyId('p2');
     // alphabetic
     $cases = array();
     $claim = new Statement(new PropertyNoValueSnak($p1));
     $cases[] = array($claim, 'empty claim', true);
     $claim = new Statement(new PropertyValueSnak($p1, new StringValue('12')));
     $claim->setQualifiers(new SnakList(array(new PropertyValueSnak($p2, new StringValue('abc')))));
     $claim->setReferences(new ReferenceList(array(new Reference(new SnakList(array(new PropertyValueSnak($p2, new StringValue('xyz'))))))));
     $cases[] = array($claim, 'conforming claim', true);
     $brokenClaim = clone $claim;
     $brokenClaim->setMainSnak(new PropertyValueSnak($p1, new StringValue('kittens')));
     $cases[] = array($brokenClaim, 'error in main snak', false);
     $brokenClaim = clone $claim;
     $brokenClaim->setQualifiers(new SnakList(array(new PropertyValueSnak($p2, new StringValue('333')))));
     $cases[] = array($brokenClaim, 'error in qualifier', false);
     $brokenClaim = clone $claim;
     $brokenClaim->setReferences(new ReferenceList(array(new Reference(new SnakList(array(new PropertyValueSnak($p1, new StringValue('xyz'))))))));
     $cases[] = array($brokenClaim, 'error in reference', false);
     return $cases;
 }
 public function snaksProvider()
 {
     $statements = array();
     $statements[] = array(new Statement(new PropertyNoValueSnak(42)));
     $statement = new Statement(new PropertyNoValueSnak(42));
     $statement->setGuid('q42');
     $statements[] = array($statement);
     $statement = new Statement(new PropertyNoValueSnak(42));
     $statement->setRank(Statement::RANK_PREFERRED);
     $statements[] = array($statement);
     $statement = new Statement(new PropertyNoValueSnak(42));
     $statement->setRank(Statement::RANK_DEPRECATED);
     $statements[] = array($statement);
     $statement = new Statement(new PropertyNoValueSnak(42));
     $statement->setQualifiers(new SnakList(array()));
     $statements[] = array($statement);
     $statement = new Statement(new PropertyNoValueSnak(42));
     $statement->setQualifiers(new SnakList(array(new PropertySomeValueSnak(42), new PropertyNoValueSnak(42), new PropertySomeValueSnak(24))));
     $statements[] = array($statement);
     $statement = new Statement(new PropertyNoValueSnak(42));
     $statement->setReferences(new ReferenceList(array(new Reference(array(new PropertySomeValueSnak(42), new PropertyNoValueSnak(42), new PropertySomeValueSnak(24))))));
     $statements[] = array($statement);
     return $statements;
 }
 public function validateProvider()
 {
     $p11 = new PropertyId('P11');
     $q17 = new ItemId('Q17');
     //NOTE: the mock validator will consider the string "INVALID" to be invalid.
     $goodSnak = new PropertyValueSnak($p11, new StringValue('good'));
     $badSnak = new PropertyValueSnak($p11, new StringValue('INVALID'));
     $brokenSnak = new PropertyValueSnak($p11, new NumberValue(23));
     $guidGenerator = new GuidGenerator();
     $cases = array();
     $statement = new Statement($badSnak);
     $statement->setGuid($guidGenerator->newGuid($q17));
     $cases['invalid value in main snak'] = array($q17, $statement);
     $statement = new Statement($brokenSnak);
     $statement->setGuid($guidGenerator->newGuid($q17));
     $cases['mismatching value in main snak'] = array($q17, $statement);
     $statement = new Statement($goodSnak);
     $statement->setGuid($guidGenerator->newGuid($q17));
     $statement->setQualifiers(new SnakList(array($badSnak)));
     $cases['bad snak in qualifiers'] = array($q17, $statement);
     $statement = new Statement($goodSnak);
     $statement->setGuid($guidGenerator->newGuid($q17));
     $statement->setQualifiers(new SnakList(array($brokenSnak)));
     $cases['mismatching value in qualifier'] = array($q17, $statement);
     $statement = new Statement($goodSnak);
     $reference = new Reference(new SnakList(array($badSnak)));
     $statement->setGuid($guidGenerator->newGuid($q17));
     $statement->setReferences(new ReferenceList(array($reference)));
     $cases['bad snak in reference'] = array($q17, $statement);
     $statement = new Statement($goodSnak);
     $reference = new Reference(new SnakList(array($badSnak)));
     $statement->setGuid($guidGenerator->newGuid($q17));
     $statement->setReferences(new ReferenceList(array($reference)));
     $cases['mismatching value in reference'] = array($q17, $statement);
     return $cases;
 }
 private function getInvalidCases()
 {
     $store = WikibaseRepo::getDefaultInstance()->getEntityStore();
     $item = new Item();
     $store->saveEntity($item, 'setclaimtest', $GLOBALS['wgUser'], EDIT_NEW);
     $q17 = $item->getId();
     $property = Property::newFromType('string');
     $store->saveEntity($property, 'setclaimtest', $GLOBALS['wgUser'], EDIT_NEW);
     $p11 = $property->getId();
     $item = new Item();
     $store->saveEntity($item, 'setclaimtest', $GLOBALS['wgUser'], EDIT_NEW);
     $qx = $item->getId();
     $store->deleteEntity($qx, 'setclaimtest', $GLOBALS['wgUser']);
     $property = Property::newFromType('string');
     $store->saveEntity($property, 'setclaimtest', $GLOBALS['wgUser'], EDIT_NEW);
     $px = $property->getId();
     $store->deleteEntity($px, 'setclaimtest', $GLOBALS['wgUser']);
     $goodSnak = new PropertyValueSnak($p11, new StringValue('good'));
     $badSnak = new PropertyValueSnak($p11, new StringValue(' x '));
     $brokenSnak = new PropertyValueSnak($p11, new NumberValue(23));
     $obsoleteSnak = new PropertyValueSnak($px, new StringValue(' x '));
     $guidGenerator = new GuidGenerator();
     $cases = array();
     $statement = new Statement($badSnak);
     $statement->setGuid($guidGenerator->newGuid($q17));
     $cases['invalid value in main snak'] = array($q17, $statement, 'modification-failed');
     $statement = new Statement($brokenSnak);
     $statement->setGuid($guidGenerator->newGuid($q17));
     $cases['mismatching value in main snak'] = array($q17, $statement, 'modification-failed');
     $statement = new Statement($obsoleteSnak);
     $statement->setGuid($guidGenerator->newGuid($q17));
     $cases['obsolete snak using deleted property'] = array($q17, $statement, 'modification-failed');
     $statement = new Statement($goodSnak);
     $statement->setGuid($guidGenerator->newGuid($qx));
     $cases['good claim for deleted item'] = array($qx, $statement, 'cant-load-entity-content');
     $statement = new Statement($goodSnak);
     $statement->setGuid($guidGenerator->newGuid($q17));
     $statement->setQualifiers(new SnakList(array($badSnak)));
     $cases['bad snak in qualifiers'] = array($q17, $statement, 'modification-failed');
     $statement = new Statement($goodSnak);
     $statement->setGuid($guidGenerator->newGuid($q17));
     $statement->setQualifiers(new SnakList(array($brokenSnak)));
     $cases['mismatching value in qualifier'] = array($q17, $statement, 'modification-failed');
     $statement = new Statement($goodSnak);
     $reference = new Reference(new SnakList(array($badSnak)));
     $statement->setGuid($guidGenerator->newGuid($q17));
     $statement->setReferences(new ReferenceList(array($reference)));
     $cases['bad snak in reference'] = array($q17, $statement, 'modification-failed');
     $statement = new Statement($goodSnak);
     $reference = new Reference(new SnakList(array($badSnak)));
     $statement->setGuid($guidGenerator->newGuid($q17));
     $statement->setReferences(new ReferenceList(array($reference)));
     $cases['mismatching value in reference'] = array($q17, $statement, 'modification-failed');
     $statement = new Statement($goodSnak);
     $statement->setGuid('XXXX');
     $cases['invalid GUID'] = array($qx, $statement, 'invalid-claim');
     return $cases;
 }
 private function setQualifiersFromSerialization(array &$serialization, Statement $statement)
 {
     if (!array_key_exists('qualifiers', $serialization)) {
         return;
     }
     $qualifiers = $this->snaksDeserializer->deserialize($serialization['qualifiers']);
     if (array_key_exists('qualifiers-order', $serialization)) {
         $this->assertQualifiersOrderIsArray($serialization);
         $qualifiers->orderByProperty($serialization['qualifiers-order']);
     }
     $statement->setQualifiers($qualifiers);
 }