jenkins-bot has submitted this change and it was merged. Change subject: Functionality test for SpecialSetLabelDescriptionAliases ......................................................................
Functionality test for SpecialSetLabelDescriptionAliases Change-Id: Ib8b74b6ec9db9cf039b38ce5c9278134b3c88aae --- M repo/tests/phpunit/includes/specials/SpecialSetLabelDescriptionAliasesTest.php 1 file changed, 90 insertions(+), 9 deletions(-) Approvals: Thiemo Mättig (WMDE): Looks good to me, approved jenkins-bot: Verified diff --git a/repo/tests/phpunit/includes/specials/SpecialSetLabelDescriptionAliasesTest.php b/repo/tests/phpunit/includes/specials/SpecialSetLabelDescriptionAliasesTest.php index 1561273..bc05ff5 100644 --- a/repo/tests/phpunit/includes/specials/SpecialSetLabelDescriptionAliasesTest.php +++ b/repo/tests/phpunit/includes/specials/SpecialSetLabelDescriptionAliasesTest.php @@ -3,6 +3,7 @@ namespace Wikibase\Test; use FauxRequest; +use FauxResponse; use ValueValidators\Result; use WebRequest; use Wikibase\ChangeOp\FingerprintChangeOpFactory; @@ -154,6 +155,31 @@ return $languages; } + /** + * @param string[] $labels + * @param string[] $descriptions + * @param array[] $aliases + * + * @return Fingerprint + */ + private function makeFingerprint( array $labels, array $descriptions, array $aliases ) { + $fingerprint = new Fingerprint(); + + foreach ( $labels as $lang => $text ) { + $fingerprint->setLabel( $lang, $text ); + } + + foreach ( $descriptions as $lang => $text ) { + $fingerprint->setDescription( $lang, $text ); + } + + foreach ( $aliases as $lang => $texts ) { + $fingerprint->setAliasGroup( $lang, $texts ); + } + + return $fingerprint; + } + public function executeProvider() { global $wgLang; @@ -224,8 +250,11 @@ $withLanguageMatchers['language']['attributes']['value'] = 'de'; $withLanguageMatchers['label']['attributes']['value'] = 'foo'; - $fooFingerprint = new Fingerprint(); - $fooFingerprint->setLabel( 'de', 'foo' ); + $fooFingerprint = $this->makeFingerprint( + array( 'de' => 'foo' ), + array(), + array() + ); return array( 'no input' => array( @@ -259,6 +288,55 @@ $withLanguageMatchers, null ), + + 'add label' => array( + $fooFingerprint, + '$id', + new FauxRequest( array( 'language' => 'en', 'label' => 'FOO' ), true ), + array(), + $this->makeFingerprint( + array( 'de' => 'foo', 'en' => 'FOO' ), + array(), + array() + ), + ), + + 'replace label' => array( + $fooFingerprint, + '$id', + new FauxRequest( array( 'language' => 'de', 'label' => 'FOO' ), true ), + array(), + $this->makeFingerprint( + array( 'de' => 'FOO' ), + array(), + array() + ), + ), + + 'add description, keep label' => array( + $fooFingerprint, + '$id', + new FauxRequest( array( 'language' => 'de', 'description' => 'Lorem Ipsum' ), true ), + array(), + $this->makeFingerprint( + array( 'de' => 'foo' ), + array( 'de' => 'Lorem Ipsum' ), + array() + ), + ), + + 'set aliases' => array( + $fooFingerprint, + '$id', + new FauxRequest( array( 'language' => 'de', 'aliases' => 'foo|bar' ), true ), + array(), + $this->makeFingerprint( + array( 'de' => 'foo' ), + array(), + array( 'de' => array( 'foo', 'bar' ) ) + ), + ), + ); } @@ -267,7 +345,7 @@ */ public function testExecute( Fingerprint $inputFingerprint, - $subpage, + $subPage, WebRequest $request = null, array $tagMatchers, Fingerprint $expectedFingerprint = null @@ -278,18 +356,22 @@ $this->mockRepository->putEntity( $inputEntity ); $id = $inputEntity->getId(); - $this->setMwGlobals( 'wgGroupPermissions', array( '*' => array( 'edit' => true ) ) ); - $this->newSpecialPage(); - $subpage = str_replace( '$id', $id->getSerialization(), $subpage ); - list( $output, ) = $this->executeSpecialPage( $subpage, $request ); + $subPage = str_replace( '$id', $id->getSerialization(), $subPage ); + list( $output, $response ) = $this->executeSpecialPage( $subPage, $request ); + + $redirect = $response instanceof FauxResponse ? $response->getHeader( 'Location' ) : null; foreach ( $tagMatchers as $key => $matcher ) { $this->assertTag( $matcher, $output, "Failed to assert output: $key" ); } - if ( $expectedFingerprint ) { + if ( $expectedFingerprint !== null ) { + // TODO: Look for an error message in $output. + $this->assertNotEmpty( $redirect, 'Expected redirect after successful edit' ); + + /** @var Item $actualEntity */ $actualEntity = $this->mockRepository->getEntity( $id ); $actualFingerprint = $actualEntity->getFingerprint(); @@ -300,7 +382,6 @@ private function assetFingerprintEquals( Fingerprint $expected, Fingerprint $actual, $message = 'Fingerprint mismatches' ) { // TODO: Compare serializations. $this->assertTrue( $expected->equals( $actual ), $message ); - } } -- To view, visit https://gerrit.wikimedia.org/r/194961 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ib8b74b6ec9db9cf039b38ce5c9278134b3c88aae Gerrit-PatchSet: 5 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Daniel Kinzler <daniel.kinz...@wikimedia.de> Gerrit-Reviewer: Addshore <addshorew...@gmail.com> Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits