Sumit has uploaded a new change for review. https://gerrit.wikimedia.org/r/258511
Change subject: WPB fix inconsistent ImageDisabled test ...................................................................... WPB fix inconsistent ImageDisabled test Use reflection class to set disableImages variable which is used for testimg against images disabled feature. Bug: T121066 Change-Id: Ifb183abf2af2629350e855199509b435686baf58 --- M tests/phpunit/BannerMFTest.php 1 file changed, 38 insertions(+), 15 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikidataPageBanner refs/changes/11/258511/1 diff --git a/tests/phpunit/BannerMFTest.php b/tests/phpunit/BannerMFTest.php index 7811a74..6702b99 100644 --- a/tests/phpunit/BannerMFTest.php +++ b/tests/phpunit/BannerMFTest.php @@ -8,16 +8,10 @@ */ class BannerMFTest extends MediaWikiTestCase { /** - * Stores the original value for disableImages cookie + * Stores the original value for MobileContext * @var bool $oldDisableImages; */ - private $oldDisableImages; - - /** - * Stores the original value for forcedMobileView - * @var bool $oldForceMobile; - */ - private $oldForceMobileView; + private static $oldMobileContext = null; /** * Add test pages to database @@ -35,11 +29,15 @@ protected function setUp() { parent::setUp(); if ( class_exists( 'MobileContext' ) ) { - $mobileContext = MobileContext::singleton(); - $this->oldDisableImages = $mobileContext->imagesDisabled(); - $this->oldForceMobileView = $mobileContext->getForceMobileView(); - $mobileContext->setDisableImagesCookie( true ); + self::$oldMobileContext = MobileContext::singleton(); + $mobileContext = $this->makeContext(); $mobileContext->setForceMobileView( true ); + MobileContext::setInstance( $mobileContext ); + // set protected disableImages property to true, so that we can simulate images disabled + $reflectionClass = new ReflectionClass('MobileContext'); + $reflectionProperty = $reflectionClass->getProperty('disableImages'); + $reflectionProperty->setAccessible( true ); + $reflectionProperty->setValue( $mobileContext, true ); } $this->addDBData(); $this->setMwGlobals( 'wgWPBImage', "DefaultBanner" ); @@ -48,9 +46,8 @@ protected function tearDown() { if ( class_exists( 'MobileContext' ) ) { - $mobileContext = MobileContext::singleton(); - $mobileContext->setDisableImagesCookie( $this->oldDisableImages ); - $mobileContext->setForceMobileView( $this->oldForceMobileView ); + // restore old mobile context class + $mobileContext = MobileContext::setInstance( self::$oldMobileContext ); } parent::tearDown(); } @@ -83,4 +80,30 @@ $out->setArticleFlag( true ); return $out; } + + /** + * @param string $url + * @param array $cookies + * @return MobileContext + */ + private function makeContext( $url = '/', $cookies = array() ) { + $query = array(); + if ( $url ) { + $params = wfParseUrl( wfExpandUrl( $url ) ); + if ( isset( $params['query'] ) ) { + $query = wfCgiToArray( $params['query'] ); + } + } + + $request = new FauxRequest( array() ); + $request->setRequestURL( $url ); + $request->setCookies( $cookies, '' ); + + $context = new DerivativeContext( RequestContext::getMain() ); + $context->setRequest( $request ); + $context->setOutput( new OutputPage( $context ) ); + $instance = unserialize( 'O:13:"MobileContext":0:{}' ); + $instance->setContext( $context ); + return $instance; + } } -- To view, visit https://gerrit.wikimedia.org/r/258511 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ifb183abf2af2629350e855199509b435686baf58 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikidataPageBanner Gerrit-Branch: master Gerrit-Owner: Sumit <asthana.sumi...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits