Jdlrobson has submitted this change and it was merged.

Change subject: Make sure globals are not overwritten in MobileContextTest
......................................................................


Make sure globals are not overwritten in MobileContextTest

Includes whitespace changes for readability

Change-Id: I12299805b094c7dfa44203bd6af3b04ab13ec553
---
M tests/MobileContextTest.php
1 file changed, 11 insertions(+), 8 deletions(-)

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



diff --git a/tests/MobileContextTest.php b/tests/MobileContextTest.php
index 5b37fc6..ae0c4c6 100644
--- a/tests/MobileContextTest.php
+++ b/tests/MobileContextTest.php
@@ -4,6 +4,8 @@
  * @group MobileFrontend
  */
 class MobileContextTest extends MediaWikiTestCase {
+       private $savedGlobals;
+
        /**
        * PHP 5.3.2 introduces the ReflectionMethod::setAccessible() method to 
allow the invocation of
        * protected and private methods directly through the Reflection API
@@ -20,7 +22,9 @@
 
        protected function setUp() {
                global $wgMFAutodetectMobileView;
+
                parent::setUp();
+               $this->savedGlobals = $GLOBALS;
                $context = new DerivativeContext( RequestContext::getMain() );
                $context->setRequest( new FauxRequest() );
                $wgMFAutodetectMobileView = false;
@@ -28,6 +32,7 @@
        }
 
        protected function tearDown() {
+               $GLOBALS = $this->savedGlobals;
                MobileContext::setInstance( null ); //refresh it
                parent::tearDown();
        }
@@ -41,6 +46,7 @@
 
        public function testGetMobileUrl() {
                global $wgMobileUrlTemplate;
+
                $wgMobileUrlTemplate = "%h0.m.%h1.%h2";
                $this->assertEquals( 'http://en.m.wikipedia.org/wiki/Article', 
MobileContext::singleton()->getMobileUrl( 
'http://en.wikipedia.org/wiki/Article' ) );
                $this->assertEquals( '//en.m.wikipedia.org/wiki/Article', 
MobileContext::singleton()->getMobileUrl( '//en.wikipedia.org/wiki/Article' ) );
@@ -48,6 +54,7 @@
 
        public function testParseMobileUrlTemplate() {
                global $wgMobileUrlTemplate;
+
                $wgMobileUrlTemplate = "%h0.m.%h1.%h2/path/morepath";
                $this->assertEquals( '%h0.m.%h1.%h2', 
MobileContext::singleton()->parseMobileUrlTemplate( 'host' ) );
                $this->assertEquals( '/path/morepath', 
MobileContext::singleton()->parseMobileUrlTemplate( 'path' ) );
@@ -56,6 +63,7 @@
 
        public function testUpdateMobileUrlHost() {
                global $wgMobileUrlTemplate;
+
                $updateMobileUrlHost = self::getMethod( "updateMobileUrlHost" );
                $wgMobileUrlTemplate = "%h0.m.%h1.%h2";
                $parsedUrl = wfParseUrl( 
"http://en.wikipedia.org/wiki/Gustavus_Airport"; );
@@ -85,6 +93,7 @@
         */
        public function testUpdateDesktopUrlHost( $mobile, $desktop ) {
                global $wgMobileUrlTemplate;
+
                $updateMobileUrlHost = self::getMethod( "updateDesktopUrlHost" 
);
                $wgMobileUrlTemplate = "%h0.m.%h1.%h2";
                $parsedUrl = wfParseUrl( $mobile );
@@ -109,6 +118,7 @@
 
        public function testUpdateMobileUrlPath() {
                global $wgMobileUrlTemplate, $wgScriptPath;
+
                $wgScriptPath = '/wiki';
                $updateMobileUrlHost = self::getMethod( "updateMobileUrlPath" );
                $wgMobileUrlTemplate = "/mobile/%p";
@@ -317,7 +327,6 @@
                global $wgCookieExpiration, $wgMobileFrontendFormatCookieExpiry;
                $getUseFormatCookieExpiry = self::getMethod( 
'getUseFormatCookieExpiry' );
 
-               $origMFCookieExpiry = $wgMobileFrontendFormatCookieExpiry;
                $startTime = time();
                $wgMobileFrontendFormatCookieExpiry = 60;
                $mfCookieExpected = $startTime + 60;
@@ -326,9 +335,6 @@
                $wgMobileFrontendFormatCookieExpiry = null;
                $defaultMWCookieExpected = $startTime + $wgCookieExpiration;
                $this->assertTrue( $defaultMWCookieExpected == 
$getUseFormatCookieExpiry->invokeArgs( MobileContext::singleton(), array( 
$startTime ) ), 'Using default MediaWiki cookie expiry.' );
-
-               // reset global back to original value
-               $wgMobileFrontendFormatCookieExpiry = $origMFCookieExpiry;
        }
 
        public function testGetStopMobileRedirectCookieDomain(){
@@ -349,16 +355,13 @@
 
        public function testDisableIncompatibleJs() {
                global $wgUseSiteJs, $wgAllowUserJs;
-               $wgUseSiteJsOrig = $wgUseSiteJs;
-               $wgAllowUserJsOrig = $wgAllowUserJs;
+
                $wgUseSiteJs = true;
                $wgAllowUserJs = true;
                $disablsIncompatibleJs = $this->getMethod( 
'disableIncompatibleJs' );
                $disablsIncompatibleJs->invoke( MobileContext::singleton() );
                $this->assertFalse( $wgAllowUserJs );
                $this->assertFalse( $wgUseSiteJs );
-               $wgUseSiteJs = $wgUseSiteJsOrig;
-               $wgAllowUserJs = $wgAllowUserJsOrig;
        }
 
        /**

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I12299805b094c7dfa44203bd6af3b04ab13ec553
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: awjrichards <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: awjrichards <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to