Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/367706 )

Change subject: Make ChangeOps to set generic summary message if several 
changeOps given
......................................................................

Make ChangeOps to set generic summary message if several changeOps given

Change-Id: I8f73a0c292b3d7ecefb8d1cb7eab74d09366f4bd
---
M repo/includes/ChangeOp/ChangeOps.php
M repo/tests/phpunit/includes/ChangeOp/ChangeOpsTest.php
2 files changed, 69 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/06/367706/1

diff --git a/repo/includes/ChangeOp/ChangeOps.php 
b/repo/includes/ChangeOp/ChangeOps.php
index 120d34a..8cbd8ed 100644
--- a/repo/includes/ChangeOp/ChangeOps.php
+++ b/repo/includes/ChangeOp/ChangeOps.php
@@ -71,8 +71,17 @@
         * @throws ChangeOpException
         */
        public function apply( EntityDocument $entity, Summary $summary = null 
) {
-               foreach ( $this->changeOps as $changeOp ) {
-                       $changeOp->apply( $entity, $summary );
+               if ( count( $this->changeOps ) === 1 ) {
+                       current( $this->changeOps )->apply( $entity, $summary );
+               } elseif ( count( $this->changeOps ) === 0 ) {
+                       return;
+               } else {
+                       foreach ( $this->changeOps as $changeOp ) {
+                               $changeOp->apply( $entity, null );
+                       }
+                       if ( $summary ) {
+                               $summary->setAction( 'update' );
+                       }
                }
        }
 
diff --git a/repo/tests/phpunit/includes/ChangeOp/ChangeOpsTest.php 
b/repo/tests/phpunit/includes/ChangeOp/ChangeOpsTest.php
index 9996693..ec26946 100644
--- a/repo/tests/phpunit/includes/ChangeOp/ChangeOpsTest.php
+++ b/repo/tests/phpunit/includes/ChangeOp/ChangeOpsTest.php
@@ -4,8 +4,10 @@
 
 use DataValues\StringValue;
 use InvalidArgumentException;
+use Prophecy\Argument;
 use ValueValidators\Error;
 use ValueValidators\Result;
+use Wikibase\DataModel\Entity\EntityDocument;
 use Wikibase\Repo\ChangeOp\ChangeOp;
 use Wikibase\Repo\ChangeOp\ChangeOpDescription;
 use Wikibase\Repo\ChangeOp\ChangeOpLabel;
@@ -16,7 +18,9 @@
 use Wikibase\DataModel\Services\Statement\GuidGenerator;
 use Wikibase\DataModel\Snak\PropertyValueSnak;
 use Wikibase\Repo\Store\EntityPermissionChecker;
+use Wikibase\Repo\Tests\NewItem;
 use Wikibase\Repo\Validators\SnakValidator;
+use Wikibase\Summary;
 
 /**
  * @covers Wikibase\Repo\ChangeOp\ChangeOps
@@ -198,4 +202,58 @@
                $this->assertContains( EntityPermissionChecker::ACTION_EDIT, 
$actions );
        }
 
+       public function testApply_HasTwoChangeOps_DoesNotPassSummaryObject() {
+               $changeOp1 = $this->prophesize( ChangeOp::class );
+               $changeOp2 = $this->prophesize( ChangeOp::class );
+
+               $changeOps = new ChangeOps( [ $changeOp1->reveal(), 
$changeOp2->reveal() ] );
+               $changeOps->apply(
+                       $this->prophesize( EntityDocument::class )->reveal(),
+                       $this->prophesize( Summary::class )->reveal()
+               );
+
+               $changeOp1->apply( Argument::any(), null 
)->shouldHaveBeenCalled();
+               $changeOp2->apply( Argument::any(), null 
)->shouldHaveBeenCalled();
+       }
+
+       public function testApply_HasOneChangeOp_PassesSummaryObject() {
+               $changeOp = $this->prophesize( ChangeOp::class );
+
+               $changeOps = new ChangeOps( [ $changeOp->reveal() ] );
+               $changeOps->apply(
+                       $this->prophesize( EntityDocument::class )->reveal(),
+                       $this->prophesize( Summary::class )->reveal()
+               );
+
+               $changeOp->apply( Argument::any(), Argument::type( 
Summary::class ) )
+                       ->shouldHaveBeenCalled();
+       }
+
+       public function testApply_HasTwoChangeOps_SetsGenericSummaryMessage() {
+               $changeOps = new ChangeOps( [
+                       $this->prophesize( ChangeOp::class )->reveal(),
+                       $this->prophesize( ChangeOp::class )->reveal()
+               ] );
+
+               $summary = $this->prophesize( Summary::class );
+               $changeOps->apply(
+                       $this->prophesize( EntityDocument::class )->reveal(),
+                       $summary->reveal()
+               );
+
+               $summary->setAction( 'update' )->shouldHaveBeenCalled();
+       }
+
+       public function testApply_HasZeroChangeOps_DoesNotUpdateSummaryAction() 
{
+               $changeOps = new ChangeOps( [] );
+
+               $summary = $this->prophesize( Summary::class );
+               $changeOps->apply(
+                       $this->prophesize( EntityDocument::class )->reveal(),
+                       $summary->reveal()
+               );
+
+               $summary->setAction( Argument::any() 
)->shouldNotHaveBeenCalled();
+       }
+
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/367706
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8f73a0c292b3d7ecefb8d1cb7eab74d09366f4bd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to