Addshore has uploaded a new change for review. https://gerrit.wikimedia.org/r/209992
Change subject: Merge EditFilterHookStatus into EditEntity Status ...................................................................... Merge EditFilterHookStatus into EditEntity Status This call to merge was removed in: Gerrit: I242567615f56fb834901f491961b3d144a0ed10f Hash: fcaa45993a3e172baa3e90294fb64339da8f0182 Tests has now also been added Bug:T98669 Change-Id: I1fd790dd028e0459c28bdcabe8812387c449ee8f --- M repo/includes/EditEntity.php M repo/tests/phpunit/includes/EditEntityTest.php 2 files changed, 53 insertions(+), 5 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/92/209992/1 diff --git a/repo/includes/EditEntity.php b/repo/includes/EditEntity.php index 74a57a2..e1e7c1d 100644 --- a/repo/includes/EditEntity.php +++ b/repo/includes/EditEntity.php @@ -627,6 +627,7 @@ if ( !$hookStatus->isOK() ) { $this->errorType |= self::FILTERED; } + $this->status->merge( $hookStatus ); if ( !$this->status->isOK() ) { $this->status->setResult( false, array( 'errorFlags' => $this->errorType ) ); diff --git a/repo/tests/phpunit/includes/EditEntityTest.php b/repo/tests/phpunit/includes/EditEntityTest.php index 06f3010..7ea0adf 100644 --- a/repo/tests/phpunit/includes/EditEntityTest.php +++ b/repo/tests/phpunit/includes/EditEntityTest.php @@ -5,6 +5,7 @@ use FauxRequest; use HashBagOStuff; use IContextSource; +use PHPUnit_Framework_MockObject_Matcher_Invocation; use ReflectionMethod; use RequestContext; use Status; @@ -18,6 +19,7 @@ use Wikibase\EditEntity; use Wikibase\Lib\Store\EntityRevisionLookup; use Wikibase\Lib\Store\EntityTitleLookup; +use Wikibase\Repo\Hooks\EditFilterHookRunner; use Wikibase\Repo\Store\EntityPermissionChecker; use Wikibase\Repo\WikibaseRepo; @@ -101,14 +103,23 @@ return $permissionChecker; } - private function getMockEditFitlerHookRunner () { + private function getMockEditFitlerHookRunner ( + Status $status = null, + PHPUnit_Framework_MockObject_Matcher_Invocation $expects = null + ) { + if( is_null( $status ) ) { + $status = Status::newGood(); + } + if( is_null( $expects ) ) { + $expects = $this->any(); + } $runner = $this->getMockBuilder( 'Wikibase\Repo\Hooks\EditFilterHookRunner' ) ->setMethods( array( 'run' ) ) ->disableOriginalConstructor() ->getMock(); - $runner->expects( $this->any() ) + $runner->expects( $expects ) ->method( 'run' ) - ->will( $this->returnValue( Status::newGood() ) ); + ->will( $this->returnValue( $status ) ); return $runner; } @@ -118,6 +129,7 @@ * @param EntityTitleLookup $titleLookup * @param User|null $user * @param bool $baseRevId + * @param EditFilterHookRunner $editFilterHookRunner * * @param null|array $permissions map of actions to bool, indicating which actions are allowed. * @@ -129,13 +141,17 @@ EntityTitleLookup $titleLookup, User $user = null, $baseRevId = false, - $permissions = null + $permissions = null, + $editFilterHookRunner = null ) { $context = new RequestContext(); $context->setRequest( new FauxRequest() ); if ( $user === null ) { $user = User::newFromName( 'EditEntityTestUser' ); + } + if( $editFilterHookRunner === null ) { + $editFilterHookRunner = $this->getMockEditFitlerHookRunner(); } $permissionChecker = $this->getEntityPermissionChecker( $permissions ); @@ -147,7 +163,7 @@ $permissionChecker, $entity, $user, - $this->getMockEditFitlerHookRunner(), + $editFilterHookRunner, $baseRevId, $context ); @@ -772,4 +788,35 @@ $edit = $this->makeEditEntity( $repo, $item, $titleLookup ); $this->assertFalse( $isNew->invoke( $edit ), "Entity exists" ); } + + public function provideHookRunnerReturnStatus() { + return array( + array( Status::newGood() ), + array( Status::newFatal( 'OMG' ) ), + ); + } + + /** + * @dataProvider provideHookRunnerReturnStatus + */ + public function testEditFilterHookRunnerInteraction( Status $hookReturnStatus ) { + $edit = $this->makeEditEntity( + $this->getMockRepository(), + new Item(), + $this->getEntityTitleLookup(), + null, + false, + null, + $this->getMockEditFitlerHookRunner( $hookReturnStatus, $this->once() ) + ); + $user = $this->getUser( 'EditEntityTestUser' ); + + $saveStatus = $edit->attemptSave( + 'some Summary', + EDIT_MINOR, + $user->getEditToken() + ); + + $this->assertEquals( $hookReturnStatus->isGood(), $saveStatus->isGood() ); + } } -- To view, visit https://gerrit.wikimedia.org/r/209992 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1fd790dd028e0459c28bdcabe8812387c449ee8f Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Addshore <addshorew...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits