Thiemo Mättig (WMDE) has uploaded a new change for review. https://gerrit.wikimedia.org/r/156526
Change subject: Make tests compatible with DataModel 1.0 ...................................................................... Make tests compatible with DataModel 1.0 Change-Id: I7a4aaf0c0da0077bfac3d55f4c4225ee3cb96b9a Basically: Do not add Claim objects to Items. Use Statement objects. --- M repo/tests/phpunit/includes/ChangeOp/ChangeOpClaimTest.php M repo/tests/phpunit/includes/Hook/MakeGlobalVariablesScriptHandlerTest.php M repo/tests/phpunit/includes/ParserOutputJsConfigBuilderTest.php M repo/tests/phpunit/includes/api/ApiHelperFactoryTest.php 4 files changed, 98 insertions(+), 101 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/26/156526/1 diff --git a/repo/tests/phpunit/includes/ChangeOp/ChangeOpClaimTest.php b/repo/tests/phpunit/includes/ChangeOp/ChangeOpClaimTest.php index 0e983bb..9a0f78f 100644 --- a/repo/tests/phpunit/includes/ChangeOp/ChangeOpClaimTest.php +++ b/repo/tests/phpunit/includes/ChangeOp/ChangeOpClaimTest.php @@ -6,10 +6,8 @@ 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; use Wikibase\DataModel\Entity\BasicEntityIdParser; use Wikibase\DataModel\Entity\Entity; use Wikibase\DataModel\Entity\EntityId; @@ -22,6 +20,7 @@ use Wikibase\DataModel\Snak\PropertySomeValueSnak; use Wikibase\DataModel\Snak\PropertyValueSnak; use Wikibase\DataModel\Snak\SnakList; +use Wikibase\DataModel\Statement\Statement; use Wikibase\Lib\ClaimGuidGenerator; use Wikibase\Lib\ClaimGuidValidator; @@ -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 ), diff --git a/repo/tests/phpunit/includes/Hook/MakeGlobalVariablesScriptHandlerTest.php b/repo/tests/phpunit/includes/Hook/MakeGlobalVariablesScriptHandlerTest.php index 95d0dfb..5e08bab 100644 --- a/repo/tests/phpunit/includes/Hook/MakeGlobalVariablesScriptHandlerTest.php +++ b/repo/tests/phpunit/includes/Hook/MakeGlobalVariablesScriptHandlerTest.php @@ -6,7 +6,7 @@ use DataValues\StringValue; use RequestContext; use Title; -use Wikibase\DataModel\Claim\Claim; +use Wikibase\DataModel\Claim\Statement; use Wikibase\DataModel\Entity\EntityId; use Wikibase\DataModel\Entity\Item; use Wikibase\DataModel\Entity\ItemId; @@ -172,10 +172,10 @@ $snak = new PropertyValueSnak( new PropertyId( 'P794' ), new StringValue( 'a' ) ); - $claim = new Claim( $snak ); - $claim->setGuid( 'P794$muahahaha' ); + $statement = new Statement( $snak ); + $statement->setGuid( 'P794$muahahaha' ); - $item->addClaim( $claim ); + $item->addClaim( $statement ); $entityContent = ItemContent::newFromItem( $item ); return $entityContent; diff --git a/repo/tests/phpunit/includes/ParserOutputJsConfigBuilderTest.php b/repo/tests/phpunit/includes/ParserOutputJsConfigBuilderTest.php index fe205ff..a7dd9bd 100644 --- a/repo/tests/phpunit/includes/ParserOutputJsConfigBuilderTest.php +++ b/repo/tests/phpunit/includes/ParserOutputJsConfigBuilderTest.php @@ -4,7 +4,7 @@ use Language; use Title; -use Wikibase\DataModel\Claim\Claim; +use Wikibase\DataModel\Claim\Statement; use Wikibase\DataModel\Entity\BasicEntityIdParser; use Wikibase\DataModel\Entity\Entity; use Wikibase\DataModel\Entity\EntityId; @@ -144,10 +144,10 @@ new EntityIdValue( $redirect->getEntityId() ) ); - $claim = new Claim( $snak ); - $claim->setGuid( 'P794$muahahaha' ); + $statement = new Statement( $snak ); + $statement->setGuid( 'P794$muahahaha' ); - $item->addClaim( $claim ); + $item->addClaim( $statement ); return $item; } diff --git a/repo/tests/phpunit/includes/api/ApiHelperFactoryTest.php b/repo/tests/phpunit/includes/api/ApiHelperFactoryTest.php index 545a233..1fcac96 100644 --- a/repo/tests/phpunit/includes/api/ApiHelperFactoryTest.php +++ b/repo/tests/phpunit/includes/api/ApiHelperFactoryTest.php @@ -1,6 +1,7 @@ <?php namespace Wikibase\Test\Api; + use Language; use Wikibase\Api\ApiHelperFactory; use Wikibase\EntityFactory; @@ -14,9 +15,9 @@ class ApiHelperFactoryTest extends \PHPUnit_Framework_TestCase { private function newApiHelperFactory() { - $titleLookup = $this->getMock( '\Wikibase\EntityTitleLookup' ); - $exceptionLocalizer = $this->getMock( '\Wikibase\Lib\Localizer\ExceptionLocalizer' ); - $dataTypeLookup = $this->getMock( '\Wikibase\Lib\PropertyDataTypeLookup' ); + $titleLookup = $this->getMock( 'Wikibase\Lib\Store\EntityTitleLookup' ); + $exceptionLocalizer = $this->getMock( 'Wikibase\Lib\Localizer\ExceptionLocalizer' ); + $dataTypeLookup = $this->getMock( 'Wikibase\Lib\PropertyDataTypeLookup' ); return new ApiHelperFactory( $titleLookup, @@ -76,4 +77,3 @@ } } - \ No newline at end of file -- To view, visit https://gerrit.wikimedia.org/r/156526 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7a4aaf0c0da0077bfac3d55f4c4225ee3cb96b9a Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits