jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/391577 )

Change subject: Action override callbacks must still accept WikiPage for now.
......................................................................


Action override callbacks must still accept WikiPage for now.

Bug: T180605
Change-Id: I81516b66a0831d0d89ab7b0cbe8d6b01e185e543
---
M repo/includes/Actions/HistoryEntityAction.php
M repo/includes/Content/ItemHandler.php
M repo/includes/Content/PropertyHandler.php
M repo/tests/phpunit/includes/Content/EntityHandlerTest.php
4 files changed, 89 insertions(+), 15 deletions(-)

Approvals:
  WMDE-leszek: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/repo/includes/Actions/HistoryEntityAction.php 
b/repo/includes/Actions/HistoryEntityAction.php
index 770582f..ebf012f 100644
--- a/repo/includes/Actions/HistoryEntityAction.php
+++ b/repo/includes/Actions/HistoryEntityAction.php
@@ -28,18 +28,18 @@
        private $labelLookup;
 
        /**
-        * @param Article $page
+        * @param Article $article
         * @param IContextSource|null $context
         * @param EntityIdLookup $entityIdLookup
         * @param LabelDescriptionLookup $labelLookup
         */
        public function __construct(
-               Article $page,
+               Article $article,
                IContextSource $context = null,
                EntityIdLookup $entityIdLookup,
                LabelDescriptionLookup $labelLookup
        ) {
-               parent::__construct( $page, $context );
+               parent::__construct( $article, $context );
 
                $this->entityIdLookup = $entityIdLookup;
                $this->labelLookup = $labelLookup;
diff --git a/repo/includes/Content/ItemHandler.php 
b/repo/includes/Content/ItemHandler.php
index b55eb9b..10a800c 100644
--- a/repo/includes/Content/ItemHandler.php
+++ b/repo/includes/Content/ItemHandler.php
@@ -2,6 +2,7 @@
 
 namespace Wikibase\Repo\Content;
 
+use Article;
 use DataUpdate;
 use IContextSource;
 use Page;
@@ -109,7 +110,13 @@
         */
        public function getActionOverrides() {
                return [
-                       'history' => function( Page $page, IContextSource 
$context = null ) {
+                       'history' => function( Page $page, IContextSource 
$context ) {
+                               // NOTE: for now, the callback must work with a 
WikiPage as well as an Article
+                               // object. Once I0335100b2 is merged, this is 
no longer needed.
+                               if ( !( $page instanceof Article ) ) {
+                                       $page = Article::newFromWikiPage( 
$page, $context );
+                               }
+
                                return new HistoryEntityAction(
                                        $page,
                                        $context,
diff --git a/repo/includes/Content/PropertyHandler.php 
b/repo/includes/Content/PropertyHandler.php
index 2cc9b5a..e201c0e 100644
--- a/repo/includes/Content/PropertyHandler.php
+++ b/repo/includes/Content/PropertyHandler.php
@@ -2,6 +2,7 @@
 
 namespace Wikibase\Repo\Content;
 
+use Article;
 use DataUpdate;
 use IContextSource;
 use Page;
@@ -104,7 +105,13 @@
         */
        public function getActionOverrides() {
                return [
-                       'history' => function( Page $page, IContextSource 
$context = null ) {
+                       'history' => function( Page $page, IContextSource 
$context ) {
+                               // NOTE: for now, the callback must work with a 
WikiPage as well as an Article
+                               // object. Once I0335100b2 is merged, this is 
no longer needed.
+                               if ( !( $page instanceof Article ) ) {
+                                       $page = Article::newFromWikiPage( 
$page, $context );
+                               }
+
                                return new HistoryEntityAction(
                                        $page,
                                        $context,
diff --git a/repo/tests/phpunit/includes/Content/EntityHandlerTest.php 
b/repo/tests/phpunit/includes/Content/EntityHandlerTest.php
index 0d2c12e..60ccd2f 100644
--- a/repo/tests/phpunit/includes/Content/EntityHandlerTest.php
+++ b/repo/tests/phpunit/includes/Content/EntityHandlerTest.php
@@ -2,6 +2,8 @@
 
 namespace Wikibase\Repo\Tests\Content;
 
+use Action;
+use Article;
 use ContentHandler;
 use DataValues\Serializers\DataValueSerializer;
 use DummySearchIndexFieldDefinition;
@@ -10,6 +12,7 @@
 use Language;
 use LogicException;
 use MWException;
+use PHPUnit_Framework_MockObject_MockObject;
 use RequestContext;
 use Revision;
 use RuntimeException;
@@ -69,7 +72,7 @@
                );
        }
 
-       private function getEntityTypeDefinitions() {
+       protected function getEntityTypeDefinitions() {
                return new EntityTypeDefinitions(
                        array_merge_recursive(
                                require __DIR__ . 
'/../../../../../lib/WikibaseLib.entitytypes.php',
@@ -493,15 +496,25 @@
                $this->assertRegExp( '/wb\d+/', $hash, 'contains Wikibase 
version' );
        }
 
+       /**
+        * @param Title $title
+        * @return RequestContext
+        * @throws MWException
+        */
+       protected function getContext( Title $title ) {
+               $context = new RequestContext( new FauxRequest() );
+               $context->setLanguage( 'qqx' );
+               $context->setTitle( $title );
+
+               return $context;
+       }
+
        public function testShowMissingEntity() {
                $handler = $this->getHandler();
 
                $title = Title::makeTitle( $handler->getEntityNamespace(), 
'MISSING' );
 
-               $context = new RequestContext( new FauxRequest() );
-               $context->setLanguage( 'qqx' );
-               $context->setTitle( $title );
-
+               $context = $this->getContext( $title );
                $handler->showMissingEntity( $title, $context );
 
                $this->assertContains( '(wikibase-noentity)', 
$context->getOutput()->getHTML() );
@@ -554,15 +567,28 @@
 
        abstract protected function getTestItemContent();
 
+       /**
+        * @param EntityHandler $handler
+        * @return PHPUnit_Framework_MockObject_MockObject|WikiPage
+        */
+       protected function getMockWikiPage( EntityHandler $handler ) {
+               $title = Title::makeTitle( $handler->getEntityNamespace(), 
"Asdflogjkasdefgo" );
+
+               $page = $this->getMockBuilder( WikiPage::class )
+                       ->setConstructorArgs( [ Title::newFromText( 'Q1' ) ] )
+                       ->getMock();
+
+               $page->method( 'getContent' )->willReturn( 
$this->getTestItemContent() );
+               $page->method( 'getTitle' )->willReturn( $title );
+
+               return $page;
+       }
+
        public function testDataForSearchIndex() {
                $handler = $this->getHandler();
                $engine = $this->getMock( \SearchEngine::class );
 
-               $page =
-                       $this->getMockBuilder( WikiPage::class )
-                               ->setConstructorArgs( [ Title::newFromText( 
'Q1' ) ] )
-                               ->getMock();
-               $page->method( 'getContent' )->willReturn( 
$this->getTestItemContent() );
+               $page = $this->getMockWikiPage( $handler );
 
                $data = $handler->getDataForSearchIndex( $page, new 
\ParserOutput(), $engine );
                $this->assertSame( 1, $data['label_count'], 'label_count' );
@@ -572,4 +598,38 @@
                $this->assertSame( 1, $data['statement_count'], 
'statement_count' );
        }
 
+       public function testGetActionOverrides() {
+               $handler = $this->getHandler();
+               $overrides = $handler->getActionOverrides();
+
+               foreach ( $overrides as $name => $classOrCallback ) {
+                       if ( is_string( $classOrCallback ) ) {
+                               $this->assertTrue(
+                                       is_subclass_of( $classOrCallback, 
Action::class ),
+                                       'Override for ' . $name . ' must be an 
action class, found ' . $classOrCallback
+                               );
+                       } elseif ( is_callable( $classOrCallback ) ) {
+                               // NOTE: for now, the callback must work with a 
WikiPage as well as an Article
+                               // object. Once I0335100b2 is merged, this is 
no longer needed.
+                               $wikiPage = $this->getMockWikiPage( $handler );
+                               $context = $this->getContext( 
$wikiPage->getTitle() );
+
+                               $action = $classOrCallback( $wikiPage, $context 
);
+                               $this->assertTrue(
+                                       is_subclass_of( $action, Action::class 
),
+                                       'Callback for action ' . $name . ' must 
return an Action instance!'
+                               );
+
+                               $article = Article::newFromWikiPage( $wikiPage, 
$context );
+                               $action = $classOrCallback( $article, $context 
);
+                               $this->assertTrue(
+                                       is_subclass_of( $action, Action::class 
),
+                                       'Callback for action ' . $name . ' must 
return an Action instance!'
+                               );
+                       } else {
+                               $this->fail( 'Expected a class name or callback 
as action override for ' . $name );
+                       }
+               }
+       }
+
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I81516b66a0831d0d89ab7b0cbe8d6b01e185e543
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Lucas Werkmeister (WMDE) <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: WMDE-leszek <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to