Daniel Kinzler has uploaded a new change for review. (
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.
Usinga 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, 46 insertions(+), 21 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/04/391604/1
diff --git a/repo/tests/phpunit/includes/Content/EntityHandlerTest.php
b/repo/tests/phpunit/includes/Content/EntityHandlerTest.php
index 60ccd2f..a3f7115 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;
@@ -130,7 +131,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 +389,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 +426,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 +466,12 @@
public function testGetLegacyExportFormatDetector() {
$detector =
$this->getHandler()->getLegacyExportFormatDetector();
- $this->assertInternalType( 'callable', $detector );
+
+ if ( $detector === null ) {
+ $this->assertTrue( true ); // make sure PHPUnit is happy
+ } else {
+ $this->assertInternalType( 'callable', $detector );
+ }
}
public function forCreationParamProvider() {
@@ -565,7 +579,7 @@
}
}
- abstract protected function getTestItemContent();
+ abstract protected function getTestContent();
/**
* @param EntityHandler $handler
@@ -578,25 +592,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' );
- }
+ public abstract 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..18febdc 100644
--- a/repo/tests/phpunit/includes/Content/PropertyHandlerTest.php
+++ b/repo/tests/phpunit/includes/Content/PropertyHandlerTest.php
@@ -111,7 +111,7 @@
$this->assertFalse( $handler->canCreateWithCustomId( $id ) );
}
- protected function getTestItemContent() {
+ protected function getTestContent() {
$item = new Property( null, null, 'string' );
$item->getFingerprint()->setLabel( 'en', 'Kitten' );
$item->getStatements()->addNewStatement(
@@ -125,4 +125,15 @@
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: newchange
Gerrit-Change-Id: I487a4fcc62aa2ad9a4aeebab4d871583bbe876b8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits