Thiemo Mättig (WMDE) has uploaded a new change for review.
https://gerrit.wikimedia.org/r/231264
Change subject: End all Claim's
......................................................................
End all Claim's
Change-Id: I420b1cbcd05c161c8736994808898783562356ad
---
M repo/includes/ClaimSummaryBuilder.php
M repo/tests/phpunit/includes/ClaimSummaryBuilderTest.php
M repo/tests/phpunit/includes/Diff/ClaimDifferTest.php
M repo/tests/phpunit/includes/Validators/SnakValidatorTest.php
M repo/tests/phpunit/includes/api/SetClaimTest.php
M repo/tests/phpunit/includes/api/SetClaimValueTest.php
M repo/tests/phpunit/includes/api/SetQualifierTest.php
M repo/tests/phpunit/includes/api/SetReferenceTest.php
M view/tests/phpunit/ClaimHtmlGeneratorTest.php
M view/tests/phpunit/StatementGroupListViewTest.php
10 files changed, 83 insertions(+), 90 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/64/231264/1
diff --git a/repo/includes/ClaimSummaryBuilder.php
b/repo/includes/ClaimSummaryBuilder.php
index 87bf980..674e7c3 100644
--- a/repo/includes/ClaimSummaryBuilder.php
+++ b/repo/includes/ClaimSummaryBuilder.php
@@ -3,7 +3,7 @@
namespace Wikibase;
use InvalidArgumentException;
-use Wikibase\DataModel\Claim\Claim;
+use Wikibase\DataModel\Statement\Statement;
use Wikibase\Repo\Diff\ClaimDiffer;
/**
@@ -47,29 +47,30 @@
}
/**
- * Checks what has actually changed inside a claim by looking at a
ClaimDifference,
+ * Checks what has actually changed inside a statement by looking at a
ClaimDifference,
* constructs an edit-summary based upon that information and returns
* a Summary object holding this edit-summary
*
- * @param Claim|null $oldClaim
- * @param Claim $newClaim
+ * @param Statement|null $oldStatement
+ * @param Statement $newStatement
*
* @return Summary
*/
- public function buildClaimSummary( Claim $oldClaim = null, Claim
$newClaim ) {
- $guid = $newClaim->getGuid();
+ public function buildClaimSummary( Statement $oldStatement = null,
Statement $newStatement ) {
+ $guid = $newStatement->getGuid();
$summary = new Summary( $this->apiModuleName );
- $summary->addAutoCommentArgs( 1 ); // only one claim touched,
so we're always having singular here
+ // Only one statement touched, so we're always having singular
here.
+ $summary->addAutoCommentArgs( 1 );
$summaryArgs = $this->buildSummaryArgs(
- $newClaim,
+ $newStatement,
$guid
);
$summary->addAutoSummaryArgs( $summaryArgs );
- if ( $oldClaim !== null ) {
+ if ( $oldStatement !== null ) {
//claim is changed
- $claimDifference = $this->claimDiffer->diffClaims(
$oldClaim, $newClaim );
+ $claimDifference = $this->claimDiffer->diffClaims(
$oldStatement, $newStatement );
if ( $claimDifference->isAtomic() ) {
if ( $claimDifference->getMainSnakChange() !==
null ) {
@@ -101,18 +102,18 @@
/**
* Builds an associative array that can be used as summary arguments.
It uses property IDs as
- * array keys and builds arrays of the main Snaks of all Claims given
by the GUIDs.
+ * array keys and builds arrays of the main Snaks of all statements
given by the GUIDs.
*
- * @param Claim $newClaim
+ * @param Statement $newStatement
* @param string $guid
*
* @return array[] Associative array that contains property ID => array
of main Snaks
*/
- private function buildSummaryArgs( Claim $newClaim, $guid ) {
+ private function buildSummaryArgs( Statement $newStatement, $guid ) {
$pairs = array();
- if ( $newClaim->getGuid() === $guid ) {
- $snak = $newClaim->getMainSnak();
+ if ( $newStatement->getGuid() === $guid ) {
+ $snak = $newStatement->getMainSnak();
$key = $snak->getPropertyId()->getSerialization();
if ( !array_key_exists( $key, $pairs ) ) {
diff --git a/repo/tests/phpunit/includes/ClaimSummaryBuilderTest.php
b/repo/tests/phpunit/includes/ClaimSummaryBuilderTest.php
index 92d2286..5ad9a44 100644
--- a/repo/tests/phpunit/includes/ClaimSummaryBuilderTest.php
+++ b/repo/tests/phpunit/includes/ClaimSummaryBuilderTest.php
@@ -6,7 +6,6 @@
use Diff\Comparer\ComparableComparer;
use Diff\Differ\OrderedListDiffer;
use Wikibase\ClaimSummaryBuilder;
-use Wikibase\DataModel\Claim\Claim;
use Wikibase\DataModel\Reference;
use Wikibase\DataModel\Snak\PropertyNoValueSnak;
use Wikibase\DataModel\Snak\PropertySomeValueSnak;
@@ -43,9 +42,9 @@
}
/**
- * @return Claim[]
+ * @return Statement[]
*/
- protected function claimProvider() {
+ protected function statementProvider() {
$statements = array();
$mainSnak = new PropertyValueSnak( 112358, new StringValue(
"don't panic" ) );
@@ -83,43 +82,43 @@
public function buildUpdateClaimSummaryProvider() {
$arguments = array();
- foreach ( $this->claimProvider() as $claim ) {
+ foreach ( $this->statementProvider() as $statement ) {
$testCaseArgs = array();
//change mainsnak
- $modifiedClaim = clone $claim;
- $modifiedClaim->setMainSnak(
+ $modifiedStatement = clone $statement;
+ $modifiedStatement->setMainSnak(
new PropertyValueSnak( 112358, new StringValue(
"let's panic!!!" ) )
);
- $testCaseArgs[] = $claim;
- $testCaseArgs[] = $modifiedClaim;
+ $testCaseArgs[] = $statement;
+ $testCaseArgs[] = $modifiedStatement;
$testCaseArgs[] = 'update';
$arguments[] = $testCaseArgs;
//change qualifiers
- $modifiedClaim = clone $claim;
- $modifiedClaim->setQualifiers( new SnakList(
$this->snakProvider() ) );
- $testCaseArgs[] = $claim;
- $testCaseArgs[] = $modifiedClaim;
+ $modifiedStatement = clone $statement;
+ $modifiedStatement->setQualifiers( new SnakList(
$this->snakProvider() ) );
+ $testCaseArgs[] = $statement;
+ $testCaseArgs[] = $modifiedStatement;
$testCaseArgs[] = 'update-qualifiers';
$arguments[] = $testCaseArgs;
//change rank
- $modifiedClaim = clone $claim;
- $modifiedClaim->setRank( Statement::RANK_PREFERRED );
- $testCaseArgs[] = $claim;
- $testCaseArgs[] = $modifiedClaim;
+ $modifiedStatement = clone $statement;
+ $modifiedStatement->setRank( Statement::RANK_PREFERRED
);
+ $testCaseArgs[] = $statement;
+ $testCaseArgs[] = $modifiedStatement;
$testCaseArgs[] = 'update-rank';
$arguments[] = $testCaseArgs;
//change mainsnak & qualifiers
- $modifiedClaim = clone $claim;
- $modifiedClaim->setMainSnak(
+ $modifiedStatement = clone $statement;
+ $modifiedStatement->setMainSnak(
new PropertyValueSnak( 112358, new StringValue(
"let's panic!!!" ) )
);
- $modifiedClaim->setQualifiers( new SnakList(
$this->snakProvider() ) );
- $testCaseArgs[] = $claim;
- $testCaseArgs[] = $modifiedClaim;
+ $modifiedStatement->setQualifiers( new SnakList(
$this->snakProvider() ) );
+ $testCaseArgs[] = $statement;
+ $testCaseArgs[] = $modifiedStatement;
$testCaseArgs[] = 'update-rank';
$arguments[] = $testCaseArgs;
}
@@ -133,10 +132,10 @@
new ClaimDiffer( new OrderedListDiffer( new
ComparableComparer() ) )
);
- $newClaims = $this->claimProvider();
+ $newStatements = $this->statementProvider();
- foreach ( $newClaims as $newClaim ) {
- $summary = $claimSummaryBuilder->buildClaimSummary(
null, $newClaim );
+ foreach ( $newStatements as $newStatement ) {
+ $summary = $claimSummaryBuilder->buildClaimSummary(
null, $newStatement );
$this->assertInstanceOf( 'Wikibase\Summary', $summary,
"this should return a Summary object" );
$this->assertEquals( 'wbsetclaim',
$summary->getModuleName() );
$this->assertEquals( 'create',
$summary->getActionName() );
@@ -145,18 +144,18 @@
/**
* @dataProvider buildUpdateClaimSummaryProvider
- *
- * @param Claim $originalClaim
- * @param Claim $modifiedClaim
- * @param string $action
*/
- public function testBuildUpdateClaimSummary( $originalClaim,
$modifiedClaim, $action ) {
+ public function testBuildUpdateClaimSummary(
+ Statement $originalStatement,
+ Statement $modifiedStatement,
+ $action
+ ) {
$claimSummaryBuilder = new ClaimSummaryBuilder(
'wbsetclaim',
new ClaimDiffer( new OrderedListDiffer( new
ComparableComparer() ) )
);
- $summary = $claimSummaryBuilder->buildClaimSummary(
$originalClaim, $modifiedClaim );
+ $summary = $claimSummaryBuilder->buildClaimSummary(
$originalStatement, $modifiedStatement );
$this->assertInstanceOf( 'Wikibase\Summary', $summary, "this
should return a Summary object" );
$this->assertEquals( 'wbsetclaim', $summary->getModuleName() );
$this->assertEquals( $action, $summary->getActionName() );
diff --git a/repo/tests/phpunit/includes/Diff/ClaimDifferTest.php
b/repo/tests/phpunit/includes/Diff/ClaimDifferTest.php
index 85956b1..75aa3de 100644
--- a/repo/tests/phpunit/includes/Diff/ClaimDifferTest.php
+++ b/repo/tests/phpunit/includes/Diff/ClaimDifferTest.php
@@ -8,7 +8,6 @@
use Diff\DiffOp\DiffOpAdd;
use Diff\DiffOp\DiffOpChange;
use Diff\DiffOp\DiffOpRemove;
-use Wikibase\DataModel\Claim\Claim;
use Wikibase\DataModel\Reference;
use Wikibase\DataModel\ReferenceList;
use Wikibase\DataModel\Snak\PropertyNoValueSnak;
@@ -112,9 +111,9 @@
/**
* @dataProvider diffClaimsProvider
*/
- public function testDiffClaims( Claim $oldClaim, Claim $newClaim,
ClaimDifference $expected ) {
+ public function testDiffClaims( Statement $oldStatement, Statement
$newStatement, ClaimDifference $expected ) {
$differ = new ClaimDiffer( new OrderedListDiffer( new
ComparableComparer() ) );
- $actual = $differ->diffClaims( $oldClaim, $newClaim );
+ $actual = $differ->diffClaims( $oldStatement, $newStatement );
$this->assertTrue( $expected->equals( $actual ) );
// Additional fail-safe checks to guard against an ArrayObject
bug in PHP 5.3, that returned
diff --git a/repo/tests/phpunit/includes/Validators/SnakValidatorTest.php
b/repo/tests/phpunit/includes/Validators/SnakValidatorTest.php
index 84d0ddb..45fb5de 100644
--- a/repo/tests/phpunit/includes/Validators/SnakValidatorTest.php
+++ b/repo/tests/phpunit/includes/Validators/SnakValidatorTest.php
@@ -9,7 +9,6 @@
use DataValues\UnDeserializableValue;
use DataValues\UnknownValue;
use PHPUnit_Framework_TestCase;
-use Wikibase\DataModel\Claim\Claim;
use Wikibase\DataModel\Entity\PropertyId;
use Wikibase\DataModel\Reference;
use Wikibase\DataModel\ReferenceList;
@@ -132,10 +131,10 @@
/**
* @dataProvider provideValidateClaimSnaks
*/
- public function testValidateClaimSnaks( Claim $claim, $description,
$expectedValid = true ) {
+ public function testValidateClaimSnaks( Statement $statement,
$description, $expectedValid = true ) {
$validator = $this->getSnakValidator();
- $result = $validator->validateClaimSnaks( $claim );
+ $result = $validator->validateClaimSnaks( $statement );
$this->assertEquals( $expectedValid, $result->isValid(),
$description );
}
diff --git a/repo/tests/phpunit/includes/api/SetClaimTest.php
b/repo/tests/phpunit/includes/api/SetClaimTest.php
index 11df88d..c8c58f4 100644
--- a/repo/tests/phpunit/includes/api/SetClaimTest.php
+++ b/repo/tests/phpunit/includes/api/SetClaimTest.php
@@ -366,27 +366,27 @@
}
/**
- * @param Claim $claim
+ * @param Statement $statement
* @param ItemId $itemId
* @param int $claimCount
* @param string $requestLabel A label to identify requests that are
made in errors.
*/
private function assertClaimWasSet(
- Claim $claim,
+ Statement $statement,
ItemId $itemId,
$claimCount,
$requestLabel
) {
- $this->assertNotNull( $claim->getGuid(), 'Cannot search for
claims with no GUID' );
+ $this->assertNotNull( $statement->getGuid(), 'Cannot search for
statements with no GUID' );
/** @var Item $item */
$item =
WikibaseRepo::getDefaultInstance()->getEntityLookup()->getEntity( $itemId );
$claims = new Claims( $item->getClaims() );
- $savedClaim = $claims->getClaimWithGuid( $claim->getGuid() );
+ $savedClaim = $claims->getClaimWithGuid( $statement->getGuid()
);
$this->assertNotNull( $savedClaim, "Claims list does not have
claim after {$requestLabel}" );
- if ( count( $claim->getQualifiers() ) ) {
- $this->assertTrue( $claim->getQualifiers()->equals(
$savedClaim->getQualifiers() ) );
+ if ( count( $statement->getQualifiers() ) ) {
+ $this->assertTrue( $statement->getQualifiers()->equals(
$savedClaim->getQualifiers() ) );
}
$this->assertSame( $claimCount, $claims->count(), "Claims count
is wrong after {$requestLabel}" );
@@ -399,15 +399,13 @@
public function testBugT60394SpecifiedIndexOutOfBounds() {
$store = WikibaseRepo::getDefaultInstance()->getEntityStore();
- // Initialize item content with empty claims:
+ // Save new Item with empty statements:
$item = new Item();
$store->saveEntity( $item, 'setclaimtest', $GLOBALS['wgUser'],
EDIT_NEW );
- // Generate a single claim:
+ // Update the same Item with a single statement:
$itemId = $item->getId();
$guidGenerator = new GuidGenerator();
-
- // Save the single claim
$item->getStatements()->addNewStatement(
new PropertyNoValueSnak( self::$propertyIds[1] ),
null,
@@ -432,7 +430,6 @@
/** @var Item $item */
$item = $store->saveEntity( $item, '', $GLOBALS['wgUser'],
EDIT_NEW )->getEntity();
- // add a claim
$guidGenerator = new GuidGenerator();
$statement = new Statement( new PropertyNoValueSnak(
$property->getId() ) );
$statement->setGuid( $guidGenerator->newGuid( $item->getId() )
);
diff --git a/repo/tests/phpunit/includes/api/SetClaimValueTest.php
b/repo/tests/phpunit/includes/api/SetClaimValueTest.php
index 79571f6..803b842 100644
--- a/repo/tests/phpunit/includes/api/SetClaimValueTest.php
+++ b/repo/tests/phpunit/includes/api/SetClaimValueTest.php
@@ -167,16 +167,16 @@
/**
* @dataProvider invalidRequestProvider
*/
- public function testInvalidRequest( $itemHandle, $claimGuid, $snakType,
$value, $error ) {
+ public function testInvalidRequest( $itemHandle, $guid, $snakType,
$value, $error ) {
$itemId = new ItemId( EntityTestHelper::getId( $itemHandle ) );
$item =
WikibaseRepo::getDefaultInstance()->getEntityLookup()->getEntity( $itemId );
- if ( $claimGuid === null ) {
- $claims = $item->getClaims();
-
- /* @var Claim $claim */
- $claim = reset( $claims );
- $claimGuid = $claim->getGuid();
+ if ( $guid === null ) {
+ /** @var Item $item */
+ $statements = $item->getStatements()->toArray();
+ /** @var Statement $statement */
+ $statement = reset( $statements );
+ $guid = $statement->getGuid();
}
if ( !is_string( $value ) ) {
@@ -185,7 +185,7 @@
$params = array(
'action' => 'wbsetclaimvalue',
- 'claim' => $claimGuid,
+ 'claim' => $guid,
'snaktype' => $snakType,
'value' => $value,
);
diff --git a/repo/tests/phpunit/includes/api/SetQualifierTest.php
b/repo/tests/phpunit/includes/api/SetQualifierTest.php
index e5eb481..8dcfee9 100644
--- a/repo/tests/phpunit/includes/api/SetQualifierTest.php
+++ b/repo/tests/phpunit/includes/api/SetQualifierTest.php
@@ -204,18 +204,18 @@
/**
* @dataProvider invalidRequestProvider
*/
- public function testInvalidRequest( $itemHandle, $claimGuid,
$propertyHande, $snakType, $value, $error ) {
+ public function testInvalidRequest( $itemHandle, $guid, $propertyHande,
$snakType, $value, $error ) {
$itemId = new ItemId( EntityTestHelper::getId( $itemHandle ) );
$item =
WikibaseRepo::getDefaultInstance()->getEntityLookup()->getEntity( $itemId );
$propertyId = EntityTestHelper::getId( $propertyHande );
- if ( $claimGuid === null ) {
- $claims = $item->getClaims();
-
- /* @var Claim $claim */
- $claim = reset( $claims );
- $claimGuid = $claim->getGuid();
+ if ( $guid === null ) {
+ /** @var Item $item */
+ $statements = $item->getStatements()->toArray();
+ /** @var Statement $statement */
+ $statement = reset( $statements );
+ $guid = $statement->getGuid();
}
if ( !is_string( $value ) ) {
@@ -224,7 +224,7 @@
$params = array(
'action' => 'wbsetqualifier',
- 'claim' => $claimGuid,
+ 'claim' => $guid,
'property' => $propertyId,
'snaktype' => $snakType,
'value' => $value,
diff --git a/repo/tests/phpunit/includes/api/SetReferenceTest.php
b/repo/tests/phpunit/includes/api/SetReferenceTest.php
index 4613789..cc3c791 100644
--- a/repo/tests/phpunit/includes/api/SetReferenceTest.php
+++ b/repo/tests/phpunit/includes/api/SetReferenceTest.php
@@ -389,12 +389,11 @@
$item =
WikibaseRepo::getDefaultInstance()->getEntityLookup()->getEntity( $itemId );
if ( $guid === null ) {
- /* @var Item $item */
+ /** @var Item $item */
$statements = $item->getStatements()->toArray();
-
- /* @var Claim $claim */
- $claim = reset( $statements );
- $guid = $claim->getGuid();
+ /** @var Statement $statement */
+ $statement = reset( $statements );
+ $guid = $statement->getGuid();
}
$prop = new PropertyId( EntityTestHelper::getId( 'StringProp' )
);
diff --git a/view/tests/phpunit/ClaimHtmlGeneratorTest.php
b/view/tests/phpunit/ClaimHtmlGeneratorTest.php
index a7fccfb..2ed57b5 100644
--- a/view/tests/phpunit/ClaimHtmlGeneratorTest.php
+++ b/view/tests/phpunit/ClaimHtmlGeneratorTest.php
@@ -5,7 +5,6 @@
use DataValues\StringValue;
use Html;
use PHPUnit_Framework_TestCase;
-use Wikibase\DataModel\Claim\Claim;
use Wikibase\DataModel\Entity\EntityId;
use Wikibase\DataModel\Reference;
use Wikibase\DataModel\ReferenceList;
@@ -73,7 +72,7 @@
*/
public function testGetHtmlForClaim(
SnakHtmlGenerator $snakHtmlGenerator,
- Claim $claim,
+ Statement $statement,
$patterns
) {
$templateFactory = TemplateFactory::getDefaultInstance();
@@ -82,7 +81,7 @@
$snakHtmlGenerator
);
- $html = $claimHtmlGenerator->getHtmlForClaim( $claim, 'edit' );
+ $html = $claimHtmlGenerator->getHtmlForClaim( $statement,
'edit' );
foreach ( $patterns as $message => $pattern ) {
$this->assertRegExp( $pattern, $html, $message );
@@ -96,7 +95,7 @@
$testCases[] = array(
$snakHtmlGenerator,
- new Claim( new PropertySomeValueSnak( 42 ) ),
+ new Statement( new PropertySomeValueSnak( 42 ) ),
array(
'snak html' => '/SNAK HTML/',
)
@@ -104,7 +103,7 @@
$testCases[] = array(
$snakHtmlGenerator,
- new Claim(
+ new Statement(
new PropertySomeValueSnak( 42 ),
new SnakList( array(
new PropertyValueSnak( 50, new
StringValue( 'second snak' ) ),
diff --git a/view/tests/phpunit/StatementGroupListViewTest.php
b/view/tests/phpunit/StatementGroupListViewTest.php
index d7e10d8..f93f11d 100644
--- a/view/tests/phpunit/StatementGroupListViewTest.php
+++ b/view/tests/phpunit/StatementGroupListViewTest.php
@@ -142,8 +142,8 @@
$claimHtmlGenerator->expects( $this->any() )
->method( 'getHtmlForClaim' )
- ->will( $this->returnCallback( function( Claim $claim,
$editSectionHtml = null ) {
- return $claim->getGuid();
+ ->will( $this->returnCallback( function( Statement
$statement, $editSectionHtml = null ) {
+ return $statement->getGuid();
} ) );
return $claimHtmlGenerator;
--
To view, visit https://gerrit.wikimedia.org/r/231264
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I420b1cbcd05c161c8736994808898783562356ad
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits