jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/335650 )

Change subject: Removed assertTag from SpecialSetSiteLinkTest
......................................................................


Removed assertTag from SpecialSetSiteLinkTest

Bug: T69122
Change-Id: I04c13d0572a58a52b29e118d876c599cb02d139c
---
M repo/tests/phpunit/includes/Specials/SpecialSetSiteLinkTest.php
1 file changed, 76 insertions(+), 107 deletions(-)

Approvals:
  WMDE-leszek: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/repo/tests/phpunit/includes/Specials/SpecialSetSiteLinkTest.php 
b/repo/tests/phpunit/includes/Specials/SpecialSetSiteLinkTest.php
index ce938d9..3820f77 100644
--- a/repo/tests/phpunit/includes/Specials/SpecialSetSiteLinkTest.php
+++ b/repo/tests/phpunit/includes/Specials/SpecialSetSiteLinkTest.php
@@ -4,6 +4,7 @@
 
 use FauxRequest;
 use FauxResponse;
+use Hamcrest\Matcher;
 use MediaWiki\MediaWikiServices;
 use SpecialPageTestBase;
 use TestSites;
@@ -36,37 +37,7 @@
        /**
         * @var array
         */
-       private static $matchers = array(
-               'id' => array(
-                       'tag' => 'input',
-                       'attributes' => array(
-                               'id' => 'wb-modifyentity-id',
-                               'class' => 'wb-input',
-                               'name' => 'id',
-                       ) ),
-               'site' => array(
-                       'tag' => 'input',
-                       'attributes' => array(
-                               'id' => 'wb-setsitelink-site',
-                               'class' => 'wb-input',
-                               'name' => 'site',
-                       ) ),
-               'page' => array(
-                       'tag' => 'input',
-                       'attributes' => array(
-                               'id' => 'wb-setsitelink-page',
-                               'class' => 'wb-input',
-                               'name' => 'page',
-                       ) ),
-               'submit' => array(
-                       'tag' => 'input',
-                       'attributes' => array(
-                               'id' => 'wb-setsitelink-submit',
-                               'class' => 'wb-button',
-                               'type' => 'submit',
-                               'name' => 'wikibase-setsitelink-submit',
-                       ) )
-       );
+       private static $matchers = [];
 
        /**
         * @var string|null
@@ -116,6 +87,7 @@
                $this->setMwGlobals( 'wgGroupPermissions', array( '*' => array( 
'edit' => true ) ) );
 
                if ( !self::$badgeId ) {
+                       self::$matchers = self::createMatchers();
                        $sitesTable = 
MediaWikiServices::getInstance()->getSiteStore();
                        $sitesTable->clear();
                        $sitesTable->saveSites( TestSites::getSites() );
@@ -157,20 +129,12 @@
 
        private function addBadgeMatcher() {
                $name = 'badge-' . self::$badgeId;
-               self::$matchers['badgeinput'] = array(
-                       'tag' => 'input',
-                       'attributes' => array(
-                               'name' => $name,
-                               'id' => $name,
-                               'type' => 'checkbox'
-                       ) );
+               self::$matchers['badgeinput'] = tagMatchingOutline( "<input 
type='checkbox' name='$name' id='$name'>" );
 
-               self::$matchers['badgelabel'] = array(
-                       'tag' => 'label',
-                       'attributes' => array(
-                               'for' => $name
-                       ),
-                       'content' => 'Guter Artikel'
+               self::$matchers['badgelabel'] = both(
+                       tagMatchingOutline( "<label for='$name'>" )
+               )->andAlso(
+                       havingTextContents( 'Guter Artikel' )
                );
        }
 
@@ -179,9 +143,7 @@
                // Execute with no subpage value
                list( $output, ) = $this->executeSpecialPage( '', null, 'de' );
 
-               foreach ( $matchers as $key => $matcher ) {
-                       $this->assertTag( $matcher, $output, "Failed to match 
html output with tag '{$key}'" );
-               }
+               $this->assertHtmlContainsTagsMatching( $output, $matchers );
        }
 
        public function testExecuteOneValuePreset() {
@@ -190,15 +152,11 @@
                // Note: use language fallback de-ch => de
                list( $output, ) = $this->executeSpecialPage( self::$itemId, 
null, 'de-ch' );
 
-               $matchers['id']['attributes']['value'] = self::$itemId;
+               $matchers['id'] = both( $matchers['id'] )->andAlso(
+                       withAttribute( 'value' )->havingValue( self::$itemId )
+               );
 
-               foreach ( $matchers as $key => $matcher ) {
-                       $this->assertTag(
-                               $matcher,
-                               $output,
-                               "Failed to match html output with tag '{$key}' 
passing one subpage value"
-                       );
-               }
+               $this->assertHtmlContainsTagsMatching( $output, $matchers );
        }
 
        public function testExecuteTwoValuesPreset() {
@@ -207,41 +165,22 @@
                // Note: use language fallback de-ch => de
                list( $output, ) = $this->executeSpecialPage( self::$itemId . 
'/dewiki', null, 'de-ch' );
 
-               $matchers['id'] = array(
-                       'tag' => 'input',
-                       'attributes' => array(
-                               'type' => 'hidden',
-                               'name' => 'id',
-                               'value' => self::$itemId,
-               ) );
+               $itemId = self::$itemId;
+               $matchers['id'] = tagMatchingOutline(
+                       "<input type='hidden' name='id' value='$itemId'/>"
+               );
+               $matchers['site'] = tagMatchingOutline(
+                       "<input type='hidden' name='site' value='dewiki'/>"
+               );
+               $matchers['remove'] = tagMatchingOutline(
+                       "<input type='hidden' name='remove' value='remove'/>"
+               );
 
-               $matchers['site'] = array(
-                       'tag' => 'input',
-                       'attributes' => array(
-                               'type' => 'hidden',
-                               'name' => 'site',
-                               'value' => 'dewiki',
-               ) );
+               $matchers['page'] = both( $matchers['page'] )->andAlso(
+                       withAttribute( 'value' )->havingValue( 'Wikidata' )
+               );
 
-               $matchers['remove'] = array(
-                       'tag' => 'input',
-                       'attributes' => array(
-                               'type' => 'hidden',
-                               'name' => 'remove',
-                               'value' => 'remove',
-                       ) );
-
-               $matchers['value']['attributes']['value'] = 'Wikidata';
-
-               
$matchers['badges']['children']['only']['attributes']['selected'] = '';
-
-               foreach ( $matchers as $key => $matcher ) {
-                       $this->assertTag(
-                               $matcher,
-                               $output,
-                               "Failed to match html output with tag '{$key}' 
passing two subpage values"
-                       );
-               }
+               $this->assertHtmlContainsTagsMatching( $output, $matchers );
        }
 
        public function testExecuteTwoValuesPreset_no_label() {
@@ -255,17 +194,18 @@
                unset( $matchers['site'] );
                unset( $matchers['remove'] );
 
-               $matchers['badgelabel']['content'] = self::$badgeId;
-               $matchers['value']['attributes']['value'] = 'Wikidata';
-               
$matchers['badges']['children']['only']['attributes']['selected'] = '';
+               $name = 'badge-' . self::$badgeId;
+               $matchers['badgelabel'] = both(
+                       tagMatchingOutline( "<label for='$name'>" )
+               )->andAlso(
+                       havingTextContents( self::$badgeId )
+               );
 
-               foreach ( $matchers as $key => $matcher ) {
-                       $this->assertTag(
-                               $matcher,
-                               $output,
-                               "Failed to match html output with tag '{$key}' 
passing two subpage values"
-                       );
-               }
+               $matchers['page'] = both( $matchers['page'] )->andAlso(
+                       withAttribute( 'value' )->havingValue( 'Wikidata' )
+               );
+
+               $this->assertHtmlContainsTagsMatching( $output, $matchers );
        }
 
        public function testExecuteRedirect() {
@@ -287,15 +227,11 @@
 
                list( $output, ) = $this->executeSpecialPage( '', $request );
 
-               $this->assertTag( array(
-                       'tag' => 'input',
-                       'attributes' => array(
-                               'id' => 'wb-setsitelink-page',
-                               'class' => 'wb-input',
-                               'name' => 'page',
-                               'value' => 'Wikidata',
-                       )
-               ), $output, 'Value still preserves when no value was entered in 
the big form' );
+               assertThat(
+                       $output,
+                       is( htmlPiece( havingChild( tagMatchingOutline(
+                               '<input id="wb-setsitelink-page" 
class="wb-input" name="page" value="Wikidata">'
+                       ) ) ) ) );
        }
 
        public function testExecutePostModifySiteLink() {
@@ -341,4 +277,37 @@
                $this->assertFalse( $item->hasLinkToSite( 'dewiki' ), "Should 
no longer contain site link" );
        }
 
+       private static function createMatchers() {
+               return [
+                       'id' => tagMatchingOutline(
+                               '<input id="wb-modifyentity-id" 
class="wb-input" name="id"/>'
+                       ),
+                       'site' => tagMatchingOutline(
+                               '<input id="wb-setsitelink-site" 
class="wb-input" name="site"/>'
+                       ),
+                       'page' => tagMatchingOutline(
+                               '<input id="wb-setsitelink-page" 
class="wb-input" name="page"/>'
+                       ),
+                       'submit' => tagMatchingOutline(
+                               '<input id="wb-setsitelink-submit" 
class="wb-button" type="submit" name="wikibase-setsitelink-submit"/>'
+                       ),
+               ];
+       }
+
+       /**
+        * @param string $html
+        * @param Matcher[] $tagMatchers
+        */
+       private function assertHtmlContainsTagsMatching( $html, array 
$tagMatchers ) {
+               foreach ( $tagMatchers as $key => $matcher ) {
+                       $message = "Failed to match html output with tag 
'{$key}'";
+                       assertThat(
+                               $message,
+                               $html,
+                               is( htmlPiece( havingChild( $matcher ) ) )
+                       );
+
+               }
+       }
+
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/335650
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I04c13d0572a58a52b29e118d876c599cb02d139c
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Aleksey Bekh-Ivanov (WMDE) <[email protected]>
Gerrit-Reviewer: Jonas Kress (WMDE) <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: WMDE-leszek <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to