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

Change subject: WPB show no banner when images disabled
......................................................................


WPB show no banner when images disabled

Turns off pagebanner when using skin minerva with images disabled. PHP unit test
added for the same.

Bug: T107368
Change-Id: If4aa5110ad51258ea4a147e46b531e719fe49363
---
M includes/WikidataPageBanner.hooks.php
A tests/phpunit/BannerMFTest.php
2 files changed, 93 insertions(+), 0 deletions(-)

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



diff --git a/includes/WikidataPageBanner.hooks.php 
b/includes/WikidataPageBanner.hooks.php
index f8cbb25..8bb7242 100644
--- a/includes/WikidataPageBanner.hooks.php
+++ b/includes/WikidataPageBanner.hooks.php
@@ -73,6 +73,13 @@
         * @return  bool
         */
        public static function addBanner( OutputPage $out, Skin $skin ) {
+               // if images are disabled on Minerva skin, then do nothing
+               if ( class_exists( 'MobileContext' )
+                               && 
MobileContext::singleton()->shouldDisplayMobileView()
+                               && MobileContext::singleton()->imagesDisabled() 
=== true
+                       ) {
+                       return true;
+               }
                $config = WikidataPageBannerFunctions::getWPBConfig();
                $title = $out->getTitle();
                $isDiff = $out->getRequest()->getVal( 'diff' );
diff --git a/tests/phpunit/BannerMFTest.php b/tests/phpunit/BannerMFTest.php
new file mode 100644
index 0000000..7811a74
--- /dev/null
+++ b/tests/phpunit/BannerMFTest.php
@@ -0,0 +1,86 @@
+<?php
+/**
+ * @group WikidataPageBanner
+ */
+
+/**
+ * Test for checking compatibility with imagesDisabled option in 
MobileFrontendExtension
+ */
+class BannerMFTest extends MediaWikiTestCase {
+       /**
+        * Stores the original value for disableImages cookie
+        * @var bool $oldDisableImages;
+        */
+       private $oldDisableImages;
+
+       /**
+        * Stores the original value for forcedMobileView
+        * @var bool $oldForceMobile;
+        */
+       private $oldForceMobileView;
+
+       /**
+        * Add test pages to database
+        * @see MediaWikiTestCase::addDBData()
+        */
+       public function addDBData() {
+               try {
+                       if ( !Title::newFromText( 'PageWithoutCustomBanner', 
NS_MAIN )->exists() ) {
+                               $this->insertPage( 'PageWithoutCustomBanner', 
'Some Text' );
+                       }
+               } catch ( Exception $e ) {
+               }
+       }
+
+       protected function setUp() {
+               parent::setUp();
+               if ( class_exists( 'MobileContext' ) ) {
+                       $mobileContext = MobileContext::singleton();
+                       $this->oldDisableImages = 
$mobileContext->imagesDisabled();
+                       $this->oldForceMobileView = 
$mobileContext->getForceMobileView();
+                       $mobileContext->setDisableImagesCookie( true );
+                       $mobileContext->setForceMobileView( true );
+               }
+               $this->addDBData();
+               $this->setMwGlobals( 'wgWPBImage', "DefaultBanner" );
+               $this->setMwGlobals( 'wgWPBEnableDefaultBanner', true );
+       }
+
+       protected function tearDown() {
+               if ( class_exists( 'MobileContext' ) ) {
+                       $mobileContext = MobileContext::singleton();
+                       $mobileContext->setDisableImagesCookie( 
$this->oldDisableImages );
+                       $mobileContext->setForceMobileView( 
$this->oldForceMobileView );
+               }
+               parent::tearDown();
+       }
+
+       /**
+        * Test banner addition on disabling images in MobileFrontend
+        */
+       public function testMFBannerWithImageDisabled() {
+               if ( class_exists( 'MobileContext' ) ) {
+                       $skin = $this->getMock( "Skin" );
+                       $out = $this->createPage( 'PageWithoutCustomBanner', 
NS_MAIN );
+                       WikidataPageBanner::addBanner( $out, $skin );
+                       $this->assertNull( $out->getProperty( 
'articlebanner-name' ) );
+               }
+       }
+
+       /**
+        * Helper function for testDefaultBanner
+        * @param string $title
+        * @param int $namespace
+        * @return OutputPage
+        */
+       protected function createPage( $title, $namespace ) {
+               $context = new RequestContext();
+               $curTitle = Title::newFromText( $title, $namespace );
+               $context->setTitle( $curTitle );
+               $out = $context->getOutput();
+               $out->setTitle( $curTitle );
+               $out->setPageTitle( $title );
+               $out->setArticleFlag( true );
+               return $out;
+       }
+}

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

Gerrit-MessageType: merged
Gerrit-Change-Id: If4aa5110ad51258ea4a147e46b531e719fe49363
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/WikidataPageBanner
Gerrit-Branch: master
Gerrit-Owner: Sumit <[email protected]>
Gerrit-Reviewer: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: Sumit <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to