Ladsgroup has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/333589 )
Change subject: [WIP] CI tests for Lexeme Edit Entity API ...................................................................... [WIP] CI tests for Lexeme Edit Entity API Bug: T155990 Change-Id: Iad2547d147c26c9eb1d2148ed8cbdbd27a389c3a --- A tests/phpunit/mediawiki/Api/LexemeEditEntityTest.php 1 file changed, 137 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/89/333589/1 diff --git a/tests/phpunit/mediawiki/Api/LexemeEditEntityTest.php b/tests/phpunit/mediawiki/Api/LexemeEditEntityTest.php new file mode 100644 index 0000000..249bd56 --- /dev/null +++ b/tests/phpunit/mediawiki/Api/LexemeEditEntityTest.php @@ -0,0 +1,137 @@ +<?php + +namespace Wikibase\Lexeme\Tests\Api; + +use Wikibase\Repo\Tests\Api\EntityTestHelper; +use Wikibase\Repo\Tests\Api\WikibaseApiTestCase; + +/** + * @covers Wikibase\Lexeme\ChangeOp\LexemeChangeOpDeserializer + * + * @license GPL-2.0+ + * @author Amir Sarabadani <[email protected]> + * + * @group API + * @group Wikibase + * @group WikibaseAPI + * @group BreakingTheSlownessBarrier + * @group Database + * @group medium + */ +class LexemeEditEntityTest extends WikibaseApiTestCase { + + /** + * @var string[] + */ + private static $idMap; + + /** + * @var bool + */ + private static $hasSetup; + + protected function setUp() { + parent::setUp(); + + if ( !isset( self::$hasSetup ) ) { + $this->initTestEntities( [ 'Apple' ], self::$idMap ); + self::$idMap['%Apple%'] = EntityTestHelper::getId( 'Apple' ); + } + self::$hasSetup = true; + } + + /** + * Provide data for a sequence of requests that will work when run in order + */ + public function provideData() { + return [ + 'make a null edit' => [ + 'p' => [ 'data' => '{}' ], + 'e' => [ 'nochange' => '' ] + ], + // It should not make any changes for now but it will soon + 'clear a lexeme with no value' => [ + 'p' => [ 'data' => '{}', 'clear' => '' ], + 'e' => [ 'nochange' => '' ] + ], + ]; + } + + /** + * Applies self::$idMap to all data in the given data structure, recursively. + * + * @param mixed &$data + */ + protected function injectIds( &$data ) { + EntityTestHelper::injectIds( $data, self::$idMap ); + } + + /** + * @dataProvider provideData + */ + public function testEditEntity( $params, $expected ) { + + $this->injectIds( $params ); + $this->injectIds( $expected ); + + $p56 = '%P56%'; + $this->injectIds( $p56 ); + + if ( isset( $params['data'] ) && is_array( $params['data'] ) ) { + $params['data'] = json_encode( $params['data'] ); + } + + // -- set any defaults ------------------------------------ + $params['action'] = 'wbeditentity'; + if ( !array_key_exists( 'id', $params ) + && !array_key_exists( 'new', $params ) + && !array_key_exists( 'site', $params ) + && !array_key_exists( 'title', $params ) + ) { + $params['id'] = self::$idMap['!lastEntityId!']; + } + + // -- do the request -------------------------------------------------- + list( $result, , ) = $this->doApiRequestWithToken( $params ); + + // -- check the result ------------------------------------------------ + $this->assertArrayHasKey( 'success', $result, "Missing 'success' marker in response." ); + $this->assertResultHasEntityType( $result ); + $this->assertArrayHasKey( 'entity', $result, "Missing 'entity' section in response." ); + + $this->assertArrayHasKey( + 'id', + $result['entity'], + "Missing 'id' section in entity in response." + ); + + $this->assertEntityEquals( $expected, $result['entity'] ); + + // -- check null edits --------------------------------------------- + if ( isset( $expected['nochange'] ) ) { + $this->assertArrayHasKey( 'nochange', $result['entity'] ); + } + + // -- check the item in the database ------------------------------- + $dbEntity = $this->loadEntity( $result['entity']['id'] ); + $this->assertEntityEquals( $expected, $dbEntity, false ); + + // -- check the edit summary -------------------------------------------- + if ( !array_key_exists( 'warning', $expected ) + || $expected['warning'] != 'edit-no-change' + ) { + $this->assertRevisionSummary( + array( 'wbeditentity' ), + $result['entity']['lastrevid'] + ); + + if ( array_key_exists( 'summary', $params ) ) { + $this->assertRevisionSummary( + '/' . $params['summary'] . '/', + $result['entity']['lastrevid'] + ); + } + } + } + +} -- To view, visit https://gerrit.wikimedia.org/r/333589 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iad2547d147c26c9eb1d2148ed8cbdbd27a389c3a 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
