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

Change subject: Make LexemeId and LexemeHandlerTest compatible with changes in 
Wikibase
......................................................................


Make LexemeId and LexemeHandlerTest compatible with changes in Wikibase

Makes LexemeId compatible with DataModel 7.3

The current release of DataModel 7.3 contains an unintended breaking
change. This small change here makes the WikibaseLexeme code base
compatible again.

Also allows action overrides to work with WikiPage for now.

This is needed until I0335100b2b is merged.

In order to test compliance, this patch changes LexemeHandlerTest to use
the EntityHandlerTest base class.

NOTE: the same should be done for MediaInfo.

Finally fixes broken LexemeHandler tests

Change-Id: I9d105df786c2c5cad67a586f737dffe50e0d0f15
---
M composer.json
M i18n/en.json
M i18n/qqq.json
M src/Content/LexemeHandler.php
M src/DataModel/LexemeId.php
M tests/phpunit/composer/DataModel/LexemeIdTest.php
M tests/phpunit/mediawiki/Content/LexemeHandlerTest.php
7 files changed, 153 insertions(+), 77 deletions(-)

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



diff --git a/composer.json b/composer.json
index 33034a1..8129578 100644
--- a/composer.json
+++ b/composer.json
@@ -17,7 +17,7 @@
                "php": ">=5.5.9",
                "serialization/serialization": "~3.2",
                "wikimedia/assert": "~0.2.2",
-               "wikibase/data-model": "^7.0",
+               "wikibase/data-model": "^7.3.0",
                "wikibase/data-model-serialization": "~2.0",
                "wikibase/data-model-services": "~3.6",
                "wmde/php-vuejs-templating": "dev-master"
diff --git a/i18n/en.json b/i18n/en.json
index c83081e..f90a514 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -52,5 +52,6 @@
        "wikibaselexeme-diffview-lemma": "Lemma",
        "wikibaselexeme-diffview-lexical-category": "lexical category",
        "wikibaselexeme-diffview-language": "language",
-       "wikibaselexeme-diffview-form": "form"
+       "wikibaselexeme-diffview-form": "form",
+       "content-model-wikibase-lexeme": "Wikibase lexeme"
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 0f762d7..3c0ae58 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -57,5 +57,6 @@
        "wikibaselexeme-diffview-lemma": "Title of lemma in diff page",
        "wikibaselexeme-diffview-lexical-category": "Title of lexical category 
in diff page",
        "wikibaselexeme-diffview-language": "Title of language in diff 
page\n{{Identical|Language}}",
-       "wikibaselexeme-diffview-form": "Title of form in diff page"
+       "wikibaselexeme-diffview-form": "Title of form in diff page",
+       "content-model-wikibase-lexeme": "The name for Wikibase lexeme content 
model, used when describing what type of content a page contains."
 }
diff --git a/src/Content/LexemeHandler.php b/src/Content/LexemeHandler.php
index 54b5968..164f290 100644
--- a/src/Content/LexemeHandler.php
+++ b/src/Content/LexemeHandler.php
@@ -2,6 +2,7 @@
 
 namespace Wikibase\Lexeme\Content;
 
+use Article;
 use IContextSource;
 use Page;
 use Wikibase\Content\EntityHolder;
@@ -79,7 +80,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/src/DataModel/LexemeId.php b/src/DataModel/LexemeId.php
index 3f3261c..9a95d9a 100644
--- a/src/DataModel/LexemeId.php
+++ b/src/DataModel/LexemeId.php
@@ -64,6 +64,9 @@
         */
        public function unserialize( $serialized ) {
                $this->serialization = $serialized;
+               list( $this->repositoryName, $this->localPart ) = 
self::extractRepositoryNameAndLocalPart(
+                       $serialized
+               );
        }
 
        /**
diff --git a/tests/phpunit/composer/DataModel/LexemeIdTest.php 
b/tests/phpunit/composer/DataModel/LexemeIdTest.php
index 65c505b..48905a3 100644
--- a/tests/phpunit/composer/DataModel/LexemeIdTest.php
+++ b/tests/phpunit/composer/DataModel/LexemeIdTest.php
@@ -27,8 +27,23 @@
         * @dataProvider idSerializationProvider
         */
        public function testSerializationWorksProperly( $serialization ) {
-               $id = new LexemeId( $serialization );
-               $this->assertEquals( $id, unserialize( serialize( $id ) ) );
+               $expected = new LexemeId( $serialization );
+
+               /** @var LexemeId $unserialized */
+               $unserialized = unserialize( serialize( $expected ) );
+
+               $this->assertTrue( $expected->equals( $unserialized ), 
'equality as defined in EntityId' );
+
+               $this->assertSame(
+                       $expected->getRepositoryName(),
+                       $unserialized->getRepositoryName(),
+                       'getRepositoryName works as expected after unserialize'
+               );
+               $this->assertSame(
+                       $expected->getLocalPart(),
+                       $unserialized->getLocalPart(),
+                       'getLocalPart works as expected after unserialize'
+               );
        }
 
        public function idSerializationProvider() {
diff --git a/tests/phpunit/mediawiki/Content/LexemeHandlerTest.php 
b/tests/phpunit/mediawiki/Content/LexemeHandlerTest.php
index a61d942..cc72d91 100644
--- a/tests/phpunit/mediawiki/Content/LexemeHandlerTest.php
+++ b/tests/phpunit/mediawiki/Content/LexemeHandlerTest.php
@@ -2,25 +2,27 @@
 
 namespace Wikibase\Lexeme\Tests\MediaWiki\Content;
 
-use Action;
-use Closure;
-use FauxRequest;
-use IContextSource;
-use Language;
-use Page;
-use PHPUnit_Framework_TestCase;
-use RequestContext;
-use Title;
+use Wikibase\DataModel\Entity\EntityDocument;
+use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\DataModel\Entity\EntityIdParser;
+use Wikibase\DataModel\Entity\ItemId;
 use Wikibase\DataModel\Services\Lookup\LabelDescriptionLookup;
+use Wikibase\DataModel\Term\Term;
+use Wikibase\DataModel\Term\TermList;
+use Wikibase\Lexeme\Content\LexemeContent;
 use Wikibase\Lexeme\Search\LexemeFieldDefinitions;
+use Wikibase\Lib\EntityTypeDefinitions;
 use Wikibase\Lib\Store\EntityContentDataCodec;
 use Wikibase\Lib\Store\LanguageFallbackLabelDescriptionLookupFactory;
 use Wikibase\Lexeme\Content\LexemeHandler;
 use Wikibase\Lexeme\DataModel\Lexeme;
 use Wikibase\Lexeme\DataModel\LexemeId;
+use Wikibase\Repo\Content\EntityHandler;
+use Wikibase\Repo\Tests\Content\EntityHandlerTest;
 use Wikibase\Repo\Validators\EntityConstraintProvider;
 use Wikibase\Repo\Validators\ValidatorErrorLocalizer;
+use Wikibase\Repo\WikibaseRepo;
+use Wikibase\SettingsArray;
 use Wikibase\Store\EntityIdLookup;
 use Wikibase\TermIndex;
 
@@ -32,7 +34,100 @@
  * @license GPL-2.0+
  * @author Bene* < benestar.wikime...@gmail.com >
  */
-class LexemeHandlerTest extends PHPUnit_Framework_TestCase {
+class LexemeHandlerTest extends EntityHandlerTest {
+
+       /**
+        * @return string
+        */
+       public function getModelId() {
+               return LexemeContent::CONTENT_MODEL_ID;
+       }
+
+       /**
+        * @param SettingsArray|null $settings
+        *
+        * @return EntityHandler
+        */
+       protected function getHandler( SettingsArray $settings = null ) {
+               return $this->getWikibaseRepo( $settings )
+                       ->getEntityContentFactory()
+                       ->getContentHandlerForType( Lexeme::ENTITY_TYPE );
+       }
+
+       /**
+        * @param EntityId|null $id
+        *
+        * @return EntityDocument
+        */
+       protected function newEntity( EntityId $id = null ) {
+               if ( !$id ) {
+                       $id = new LexemeId( 'L7' );
+               }
+
+               $lexeme = new Lexeme( $id );
+               $lexeme->setLemmas(
+                       new TermList(
+                               [
+                                       new Term( 'en', 'goat' ),
+                                       new Term( 'de', 'Ziege' ),
+                               ]
+                       )
+               );
+               $lexeme->setLanguage( new ItemId( 'Q123' ) );
+               $lexeme->setLexicalCategory( new ItemId( 'Q567' ) );
+
+               return $lexeme;
+       }
+
+       /**
+        * Returns EntityContents that can be serialized by the EntityHandler 
deriving class.
+        *
+        * @return array[]
+        */
+       public function contentProvider() {
+               $content = $this->newEntityContent();
+
+               return [
+                       [ $content ],
+               ];
+       }
+
+       /**
+        * @return array
+        */
+       public function entityIdProvider() {
+               return [
+                       [ 'L7' ],
+               ];
+       }
+
+       /**
+        * @return array
+        */
+       protected function getExpectedSearchIndexFields() {
+               return [ 'statement_count' ];
+       }
+
+       /**
+        * @return LexemeContent
+        */
+       protected function getTestContent() {
+               return $this->newEntityContent();
+       }
+
+       protected function getEntityTypeDefinitions() {
+               return new EntityTypeDefinitions(
+                       require __DIR__ . 
'/../../../../WikibaseLexeme.entitytypes.php'
+               );
+       }
+
+       protected function getEntitySerializer() {
+               $baseModelSerializerFactory = WikibaseRepo::getDefaultInstance()
+                       ->getBaseDataModelSerializerFactory();
+               $entityTypeDefinitions = $this->getEntityTypeDefinitions();
+               $serializerFactoryCallbacks = 
$entityTypeDefinitions->getSerializerFactoryCallbacks();
+               return $serializerFactoryCallbacks['lexeme']( 
$baseModelSerializerFactory );
+       }
 
        private function getMockWithoutConstructor( $className ) {
                return $this->getMockBuilder( $className )
@@ -60,67 +155,6 @@
                );
        }
 
-       public function testGetActionOverrides() {
-               $lexemeHandler = $this->newLexemeHandler();
-               $overrides = $lexemeHandler->getActionOverrides();
-
-               $this->assertSame( [ 'history', 'view', 'edit', 'submit' ], 
array_keys( $overrides ) );
-
-               $this->assertActionOverride( $overrides['history'] );
-               $this->assertActionOverride( $overrides['view'] );
-               $this->assertActionOverride( $overrides['edit'] );
-               $this->assertActionOverride( $overrides['submit'] );
-       }
-
-       private function assertActionOverride( $override ) {
-               if ( $override instanceof Closure ) {
-                       $context = $this->getMock( IContextSource::class );
-                       $context->expects( $this->any() )
-                               ->method( 'getLanguage' )
-                               ->will( $this->returnValue( 
$this->getMockWithoutConstructor( Language::class ) ) );
-
-                       $action = $override( $this->getMock( Page::class ), 
$context );
-                       $this->assertInstanceOf( Action::class, $action );
-               } else {
-                       $this->assertTrue( is_subclass_of( $override, 
Action::class ) );
-               }
-       }
-
-       public function testMakeEmptyEntity() {
-               $lexemeHandler = $this->newLexemeHandler();
-
-               $this->assertTrue(
-                       $lexemeHandler->makeEmptyEntity()->equals( new Lexeme() 
)
-               );
-       }
-
-       public function testMakeEntityId() {
-               $lexemeHandler = $this->newLexemeHandler();
-
-               $this->assertTrue(
-                       $lexemeHandler->makeEntityId( 'L1' )->equals( new 
LexemeId( 'L1' ) )
-               );
-       }
-
-       public function testGetEntityType() {
-               $lexemeHandler = $this->newLexemeHandler();
-
-               $this->assertSame( Lexeme::ENTITY_TYPE, 
$lexemeHandler->getEntityType() );
-       }
-
-       public function testShowMissingEntity() {
-               $lexemeHandler = $this->newLexemeHandler();
-
-               $title = Title::makeTitle( 112, 'L11' );
-               $context = new RequestContext( new FauxRequest() );
-               $context->setTitle( $title );
-
-               $lexemeHandler->showMissingEntity( $title, $context );
-
-               $html = $context->getOutput()->getHTML();
-               $this->assertContains( 'noarticletext', $html );
-       }
-
        public function testAllowAutomaticIds() {
                $lexemeHandler = $this->newLexemeHandler();
 
@@ -133,4 +167,19 @@
                $this->assertFalse( $lexemeHandler->canCreateWithCustomId( new 
LexemeId( 'L1' ) ) );
        }
 
+       public function testDataForSearchIndex() {
+               $handler = $this->getHandler();
+               $engine = $this->getMock( \SearchEngine::class );
+
+               $page = $this->getMockWikiPage( $handler );
+
+               // TODO: test with statements!
+               $data = $handler->getDataForSearchIndex( $page, new 
\ParserOutput(), $engine );
+               $this->assertSame( 0, $data['statement_count'], 
'statement_count' );
+       }
+
+       public function testExportTransform() {
+               $this->markTestSkipped( 'serialized data transformation issues 
are irrelevant to Lexemes' );
+       }
+
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I9d105df786c2c5cad67a586f737dffe50e0d0f15
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/WikibaseLexeme
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.kr...@wikimedia.de>
Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de>
Gerrit-Reviewer: Ladsgroup <ladsgr...@gmail.com>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.kr...@wikimedia.de>
Gerrit-Reviewer: WMDE-leszek <leszek.mani...@wikimedia.de>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to