jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/337882 )
Change subject: Process lemmas in LexemeChangeOpDeserializer ...................................................................... Process lemmas in LexemeChangeOpDeserializer LexemeChangeOpDeserializer uses LemmaChangeOpDeserializer to process serialized lemma change requests. Bug: T153677 Bug: T155700 Change-Id: Ie9d8bf69eb1f121d06ad9dfbcf68743531799137 Depends-On: I9654640b2fdd47cb02afbbcae5bb17d447723555 --- M WikibaseLexeme.entitytypes.php A src/ChangeOp/Deserialization/LexemeChangeOpDeserializer.php D src/ChangeOp/LexemeChangeOpDeserializer.php M tests/phpunit/mediawiki/ChangeOp/Deserialization/LemmaChangeOpDeserializerTest.php A tests/phpunit/mediawiki/ChangeOp/Deserialization/LexemeChangeOpDeserializerTest.php 5 files changed, 120 insertions(+), 33 deletions(-) Approvals: Ladsgroup: Looks good to me, approved jenkins-bot: Verified diff --git a/WikibaseLexeme.entitytypes.php b/WikibaseLexeme.entitytypes.php index 494fe77..7566b13 100644 --- a/WikibaseLexeme.entitytypes.php +++ b/WikibaseLexeme.entitytypes.php @@ -12,6 +12,9 @@ * @author Amir Sarabadani <ladsgr...@gmail.com> */ use Wikibase\DataModel\Entity\EntityId; +use Wikibase\Lexeme\ChangeOp\Deserialization\LemmaChangeOpDeserializer; +use Wikibase\Lexeme\Validators\LexemeValidatorFactory; +use Wikibase\Repo\ChangeOp\Deserialization\TermChangeOpSerializationValidator; use Wikibase\Repo\MediaWikiLanguageDirectionalityLookup; use Wikibase\Repo\ParserOutput\FallbackHintHtmlTermRenderer; use Wikibase\Repo\WikibaseRepo; @@ -20,7 +23,7 @@ use Wikibase\DataModel\Services\Lookup\LabelDescriptionLookup; use Wikibase\Lib\LanguageNameLookup; use Wikibase\LanguageFallbackChain; -use Wikibase\Lexeme\ChangeOp\LexemeChangeOpDeserializer; +use Wikibase\Lexeme\ChangeOp\Deserialization\LexemeChangeOpDeserializer; use Wikibase\Lexeme\Content\LexemeContent; use Wikibase\Lexeme\Content\LexemeHandler; use Wikibase\Lexeme\DataModel\Lexeme; @@ -116,7 +119,20 @@ // returning a deserializer 'js-deserializer-factory-function' => 'wikibase.lexeme.getDeserializer', 'changeop-deserializer-callback' => function () { - return new LexemeChangeOpDeserializer(); - } + $wikibaseRepo = WikibaseRepo::getDefaultInstance(); + return new LexemeChangeOpDeserializer( + new LemmaChangeOpDeserializer( + // TODO: WikibaseRepo should probably provide this validator? + // TODO: WikibaseRepo::getTermsLanguage is not necessarily the list of language codes + // that should be allowed as "languages" of lemma terms + new TermChangeOpSerializationValidator( $wikibaseRepo->getTermsLanguages() ), + new LexemeValidatorFactory( + 1000, // TODO: move to setting, at least change to some reasonable hard-coded value + $wikibaseRepo->getTermValidatorFactory() + ), + $wikibaseRepo->getStringNormalizer() + ) + ); + }, ] ]; diff --git a/src/ChangeOp/Deserialization/LexemeChangeOpDeserializer.php b/src/ChangeOp/Deserialization/LexemeChangeOpDeserializer.php new file mode 100644 index 0000000..833fdea --- /dev/null +++ b/src/ChangeOp/Deserialization/LexemeChangeOpDeserializer.php @@ -0,0 +1,42 @@ +<?php + +namespace Wikibase\Lexeme\ChangeOp\Deserialization; + +use Wikibase\ChangeOp\ChangeOp; +use Wikibase\ChangeOp\ChangeOps; +use Wikibase\Repo\ChangeOp\ChangeOpDeserializer; + +/** + * Class for creating ChangeOp for EditEntity API + * + * @license GPL-2.0+ + * @author Amir Sarabadani <ladsgr...@gmail.com> + */ +class LexemeChangeOpDeserializer implements ChangeOpDeserializer { + + /** + * @var LemmaChangeOpDeserializer + */ + private $lemmaChangeOpDeserializer; + + public function __construct( LemmaChangeOpDeserializer $lemmaChangeOpDeserializer ) { + $this->lemmaChangeOpDeserializer = $lemmaChangeOpDeserializer; + } + + /** + * @see ChangeOpDeserializer::createEntityChangeOp + * + * @param array[] $changeRequest + * @return ChangeOp + */ + public function createEntityChangeOp( array $changeRequest ) { + $changeOps = new ChangeOps(); + + if ( array_key_exists( 'lemmas', $changeRequest ) ) { + $changeOps->add( $this->lemmaChangeOpDeserializer->createEntityChangeOp( $changeRequest ) ); + } + + return $changeOps; + } + +} diff --git a/src/ChangeOp/LexemeChangeOpDeserializer.php b/src/ChangeOp/LexemeChangeOpDeserializer.php deleted file mode 100644 index 014dbff..0000000 --- a/src/ChangeOp/LexemeChangeOpDeserializer.php +++ /dev/null @@ -1,29 +0,0 @@ -<?php - -namespace Wikibase\Lexeme\ChangeOp; - -use Wikibase\ChangeOp\ChangeOp; -use Wikibase\Repo\ChangeOp\ChangeOpDeserializer; -use Wikibase\Repo\ChangeOp\NullChangeOp; -use Wikibase\StringNormalizer; - -/** - * Class for creating ChangeOp for EditEntity API - * - * @license GPL-2.0+ - * @author Amir Sarabadani <ladsgr...@gmail.com> - */ -class LexemeChangeOpDeserializer implements ChangeOpDeserializer { - - /** - * @see ChangeOpDeserializer::createEntityChangeOp - * - * @param array[] $changeRequest - * @return ChangeOp - */ - public function createEntityChangeOp( array $changeRequest ) { - // Do nothing - return new NullChangeOp(); - } - -} diff --git a/tests/phpunit/mediawiki/ChangeOp/Deserialization/LemmaChangeOpDeserializerTest.php b/tests/phpunit/mediawiki/ChangeOp/Deserialization/LemmaChangeOpDeserializerTest.php index e253291..fdc0202 100644 --- a/tests/phpunit/mediawiki/ChangeOp/Deserialization/LemmaChangeOpDeserializerTest.php +++ b/tests/phpunit/mediawiki/ChangeOp/Deserialization/LemmaChangeOpDeserializerTest.php @@ -16,7 +16,7 @@ use Wikibase\StringNormalizer; /** - * @covers Wikibase\Lexeme\ChangeOp\Deserialiazation\LemmaChangeOpDeserializer + * @covers Wikibase\Lexeme\ChangeOp\Deserialization\LemmaChangeOpDeserializer * * @group WikibaseLexeme * diff --git a/tests/phpunit/mediawiki/ChangeOp/Deserialization/LexemeChangeOpDeserializerTest.php b/tests/phpunit/mediawiki/ChangeOp/Deserialization/LexemeChangeOpDeserializerTest.php new file mode 100644 index 0000000..e939578 --- /dev/null +++ b/tests/phpunit/mediawiki/ChangeOp/Deserialization/LexemeChangeOpDeserializerTest.php @@ -0,0 +1,58 @@ +<?php + +namespace Wikibase\Lexeme\Tests\ChangeOp\Deserialization; + +use Wikibase\ChangeOp\ChangeOp; +use Wikibase\Lexeme\ChangeOp\Deserialization\LemmaChangeOpDeserializer; +use Wikibase\Lexeme\ChangeOp\Deserialization\LexemeChangeOpDeserializer; + +/** + * @covers Wikibase\Lexeme\ChangeOp\Deserialization\LexemeChangeOpDeserializer + * + * @group WikibaseLexeme + * + * @license GPL-2.0+ + */ +class LexemeChangeOpDeserializerTest extends \PHPUnit_Framework_TestCase { + + /** + * @return LemmaChangeOpDeserializer + */ + private function getLemmaChangeOpDeserializer() { + return $this->getMockBuilder( LemmaChangeOpDeserializer::class ) + ->disableOriginalConstructor() + ->getMock(); + } + + public function testCreateEntityChangeOpReturnsChangeOpInstance() { + $deserializer = new LexemeChangeOpDeserializer( $this->getLemmaChangeOpDeserializer() ); + + $this->assertInstanceOf( ChangeOp::class, $deserializer->createEntityChangeOp( [] ) ); + } + + public function testGivenLemmasInChangeRequest_lemmaChangeOpDeserializerIsUsed() { + $lemmaDeserializer = $this->getLemmaChangeOpDeserializer(); + $lemmaDeserializer->expects( $this->atLeastOnce() ) + ->method( 'createEntityChangeOp' ) + ->will( $this->returnValue( $this->getMock( ChangeOp::class ) ) ); + + $deserializer = new LexemeChangeOpDeserializer( $lemmaDeserializer ); + + $deserializer->createEntityChangeOp( + [ 'lemmas' => [ 'en' => [ 'language' => 'en', 'value' => 'rat' ] ] ] + ); + } + + public function testGivenNoLexemeRelevantFieldsInRequest_lemmaChangeOpDeserializerIsNotUsed() { + $lemmaDeserializer = $this->getLemmaChangeOpDeserializer(); + $lemmaDeserializer->expects( $this->never() ) + ->method( $this->anything() ); + + $deserializer = new LexemeChangeOpDeserializer( $lemmaDeserializer ); + + $deserializer->createEntityChangeOp( + [ 'labels' => [ 'en' => [ 'language' => 'en', 'value' => 'rat' ] ] ] + ); + } + +} -- To view, visit https://gerrit.wikimedia.org/r/337882 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ie9d8bf69eb1f121d06ad9dfbcf68743531799137 Gerrit-PatchSet: 5 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: WMDE-leszek <leszek.mani...@wikimedia.de> Gerrit-Reviewer: Ladsgroup <ladsgr...@gmail.com> 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