jenkins-bot has submitted this change and it was merged.

Change subject: Data provider for testing SpecialSetLabelDescritionAliases
......................................................................


Data provider for testing SpecialSetLabelDescritionAliases

Change-Id: I1acae8dc08cf4c6ed833751fedf189886111a950
---
M repo/tests/phpunit/includes/specials/SpecialSetLabelDescriptionAliasesTest.php
1 file changed, 94 insertions(+), 52 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 46651c9..55b3f7c 100644
--- 
a/repo/tests/phpunit/includes/specials/SpecialSetLabelDescriptionAliasesTest.php
+++ 
b/repo/tests/phpunit/includes/specials/SpecialSetLabelDescriptionAliasesTest.php
@@ -2,11 +2,14 @@
 
 namespace Wikibase\Test;
 
+use FauxRequest;
 use ValueValidators\Result;
+use WebRequest;
 use Wikibase\ChangeOp\FingerprintChangeOpFactory;
 use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\DataModel\Entity\Item;
 use Wikibase\DataModel\Entity\ItemId;
+use Wikibase\DataModel\Term\Fingerprint;
 use Wikibase\LabelDescriptionDuplicateDetector;
 use Wikibase\Lib\ContentLanguages;
 use Wikibase\Repo\Specials\SpecialSetLabelDescriptionAliases;
@@ -106,16 +109,16 @@
         *
         * @param string[] $terms
         *
-        * @return array
+        * @return UniquenessViolation[]
         */
-       public function detectDupes( $terms ) {
+       public function detectDupes( array $terms ) {
                $errors = array();
 
                foreach ( $terms as $languageCode => $term ) {
                        if ( $term === 'DUPE' ) {
                                $q666 = new ItemId( 'Q666' );
 
-                               $errors[] =  new UniquenessViolation(
+                               $errors[] = new UniquenessViolation(
                                        $q666,
                                        'found conflicting terms',
                                        'test-conflict',
@@ -151,31 +154,8 @@
                return $languages;
        }
 
-       /**
-        * @return string
-        */
-       private function createNewItem() {
-               $item = Item::newEmpty();
-               // add data and check if it is shown in the form
-               $item->setLabel( 'de', 'foo' );
-               $item->setDescription( 'de', 'foo' );
-               $item->setAliases( 'de', array( 'foo' ) );
-
-               // save the item
-               $this->mockRepository->putEntity( $item );
-
-               // return the id
-               return $item->getId()->getSerialization();
-       }
-
-       public function testExecute() {
-               $id = $this->createNewItem();
-
-               $this->setMwGlobals( 'wgGroupPermissions', array( '*' => array( 
'edit' => true ) ) );
-
-               $this->newSpecialPage();
-
-               $matchers['id'] = array(
+       public function executeProvider() {
+               $formMatchers['id'] = array(
                        'tag' => 'input',
                        'attributes' => array(
                                'id' => 'wb-modifyentity-id',
@@ -183,7 +163,7 @@
                                'name' => 'id',
                        ),
                );
-               $matchers['language'] = array(
+               $formMatchers['language'] = array(
                        'tag' => 'input',
                        'attributes' => array(
                                'id' => 
'wikibase-setlabeldescriptionaliases-language',
@@ -192,7 +172,7 @@
                                'value' => 'en',
                        ),
                );
-               $matchers['label'] = array(
+               $formMatchers['label'] = array(
                        'tag' => 'input',
                        'attributes' => array(
                                'id' => 
'wikibase-setlabeldescriptionaliases-label',
@@ -200,7 +180,7 @@
                                'name' => 'label',
                        ),
                );
-               $matchers['description'] = array(
+               $formMatchers['description'] = array(
                        'tag' => 'input',
                        'attributes' => array(
                                'id' => 
'wikibase-setlabeldescriptionaliases-description',
@@ -208,7 +188,7 @@
                                'name' => 'description',
                        ),
                );
-               $matchers['aliases'] = array(
+               $formMatchers['aliases'] = array(
                        'tag' => 'input',
                        'attributes' => array(
                                'id' => 
'wikibase-setlabeldescriptionaliases-aliases',
@@ -216,7 +196,7 @@
                                'name' => 'aliases',
                        ),
                );
-               $matchers['submit'] = array(
+               $formMatchers['submit'] = array(
                        'tag' => 'input',
                        'attributes' => array(
                                'id' => 'wb-setlabeldescriptionaliases-submit',
@@ -226,37 +206,99 @@
                        ),
                );
 
-               // execute with no subpage value
-               list( $output, ) = $this->executeSpecialPage( '', null, 'en' );
-               foreach( $matchers as $key => $matcher ) {
-                       $this->assertTag( $matcher, $output, "Failed to match 
html output with tag '{$key}'" );
-               }
-
-               // execute with one subpage value
-               list( $output, ) = $this->executeSpecialPage( $id, null, 'en' );
-               $matchers['id']['attributes'] = array(
+               $withIdMatchers = $formMatchers;
+               $withIdMatchers['id']['attributes'] = array(
                        'type' => 'hidden',
                        'name' => 'id',
-                       'value' => $id,
+                       'value' => 'regexp:/Q\d+/',
                );
-               $matchers['language']['attributes'] = array(
+               $withIdMatchers['language']['attributes'] = array(
                        'type' => 'hidden',
                        'name' => 'language',
                        'value' => 'en',
                );
 
-               foreach( $matchers as $key => $matcher ) {
-                       $this->assertTag( $matcher, $output, "Failed to match 
html output with tag '{$key}' passing one subpage value" );
+               $withLanguageMatchers = $withIdMatchers;
+               $withLanguageMatchers['language']['attributes']['value'] = 'de';
+               $withLanguageMatchers['label']['attributes']['value'] = 'foo';
+
+               $fooFingerprint = new Fingerprint();
+               $fooFingerprint->setLabel( 'de', 'foo' );
+
+               return array(
+                       'no input' => array(
+                               $fooFingerprint,
+                               '',
+                               null,
+                               $formMatchers,
+                               null
+                       ),
+
+                       'with id but no language' => array(
+                               $fooFingerprint,
+                               '$id',
+                               null,
+                               $withIdMatchers,
+                               null
+                       ),
+
+                       'with id and language' => array(
+                               $fooFingerprint,
+                               '$id/de',
+                               null,
+                               $withLanguageMatchers,
+                               null
+                       ),
+
+                       'with id and language attribute' => array(
+                               $fooFingerprint,
+                               '$id',
+                               new FauxRequest( array( 'language' => 'de' ) ),
+                               $withLanguageMatchers,
+                               null
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider executeProvider
+        */
+       public function testExecute(
+               Fingerprint $inputFingerprint,
+               $subpage,
+               WebRequest $request = null,
+               array $tagMatchers,
+               Fingerprint $expectedFingerprint = null
+       ) {
+               $inputEntity = new Item();
+               $inputEntity->setFingerprint( $inputFingerprint );
+
+               $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 );
+
+               foreach ( $tagMatchers as $key => $matcher ) {
+                       $this->assertTag( $matcher, $output, "Failed to assert 
output: $key" );
                }
 
-               // execute with two subpage values
-               list( $output, ) = $this->executeSpecialPage( $id . '/de', 
null, 'en' );
-               $matchers['language']['attributes']['value'] = 'de';
-               $matchers['value']['attributes']['value'] = 'foo';
+               if ( $expectedFingerprint ) {
+                       $actualEntity = $this->mockRepository->getEntity( $id );
+                       $actualFingerprint = $actualEntity->getFingerprint();
 
-               foreach( $matchers as $key => $matcher ) {
-                       $this->assertTag( $matcher, $output, "Failed to match 
html output with tag '{$key}' passing two subpage values" );
+                       $this->assetFingerprintEquals( $expectedFingerprint, 
$actualFingerprint );
                }
        }
 
+       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/194524
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I1acae8dc08cf4c6ed833751fedf189886111a950
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to