Ladsgroup has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/340752 )
Change subject: Add ChangeOp, ChangeOpDeserializer and Validator for
LexicalCategory
......................................................................
Add ChangeOp, ChangeOpDeserializer and Validator for LexicalCategory
Bug: T155703
Bug: T158780
Change-Id: I7ab98d3b7f8844fba6245dd859d7aa87cd0394b6
---
A src/ChangeOp/ChangeOpLexicalCategory.php
M src/ChangeOp/Deserialization/LexemeChangeOpDeserializer.php
A src/ChangeOp/Deserialization/LexicalCategoryChangeOpDeserializer.php
M src/Validators/LexemeValidatorFactory.php
A tests/phpunit/mediawiki/ChangeOp/ChangeOpLexicalCategoryTest.php
A
tests/phpunit/mediawiki/ChangeOp/Deserialization/LexicalCategoryChangeOpDeserializerTest.php
M tests/phpunit/mediawiki/Validators/LexemeValidatorFactoryTest.php
7 files changed, 564 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme
refs/changes/52/340752/1
diff --git a/src/ChangeOp/ChangeOpLexicalCategory.php
b/src/ChangeOp/ChangeOpLexicalCategory.php
new file mode 100644
index 0000000..47a9cfd
--- /dev/null
+++ b/src/ChangeOp/ChangeOpLexicalCategory.php
@@ -0,0 +1,92 @@
+<?php
+
+namespace Wikibase\Lexeme\ChangeOp;
+
+use InvalidArgumentException;
+use ValueValidators\Result;
+use Wikibase\ChangeOp\ChangeOpBase;
+use Wikibase\DataModel\Entity\EntityDocument;
+use Wikibase\DataModel\Entity\ItemId;
+use Wikibase\Lexeme\DataModel\Lexeme;
+use Wikibase\Lexeme\DataModel\Providers\LanguageProvider;
+use Wikibase\Lexeme\Validators\LexemeValidatorFactory;
+use Wikibase\Summary;
+use Wikimedia\Assert\Assert;
+
+/**
+ * @license GPL-2.0+
+ */
+class ChangeOpLexicalCategory extends ChangeOpBase {
+
+ /**
+ * @var ItemId|null
+ */
+ private $lexicalCategory;
+
+ /**
+ * @var LexemeValidatorFactory
+ */
+ private $lexemeValidatorFactory;
+
+ /**
+ * @param ItemId|null $lexicalCategory
+ * @param LexemeValidatorFactory $lexemeValidatorFactory
+ *
+ * @throws InvalidArgumentException
+ */
+ public function __construct( $lexicalCategory, LexemeValidatorFactory
$lexemeValidatorFactory ) {
+ if ( $lexicalCategory !== null ) {
+ Assert::parameterType( ItemId::class, $lexicalCategory,
'$lexicalCategory' );
+ }
+
+ $this->lexicalCategory = $lexicalCategory;
+ $this->lexemeValidatorFactory = $lexemeValidatorFactory;
+ }
+
+ /**
+ * @param EntityDocument $entity
+ *
+ * @return Result
+ *
+ * @throws InvalidArgumentException
+ */
+ public function validate( EntityDocument $entity ) {
+ Assert::parameterType( LanguageProvider::class, $entity,
'$entity' );
+
+ $lexicalCategoryValidator =
$this->lexemeValidatorFactory->getLexicalCategoryValidator();
+
+ return $lexicalCategoryValidator->validate(
$this->lexicalCategory );
+ }
+
+ /**
+ * @param EntityDocument $entity
+ * @param Summary|null $summary
+ *
+ * @throws InvalidArgumentException
+ */
+ public function apply( EntityDocument $entity, Summary $summary = null
) {
+ Assert::parameterType( Lexeme::class, $entity, '$entity' );
+
+ /** @var Lexeme $entity */
+ // TODO: Add setLexicalCategory to LexicalCategoryProvider
interface
+ $lexicalCategory = $entity->getLexicalCategory();
+
+ if ( $this->lexicalCategory === null ) {
+ if ( $lexicalCategory ) {
+ $this->updateSummary(
+ $summary,
+ 'remove',
+ '',
+ $lexicalCategory->getSerialization()
+ );
+ $entity->setLexicalCategory( null );
+ }
+
+ return;
+ }
+
+ $this->updateSummary( $summary, 'set', '',
$this->lexicalCategory->getSerialization() );
+ $entity->setLexicalCategory( $this->lexicalCategory );
+ }
+
+}
diff --git a/src/ChangeOp/Deserialization/LexemeChangeOpDeserializer.php
b/src/ChangeOp/Deserialization/LexemeChangeOpDeserializer.php
index 46dc63d..f119060 100644
--- a/src/ChangeOp/Deserialization/LexemeChangeOpDeserializer.php
+++ b/src/ChangeOp/Deserialization/LexemeChangeOpDeserializer.php
@@ -24,12 +24,19 @@
*/
private $languageChangeOpDeserializer;
+ /**
+ * @var LexicalCategoryChangeOpDeserializer
+ */
+ private $lexicalCategoryChangeOpDeserializer;
+
public function __construct(
LemmaChangeOpDeserializer $lemmaChangeOpDeserializer,
- LanguageChangeOpDeserializer $languageChangeOpDeserializer
+ LanguageChangeOpDeserializer $languageChangeOpDeserializer,
+ LexicalCategoryChangeOpDeserializer
$lexicalCategoryChangeOpDeserializer
) {
$this->lemmaChangeOpDeserializer = $lemmaChangeOpDeserializer;
$this->languageChangeOpDeserializer =
$languageChangeOpDeserializer;
+ $this->lexicalCategoryChangeOpDeserializer =
$lexicalCategoryChangeOpDeserializer;
}
/**
@@ -49,6 +56,12 @@
$changeOps->add(
$this->languageChangeOpDeserializer->createEntityChangeOp( $changeRequest ) );
}
+ if ( array_key_exists( 'lexical_category', $changeRequest ) ) {
+ $changeOps->add(
+
$this->lexicalCategoryChangeOpDeserializer->createEntityChangeOp(
$changeRequest )
+ );
+ }
+
return $changeOps;
}
diff --git
a/src/ChangeOp/Deserialization/LexicalCategoryChangeOpDeserializer.php
b/src/ChangeOp/Deserialization/LexicalCategoryChangeOpDeserializer.php
new file mode 100644
index 0000000..fa8d4cb
--- /dev/null
+++ b/src/ChangeOp/Deserialization/LexicalCategoryChangeOpDeserializer.php
@@ -0,0 +1,107 @@
+<?php
+
+namespace Wikibase\Lexeme\ChangeOp\Deserialization;
+
+use InvalidArgumentException;
+use ValueValidators\StringValidator;
+use Wikibase\ChangeOp\ChangeOp;
+use Wikibase\ChangeOp\ChangeOps;
+use Wikibase\DataModel\Entity\ItemId;
+use Wikibase\Lexeme\ChangeOp\ChangeOpLexicalCategory;
+use Wikibase\Lexeme\Validators\LexemeValidatorFactory;
+use Wikibase\Repo\ChangeOp\ChangeOpDeserializer;
+use Wikibase\Repo\ChangeOp\Deserialization\ChangeOpDeserializationException;
+use Wikibase\StringNormalizer;
+
+/**
+ * Deserializer for lexical category change request data.
+ *
+ * @see docs/change-op-serialization.wiki for a description of the
serialization format.
+ *
+ * @license GPL-2.0+
+ */
+class LexicalCategoryChangeOpDeserializer implements ChangeOpDeserializer {
+
+ /**
+ * @var LexemeValidatorFactory
+ */
+ private $lexemeValidatorFactory;
+
+ /**
+ * @var StringNormalizer
+ */
+ private $stringNormalizer;
+
+ /**
+ * @var StringValidator
+ */
+ private $stringValidator;
+
+ public function __construct(
+ LexemeValidatorFactory $lexemeValidatorFactory,
+ StringNormalizer $stringNormalizer,
+ StringValidator $stringValidator
+ ) {
+ $this->lexemeValidatorFactory = $lexemeValidatorFactory;
+ $this->stringNormalizer = $stringNormalizer;
+ $this->stringValidator = $stringValidator;
+ }
+
+ /**
+ * @see ChangeOpDeserializer::createEntityChangeOp
+ *
+ * @param array $changeRequest
+ *
+ * @throws ChangeOpDeserializationException
+ *
+ * @return ChangeOp
+ */
+ public function createEntityChangeOp( array $changeRequest ) {
+ $changeOps = new ChangeOps();
+
+ $result = $this->stringValidator->validate(
$changeRequest['lexical_category'] );
+ if ( $result->isValid() !== true ) {
+ throw new ChangeOpDeserializationException(
+ 'lexical_category needs to be string',
+ 'invalid-lexical-category'
+ );
+ }
+ $lexicalCategorySerialization =
$this->stringNormalizer->cleanupToNFC(
+ $changeRequest['lexical_category'] );
+
+ if ( $lexicalCategorySerialization === '' ) {
+ $changeOps->add( new ChangeOpLexicalCategory(
+ null,
+ $this->lexemeValidatorFactory
+ ) );
+ return $changeOps;
+ }
+
+ $itemId = $this->validateItemId( $lexicalCategorySerialization
);
+ $changeOps->add( new ChangeOpLexicalCategory(
+ $itemId,
+ $this->lexemeValidatorFactory
+ ) );
+
+ return $changeOps;
+ }
+
+ /**
+ * @param string $idSerialization
+ * @return ItemId
+ * @throws ChangeOpDeserializationException
+ */
+ private function validateItemId( $idSerialization ) {
+ try {
+ $itemId = new ItemId( $idSerialization );
+ } catch ( InvalidArgumentException $e ) {
+ throw new ChangeOpDeserializationException(
+ 'Item id can not be parsed',
+ 'invalid-item-id'
+ );
+ }
+
+ return $itemId;
+ }
+
+}
diff --git a/src/Validators/LexemeValidatorFactory.php
b/src/Validators/LexemeValidatorFactory.php
index c9b8e21..d8adeaf 100644
--- a/src/Validators/LexemeValidatorFactory.php
+++ b/src/Validators/LexemeValidatorFactory.php
@@ -81,4 +81,14 @@
);
}
+ /**
+ * @return ValueValidator
+ */
+ public function getLexicalCategoryValidator() {
+ return new CompositeValidator(
+ $this->itemValidators,
+ true
+ );
+ }
+
}
diff --git a/tests/phpunit/mediawiki/ChangeOp/ChangeOpLexicalCategoryTest.php
b/tests/phpunit/mediawiki/ChangeOp/ChangeOpLexicalCategoryTest.php
new file mode 100644
index 0000000..d754b64
--- /dev/null
+++ b/tests/phpunit/mediawiki/ChangeOp/ChangeOpLexicalCategoryTest.php
@@ -0,0 +1,161 @@
+<?php
+
+namespace Wikibase\Lexeme\Tests\MediaWiki\ChangeOp;
+
+use InvalidArgumentException;
+use Wikibase\DataModel\Entity\EntityDocument;
+use Wikibase\DataModel\Entity\Item;
+use Wikibase\DataModel\Entity\ItemId;
+use Wikibase\Lexeme\ChangeOp\ChangeOpLexicalCategory;
+use Wikibase\Lexeme\DataModel\Lexeme;
+use
Wikibase\Lexeme\Tests\MediaWiki\Validators\LexemeValidatorFactoryTestMockProvider;
+use Wikibase\Repo\Tests\ChangeOp\ChangeOpTestMockProvider;
+use Wikibase\Summary;
+
+/**
+ * @covers Wikibase\Lexeme\ChangeOp\ChangeOpLexicalCategory
+ *
+ * @group WikibaseLexeme
+ *
+ * @license GPL-2.0+
+ */
+class ChangeOpLexicalCategoryTest extends \PHPUnit_Framework_TestCase {
+
+ /**
+ * @dataProvider invalidConstructorArgumentsProvider
+ */
+ public function testGivenInvalidArguments_constructorThrowsException(
$lexicalCategory ) {
+ $this->setExpectedException( InvalidArgumentException::class );
+ new ChangeOpLexicalCategory( $lexicalCategory,
$this->getLexemeValidatorFactory() );
+ }
+
+ public function invalidConstructorArgumentsProvider() {
+ return [
+ 'not a ItemId as a lexical category code (int)' => [
123 ],
+ 'not a ItemId as a lexical category code (string)' => [
'duck' ],
+ ];
+ }
+
+ /**
+ * @dataProvider invalidEntityProvider
+ */
+ public function
testGivenNotALexicalCategoryProvider_validateThrowsException(
+ EntityDocument $entity
+ ) {
+ $this->setExpectedException( InvalidArgumentException::class );
+ $changeOp = new ChangeOpLexicalCategory( new ItemId( 'Q2' ),
$this->getLexemeValidatorFactory() );
+ $changeOp->validate( $entity );
+ }
+
+ public function invalidEntityProvider() {
+ return [
+ [ $this->getMock( EntityDocument::class ) ],
+ [ new Item( new ItemId( 'Q234' ) ) ],
+ ];
+ }
+
+ public function
testGivenValidLexicalCategory_validateReturnsValidResult() {
+ $lexeme = new Lexeme();
+
+ $changeOp = new ChangeOpLexicalCategory(
+ new ItemId( 'Q234' ),
+ $this->getLexemeValidatorFactory()
+ );
+
+ $this->assertTrue( $changeOp->validate( $lexeme )->isValid() );
+ }
+
+ public function
testGivenLexicalCategoryIsNull_validateReturnsValidResult() {
+ $lexeme = new Lexeme();
+
+ $changeOp = new ChangeOpLexicalCategory( null,
$this->getLexemeValidatorFactory() );
+
+ $this->assertTrue( $changeOp->validate( $lexeme )->isValid() );
+ }
+
+ /**
+ * @dataProvider invalidEntityProvider
+ */
+ public function
testGivenNotALexicalCategoryProvider_applyThrowsException(
+ EntityDocument $entity
+ ) {
+ $this->setExpectedException( InvalidArgumentException::class );
+ $changeOp = new ChangeOpLexicalCategory(
+ new ItemId( 'Q234' ),
+ $this->getLexemeValidatorFactory()
+ );
+ $changeOp->apply( $entity );
+ }
+
+ public function
testGivenLexicalCategoryIsNull_applyRemovesLexicalCategoryAndSetsTheSummary() {
+ $lexicalCategory = new ItemId( 'Q234' );
+ $lexeme = new Lexeme( null, null, $lexicalCategory );
+ $summary = new Summary();
+
+ $changeOp = new ChangeOpLexicalCategory( null,
$this->getLexemeValidatorFactory() );
+ $changeOp->apply( $lexeme, $summary );
+
+ $this->assertNull( $lexeme->getLexicalCategory() );
+
+ $this->assertSame( 'remove', $summary->getActionName() );
+ $this->assertSame( [ 'Q234' ], $summary->getAutoSummaryArgs() );
+ }
+
+ public function
testGivenLexicalCategoryExists_applySetsLexicalCategoryAndSetsTheSummary() {
+ $lexicalCategory = new ItemId( 'Q234' );
+ $lexeme = new Lexeme( null, null, $lexicalCategory );
+ $summary = new Summary();
+
+ $changeOp = new ChangeOpLexicalCategory(
+ new ItemId( 'Q432' ),
+ $this->getLexemeValidatorFactory()
+ );
+
+ $changeOp->apply( $lexeme, $summary );
+
+ $this->assertSame( 'Q432',
$lexeme->getLexicalCategory()->getSerialization() );
+
+ $this->assertSame( 'set', $summary->getActionName() );
+ $this->assertSame( [ 'Q432' ], $summary->getAutoSummaryArgs() );
+ }
+
+ public function
testGivenLexicalCategoryIsNull_applySetsLexicalCategoryAndSetsTheSummary() {
+ $lexeme = new Lexeme();
+ $summary = new Summary();
+
+ $changeOp = new ChangeOpLexicalCategory(
+ new ItemId( 'Q234' ),
+ $this->getLexemeValidatorFactory()
+ );
+
+ $changeOp->apply( $lexeme, $summary );
+
+ $this->assertSame( 'Q234',
$lexeme->getLexicalCategory()->getSerialization() );
+
+ $this->assertSame( 'set', $summary->getActionName() );
+ $this->assertSame( [ 'Q234' ], $summary->getAutoSummaryArgs() );
+ }
+
+ public function
testGivenLexicalCategoryIsNullAndNoLexicalCategoryExists_applyMakesNoChange() {
+ $lexeme = new Lexeme();
+ $summary = new Summary();
+
+ $changeOp = new ChangeOpLexicalCategory( null,
$this->getLexemeValidatorFactory() );
+ $changeOp->apply( $lexeme, $summary );
+
+ $this->assertNull( $lexeme->getLexicalCategory() );
+ $this->assertNull( $summary->getActionName() );
+ }
+
+ private function getLexemeValidatorFactory() {
+ $mockProvider = new ChangeOpTestMockProvider( $this );
+ $validatorFactoryMockProvider = new
LexemeValidatorFactoryTestMockProvider();
+ return $validatorFactoryMockProvider->getLexemeValidatorFactory(
+ $this,
+ 10,
+ $mockProvider->getMockTermValidatorFactory(),
+ [ 'Q234', 'Q432' ]
+ );
+ }
+
+}
diff --git
a/tests/phpunit/mediawiki/ChangeOp/Deserialization/LexicalCategoryChangeOpDeserializerTest.php
b/tests/phpunit/mediawiki/ChangeOp/Deserialization/LexicalCategoryChangeOpDeserializerTest.php
new file mode 100644
index 0000000..bc4415f
--- /dev/null
+++
b/tests/phpunit/mediawiki/ChangeOp/Deserialization/LexicalCategoryChangeOpDeserializerTest.php
@@ -0,0 +1,117 @@
+<?php
+
+namespace Wikibase\Lexeme\Tests\ChangeOp\Deserialization;
+
+use ValueValidators\StringValidator;
+use Wikibase\DataModel\Entity\ItemId;
+use
Wikibase\Lexeme\ChangeOp\Deserialization\LexicalCategoryChangeOpDeserializer;
+use Wikibase\Lexeme\DataModel\Lexeme;
+use Wikibase\Lexeme\DataModel\LexemeId;
+use
Wikibase\Lexeme\Tests\MediaWiki\Validators\LexemeValidatorFactoryTestMockProvider;
+use Wikibase\Lexeme\Validators\LexemeValidatorFactory;
+use Wikibase\Repo\ChangeOp\Deserialization\ChangeOpDeserializationException;
+use Wikibase\Repo\Tests\ChangeOp\ChangeOpTestMockProvider;
+use Wikibase\StringNormalizer;
+
+/**
+ * @covers
Wikibase\Lexeme\ChangeOp\Deserialiazation\LexicalCategoryChangeOpDeserializer
+ *
+ * @group WikibaseLexeme
+ *
+ * @license GPL-2.0+
+ */
+class LexicalCategoryChangeOpDeserializerTest extends
\PHPUnit_Framework_TestCase {
+
+ private function newLexicalCategoryChangeOpDeserializer() {
+ $mockProvider = new ChangeOpTestMockProvider( $this );
+ $validatorFactoryMockProvider = new
LexemeValidatorFactoryTestMockProvider();
+ return new LexicalCategoryChangeOpDeserializer(
+
$validatorFactoryMockProvider->getLexemeValidatorFactory(
+ $this,
+ 10,
+ $mockProvider->getMockTermValidatorFactory()
+ ),
+ new StringNormalizer(),
+ new StringValidator()
+ );
+ }
+
+ public function
testGivenLexicalCategorySerializationIsNotString_exceptionIsThrown() {
+ $deserializer = $this->newLexicalCategoryChangeOpDeserializer();
+
+ $this->setExpectedException(
ChangeOpDeserializationException::class );
+
+ $deserializer->createEntityChangeOp( [ 'lexical_category' => []
] );
+ }
+
+ public function
testGivenLexicalCategorySerializationIsInvalid_exceptionIsThrown() {
+
+ $lexemeValidatorFactory = $this->getMockBuilder(
LexemeValidatorFactory::class )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $deserializer = new LexicalCategoryChangeOpDeserializer(
+ $lexemeValidatorFactory,
+ new StringNormalizer(),
+ new StringValidator()
+ );
+
+ $this->setExpectedException(
ChangeOpDeserializationException::class );
+
+ // Invalid ItemId (not a Q###)
+ $deserializer->createEntityChangeOp( [ 'lexical_category' =>
'invalid item id' ] );
+ }
+
+ public function
testGivenRequestLexicalCategoryAndNoLexicalCategory_changeOpAddsLexicalCategory()
{
+ $lexeme = new Lexeme( new LexemeId( 'L100' ) );
+
+ $deserializer = $this->newLexicalCategoryChangeOpDeserializer();
+
+ $changeOp = $deserializer->createEntityChangeOp(
+ [ 'lexical_category' => 'q100' ]
+ );
+
+ $changeOp->apply( $lexeme );
+ $this->assertSame( 'Q100',
$lexeme->getLexicalCategory()->getSerialization() );
+ }
+
+ public function
testGivenRequestWithLexicalCategoryExists_changeOpSetsLexicalCategoryToNewValue()
{
+ $lexeme = new Lexeme( new LexemeId( 'L100' ), null, null, new
ItemId( 'Q100' ) );
+
+ $deserializer = $this->newLexicalCategoryChangeOpDeserializer();
+
+ $changeOp = $deserializer->createEntityChangeOp(
+ [ 'lexical_category' => 'q200' ]
+ );
+
+ $changeOp->apply( $lexeme );
+ $this->assertSame( 'Q200',
$lexeme->getLexicalCategory()->getSerialization() );
+ }
+
+ public function
testGivenRemoveRequestLexicalCategoryExists_changeOpRemovesLexicalCategory() {
+ $lexeme = new Lexeme( new LexemeId( 'L100' ), null, null, new
ItemId( 'Q100' ) );
+
+ $deserializer = $this->newLexicalCategoryChangeOpDeserializer();
+
+ $changeOp = $deserializer->createEntityChangeOp(
+ [ 'lexical_category' => '' ]
+ );
+
+ $changeOp->apply( $lexeme );
+ $this->assertNull( $lexeme->getLexicalCategory() );
+ }
+
+ public function
testRequestRemoveLexicalCategoryDoesNotExist_changeOpDoesNothing() {
+ $lexeme = new Lexeme( new LexemeId( 'L100' ) );
+
+ $deserializer = $this->newLexicalCategoryChangeOpDeserializer();
+
+ $changeOp = $deserializer->createEntityChangeOp(
+ [ 'lexical_category' => '' ]
+ );
+
+ $changeOp->apply( $lexeme );
+ $this->assertNull( $lexeme->getLexicalCategory() );
+ }
+
+}
diff --git a/tests/phpunit/mediawiki/Validators/LexemeValidatorFactoryTest.php
b/tests/phpunit/mediawiki/Validators/LexemeValidatorFactoryTest.php
index 676a839..090b979 100644
--- a/tests/phpunit/mediawiki/Validators/LexemeValidatorFactoryTest.php
+++ b/tests/phpunit/mediawiki/Validators/LexemeValidatorFactoryTest.php
@@ -129,7 +129,7 @@
/**
* @dataProvider invalidLanguageValidatorArgsProvider
*/
- public function testGiveninputIsInvalid_validatorThrowsException(
$language ) {
+ public function
testGivenLanguageInputIsInvalid_validatorThrowsException( $language ) {
$this->setExpectedException( InvalidArgumentException::class );
$languageValidator = $this
->getLexemeValidatorFactory( 10, null, [ 'Q123' ] )
@@ -145,6 +145,68 @@
];
}
+ public function testGetLexicalCategoryValidatorValid() {
+ $lexicalCategoryValidator = $this
+ ->getLexemeValidatorFactory( 10, null, [ 'Q234' ] )
+ ->getLexicalCategoryValidator();
+
+ $this->assertTrue(
+ $lexicalCategoryValidator->validate( new ItemId( 'Q234'
) )->isValid()
+ );
+ }
+
+ public function
testGetLexicalCategoryValidatorEmptyLexicalCategoryValid() {
+ $lexicalCategoryValidator = $this
+ ->getLexemeValidatorFactory( 10, null, [ 'Q234' ] )
+ ->getLexicalCategoryValidator();
+
+ $this->assertTrue(
+ $lexicalCategoryValidator->validate( null )->isValid()
+ );
+ }
+
+ /**
+ * @dataProvider lexicalCategoryProviderInvalid
+ */
+ public function testGetLexicalCategoryValidatorInvalid(
$lexicalCategory ) {
+ $lexicalCategoryValidator = $this
+ ->getLexemeValidatorFactory( 10, null, [ 'Q234' ] )
+ ->getLexicalCategoryValidator();
+
+ $this->assertFalse(
+ $lexicalCategoryValidator->validate( $lexicalCategory
)->isValid()
+ );
+ }
+
+ public function lexicalCategoryProviderInvalid() {
+ return [
+ 'not existing item' => [ new ItemId( 'Q432' ) ],
+ 'property' => [ new PropertyId( 'P321' ) ],
+ 'lexeme' => [ new LexemeId( 'L321' ) ],
+ ];
+ }
+
+ /**
+ * @dataProvider invalidLanguageValidatorArgsProvider
+ */
+ public function
testGivenLexicalCategoryInputIsInvalid_validatorThrowsException(
+ $lexicalCategory
+ ) {
+ $this->setExpectedException( InvalidArgumentException::class );
+ $lexicalCategoryValidator = $this
+ ->getLexemeValidatorFactory( 10, null, [ 'Q234' ] )
+ ->getLexicalCategoryValidator();
+ $lexicalCategoryValidator->validate( $lexicalCategory
)->isValid();
+ }
+
+ public function invalidLexicalCategoryValidatorArgsProvider() {
+ return [
+ [ false ],
+ [ '' ],
+ [ 'Q234' ]
+ ];
+ }
+
/**
* @param int $maxLength
* @param TermValidatorFactory|null $termValidatorFactory
--
To view, visit https://gerrit.wikimedia.org/r/340752
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I7ab98d3b7f8844fba6245dd859d7aa87cd0394b6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseLexeme
Gerrit-Branch: master
Gerrit-Owner: Ladsgroup <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits