Jeroen De Dauw has submitted this change and it was merged.
Change subject: Autosummary for setClaim
......................................................................
Autosummary for setClaim
- setClaim now uses the Summary class to build autosummaries
- UnitTests added for ClaimDifference & ClaimSummaryBuilder
- Selenium tests for autocomments in follow-up I457f42d
Bug: 45840
Bug: 45100
Change-Id: I6e90d80fc3d8d579f218a5d77906674e968d126c
---
M docs/summaries.txt
M lib/WikibaseLib.hooks.php
M lib/includes/ClaimDifference.php
A lib/tests/phpunit/ClaimDifferenceTest.php
M repo/Wikibase.hooks.php
M repo/Wikibase.i18n.php
M repo/Wikibase.php
M repo/includes/ClaimSaver.php
A repo/includes/ClaimSummaryBuilder.php
M repo/includes/api/SetClaim.php
A repo/tests/phpunit/includes/ClaimSummaryBuilderTest.php
11 files changed, 471 insertions(+), 11 deletions(-)
Approvals:
Jeroen De Dauw: Verified; Looks good to me, approved
jenkins-bot: Checked
diff --git a/docs/summaries.txt b/docs/summaries.txt
index 4f4b374..aad6402 100644
--- a/docs/summaries.txt
+++ b/docs/summaries.txt
@@ -35,6 +35,11 @@
/* wbcreateclaim-novalue: */ p123
/* wbcreateclaim-somevalue: */ p123
+/* wbsetclaim-update: */ p123
+/* wbsetclaim-create: */ p123
+/* wbsetclaim-update-qualifiers: */ p123 (claim)|p4 (qualifier)
+/* wbsetclaim-update-references: */ p123 (claim)|p4 (reference)
+/* wbsetclaim-update-rank: */ p123
The following summaries are not yet fully implemented and just included for
reference:
diff --git a/lib/WikibaseLib.hooks.php b/lib/WikibaseLib.hooks.php
index f04d7af..874188c 100644
--- a/lib/WikibaseLib.hooks.php
+++ b/lib/WikibaseLib.hooks.php
@@ -71,6 +71,7 @@
'ByPropertyIdArray',
'ChangesTable',
+ 'ClaimDifference',
'DataTypes',
'ReferencedEntitiesFinder',
'EntityRetrievingDataTypeLookup',
diff --git a/lib/includes/ClaimDifference.php b/lib/includes/ClaimDifference.php
index e0fb757..48e8a02 100644
--- a/lib/includes/ClaimDifference.php
+++ b/lib/includes/ClaimDifference.php
@@ -143,4 +143,31 @@
&& $this->getReferenceChanges() ==
$target->getReferenceChanges();
}
+ /**
+ * Checks whether the ClaimDifference is atomic, which means
+ * the Claim has only changed either its MainSnak, Qualifiers,
References or Rank
+ *
+ * @since 0.4
+ *
+ * @return boolean
+ */
+ public function isAtomic() {
+ $claimChanges = 0;
+
+ if ( $this->getMainSnakChange() !== null ) {
+ $claimChanges++;
+ }
+ if ( $this->getRankChange() !== null ) {
+ $claimChanges++;
+ }
+ if ( !$this->getQualifierChanges()->isEmpty() ) {
+ $claimChanges++;
+ }
+ if ( !$this->getReferenceChanges()->isEmpty() ) {
+ $claimChanges++;
+ }
+
+ return $claimChanges === 1;
+ }
+
}
diff --git a/lib/tests/phpunit/ClaimDifferenceTest.php
b/lib/tests/phpunit/ClaimDifferenceTest.php
new file mode 100644
index 0000000..4bd2fac
--- /dev/null
+++ b/lib/tests/phpunit/ClaimDifferenceTest.php
@@ -0,0 +1,94 @@
+<?php
+
+namespace Wikibase\Lib\Test;
+
+use Diff\Diff;
+use Diff\DiffOpChange;
+use Wikibase\ClaimDifference;
+
+/**
+ * Tests for the ClaimDifference class.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
USA
+ *
+ * @file
+ * @since 0.4
+ *
+ * @ingroup Wikibase
+ * @ingroup Test
+ *
+ * @group Wikibase
+ * @group WikibaseLib
+ *
+ * @licence GNU GPL v2+
+ * @author Tobias Gritschacher < [email protected] >
+ */
+class ClaimDifferenceTest extends \MediaWikiTestCase {
+
+ public function atomicClaimDifferenceProvider() {
+ $claimDifferenceObjects = array();
+ $changeOp = new DiffOpChange( "old", "new" );
+ $diff = new Diff( array ( $changeOp ) );
+
+ $claimDifferenceObjects[] = new ClaimDifference( $changeOp );
+ $claimDifferenceObjects[] = new ClaimDifference( null, $diff );
+ $claimDifferenceObjects[] = new ClaimDifference( null, null,
$diff );
+ $claimDifferenceObjects[] = new ClaimDifference( null, null,
null, $changeOp );
+
+ return $this->arrayWrap( $claimDifferenceObjects );
+ }
+
+ public function nonAtomicClaimDifferenceProvider() {
+ $claimDifferenceObjects = array();
+ $changeOp = new DiffOpChange( "old", "new" );
+ $diff = new Diff( array ( $changeOp ) );
+
+ $claimDifferenceObjects[] = new ClaimDifference();
+ $claimDifferenceObjects[] = new ClaimDifference( $changeOp,
$diff, null, null );
+ $claimDifferenceObjects[] = new ClaimDifference( $changeOp,
null, $diff, null );
+ $claimDifferenceObjects[] = new ClaimDifference( $changeOp,
null, null, $changeOp );
+ $claimDifferenceObjects[] = new ClaimDifference( $changeOp,
$diff, $diff, null );
+ $claimDifferenceObjects[] = new ClaimDifference( $changeOp,
$diff, null, $changeOp );
+ $claimDifferenceObjects[] = new ClaimDifference( $changeOp,
null, $diff, $changeOp );
+ $claimDifferenceObjects[] = new ClaimDifference( $changeOp,
$diff, $diff, $changeOp );
+ $claimDifferenceObjects[] = new ClaimDifference( null, null,
$diff, $changeOp );
+ $claimDifferenceObjects[] = new ClaimDifference( null, $diff,
null, $changeOp );
+ $claimDifferenceObjects[] = new ClaimDifference( null, $diff,
$diff, null );
+ $claimDifferenceObjects[] = new ClaimDifference( null, $diff,
$diff, $changeOp );
+ $claimDifferenceObjects[] = new ClaimDifference( null, new
Diff(), null, null );
+ $claimDifferenceObjects[] = new ClaimDifference( null, new
Diff(), null, null );
+
+ return $this->arrayWrap( $claimDifferenceObjects );
+ }
+
+ /**
+ * @dataProvider atomicClaimDifferenceProvider
+ *
+ * @param ClaimDifference $claimDifference
+ */
+ public function testIsAtomic( $claimDifference ) {
+ $this->assertTrue( $claimDifference->isAtomic(), "isAtomic
reports claimDifference as non-atomic, although it is" );
+ }
+
+ /**
+ * @dataProvider nonAtomicClaimDifferenceProvider
+ *
+ * @param ClaimDifference $claimDifference
+ */
+ public function testIsNotAtomic( $claimDifference ) {
+ $this->assertFalse( $claimDifference->isAtomic(), "isAtomic
reports claimDifference as atomic, although it is not" );
+ }
+
+}
diff --git a/repo/Wikibase.hooks.php b/repo/Wikibase.hooks.php
index 7b7138c..c21c2f5 100755
--- a/repo/Wikibase.hooks.php
+++ b/repo/Wikibase.hooks.php
@@ -150,6 +150,7 @@
// @codeCoverageIgnoreStart
$testFiles = array(
'Autocomment',
+ 'ClaimSummaryBuilder',
'EditEntity',
'ItemMove',
'ItemContentDiffView',
diff --git a/repo/Wikibase.i18n.php b/repo/Wikibase.i18n.php
index 8fdd47e..9ef8cc8 100644
--- a/repo/Wikibase.i18n.php
+++ b/repo/Wikibase.i18n.php
@@ -302,6 +302,11 @@
'wikibase-item-summary-special-create-item' => 'Created an [$2] item
with {{PLURAL:$1|value|values}}',
'wikibase-item-summary-wbcreateclaim-create' => 'Created claim',
'wikibase-item-summary-wbremoveclaims-remove' => 'Removed
{{PLURAL:$3|claim|claims}}',
+ 'wikibase-item-summary-wbsetclaim-update' => 'Changed
{{PLURAL:$3|claim|claims}}',
+ 'wikibase-item-summary-wbsetclaim-create' => 'Created
{{PLURAL:$3|claim|claims}}',
+ 'wikibase-item-summary-wbsetclaim-update-qualifiers' => 'Changed
{{PLURAL:$4|one|$4}} {{PLURAL:$4|qualifier|qualifiers}} of
{{PLURAL:$3|claim|claims}}',
+ 'wikibase-item-summary-wbsetclaim-update-references' => 'Changed
{{PLURAL:$4|one|$4}} {{PLURAL:$4|reference|references}} of
{{PLURAL:$3|claim|claims}}',
+ 'wikibase-item-summary-wbsetclaim-update-rank' => 'Changed rank of
{{PLURAL:$3|claim|claims}}',
// property - summary and autocomment, see docs/summaries.txt
'wikibase-property-summary-wbcreate-new' => 'Created a new property',
// legacy, backwards compatibility
@@ -914,6 +919,18 @@
'wikibase-item-summary-special-create-item' => '{{wikibase summary
messages|item|Automatic edit summary when creating an item, and supplying one
or more values. This page can take an additional sitelink, but this does not
reflect in the autocomment.}}',
'wikibase-item-summary-wbcreateclaim-create' => 'Automatic edit summary
generated when creating a new claim.',
'wikibase-item-summary-wbremoveclaims-remove' => 'Automatic edit
summary generated when removing claims.',
+ 'wikibase-item-summary-wbsetclaim-update' => 'Automatic edit summary
generated when modifying a claim using setclaim. Parameters:
+* $3 - number of claims changed',
+ 'wikibase-item-summary-wbsetclaim-create' => 'Automatic edit summary
generated when creating a new claim using setclaim. Parameters:
+* $3 - number of claims changed',
+ 'wikibase-item-summary-wbsetclaim-update-qualifiers' => 'Automatic edit
summary generated when modifying the qualifiers of a claim using setclaim.
Parameters:
+* $3 - number of claims changed
+* $4 - number of qualifiers changed',
+ 'wikibase-item-summary-wbsetclaim-update-references' => 'Automatic edit
summary generated when modifying the references of a claim using setclaim.
Parameters:
+* $3 - number of claims changed
+* $4 - number of references changed',
+ 'wikibase-item-summary-wbsetclaim-update-rank' => 'Automatic edit
summary generated when modifying the rank of a claim using setclaim. Parameters:
+* $3 - number of claims changed',
'wikibase-property-summary-wbcreate-new' => '{{wikibase summary
messages|item|Automatic edit summary generated when creating a new item. This
is for backwards compatibility for edits already made and in the database with
this message.}}',
'wikibase-property-summary-wbeditentity-create' => 'Automatic edit
summary generated when creating a new property.',
'wikibase-property-summary-wbeditentity-update' => 'Automatic edit
summary generated when updating an existing property.',
diff --git a/repo/Wikibase.php b/repo/Wikibase.php
index 98b50d1..47b9f7d 100644
--- a/repo/Wikibase.php
+++ b/repo/Wikibase.php
@@ -111,6 +111,7 @@
$wgAutoloadClasses['Wikibase\NamespaceUtils']
= $dir . 'includes/NamespaceUtils.php';
$wgAutoloadClasses['Wikibase\PropertyView']
= $dir . 'includes/PropertyView.php';
$wgAutoloadClasses['Wikibase\Summary']
= $dir . 'includes/Summary.php';
+$wgAutoloadClasses['Wikibase\ClaimSummaryBuilder']
= $dir . 'includes/ClaimSummaryBuilder.php';
$wgAutoloadClasses['Wikibase\Repo\WikibaseRepo']
= $dir . 'includes/WikibaseRepo.php';
// includes/actions
diff --git a/repo/includes/ClaimSaver.php b/repo/includes/ClaimSaver.php
index 15f9cd9..a3cabc4 100644
--- a/repo/includes/ClaimSaver.php
+++ b/repo/includes/ClaimSaver.php
@@ -6,6 +6,7 @@
use MWException;
use Status;
use ValueParsers\ParseException;
+use Wikibase\Claims;
use Wikibase\ExceptionWithCode;
use Wikibase\Repo\WikibaseRepo;
@@ -36,9 +37,9 @@
*
* @licence GNU GPL v2+
* @author Jeroen De Dauw < [email protected] >
+ * @author Tobias Gritschacher < [email protected] >
*/
class ClaimSaver {
-
/**
* @see ApiBase::execute
*
@@ -48,6 +49,7 @@
* @param int|null $baseRevId
* @param string $token
* @param User $user
+ * @param ClaimSummaryBuilder|null $claimSummaryBuilder
*
* @return Status The status. The status value is an array which may
contain
* the following fields:
@@ -58,15 +60,24 @@
*
* This status object can be used with
ApiWikibase::handleSaveStatus().
*/
- public function saveClaim( Claim $claim, $baseRevId, $token, User $user
) {
+ public function saveClaim( Claim $claim, $baseRevId, $token, User
$user, ClaimSummaryBuilder $claimSummaryBuilder = null ) {
try {
$entityId = $this->getEntityIdForClaim( $claim );
$content = $this->getEntityContent( $entityId,
$baseRevId );
+ $summary = null;
+
+ if ( $claimSummaryBuilder !== null ) {
+ $summary =
$claimSummaryBuilder->buildClaimSummary(
+ new Claims(
$content->getEntity()->getClaims() ),
+ $claim
+ );
+ }
+
$this->updateClaim( $content->getEntity(), $claim );
- $status = $this->saveChanges( $content, $baseRevId,
$token, $user );
+ $status = $this->saveChanges( $content, $baseRevId,
$token, $user, $summary );
} catch ( ExceptionWithCode $ex ) {
// put the error code into the status
$value = array( 'errorCode' => $ex->getErrorCode() );
@@ -116,16 +127,16 @@
*
* @param Entity $entity
* @param Claim $claim
+ *
*/
protected function updateClaim( Entity $entity, Claim $claim ) {
- $claims = new \Wikibase\Claims( $entity->getClaims() );
+ $claims = new Claims( $entity->getClaims() );
if ( $claims->hasClaimWithGuid( $claim->getGuid() ) ) {
$claims->removeClaimWithGuid( $claim->getGuid() );
}
$claims->addClaim( $claim );
-
$entity->setClaims( $claims );
}
@@ -167,15 +178,16 @@
* @param int|null $baseRevisionId
* @param string $token
* @param User $user
+ * @param Summary|null $summary
*
* @return Status
*/
- protected function saveChanges( EntityContent $content,
$baseRevisionId, $token, User $user ) {
+ protected function saveChanges( EntityContent $content,
$baseRevisionId, $token, User $user, Summary $summary ) {
$baseRevisionId = is_int( $baseRevisionId ) && $baseRevisionId
> 0 ? $baseRevisionId : false;
$editEntity = new \Wikibase\EditEntity( $content, $user,
$baseRevisionId );
$status = $editEntity->attemptSave(
- '', // TODO: automcomment
+ $summary !== null ? $summary->toString() : '',
EDIT_UPDATE,
$token
);
@@ -183,4 +195,4 @@
return $status;
}
-}
\ No newline at end of file
+}
diff --git a/repo/includes/ClaimSummaryBuilder.php
b/repo/includes/ClaimSummaryBuilder.php
new file mode 100644
index 0000000..d4a1f26
--- /dev/null
+++ b/repo/includes/ClaimSummaryBuilder.php
@@ -0,0 +1,130 @@
+<?php
+
+namespace Wikibase;
+
+/**
+ * EditSummary-Builder for claim operations
+ *
+ * @since 0.4
+ *
+ * @file
+ * @ingroup WikibaseRepo
+ *
+ * @licence GNU GPL v2+
+ * @author Tobias Gritschacher < [email protected] >
+ */
+class ClaimSummaryBuilder {
+ /**
+ * @var string
+ */
+ private $apiModuleName;
+
+ /**
+ * @var ClaimDiffer
+ */
+ private $claimDiffer;
+
+ /**
+ * Constructs a new ClaimSummaryBuilder
+ *
+ * @since 0.4
+ *
+ * @param string $apiModuleName
+ * @param ClaimDiffer $claimDiffer
+ *
+ */
+ public function __construct( $apiModuleName, ClaimDiffer $claimDiffer )
{
+ if ( !is_string( $apiModuleName ) ) {
+ throw new \MWException( "$apiModuleName needs to be a
string" );
+ }
+
+ $this->apiModuleName = $apiModuleName;
+ $this->claimDiffer = $claimDiffer;
+ }
+
+ /**
+ * Checks what has actually changed inside a claim by looking at a
ClaimDifference,
+ * constructs an edit-summary based upon that information and returns
+ * a Summary object holding this edit-summary
+ *
+ * @param Claims $existingClaims
+ * @param Claim $newClaim
+ *
+ * @return Summary $summary
+ */
+ public function buildClaimSummary( Claims $existingClaims, Claim
$newClaim ) {
+ $summary = new Summary( $this->apiModuleName );
+
+ $summary->addAutoCommentArgs( 1 ); // only one claim touched,
so we're always having singular here
+ $summaryArgs = $this->buildSummaryArgs(
+ new \Wikibase\Claims( array( $newClaim ) ),
+ array($newClaim->getGuid())
+ );
+ $summary->addAutoSummaryArgs( $summaryArgs );
+
+ if ( $existingClaims->hasClaimWithGuid( $newClaim->getGuid() )
) {
+ //claim is changed
+ $oldClaim = $existingClaims->getClaimWithGuid(
$newClaim->getGuid() );
+ $claimDifference = $this->claimDiffer->diffClaims(
$oldClaim, $newClaim );
+
+ if ( $claimDifference->isAtomic() ) {
+ if ( $claimDifference->getMainSnakChange() !==
null ) {
+ $summary->setAction( 'update' );
+ } elseif (
$claimDifference->getQualifierChanges()->isEmpty() === false ) {
+ $summary->addAutoCommentArgs(
$claimDifference->getQualifierChanges()->count() );
+ $summary->setAction(
'update-qualifiers' );
+ } elseif (
$claimDifference->getReferenceChanges()->isEmpty() === false ) {
+ $summary->addAutoCommentArgs(
$claimDifference->getReferenceChanges()->count() );
+ $summary->setAction(
'update-references' );
+ } elseif ( $claimDifference->getRankChange()
!== null ) {
+ $summary->setAction( 'update-rank' );
+ } else {
+ // something "else" has changed inside
the claim, so falling back to plain update message
+ $summary->setAction( 'update' );
+ }
+ } else {
+ // TODO: decide what to do if changes affect
multiple part of the claim
+ // e.g. concat several autocomments into one?
+ $summary->setAction( 'update' );
+ }
+ } else {
+ //new claim is added
+ $summary->setAction( 'create' );
+ }
+
+ return $summary;
+ }
+
+ /**
+ * Build key (property) => value pairs for summary arguments
+ *
+ * @param Claims $claims
+ * @param string[] $guids
+ *
+ * @return mixed[] // propertyId (prefixed) => array of values
+ */
+ protected function buildSummaryArgs( Claims $claims, array $guids ) {
+ $pairs = array();
+
+ foreach( $guids as $guid ) {
+ if ( $claims->hasClaimWithGuid( $guid ) ) {
+ $snak = $claims->getClaimWithGuid( $guid
)->getMainSnak();
+ $key = $snak->getPropertyId()->getPrefixedId();
+
+ if ( !array_key_exists( $key, $pairs ) ) {
+ $pairs[$key] = array();
+ }
+
+ if ( $snak instanceof PropertyValueSnak ) {
+ $value = $snak->getDataValue();
+ } else {
+ $value = '-'; // todo handle no values
in general way (needed elsewhere)
+ }
+
+ $pairs[$key][] = $value;
+ }
+ }
+
+ return ( array( $pairs ) );
+ }
+}
diff --git a/repo/includes/api/SetClaim.php b/repo/includes/api/SetClaim.php
index 7bfc5ec..69e3e3f 100644
--- a/repo/includes/api/SetClaim.php
+++ b/repo/includes/api/SetClaim.php
@@ -4,11 +4,14 @@
use MWException;
use ApiBase;
-
+use Diff\ListDiffer;
use Wikibase\EntityContent;
use Wikibase\Claim;
use Wikibase\EntityContentFactory;
+use Wikibase\ClaimDiffer;
use Wikibase\ClaimSaver;
+use Wikibase\ClaimSummaryBuilder;
+use Wikibase\Summary;
/**
* API module for creating or updating an entire Claim.
@@ -35,6 +38,7 @@
*
* @licence GNU GPL v2+
* @author Jeroen De Dauw < [email protected] >
+ * @author Tobias Gritschacher < [email protected] >
*/
class SetClaim extends ApiWikibase {
@@ -48,7 +52,9 @@
public function execute() {
$claim = $this->getClaimFromRequest();
- $claimSetter = new ClaimSaver();
+ $claimDiffer = new ClaimDiffer( new ListDiffer() );
+ $claimSummaryBuilder = new ClaimSummaryBuilder(
$this->getModuleName(), $claimDiffer );
+ $claimSaver = new ClaimSaver();
$params = $this->extractRequestParams();
$baseRevisionId = isset( $params['baserevid'] ) ? intval(
$params['baserevid'] ) : null;
@@ -56,7 +62,13 @@
$newRevisionId = null;
- $status = $claimSetter->saveClaim( $claim, $baseRevisionId,
$token, $this->getUser() );
+ $status = $claimSaver->saveClaim(
+ $claim,
+ $baseRevisionId,
+ $token,
+ $this->getUser(),
+ $claimSummaryBuilder
+ );
$this->handleSaveStatus( $status ); // die on error, report
warnings, etc
$statusValue = $status->getValue();
diff --git a/repo/tests/phpunit/includes/ClaimSummaryBuilderTest.php
b/repo/tests/phpunit/includes/ClaimSummaryBuilderTest.php
new file mode 100644
index 0000000..7dd4b3e
--- /dev/null
+++ b/repo/tests/phpunit/includes/ClaimSummaryBuilderTest.php
@@ -0,0 +1,160 @@
+<?php
+
+namespace Wikibase\Test;
+
+use Diff\ListDiffer;
+use Wikibase\ClaimDiffer;
+use Wikibase\Claim;
+use Wikibase\Claims;
+use Wikibase\ClaimSummaryBuilder;
+
+/**
+ * Tests for the ClaimSummaryBuilder class.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
USA
+ *
+ * @file
+ * @since 0.4
+ *
+ * @ingroup Wikibase
+ * @ingroup Test
+ *
+ * @group Wikibase
+ * @group WikibaseRepo
+ *
+ * @licence GNU GPL v2+
+ * @author Tobias Gritschacher < [email protected] >
+ */
+class ClaimSummaryBuilderTest extends \MediaWikiTestCase {
+
+ /**
+ * @return \Wikibase\Snak[]
+ */
+ protected function snakProvider() {
+ $snaks = array();
+
+ $snaks[] = new \Wikibase\PropertyNoValueSnak( 42 );
+ $snaks[] = new \Wikibase\PropertySomeValueSnak( 9001 );
+ $snaks[] = new \Wikibase\PropertyValueSnak( 7201010, new
\DataValues\StringValue( 'o_O' ) );
+
+ return $snaks;
+ }
+
+ /**
+ * @return Claim[]
+ */
+ protected function claimProvider() {
+ $statements = array();
+
+ $mainSnak = new \Wikibase\PropertyValueSnak( 112358, new
\DataValues\StringValue( "don't panic" ) );
+ $statement = new \Wikibase\Statement( $mainSnak );
+ $statements[] = $statement;
+
+ foreach ( $this->snakProvider() as $snak ) {
+ $statement = clone $statement;
+ $snaks = new \Wikibase\SnakList( array( $snak ) );
+ $statement->getReferences()->addReference( new
\Wikibase\Reference( $snaks ) );
+ $statements[] = $statement;
+ }
+
+ $statement = clone $statement;
+ $snaks = new \Wikibase\SnakList( $this->snakProvider() );
+ $statement->getReferences()->addReference( new
\Wikibase\Reference( $snaks ) );
+ $statements[] = $statement;
+
+ /**
+ * @var \Wikibase\Statement[] $statements
+ */
+ foreach ( $statements as &$statement ) {
+ $statement->setRank( \Wikibase\Statement::RANK_NORMAL );
+ }
+
+ return $statements;
+ }
+
+ public function buildUpdateClaimSummaryPovider() {
+ $arguments = array();
+
+ foreach ( $this->claimProvider() as $claim ) {
+ $testCaseArgs = array();
+
+ //change mainsnak
+ $modifiedClaim = clone $claim;
+ $modifiedClaim->setMainSnak( new
\Wikibase\PropertyValueSnak( 112358, new \DataValues\StringValue( "let's
panic!!!" ) ) );
+ $testCaseArgs[] = $claim;
+ $testCaseArgs[] = $modifiedClaim;
+ $testCaseArgs[] = 'update';
+ $arguments[] = $testCaseArgs;
+
+ //change qualifiers
+ $modifiedClaim = clone $claim;
+ $modifiedClaim->setQualifiers( new \Wikibase\SnakList(
$this->snakProvider() ) );
+ $testCaseArgs[] = $claim;
+ $testCaseArgs[] = $modifiedClaim;
+ $testCaseArgs[] = 'update-qualifiers';
+ $arguments[] = $testCaseArgs;
+
+ //change rank
+ $modifiedClaim = clone $claim;
+ $modifiedClaim->setRank(
\Wikibase\Statement::RANK_PREFERRED );
+ $testCaseArgs[] = $claim;
+ $testCaseArgs[] = $modifiedClaim;
+ $testCaseArgs[] = 'update-rank';
+ $arguments[] = $testCaseArgs;
+
+ //change mainsnak & qualifiers
+ $modifiedClaim = clone $claim;
+ $modifiedClaim->setMainSnak( new
\Wikibase\PropertyValueSnak( 112358, new \DataValues\StringValue( "let's
panic!!!" ) ) );
+ $modifiedClaim->setQualifiers( new \Wikibase\SnakList(
$this->snakProvider() ) );
+ $testCaseArgs[] = $claim;
+ $testCaseArgs[] = $modifiedClaim;
+ $testCaseArgs[] = 'update-rank';
+ $arguments[] = $testCaseArgs;
+ }
+
+ return $arguments;
+ }
+
+ public function testBuildCreateClaimSummary() {
+ $claimSummaryBuilder = new ClaimSummaryBuilder( 'wbsetclaim',
new ClaimDiffer( new ListDiffer() ) );
+ $claims = new Claims();
+ $newClaims = $this->claimProvider();
+
+ foreach ( $newClaims as $newClaim ) {
+ $summary = $claimSummaryBuilder->buildClaimSummary(
$claims, $newClaim );
+ $this->assertInstanceOf( 'Wikibase\Summary', $summary,
"this should return a Summary object" );
+ $this->assertEquals( 'wbsetclaim',
$summary->getModuleName() );
+ $this->assertEquals( 'create',
$summary->getActionName() );
+ }
+ }
+
+ /**
+ * @dataProvider buildUpdateClaimSummaryPovider
+ *
+ * @param Claim $originalClaim
+ * @param Claim $modifiedClaim
+ * @param string $action
+ */
+ public function testBuildUpdateClaimSummary( $originalClaim,
$modifiedClaim, $action ) {
+ $claimSummaryBuilder = new ClaimSummaryBuilder( 'wbsetclaim',
new ClaimDiffer( new ListDiffer() ) );
+ $claims = new Claims();
+ $claims->addClaim( $originalClaim );
+
+ $summary = $claimSummaryBuilder->buildClaimSummary( $claims,
$modifiedClaim );
+ $this->assertInstanceOf( 'Wikibase\Summary', $summary, "this
should return a Summary object" );
+ $this->assertEquals( 'wbsetclaim', $summary->getModuleName() );
+ $this->assertEquals( $action, $summary->getActionName() );
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/58880
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I6e90d80fc3d8d579f218a5d77906674e968d126c
Gerrit-PatchSet: 18
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: John Erling Blad <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits