jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/330231 )
Change subject: SpecialNewLexeme refactoring and addition of input validation ...................................................................... SpecialNewLexeme refactoring and addition of input validation * added separate key for lemma language label * simplified code in special page itself * added input validation for all fields Bug: T150205 Change-Id: I2d0ee034ae8ccb6af26ab287de443d6189057d4b --- M i18n/en.json M i18n/qqq.json M src/Specials/SpecialNewLexeme.php M tests/phpunit/mediawiki/Specials/SpecialNewLexemeTest.php 4 files changed, 181 insertions(+), 349 deletions(-) Approvals: jenkins-bot: Verified Thiemo Mättig (WMDE): Looks good to me, approved diff --git a/i18n/en.json b/i18n/en.json index ae92306..b85965d 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -6,6 +6,7 @@ "special-newlexeme": "Create a new lexeme", "wikibase-newlexeme-fieldset": "Create a new lexeme", "wikibase-newlexeme-lemma": "Lemma", + "wikibase-newlexeme-lemma-language": "Language of lemma", "wikibase-lemma-edit-placeholder": "Enter the lemma", "wikibase-newlexeme-lexicalcategory": "Lexical category", "wikibase-lexicalcategory-edit-placeholder": "Enter the lexical category item ID e.g. Q10", diff --git a/i18n/qqq.json b/i18n/qqq.json index d65eccb..324220c 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -11,6 +11,7 @@ "special-newlexeme": "Title of Special:NewLexeme", "wikibase-newlexeme-fieldset": "Title of the form in Special:NewLexeme", "wikibase-newlexeme-lemma": "Name for \"Lemma\"\n{{Identical|Lemma}}", + "wikibase-newlexeme-lemma-language": "Name for \"Lemma\" language", "wikibase-lemma-edit-placeholder": "Placeholder content for lemma", "wikibase-newlexeme-lexicalcategory": "Name for \"lexical category\"", "wikibase-lexicalcategory-edit-placeholder": "Placeholder content for lexical category", diff --git a/src/Specials/SpecialNewLexeme.php b/src/Specials/SpecialNewLexeme.php index 182ebbb..48a1572 100644 --- a/src/Specials/SpecialNewLexeme.php +++ b/src/Specials/SpecialNewLexeme.php @@ -2,9 +2,6 @@ namespace Wikibase\Lexeme\Specials; -use Html; -use HTMLForm; -use InvalidArgumentException; use Status; use Wikibase\CopyrightMessageBuilder; use Wikibase\DataModel\Entity\EntityDocument; @@ -12,345 +9,163 @@ use Wikibase\DataModel\Term\Term; use Wikibase\DataModel\Term\TermList; use Wikibase\Lexeme\DataModel\Lexeme; -use Wikibase\Lib\LanguageNameLookup; +use Wikibase\Repo\Specials\HTMLForm\HTMLContentLanguageField; +use Wikibase\Repo\Specials\HTMLForm\HTMLTrimmedTextField; +use Wikibase\Repo\Specials\SpecialNewEntity; use Wikibase\Repo\WikibaseRepo; -use Wikibase\Repo\Specials\SpecialWikibaseRepoPage; use Wikibase\Repo\Specials\SpecialPageCopyrightView; use Wikibase\Summary; -use Wikibase\View\LanguageDirectionalityLookup; -use Wikimedia\Assert\Assert; /** - * Page for creating new Lexeme entities that contain a Fingerprint. - * Mostly copied from SpecialNewEntity + * Page for creating new Lexeme entities. * * @license GPL-2.0+ */ -class SpecialNewLexeme extends SpecialWikibaseRepoPage { +class SpecialNewLexeme extends SpecialNewEntity { - /** - * Contains pieces of the sub-page name of this special page if a subpage was called. - * E.g. [ 'a', 'b' ] in case of 'Special:NewLexeme/a/b' - * @var string[]|null - */ - protected $parts = null; - - /** - * @var string|null - */ - private $lemma; - - /** - * @var string - */ - private $contentLanguageCode; - - /** - * @var string[] - */ - private $languageCodes; - - /** - * @var SpecialPageCopyrightView - */ - private $copyrightView; - - /** - * @var LanguageDirectionalityLookup - */ - private $languageDirectionalityLookup; - - /** - * @var string - */ - private $lexicalCategory; - - /** - * @var string - */ - private $language; - - /** - * @var LanguageNameLookup - */ - private $languageNameLookup; + const FIELD_LEXEME_LANGUAGE = 'lexeme-language'; + const FIELD_LEXICAL_CATEGORY = 'lexicalcategory'; + const FIELD_LEMMA = 'lemma'; + const FIELD_LEMMA_LANGUAGE = 'lemma-language'; public function __construct() { - parent::__construct( 'NewLexeme', 'createpage' ); $wikibaseRepo = WikibaseRepo::getDefaultInstance(); $settings = $wikibaseRepo->getSettings(); - $this->copyrightView = new SpecialPageCopyrightView( + $copyrightView = new SpecialPageCopyrightView( new CopyrightMessageBuilder(), $settings->getSetting( 'dataRightsUrl' ), $settings->getSetting( 'dataRightsText' ) ); - $this->languageCodes = $wikibaseRepo->getTermsLanguages()->getLanguages(); - $this->languageDirectionalityLookup = $wikibaseRepo->getLanguageDirectionalityLookup(); - $this->languageNameLookup = $wikibaseRepo->getLanguageNameLookup(); - } - public function doesWrites() { - return true; - } - - /** - * @see SpecialWikibasePage::execute - * - * @param string|null $subPage - */ - public function execute( $subPage ) { - parent::execute( $subPage ); - - $this->checkPermissions(); - $this->checkBlocked(); - $this->checkReadOnly(); - - $this->parts = ( $subPage === '' ? [] : explode( '/', $subPage ) ); - $this->prepareArguments(); - - $out = $this->getOutput(); - - $uiLanguageCode = $this->getLanguage()->getCode(); - - if ( $this->getRequest()->wasPosted() - && $this->getUser()->matchEditToken( $this->getRequest()->getVal( 'wpEditToken' ) ) - ) { - if ( $this->hasSufficientArguments() ) { - $entity = $this->createEntity(); - - $status = $this->modifyEntity( $entity ); - - if ( $status->isGood() ) { - $summary = new Summary( 'wbeditentity', 'create' ); - $summary->setLanguage( $uiLanguageCode ); - $summary->addAutoSummaryArgs( $this->lemma ); - - $status = $this->saveEntity( - $entity, - $summary, - $this->getRequest()->getVal( 'wpEditToken' ), - EDIT_NEW - ); - var_dump( 'can be saved' ); - $out = $this->getOutput(); - - if ( !$status->isOK() ) { - var_dump( 'here' ); - $out->addHTML( '<div class="error">' ); - $out->addWikiText( $status->getWikiText() ); - $out->addHTML( '</div>' ); - } elseif ( $entity !== null ) { - $title = $this->getEntityTitle( $entity->getId() ); - $entityUrl = $title->getFullURL(); - $this->getOutput()->redirect( $entityUrl ); - } - } else { - $out->addHTML( '<div class="error">' ); - $out->addHTML( $status->getHTML() ); - $out->addHTML( '</div>' ); - } - } - } - - $this->getOutput()->addModuleStyles( [ 'wikibase.special' ] ); - - foreach ( $this->getWarnings() as $warning ) { - $out->addHTML( Html::element( 'div', [ 'class' => 'warning' ], $warning ) ); - } - - $this->createForm( $this->getLegend(), $this->additionalFormElements() ); - } - - /** - * Tries to extract argument values from web request or of the page's sub-page parts - * - * Trimming argument values from web request. - */ - protected function prepareArguments() { - $lemma = $this->getRequest()->getVal( - 'lemma', - isset( $this->parts[0] ) ? $this->parts[0] : '' - ); - $this->lemma = $this->stringNormalizer->trimToNFC( $lemma ); - - $lexicalCategory = $this->getRequest()->getVal( - 'lexicalcategory', - isset( $this->parts[0] ) ? $this->parts[0] : '' - ); - $this->lexicalCategory = $this->stringNormalizer->trimToNFC( $lexicalCategory ); - - $language = $this->getRequest()->getVal( - 'lexeme-language', - isset( $this->parts[0] ) ? $this->parts[0] : '' - ); - $this->language = $this->stringNormalizer->trimToNFC( $language ); - - $this->contentLanguageCode = $this->getRequest()->getVal( - 'lemma-language', $this->getLanguage()->getCode() - ); - } - - /** - * Checks whether required arguments are set sufficiently - * - * @return bool - */ - protected function hasSufficientArguments() { - return $this->lemma !== ''; - } - - /** - * @see SpecialNewEntity::createEntity - */ - protected function createEntity() { - return new Lexeme(); - } - - /** - * Attempt to modify entity - * - * @param EntityDocument &$entity - * - * @throws InvalidArgumentException - * @return Status - */ - protected function modifyEntity( EntityDocument &$entity ) { - /** @var Lexeme $entity */ - Assert::parameterType( Lexeme::class, $entity, '$entity' ); - - $status = Status::newGood(); - - $languageCode = $this->contentLanguageCode; - if ( !in_array( $languageCode, $this->languageCodes ) ) { - $status->error( 'wikibase-newitem-not-recognized-language' ); - return $status; - } - - $lemmas = new TermList( [ new Term( $languageCode, $this->lemma ) ] ); - $entity->setLemmas( $lemmas ); - - if ( $this->lexicalCategory !== '' ) { - $entity->setLexicalCategory( new ItemId( $this->lexicalCategory ) ); - } - - if ( $this->language !== '' ) { - $entity->setLanguage( new ItemId( $this->language ) ); - } - - return $status; - } - - /** - * Get options for language selector - * - * @return string[] - */ - private function getLanguageOptions() { - $languageOptions = []; - foreach ( $this->languageCodes as $code ) { - $languageName = $this->languageNameLookup->getName( $code ); - $languageOptions["$languageName ($code)"] = $code; - } - return $languageOptions; + parent::__construct( 'NewLexeme', 'createpage', $copyrightView ); } /** * @return array[] */ - protected function additionalFormElements() { - $this->getOutput()->addModules( 'wikibase.special.languageLabelDescriptionAliases' ); - - $langCode = $this->contentLanguageCode; - $langDir = $this->languageDirectionalityLookup->getDirectionality( $this->contentLanguageCode ); + protected function getFormFields() { return [ - 'lemma-language' => [ - 'name' => 'lemma-language', - 'options' => $this->getLanguageOptions(), - 'default' => $langCode, - 'type' => 'combobox', + self::FIELD_LEMMA_LANGUAGE => [ + 'name' => self::FIELD_LEMMA_LANGUAGE, + 'class' => HTMLContentLanguageField::class, 'id' => 'wb-newlexeme-lemma-language', - 'label-message' => 'wikibase-newlexeme-language' + 'label-message' => 'wikibase-newlexeme-lemma-language', ], - 'lemma' => [ - 'name' => 'lemma', - 'default' => $this->lemma ?: '', - 'type' => 'text', + self::FIELD_LEMMA => [ + 'name' => self::FIELD_LEMMA, + 'class' => HTMLTrimmedTextField::class, 'id' => 'wb-newlexeme-lemma', - 'lang' => $langCode, - 'dir' => $langDir, - 'placeholder' => $this->msg( - 'wikibase-lemma-edit-placeholder' - )->text(), + 'required' => true, + 'placeholder-message' => 'wikibase-lemma-edit-placeholder', 'label-message' => 'wikibase-newlexeme-lemma' ], - 'lexicalcategory' => [ - 'name' => 'lexicalcategory', - 'default' => $this->lexicalCategory, + self::FIELD_LEXICAL_CATEGORY => [ + 'name' => self::FIELD_LEXICAL_CATEGORY, 'type' => 'text', 'id' => 'wb-newlexeme-lexicalCategory', - 'lang' => $langCode, - 'dir' => $langDir, - 'placeholder' => $this->msg( - 'wikibase-lexicalcategory-edit-placeholder' - )->text(), - 'label-message' => 'wikibase-newlexeme-lexicalcategory' + 'placeholder-message' => 'wikibase-lexicalcategory-edit-placeholder', + 'label-message' => 'wikibase-newlexeme-lexicalcategory', + 'validation-callback' => function ( $value ) { + if ( empty( $value ) ) { + return true; + } + + if ( !preg_match( ItemId::PATTERN, $value ) ) { + // FIXME add text in language files + return $this->msg( 'invalid format' ); + } + + $entityLookup = WikibaseRepo::getDefaultInstance()->getEntityLookup(); + if ( !$entityLookup->hasEntity( new ItemId( $value ) ) ) { + // FIXME add text in language files + return $this->msg( 'does not exist' ); + } + + return true; + }, ], - 'lexeme-language' => [ - 'name' => 'lexeme-language', - 'default' => $this->language, + self::FIELD_LEXEME_LANGUAGE => [ + 'name' => self::FIELD_LEXEME_LANGUAGE, 'type' => 'text', 'id' => 'wb-newlexeme-lexeme-language', - 'lang' => $langCode, - 'dir' => $langDir, - 'placeholder' => $this->msg( - 'wikibase-language-edit-placeholder' - )->text(), - 'label-message' => 'wikibase-newlexeme-language' + 'placeholder-message' => 'wikibase-language-edit-placeholder', + 'label-message' => 'wikibase-newlexeme-language', + 'validation-callback' => function ( $value ) { + if ( empty( $value ) ) { + return true; + } + + if ( !preg_match( ItemId::PATTERN, $value ) ) { + // FIXME add text in language files + return $this->msg( 'invalid format' ); + } + + $entityLookup = WikibaseRepo::getDefaultInstance()->getEntityLookup(); + if ( !$entityLookup->hasEntity( new ItemId( $value ) ) ) { + // FIXME add text in language files + return $this->msg( 'does not exist' ); + } + + return true; + }, ] ]; } /** - * Building the HTML form for creating a new item. + * @param array $formData * - * @param string|null $legend initial value for the label input box - * @param array[] $additionalFormElements initial value for the description input box + * @return Status */ - private function createForm( $legend = null, array $additionalFormElements ) { - $this->addCopyrightText(); - - HTMLForm::factory( 'ooui', $additionalFormElements, $this->getContext() ) - ->setId( 'wb-newlexeme-form1' ) - ->setSubmitID( 'wb-newlexeme-submit' ) - ->setSubmitName( 'submit' ) - ->setSubmitTextMsg( 'wikibase-newlexeme-submit' ) - ->setWrapperLegendMsg( $legend ) - ->setSubmitCallback( function () {// no-op - } )->show(); + protected function validateFormData( array $formData ) { + return Status::newGood(); } /** - * @todo could factor this out into a special page form builder and renderer + * @param array $formData + * + * @return EntityDocument */ - private function addCopyrightText() { - $html = $this->copyrightView->getHtml( $this->getLanguage(), 'wikibase-newlexeme-submit' ); + protected function createEntityFromFormData( array $formData ) { + $entity = new Lexeme(); + $lemmaLanguage = $formData[ self::FIELD_LEMMA_LANGUAGE ]; - $this->getOutput()->addHTML( $html ); + $lemmas = new TermList( [ new Term( $lemmaLanguage, $formData[ self::FIELD_LEMMA ] ) ] ); + $entity->setLemmas( $lemmas ); + + if ( !empty( $formData[ self::FIELD_LEXICAL_CATEGORY ] ) ) { + $entity->setLexicalCategory( new ItemId( $formData[ self::FIELD_LEXICAL_CATEGORY ] ) ); + } + + if ( !empty( $formData[ self::FIELD_LEXEME_LANGUAGE ] ) ) { + $entity->setLanguage( new ItemId( $formData[ self::FIELD_LEXEME_LANGUAGE ] ) ); + } + + return $entity; } /** - * @see SpecialNewEntity::getLegend() + * @param Lexeme $lexeme + * + * @return Summary */ + protected function createSummary( $lexeme ) { + $uiLanguageCode = $this->getLanguage()->getCode(); + + $summary = new Summary( 'wbeditentity', 'create' ); + $summary->setLanguage( $uiLanguageCode ); + /** @var Term|null $lemmaTerm */ + $lemmaTerm = $lexeme->getLemmas()->getIterator()->current(); + $summary->addAutoSummaryArgs( $lemmaTerm->getText() ); + + return $summary; + } + protected function getLegend() { return $this->msg( 'wikibase-newlexeme-fieldset' ); } - /** - * @see SpecialCreateEntity::getWarnings - * - * @return string[] - */ protected function getWarnings() { if ( $this->getUser()->isAnon() ) { return [ diff --git a/tests/phpunit/mediawiki/Specials/SpecialNewLexemeTest.php b/tests/phpunit/mediawiki/Specials/SpecialNewLexemeTest.php index 5101e88..0822d3e 100644 --- a/tests/phpunit/mediawiki/Specials/SpecialNewLexemeTest.php +++ b/tests/phpunit/mediawiki/Specials/SpecialNewLexemeTest.php @@ -2,12 +2,16 @@ namespace Wikibase\Lexeme\Tests\Specials; +use User; use Wikibase\DataModel\Entity\EntityDocument; use Wikibase\DataModel\Entity\EntityId; +use Wikibase\DataModel\Entity\Item; +use Wikibase\DataModel\Entity\ItemId; use Wikibase\Lexeme\DataModel\Lexeme; use Wikibase\Lexeme\DataModel\LexemeId; use Wikibase\Lexeme\Specials\SpecialNewLexeme; use Wikibase\Repo\Tests\Specials\SpecialNewEntityTest; +use Wikibase\Repo\WikibaseRepo; /** * @covers Wikibase\Lexeme\Specials\SpecialNewLexeme @@ -16,16 +20,12 @@ * @group WikibaseRepo * @group SpecialPage * @group WikibaseSpecialPage + * @group Database * * @license GPL-2.0+ * @author Amir Sarabadani <ladsgr...@gmail.com> */ class SpecialNewLemexeTest extends SpecialNewEntityTest { - - const FIELD_LEMMA_LANGUAGE = 'lemma-language'; - const FIELD_LEMMA = 'lemma'; - const FIELD_LEXICAL_CATEGORY = 'lexicalcategory'; - const FIELD_LEXEME_LANGUAGE = 'lexeme-language'; protected function newSpecialPage() { return new SpecialNewLexeme(); @@ -35,109 +35,111 @@ list( $html ) = $this->executeSpecialPage(); - $this->assertHtmlContainsInputWithName( $html, self::FIELD_LEMMA_LANGUAGE ); - $this->assertHtmlContainsInputWithName( $html, self::FIELD_LEMMA ); - $this->assertHtmlContainsInputWithName( $html, self::FIELD_LEXICAL_CATEGORY ); - $this->assertHtmlContainsInputWithName( $html, self::FIELD_LEXEME_LANGUAGE ); + $this->assertHtmlContainsInputWithName( $html, SpecialNewLexeme::FIELD_LEMMA_LANGUAGE ); + $this->assertHtmlContainsInputWithName( $html, SpecialNewLexeme::FIELD_LEMMA ); + $this->assertHtmlContainsInputWithName( $html, SpecialNewLexeme::FIELD_LEXICAL_CATEGORY ); + $this->assertHtmlContainsInputWithName( $html, SpecialNewLexeme::FIELD_LEXEME_LANGUAGE ); $this->assertHtmlContainsSubmitControl( $html ); } public function provideValidEntityCreationRequests() { + + $existingItemId = 'Q1'; + $this->givenItemExists( $existingItemId ); + return [ 'lemma is set' => [ [ - self::FIELD_LEMMA_LANGUAGE => 'en', - self::FIELD_LEMMA => 'some lemma text', - self::FIELD_LEXICAL_CATEGORY => '', - self::FIELD_LEXEME_LANGUAGE => '', + SpecialNewLexeme::FIELD_LEMMA_LANGUAGE => 'en', + SpecialNewLexeme::FIELD_LEMMA => 'some lemma text', + SpecialNewLexeme::FIELD_LEXICAL_CATEGORY => '', + SpecialNewLexeme::FIELD_LEXEME_LANGUAGE => '', ], ], 'another lemma language' => [ [ - self::FIELD_LEMMA_LANGUAGE => 'fr', - self::FIELD_LEMMA => 'some lemma text', - self::FIELD_LEXICAL_CATEGORY => '', - self::FIELD_LEXEME_LANGUAGE => '', + SpecialNewLexeme::FIELD_LEMMA_LANGUAGE => 'fr', + SpecialNewLexeme::FIELD_LEMMA => 'some lemma text', + SpecialNewLexeme::FIELD_LEXICAL_CATEGORY => '', + SpecialNewLexeme::FIELD_LEXEME_LANGUAGE => '', ], ], 'lexical category is set' => [ [ - self::FIELD_LEMMA_LANGUAGE => 'en', - self::FIELD_LEMMA => 'some lemma text', - self::FIELD_LEXICAL_CATEGORY => 'Q1', - self::FIELD_LEXEME_LANGUAGE => '', + SpecialNewLexeme::FIELD_LEMMA_LANGUAGE => 'en', + SpecialNewLexeme::FIELD_LEMMA => 'some lemma text', + SpecialNewLexeme::FIELD_LEXICAL_CATEGORY => $existingItemId, + SpecialNewLexeme::FIELD_LEXEME_LANGUAGE => '', ], ], 'lexeme language is set' => [ [ - self::FIELD_LEMMA_LANGUAGE => 'en', - self::FIELD_LEMMA => 'some lemma text', - self::FIELD_LEXICAL_CATEGORY => '', - self::FIELD_LEXEME_LANGUAGE => 'Q1', + SpecialNewLexeme::FIELD_LEMMA_LANGUAGE => 'en', + SpecialNewLexeme::FIELD_LEMMA => 'some lemma text', + SpecialNewLexeme::FIELD_LEXICAL_CATEGORY => '', + SpecialNewLexeme::FIELD_LEXEME_LANGUAGE => $existingItemId, ], ], ]; } public function provideInvalidEntityCreationRequests() { - $this->markTestSkipped( "Fixes in the code needed" ); - $nonexistentItemId = 'Q100'; return [ 'unknown language' => [ [ - self::FIELD_LEMMA_LANGUAGE => 'some-weird-language', - self::FIELD_LEMMA => 'some lemma', - self::FIELD_LEXICAL_CATEGORY => '', - self::FIELD_LEXEME_LANGUAGE => '', + SpecialNewLexeme::FIELD_LEMMA_LANGUAGE => 'some-weird-language', + SpecialNewLexeme::FIELD_LEMMA => 'some lemma', + SpecialNewLexeme::FIELD_LEXICAL_CATEGORY => '', + SpecialNewLexeme::FIELD_LEXEME_LANGUAGE => '', ], 'language code was not recognized', ], 'empty lemma' => [ [ - self::FIELD_LEMMA_LANGUAGE => 'en', - self::FIELD_LEMMA => '', - self::FIELD_LEXICAL_CATEGORY => '', - self::FIELD_LEXEME_LANGUAGE => '', + SpecialNewLexeme::FIELD_LEMMA_LANGUAGE => 'en', + SpecialNewLexeme::FIELD_LEMMA => '', + SpecialNewLexeme::FIELD_LEXICAL_CATEGORY => '', + SpecialNewLexeme::FIELD_LEXEME_LANGUAGE => '', ], - 'you need to fill', + 'value is required', ], 'lexical category has wrong format' => [ [ - self::FIELD_LEMMA_LANGUAGE => 'en', - self::FIELD_LEMMA => 'some lemma', - self::FIELD_LEXICAL_CATEGORY => 'x', - self::FIELD_LEXEME_LANGUAGE => '', + SpecialNewLexeme::FIELD_LEMMA_LANGUAGE => 'en', + SpecialNewLexeme::FIELD_LEMMA => 'some lemma', + SpecialNewLexeme::FIELD_LEXICAL_CATEGORY => 'x', + SpecialNewLexeme::FIELD_LEXEME_LANGUAGE => '', ], - '???', + 'invalid format', ], 'lexeme language has wrong format' => [ [ - self::FIELD_LEMMA_LANGUAGE => 'en', - self::FIELD_LEMMA => 'some lemma', - self::FIELD_LEXICAL_CATEGORY => '', - self::FIELD_LEXEME_LANGUAGE => 'x', + SpecialNewLexeme::FIELD_LEMMA_LANGUAGE => 'en', + SpecialNewLexeme::FIELD_LEMMA => 'some lemma', + SpecialNewLexeme::FIELD_LEXICAL_CATEGORY => '', + SpecialNewLexeme::FIELD_LEXEME_LANGUAGE => 'x', ], - '???', + 'invalid format', ], 'lexical category does not exist' => [ [ - self::FIELD_LEMMA_LANGUAGE => 'en', - self::FIELD_LEMMA => 'some lemma', - self::FIELD_LEXICAL_CATEGORY => $nonexistentItemId, - self::FIELD_LEXEME_LANGUAGE => '', + SpecialNewLexeme::FIELD_LEMMA_LANGUAGE => 'en', + SpecialNewLexeme::FIELD_LEMMA => 'some lemma', + SpecialNewLexeme::FIELD_LEXICAL_CATEGORY => $nonexistentItemId, + SpecialNewLexeme::FIELD_LEXEME_LANGUAGE => '', ], - '???', + 'does not exist', ], 'lexeme language does not exist' => [ [ - self::FIELD_LEMMA_LANGUAGE => 'en', - self::FIELD_LEMMA => 'some lemma', - self::FIELD_LEXICAL_CATEGORY => '', - self::FIELD_LEXEME_LANGUAGE => $nonexistentItemId, + SpecialNewLexeme::FIELD_LEMMA_LANGUAGE => 'en', + SpecialNewLexeme::FIELD_LEMMA => 'some lemma', + SpecialNewLexeme::FIELD_LEXICAL_CATEGORY => '', + SpecialNewLexeme::FIELD_LEXEME_LANGUAGE => $nonexistentItemId, ], - '???', + 'does not exist', ], ]; } @@ -156,25 +158,38 @@ $this->assertInstanceOf( Lexeme::class, $entity ); /** @var Lexeme $entity */ - $language = $form[ self::FIELD_LEMMA_LANGUAGE ]; + $language = $form[ SpecialNewLexeme::FIELD_LEMMA_LANGUAGE ]; self::assertEquals( - $form[ self::FIELD_LEMMA ], + $form[ SpecialNewLexeme::FIELD_LEMMA ], $entity->getLemmas()->getByLanguage( $language )->getText() ); - if ( $form[ self::FIELD_LEXICAL_CATEGORY ] ) { + if ( $form[ SpecialNewLexeme::FIELD_LEXICAL_CATEGORY ] ) { self::assertEquals( - $form[ self::FIELD_LEXICAL_CATEGORY ], + $form[ SpecialNewLexeme::FIELD_LEXICAL_CATEGORY ], $entity->getLexicalCategory()->getSerialization() ); } - if ( $form[ self::FIELD_LEXEME_LANGUAGE ] ) { + if ( $form[ SpecialNewLexeme::FIELD_LEXEME_LANGUAGE ] ) { self::assertEquals( - $form[ self::FIELD_LEXEME_LANGUAGE ], + $form[ SpecialNewLexeme::FIELD_LEXEME_LANGUAGE ], $entity->getLanguage()->getSerialization() ); } } + /** + * @param string $itemId + */ + private function givenItemExists( $itemId ) { + $wikibaseRepo = WikibaseRepo::getDefaultInstance(); + $existingItem = new Item( new ItemId( $itemId ) ); + + $editEntityFactory = $wikibaseRepo->newEditEntityFactory() + ->newEditEntity( new User(), $existingItem ); + + $editEntityFactory->attemptSave( '', EDIT_NEW, false ); + } + } -- To view, visit https://gerrit.wikimedia.org/r/330231 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I2d0ee034ae8ccb6af26ab287de443d6189057d4b Gerrit-PatchSet: 5 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) <aleksey.bekh-iva...@wikimedia.de> Gerrit-Reviewer: Aleksey Bekh-Ivanov (WMDE) <aleksey.bekh-iva...@wikimedia.de> Gerrit-Reviewer: Ladsgroup <ladsgr...@gmail.com> Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.maet...@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