Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/391606 )

Change subject: Allow action overrides to work with WikiPage for now.
......................................................................

Allow 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.

Change-Id: I37e5d31f756d7d5d6613ee09e6accb31a99bd3eb
Depends-On: I487a4fcc62aa2ad9a4aeebab4d871583bbe876b8
---
M src/Content/LexemeHandler.php
M tests/phpunit/mediawiki/Content/LexemeHandlerTest.php
2 files changed, 127 insertions(+), 64 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme 
refs/changes/06/391606/1

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/tests/phpunit/mediawiki/Content/LexemeHandlerTest.php 
b/tests/phpunit/mediawiki/Content/LexemeHandlerTest.php
index a61d942..62da31a 100644
--- a/tests/phpunit/mediawiki/Content/LexemeHandlerTest.php
+++ b/tests/phpunit/mediawiki/Content/LexemeHandlerTest.php
@@ -8,19 +8,32 @@
 use IContextSource;
 use Language;
 use Page;
-use PHPUnit_Framework_TestCase;
 use RequestContext;
 use Title;
+use Wikibase\Content\EntityInstanceHolder;
+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\DataModel\Serialization\ExternalLexemeSerializer;
+use Wikibase\Lexeme\DataModel\Serialization\StorageLexemeSerializer;
 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 +45,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 +166,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 +178,15 @@
                $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' );
+       }
+
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I37e5d31f756d7d5d6613ee09e6accb31a99bd3eb
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseLexeme
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <daniel.kinz...@wikimedia.de>

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

Reply via email to