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

Change subject: Allow EntityHandlerTest to be used with Lexemes, etc.
......................................................................


Allow EntityHandlerTest to be used with Lexemes, etc.

This is needed to allow EntityHandlerTest to be used as a base class
for the respective tests for Lexeme and MediaInfo. Which in turn
is needed to make sure we are consistently asserting the contract
of EntityHandler.

Using a base class for this isn't great, a trait would be better. That
change is left for later.

Change-Id: I487a4fcc62aa2ad9a4aeebab4d871583bbe876b8
---
M repo/tests/phpunit/includes/Content/EntityHandlerTest.php
M repo/tests/phpunit/includes/Content/ItemHandlerTest.php
M repo/tests/phpunit/includes/Content/PropertyHandlerTest.php
3 files changed, 50 insertions(+), 26 deletions(-)

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



diff --git a/repo/tests/phpunit/includes/Content/EntityHandlerTest.php 
b/repo/tests/phpunit/includes/Content/EntityHandlerTest.php
index 60ccd2f..95d6751 100644
--- a/repo/tests/phpunit/includes/Content/EntityHandlerTest.php
+++ b/repo/tests/phpunit/includes/Content/EntityHandlerTest.php
@@ -17,6 +17,7 @@
 use Revision;
 use RuntimeException;
 use SearchEngine;
+use Serializers\Serializer;
 use Title;
 use Wikibase\Content\EntityInstanceHolder;
 use Wikibase\DataModel\Entity\EntityDocument;
@@ -29,7 +30,6 @@
 use Wikibase\Lib\EntityTypeDefinitions;
 use Wikibase\Lib\RepositoryDefinitions;
 use Wikibase\Repo\Content\EntityHandler;
-use Wikibase\Repo\Content\ItemHandler;
 use Wikibase\Repo\Validators\EntityValidator;
 use Wikibase\Repo\Validators\ValidatorErrorLocalizer;
 use Wikibase\Repo\WikibaseRepo;
@@ -130,7 +130,7 @@
        abstract protected function newEntity( EntityId $id = null );
 
        /**
-        * Returns EntityContents that can be handled by the EntityHandler 
deriving class.
+        * Returns EntityContents that can be serialized by the EntityHandler 
deriving class.
         *
         * @return array[]
         */
@@ -388,6 +388,15 @@
                $this->assertEquals( $idString, $id->getSerialization() );
        }
 
+       /**
+        * @return Serializer
+        */
+       protected function getEntitySerializer() {
+               $newSerializerFactory = new SerializerFactory( new 
DataValueSerializer() );
+               $newSerializer = $newSerializerFactory->newEntitySerializer();
+               return $newSerializer;
+       }
+
        public function exportTransformProvider() {
                $entity = $this->newEntity();
 
@@ -416,8 +425,7 @@
                }
 
                // make new style blob
-               $newSerializerFactory = new SerializerFactory( new 
DataValueSerializer() );
-               $newSerializer = $newSerializerFactory->newEntitySerializer();
+               $newSerializer = $this->getEntitySerializer();
                $newBlob = json_encode( $newSerializer->serialize( $entity ) );
 
                return [
@@ -457,7 +465,12 @@
 
        public function testGetLegacyExportFormatDetector() {
                $detector = 
$this->getHandler()->getLegacyExportFormatDetector();
-               $this->assertInternalType( 'callable', $detector );
+
+               if ( $detector === null ) {
+                       $this->markTestSkipped( 'handler has no legacy export 
format detector' );
+               } else {
+                       $this->assertInternalType( 'callable', $detector );
+               }
        }
 
        public function forCreationParamProvider() {
@@ -565,7 +578,7 @@
                }
        }
 
-       abstract protected function getTestItemContent();
+       abstract protected function getTestContent();
 
        /**
         * @param EntityHandler $handler
@@ -578,25 +591,13 @@
                        ->setConstructorArgs( [ Title::newFromText( 'Q1' ) ] )
                        ->getMock();
 
-               $page->method( 'getContent' )->willReturn( 
$this->getTestItemContent() );
+               $page->method( 'getContent' )->willReturn( 
$this->getTestContent() );
                $page->method( 'getTitle' )->willReturn( $title );
 
                return $page;
        }
 
-       public function testDataForSearchIndex() {
-               $handler = $this->getHandler();
-               $engine = $this->getMock( \SearchEngine::class );
-
-               $page = $this->getMockWikiPage( $handler );
-
-               $data = $handler->getDataForSearchIndex( $page, new 
\ParserOutput(), $engine );
-               $this->assertSame( 1, $data['label_count'], 'label_count' );
-               if ( $handler instanceof ItemHandler ) {
-                       $this->assertSame( 1, $data['sitelink_count'], 
'sitelink_count' );
-               }
-               $this->assertSame( 1, $data['statement_count'], 
'statement_count' );
-       }
+       abstract public function testDataForSearchIndex();
 
        public function testGetActionOverrides() {
                $handler = $this->getHandler();
diff --git a/repo/tests/phpunit/includes/Content/ItemHandlerTest.php 
b/repo/tests/phpunit/includes/Content/ItemHandlerTest.php
index 06796f6..174082f 100644
--- a/repo/tests/phpunit/includes/Content/ItemHandlerTest.php
+++ b/repo/tests/phpunit/includes/Content/ItemHandlerTest.php
@@ -182,7 +182,7 @@
                $this->assertFalse( $handler->canCreateWithCustomId( $id ) );
        }
 
-       protected function getTestItemContent() {
+       protected function getTestContent() {
                $item = new Item();
                $item->getFingerprint()->setLabel( 'en', 'Kitten' );
                $item->getSiteLinkList()->addNewSiteLink( 'enwiki', 'Kitten' );
@@ -275,4 +275,16 @@
                ];
        }
 
+       public function testDataForSearchIndex() {
+               $handler = $this->getHandler();
+               $engine = $this->getMock( \SearchEngine::class );
+
+               $page = $this->getMockWikiPage( $handler );
+
+               $data = $handler->getDataForSearchIndex( $page, new 
\ParserOutput(), $engine );
+               $this->assertSame( 1, $data['label_count'], 'label_count' );
+               $this->assertSame( 1, $data['sitelink_count'], 'sitelink_count' 
);
+               $this->assertSame( 1, $data['statement_count'], 
'statement_count' );
+       }
+
 }
diff --git a/repo/tests/phpunit/includes/Content/PropertyHandlerTest.php 
b/repo/tests/phpunit/includes/Content/PropertyHandlerTest.php
index fae52c9..d9b36dd 100644
--- a/repo/tests/phpunit/includes/Content/PropertyHandlerTest.php
+++ b/repo/tests/phpunit/includes/Content/PropertyHandlerTest.php
@@ -111,18 +111,29 @@
                $this->assertFalse( $handler->canCreateWithCustomId( $id ) );
        }
 
-       protected function getTestItemContent() {
-               $item = new Property( null, null, 'string' );
-               $item->getFingerprint()->setLabel( 'en', 'Kitten' );
-               $item->getStatements()->addNewStatement(
+       protected function getTestContent() {
+               $property = new Property( null, null, 'string' );
+               $property->getFingerprint()->setLabel( 'en', 'Kitten' );
+               $property->getStatements()->addNewStatement(
                        new PropertyNoValueSnak( new PropertyId( 'P1' ) )
                );
 
-               return PropertyContent::newFromProperty( $item );
+               return PropertyContent::newFromProperty( $property );
        }
 
        protected function getExpectedSearchIndexFields() {
                return [ 'label_count', 'statement_count' ];
        }
 
+       public function testDataForSearchIndex() {
+               $handler = $this->getHandler();
+               $engine = $this->getMock( \SearchEngine::class );
+
+               $page = $this->getMockWikiPage( $handler );
+
+               $data = $handler->getDataForSearchIndex( $page, new 
\ParserOutput(), $engine );
+               $this->assertSame( 1, $data['label_count'], 'label_count' );
+               $this->assertSame( 1, $data['statement_count'], 
'statement_count' );
+       }
+
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I487a4fcc62aa2ad9a4aeebab4d871583bbe876b8
Gerrit-PatchSet: 2
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