jenkins-bot has submitted this change and it was merged. Change subject: Inject entity id formatter into ClaimSummaryBuilder ......................................................................
Inject entity id formatter into ClaimSummaryBuilder Change-Id: I5796574cfe8e247bf5220a3bc71884f4bb2041c2 --- M repo/includes/ClaimSummaryBuilder.php M repo/includes/api/SetClaim.php M repo/tests/phpunit/includes/ClaimSummaryBuilderTest.php 3 files changed, 48 insertions(+), 7 deletions(-) Approvals: Tobias Gritschacher: Looks good to me, approved jenkins-bot: Verified diff --git a/repo/includes/ClaimSummaryBuilder.php b/repo/includes/ClaimSummaryBuilder.php index d4a1f26..50057d7 100644 --- a/repo/includes/ClaimSummaryBuilder.php +++ b/repo/includes/ClaimSummaryBuilder.php @@ -2,6 +2,9 @@ namespace Wikibase; +use InvalidArgumentException; +use Wikibase\Lib\EntityIdFormatter; + /** * EditSummary-Builder for claim operations * @@ -14,6 +17,7 @@ * @author Tobias Gritschacher < [email protected] > */ class ClaimSummaryBuilder { + /** * @var string */ @@ -25,21 +29,29 @@ private $claimDiffer; /** + * @var EntityIdFormatter + */ + private $idFormatter; + + /** * Constructs a new ClaimSummaryBuilder * * @since 0.4 * * @param string $apiModuleName * @param ClaimDiffer $claimDiffer + * @param EntityIdFormatter $idFormatter * + * @throws InvalidArgumentException */ - public function __construct( $apiModuleName, ClaimDiffer $claimDiffer ) { + public function __construct( $apiModuleName, ClaimDiffer $claimDiffer, EntityIdFormatter $idFormatter ) { if ( !is_string( $apiModuleName ) ) { - throw new \MWException( "$apiModuleName needs to be a string" ); + throw new InvalidArgumentException( '$apiModuleName needs to be a string' ); } $this->apiModuleName = $apiModuleName; $this->claimDiffer = $claimDiffer; + $this->idFormatter = $idFormatter; } /** @@ -57,7 +69,7 @@ $summary->addAutoCommentArgs( 1 ); // only one claim touched, so we're always having singular here $summaryArgs = $this->buildSummaryArgs( - new \Wikibase\Claims( array( $newClaim ) ), + new Claims( array( $newClaim ) ), array($newClaim->getGuid()) ); $summary->addAutoSummaryArgs( $summaryArgs ); @@ -109,7 +121,7 @@ foreach( $guids as $guid ) { if ( $claims->hasClaimWithGuid( $guid ) ) { $snak = $claims->getClaimWithGuid( $guid )->getMainSnak(); - $key = $snak->getPropertyId()->getPrefixedId(); + $key = $this->idFormatter->format( $snak->getPropertyId() ); if ( !array_key_exists( $key, $pairs ) ) { $pairs[$key] = array(); diff --git a/repo/includes/api/SetClaim.php b/repo/includes/api/SetClaim.php index 69e3e3f..1bfc8e2 100644 --- a/repo/includes/api/SetClaim.php +++ b/repo/includes/api/SetClaim.php @@ -11,6 +11,7 @@ use Wikibase\ClaimDiffer; use Wikibase\ClaimSaver; use Wikibase\ClaimSummaryBuilder; +use Wikibase\Repo\WikibaseRepo; use Wikibase\Summary; /** @@ -53,7 +54,11 @@ $claim = $this->getClaimFromRequest(); $claimDiffer = new ClaimDiffer( new ListDiffer() ); - $claimSummaryBuilder = new ClaimSummaryBuilder( $this->getModuleName(), $claimDiffer ); + $claimSummaryBuilder = new ClaimSummaryBuilder( + $this->getModuleName(), + $claimDiffer, + WikibaseRepo::newInstance()->getIdFormatter() + ); $claimSaver = new ClaimSaver(); $params = $this->extractRequestParams(); diff --git a/repo/tests/phpunit/includes/ClaimSummaryBuilderTest.php b/repo/tests/phpunit/includes/ClaimSummaryBuilderTest.php index 0161515..6a3e1d9 100644 --- a/repo/tests/phpunit/includes/ClaimSummaryBuilderTest.php +++ b/repo/tests/phpunit/includes/ClaimSummaryBuilderTest.php @@ -7,6 +7,8 @@ use Wikibase\Claim; use Wikibase\Claims; use Wikibase\ClaimSummaryBuilder; +use Wikibase\Lib\EntityIdFormatter; +use Wikibase\Repo\WikibaseRepo; /** * Tests for the ClaimSummaryBuilder class. @@ -129,7 +131,18 @@ } public function testBuildCreateClaimSummary() { - $claimSummaryBuilder = new ClaimSummaryBuilder( 'wbsetclaim', new ClaimDiffer( new ListDiffer() ) ); + $idFormatter = $this->getMockBuilder( 'Wikibase\Lib\EntityIdFormatter' ) + ->disableOriginalConstructor()->getMock(); + $idFormatter->expects( $this->any() ) + ->method( 'format' ) + ->will( $this->returnValue( 'foo' ) ); + + $claimSummaryBuilder = new ClaimSummaryBuilder( + 'wbsetclaim', + new ClaimDiffer( new ListDiffer() ), + $idFormatter + ); + $claims = new Claims(); $newClaims = $this->claimProvider(); @@ -149,7 +162,18 @@ * @param string $action */ public function testBuildUpdateClaimSummary( $originalClaim, $modifiedClaim, $action ) { - $claimSummaryBuilder = new ClaimSummaryBuilder( 'wbsetclaim', new ClaimDiffer( new ListDiffer() ) ); + $idFormatter = $this->getMockBuilder( 'Wikibase\Lib\EntityIdFormatter' ) + ->disableOriginalConstructor()->getMock(); + $idFormatter->expects( $this->any() ) + ->method( 'format' ) + ->will( $this->returnValue( 'foo' ) ); + + $claimSummaryBuilder = new ClaimSummaryBuilder( + 'wbsetclaim', + new ClaimDiffer( new ListDiffer() ), + $idFormatter + ); + $claims = new Claims(); $claims->addClaim( $originalClaim ); -- To view, visit https://gerrit.wikimedia.org/r/64489 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I5796574cfe8e247bf5220a3bc71884f4bb2041c2 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Jeroen De Dauw <[email protected]> Gerrit-Reviewer: Anja Jentzsch <[email protected]> Gerrit-Reviewer: Ataherivand <[email protected]> Gerrit-Reviewer: Aude <[email protected]> Gerrit-Reviewer: Daniel Kinzler <[email protected]> Gerrit-Reviewer: Daniel Werner <[email protected]> Gerrit-Reviewer: Denny Vrandecic <[email protected]> Gerrit-Reviewer: Henning Snater <[email protected]> Gerrit-Reviewer: Jens Ohlig <[email protected]> Gerrit-Reviewer: Jeroen De Dauw <[email protected]> Gerrit-Reviewer: John Erling Blad <[email protected]> Gerrit-Reviewer: Lydia Pintscher <[email protected]> Gerrit-Reviewer: Markus Kroetzsch <[email protected]> Gerrit-Reviewer: Nikola Smolenski <[email protected]> Gerrit-Reviewer: Silke Meyer <[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
