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

Change subject: Rework EntityTermsViewTest to not break because of core change
......................................................................


Rework EntityTermsViewTest to not break because of core change

This patch fixes an issue that currently breaks all tests on Travis:
https://travis-ci.org/wikimedia/mediawiki-extensions-Wikibase/
For example:
https://travis-ci.org/wikimedia/mediawiki-extensions-Wikibase/jobs/66086125

This change removes an aspect that was tested before: The last test checked
if HTML injected via a message (from the MediaWiki: namespace) is escaped
or not. This is not tested any more. This is done on purpose. It's not
really relevant. Users that can inject HTML this way can also inject it in
a gazilion other places. It's not the responsibility of this specific test
to make sure HTML injections aren't possible.

Note that this is the only (!) place in the whole Wikibase code base
(including all components) that made use of this MessageCache trick. There
is probably an other way in core to do the same but I did not found out.

Change-Id: I80df6858e3ab3b58f721881ded82a68af4658c70
(cherry picked from commit 4e4d0dbffdc016942876f5a0c5d4e5cc29f6deb7)
---
M view/tests/phpunit/EntityTermsViewTest.php
1 file changed, 15 insertions(+), 26 deletions(-)

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



diff --git a/view/tests/phpunit/EntityTermsViewTest.php 
b/view/tests/phpunit/EntityTermsViewTest.php
index 958c22e..e06171d 100644
--- a/view/tests/phpunit/EntityTermsViewTest.php
+++ b/view/tests/phpunit/EntityTermsViewTest.php
@@ -2,8 +2,8 @@
 
 namespace Wikibase\Test;
 
+use Language;
 use MediaWikiLangTestCase;
-use MessageCache;
 use Wikibase\DataModel\Entity\ItemId;
 use Wikibase\DataModel\Term\Fingerprint;
 use Wikibase\View\EntityTermsView;
@@ -31,20 +31,9 @@
        protected function setUp() {
                parent::setUp();
 
-               $msgCache = MessageCache::singleton();
-               $msgCache->enable();
-
-               // Mocks for all "this is empty" placeholders
-               $msgCache->replace( 'Wikibase-label-empty', '<strong 
class="test">No label</strong>' );
-               $msgCache->replace( 'Wikibase-description-empty', '<strong 
class="test">No description</strong>' );
-               $msgCache->replace( 'Wikibase-aliases-empty', '<strong 
class="test">No aliases</strong>' );
-       }
-
-       protected function tearDown() {
-               $msgCache = MessageCache::singleton();
-               $msgCache->disable();
-
-               parent::tearDown();
+               $this->setMwGlobals( array(
+                       'wgLang' => Language::factory( 'qqx' ),
+               ) );
        }
 
        private function getEntityTermsView( $languageCode = 'en', $called = 
null ) {
@@ -140,17 +129,17 @@
                $noAliases->removeAliasGroup( 'en' );
 
                return array(
-                       array( new Fingerprint(), 'No' ),
-                       array( $noLabel, 'No label' ),
-                       array( $noDescription, 'No description' ),
-                       array( $noAliases, 'No aliases' ),
+                       array( new Fingerprint(), '-empty)' ),
+                       array( $noLabel, '(wikibase-label-empty)' ),
+                       array( $noDescription, '(wikibase-description-empty)' ),
+                       array( $noAliases, '(wikibase-aliases-empty)' ),
                );
        }
 
        /**
         * @dataProvider emptyFingerprintProvider
         */
-       public function testGetHtml_isMarkedAsEmptyValue( Fingerprint 
$fingerprint ) {
+       public function testGetHtml_isMarkedAsEmptyValue( Fingerprint 
$fingerprint, $expectedPlaceholder ) {
                $entityTermsView = $this->getEntityTermsView();
                $html = $entityTermsView->getHtml( $fingerprint, null, '', new 
TextInjector() );
 
@@ -172,7 +161,7 @@
                $html = $entityTermsView->getHtml( $fingerprint, $entityId, '', 
new TextInjector() );
                $idString = $entityId->getSerialization();
 
-               $this->assertContains( '(' . $idString . ')', $html );
+               $this->assertContains( '(parentheses: ' . $idString . ')', 
$html );
                $this->assertContains( '~EDITSECTION~', $html );
        }
 
@@ -180,20 +169,20 @@
                $entityTermsView = $this->getEntityTermsView();
                $html = $entityTermsView->getHtml( new Fingerprint(), null, '', 
new TextInjector() );
 
-               $this->assertNotContains( '(new)', $html );
+               $this->assertNotContains( '(parentheses', $html );
                $this->assertNotContains( '<a ', $html );
        }
 
        /**
         * @dataProvider emptyFingerprintProvider
         */
-       public function testGetHtml_containsIsEmptyPlaceholders( Fingerprint 
$fingerprint, $message ) {
+       public function testGetHtml_containsIsEmptyPlaceholders( Fingerprint 
$fingerprint, $expectedPlaceholder ) {
                $entityTermsView = $this->getEntityTermsView();
                $html = $entityTermsView->getHtml( $fingerprint, null, '', new 
TextInjector() );
 
-               $this->assertContains( $message, $html );
-               $this->assertContains( 'strong', $html, 'make sure the setUp 
works' );
-               $this->assertNotContains( '<strong class="test">', $html );
+               $this->assertContains( $expectedPlaceholder, $html );
+               $numberOfPlaceholders = $fingerprint->isEmpty() ? 3 : 1;
+               $this->assertSame( $numberOfPlaceholders, substr_count( $html, 
$expectedPlaceholder ) );
        }
 
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I80df6858e3ab3b58f721881ded82a68af4658c70
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: wmf/1.26wmf9
Gerrit-Owner: JanZerebecki <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: JanZerebecki <[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