Jeroen De Dauw has submitted this change and it was merged. Change subject: Make ChangeOpClaimTest compatible with DM 1.0 ......................................................................
Make ChangeOpClaimTest compatible with DM 1.0 Change-Id: Ifae7772d3ee2ef280092728ce201bbe0b6ce71b8 --- M repo/tests/phpunit/includes/ChangeOp/ChangeOpClaimTest.php 1 file changed, 85 insertions(+), 88 deletions(-) Approvals: WikidataJenkins: Verified Jeroen De Dauw: Looks good to me, approved jenkins-bot: Checked diff --git a/repo/tests/phpunit/includes/ChangeOp/ChangeOpClaimTest.php b/repo/tests/phpunit/includes/ChangeOp/ChangeOpClaimTest.php index 0e983bb..9ba00df 100644 --- a/repo/tests/phpunit/includes/ChangeOp/ChangeOpClaimTest.php +++ b/repo/tests/phpunit/includes/ChangeOp/ChangeOpClaimTest.php @@ -6,7 +6,6 @@ use DataValues\StringValue; use InvalidArgumentException; use Wikibase\ChangeOp\ChangeOpClaim; -use Wikibase\DataModel\Claim\Claim; use Wikibase\DataModel\Claim\ClaimGuidParser; use Wikibase\DataModel\Claim\Claims; use Wikibase\DataModel\Claim\Statement; @@ -82,61 +81,61 @@ public function provideTestApply() { $itemEmpty = Item::newEmpty(); $itemEmpty->setId( new ItemId( 'q888' ) ); - $item777 = self::makeNewItemWithClaim( 'Q777', new PropertyNoValueSnak( 45 ) ); - $item666 = self::makeNewItemWithClaim( 'Q666', new PropertySomeValueSnak( 44 ) ); + $item777 = self::makeNewItemWithStatement( 'Q777', new PropertyNoValueSnak( 45 ) ); + $item666 = self::makeNewItemWithStatement( 'Q666', new PropertySomeValueSnak( 44 ) ); - $item777Claims = $item777->getClaims(); - $item666Claims = $item666->getClaims(); + $item777Statements = $item777->getClaims(); + $item666Statements = $item666->getClaims(); - $claim777 = reset( $item777Claims ); - $claim666 = reset( $item666Claims ); + $statement777 = reset( $item777Statements ); + $statement666 = reset( $item666Statements ); //claims that exist on the given entities - $claims[0] = new Claim( new PropertyNoValueSnak( 43 ) ); - $claims[777] = clone $claim777; - $claims[666] = clone $claim666; + $statements[0] = new Statement( new PropertyNoValueSnak( 43 ) ); + $statements[777] = clone $statement777; + $statements[666] = clone $statement666; //claims with a null guid - $claims[7770] = clone $claim777; - $claims[7770]->setGuid( null ); - $claims[6660] = clone $claim666; - $claims[6660]->setGuid( null ); + $statements[7770] = clone $statement777; + $statements[7770]->setGuid( null ); + $statements[6660] = clone $statement666; + $statements[6660]->setGuid( null ); //new claims not yet on the entity - $claims[7777] = clone $claim777; - $claims[7777]->setGuid( 'Q777$D8404CDA-25E4-4334-AF13-A3290BC77777' ); - $claims[6666] = clone $claim666; - $claims[6666]->setGuid( 'Q666$D8404CDA-25E4-4334-AF13-A3290BC66666' ); + $statements[7777] = clone $statement777; + $statements[7777]->setGuid( 'Q777$D8404CDA-25E4-4334-AF13-A3290BC77777' ); + $statements[6666] = clone $statement666; + $statements[6666]->setGuid( 'Q666$D8404CDA-25E4-4334-AF13-A3290BC66666' ); - $claims[11] = new Claim( new PropertyNoValueSnak( 1 ) ); - $claims[11]->setGuid( null ); - $claims[12] = new Claim( new PropertySomeValueSnak( 1 ) ); - $claims[12]->setGuid( null ); - $claims[13] = clone $claims[12]; - $claims[13]->setGuid( 'Q666$D8404CDA-25E4-4334-AF13-A3290BC66613' ); + $statements[11] = new Statement( new PropertyNoValueSnak( 1 ) ); + $statements[11]->setGuid( null ); + $statements[12] = new Statement( new PropertySomeValueSnak( 1 ) ); + $statements[12]->setGuid( null ); + $statements[13] = clone $statements[12]; + $statements[13]->setGuid( 'Q666$D8404CDA-25E4-4334-AF13-A3290BC66613' ); $args = array(); //test adding claims with guids from other items(these shouldn't be added) - $args[] = array( $itemEmpty, $claims[666], false ); - $args[] = array( $itemEmpty, $claims[777], false ); - $args[] = array( $item666, $claims[777], false ); - $args[] = array( $item777, $claims[666], false ); + $args[] = array( $itemEmpty, $statements[666], false ); + $args[] = array( $itemEmpty, $statements[777], false ); + $args[] = array( $item666, $statements[777], false ); + $args[] = array( $item777, $statements[666], false ); //test adding the same claims with a null guid (a guid should be created) - $args[] = array( $item777, $claims[7770], array( $claims[777], $claims[7770] ) ); - $args[] = array( $item666, $claims[6660], array( $claims[666], $claims[6660] ) ); + $args[] = array( $item777, $statements[7770], array( $statements[777], $statements[7770] ) ); + $args[] = array( $item666, $statements[6660], array( $statements[666], $statements[6660] ) ); //test adding the same claims with a correct but different guid (these should be added) - $args[] = array( $item777, $claims[7777], array( $claims[777], $claims[7770], $claims[7777] ) ); - $args[] = array( $item666, $claims[6666], array( $claims[666], $claims[6660], $claims[6666] ) ); + $args[] = array( $item777, $statements[7777], array( $statements[777], $statements[7770], $statements[7777] ) ); + $args[] = array( $item666, $statements[6666], array( $statements[666], $statements[6660], $statements[6666] ) ); //test adding the same claims with and id that already exists (these shouldn't be added) - $args[] = array( $item777, $claims[7777], array( $claims[777], $claims[7770], $claims[7777] ) ); - $args[] = array( $item666, $claims[6666], array( $claims[666], $claims[6660], $claims[6666] ) ); + $args[] = array( $item777, $statements[7777], array( $statements[777], $statements[7770], $statements[7777] ) ); + $args[] = array( $item666, $statements[6666], array( $statements[666], $statements[6660], $statements[6666] ) ); // test adding a claim at a specific index - $args[] = array( $item777, $claims[0], array( $claims[0], $claims[777], $claims[7770], $claims[7777] ), 0 ); + $args[] = array( $item777, $statements[0], array( $statements[0], $statements[777], $statements[7770], $statements[7777] ), 0 ); // test moving a claim - $args[] = array( $item666, $claims[6666], array( $claims[666], $claims[6666], $claims[6660] ), 1 ); + $args[] = array( $item666, $statements[6666], array( $statements[666], $statements[6666], $statements[6660] ), 1 ); // test adding a claim featuring another property id within the boundaries of claims the // same property - $args[] = array( $item666, $claims[11], array( $claims[666], $claims[6666], $claims[6660], $claims[11] ), 1 ); + $args[] = array( $item666, $statements[11], array( $statements[666], $statements[6666], $statements[6660], $statements[11] ), 1 ); // test moving a subset of claims featuring the same property - $args[] = array( $item666, $claims[12], array( $claims[12], $claims[11], $claims[666], $claims[6666], $claims[6660] ), 0 ); + $args[] = array( $item666, $statements[12], array( $statements[12], $statements[11], $statements[666], $statements[6666], $statements[6660] ), 0 ); return $args; } @@ -145,18 +144,18 @@ * @dataProvider provideTestApply * * @param Entity $entity - * @param Claim $claim - * @param Claim[]|bool $expected + * @param Statement $statement + * @param Statement[]|bool $expected * @param int|null $index */ - public function testApply( $entity, $claim, $expected, $index = null ) { + public function testApply( Entity $entity, Statement $statement, $expected, $index = null ) { if ( $expected === false ) { $this->setExpectedException( '\Wikibase\ChangeOp\ChangeOpException' ); } $idParser = new BasicEntityIdParser(); $changeOpClaim = new ChangeOpClaim( - $claim, + $statement, new ClaimGuidGenerator(), new ClaimGuidValidator( $idParser ), new ClaimGuidParser( $idParser ), @@ -174,12 +173,12 @@ $entityClaimHashSet = array_flip( $entityClaims->getHashes() ); $i = 0; - foreach ( $expected as $expectedClaim ) { - $guid = $expectedClaim->getGuid(); - $hash = $expectedClaim->getHash(); + foreach ( $expected as $expectedStatement ) { + $guid = $expectedStatement->getGuid(); + $hash = $expectedStatement->getHash(); if ( $guid !== null ) { - $this->assertEquals( $i++, $entityClaims->indexOf( $expectedClaim ) ); + $this->assertEquals( $i++, $entityClaims->indexOf( $expectedStatement ) ); } $this->assertArrayHasKey( $hash, $entityClaimHashSet ); @@ -189,23 +188,21 @@ } public function provideInvalidApply() { - /* @var Claim $claim */ - $snak = new PropertyNoValueSnak( 67573284 ); - $item = $this->makeNewItemWithClaim( 'Q777', $snak ); - $claims = $item->getClaims(); - $claim = reset( $claims ); + $item = $this->makeNewItemWithStatement( 'Q777', $snak ); + $statements = $item->getClaims(); + $statement = reset( $statements ); // change main snak to "some value" $newSnak = new PropertySomeValueSnak( 67573284 ); - $newClaim = clone $claim; - $newClaim->setMainSnak( $newSnak ); + $newStatement = clone $statement; + $newStatement->setMainSnak( $newSnak ); // apply change to the wrong item $wrongItem = Item::newEmpty(); $wrongItem->setId( new ItemId( "Q888" ) ); $args['wrong entity'] = array ( $wrongItem, new ChangeOpClaim( - $newClaim, + $newStatement, $this->mockProvider->getGuidGenerator(), $this->mockProvider->getMockGuidValidator(), $this->mockProvider->getMockGuidParser( $item->getId() ), @@ -223,10 +220,10 @@ // update an existing claim with wrong main snak property $newSnak = new PropertyNoValueSnak( 23452345 ); - $newClaim->setMainSnak( $newSnak ); + $newStatement->setMainSnak( $newSnak ); $changeOp = new ChangeOpClaim( - $newClaim, + $newStatement, $this->mockProvider->getGuidGenerator(), $this->mockProvider->getMockGuidValidator(), $this->mockProvider->getMockGuidParser( $item->getId() ), @@ -252,19 +249,19 @@ * @param $snak * @return Item */ - protected function makeNewItemWithClaim( $itemId, $snak ) { - $entity = Item::newEmpty(); - $entity->setId( new ItemId( $itemId ) ); + protected function makeNewItemWithStatement( $itemId, $snak ) { + $item = Item::newEmpty(); + $item->setId( new ItemId( $itemId ) ); - $claim = $entity->newClaim( $snak ); + $statement = $item->newClaim( $snak ); $guidGenerator = new ClaimGuidGenerator(); - $claim->setGuid( $guidGenerator->newGuid( $entity->getId() ) ); + $statement->setGuid( $guidGenerator->newGuid( $item->getId() ) ); $claims = new Claims(); - $claims->addClaim( $claim ); - $entity->setClaims( $claims ); + $claims->addClaim( $statement ); + $item->setClaims( $claims ); - return $entity; + return $item; } public function validateProvider() { @@ -280,37 +277,37 @@ $cases = array(); - $claim = new Claim( $badSnak ); - $claim->setGuid( $guidGenerator->newGuid( $q17 ) ); - $cases['invalid value in main snak'] = array( $q17, $claim ); + $statement = new Statement( $badSnak ); + $statement->setGuid( $guidGenerator->newGuid( $q17 ) ); + $cases['invalid value in main snak'] = array( $q17, $statement ); - $claim = new Claim( $brokenSnak ); - $claim->setGuid( $guidGenerator->newGuid( $q17 ) ); - $cases['mismatching value in main snak'] = array( $q17, $claim ); + $statement = new Statement( $brokenSnak ); + $statement->setGuid( $guidGenerator->newGuid( $q17 ) ); + $cases['mismatching value in main snak'] = array( $q17, $statement ); - $claim = new Claim( $goodSnak ); - $claim->setGuid( $guidGenerator->newGuid( $q17 ) ); - $claim->setQualifiers( new SnakList( array( $badSnak ) ) ); - $cases['bad snak in qualifiers'] = array( $q17, $claim ); + $statement = new Statement( $goodSnak ); + $statement->setGuid( $guidGenerator->newGuid( $q17 ) ); + $statement->setQualifiers( new SnakList( array( $badSnak ) ) ); + $cases['bad snak in qualifiers'] = array( $q17, $statement ); - $claim = new Claim( $goodSnak ); - $claim->setGuid( $guidGenerator->newGuid( $q17 ) ); - $claim->setQualifiers( new SnakList( array( $brokenSnak ) ) ); - $cases['mismatching value in qualifier'] = array( $q17, $claim ); + $statement = new Statement( $goodSnak ); + $statement->setGuid( $guidGenerator->newGuid( $q17 ) ); + $statement->setQualifiers( new SnakList( array( $brokenSnak ) ) ); + $cases['mismatching value in qualifier'] = array( $q17, $statement ); - $claim = new Statement( $goodSnak ); + $statement = new Statement( $goodSnak ); $reference = new Reference( new SnakList( array( $badSnak ) ) ); - $claim->setGuid( $guidGenerator->newGuid( $q17 ) ); - $claim->setReferences( new ReferenceList( array( $reference ) ) ); - $cases['bad snak in reference'] = array( $q17, $claim ); + $statement->setGuid( $guidGenerator->newGuid( $q17 ) ); + $statement->setReferences( new ReferenceList( array( $reference ) ) ); + $cases['bad snak in reference'] = array( $q17, $statement ); - $claim = new Statement( $goodSnak ); + $statement = new Statement( $goodSnak ); $reference = new Reference( new SnakList( array( $badSnak ) ) ); - $claim->setGuid( $guidGenerator->newGuid( $q17 ) ); - $claim->setReferences( new ReferenceList( array( $reference ) ) ); - $cases['mismatching value in reference'] = array( $q17, $claim ); + $statement->setGuid( $guidGenerator->newGuid( $q17 ) ); + $statement->setReferences( new ReferenceList( array( $reference ) ) ); + $cases['mismatching value in reference'] = array( $q17, $statement ); return $cases; } @@ -318,9 +315,9 @@ /** * @dataProvider validateProvider */ - public function testValidate( EntityId $entityId, Claim $claim ) { + public function testValidate( EntityId $entityId, Statement $statement ) { $changeOpClaim = new ChangeOpClaim( - $claim, + $statement, new ClaimGuidGenerator(), $this->mockProvider->getMockGuidValidator(), $this->mockProvider->getMockGuidParser( $entityId ), -- To view, visit https://gerrit.wikimedia.org/r/156524 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ifae7772d3ee2ef280092728ce201bbe0b6ce71b8 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de> Gerrit-Reviewer: Addshore <addshorew...@gmail.com> Gerrit-Reviewer: Jeroen De Dauw <jeroended...@gmail.com> Gerrit-Reviewer: WikidataJenkins <wikidata-servi...@wikimedia.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits