Tests: Use more setMwGlobals
authorumherirrender <umherirrender_de.wp@web.de>
Thu, 21 Mar 2013 19:35:44 +0000 (20:35 +0100)
committerumherirrender <umherirrender_de.wp@web.de>
Thu, 21 Mar 2013 19:35:44 +0000 (20:35 +0100)
Change some tests to use setMwGlobals to have restoring of globals after
the test.
This also removes some save/restore code, which is not needed, due to
the automatically restoring on tearDown with setMwGlobals.

Change-Id: I8d2ac9f6cc14f0bd4ee8eb851c09f2e71babc6e0

15 files changed:
tests/phpunit/includes/ExtraParserTest.php
tests/phpunit/includes/GlobalFunctions/wfExpandUrlTest.php
tests/phpunit/includes/HtmlTest.php
tests/phpunit/includes/RevisionStorageTest_ContentHandlerUseDB.php
tests/phpunit/includes/RevisionTest.php
tests/phpunit/includes/SeleniumConfigurationTest.php
tests/phpunit/includes/WebRequestTest.php
tests/phpunit/includes/WikiPageTest_ContentHandlerUseDB.php
tests/phpunit/includes/content/TextContentTest.php
tests/phpunit/includes/jobqueue/JobQueueTest.php
tests/phpunit/includes/media/BitmapMetadataHandlerTest.php
tests/phpunit/includes/media/ExifRotationTest.php
tests/phpunit/includes/upload/UploadFromUrlTest.php
tests/phpunit/includes/upload/UploadStashTest.php
tests/phpunit/maintenance/DumpTestCase.php

index e0e5535..c840056 100644 (file)
@@ -87,8 +87,7 @@ class ExtraParserTest extends MediaWikiTestCase {
         * cleanSig() should do nothing if disabled
         */
        function testCleanSigDisabled() {
-               global $wgCleanSignatures;
-               $wgCleanSignatures = false;
+               $this->setMwGlobals( 'wgCleanSignatures', false );
 
                $title = Title::newFromText( __FUNCTION__ );
                $outputText = $this->parser->cleanSig( "{{Foo}} ~~~~" );
index c1225e3..8c67ced 100644 (file)
@@ -6,11 +6,10 @@ class WfExpandUrlTest extends MediaWikiTestCase {
        /** @dataProvider provideExpandableUrls */
        public function testWfExpandUrl( $fullUrl, $shortUrl, $defaultProto, $server, $canServer, $httpsMode, $message ) {
                // Fake $wgServer and $wgCanonicalServer
-               global $wgServer, $wgCanonicalServer;
-               $oldServer = $wgServer;
-               $oldCanServer = $wgCanonicalServer;
-               $wgServer = $server;
-               $wgCanonicalServer = $canServer;
+               $this->setMwGlobals( array(
+                       'wgServer' => $server,
+                       'wgCanonicalServer' => $canServer,
+               ) );
 
                // Fake $_SERVER['HTTPS'] if needed
                if ( $httpsMode ) {
@@ -20,10 +19,6 @@ class WfExpandUrlTest extends MediaWikiTestCase {
                }
 
                $this->assertEquals( $fullUrl, wfExpandUrl( $shortUrl, $defaultProto ), $message );
-
-               // Restore $wgServer and $wgCanonicalServer
-               $wgServer = $oldServer;
-               $wgCanonicalServer = $oldCanServer;
        }
 
        /**
index 590664e..554a6d0 100644 (file)
@@ -43,8 +43,6 @@ class HtmlTest extends MediaWikiTestCase {
        }
 
        public function testElementBasics() {
-               global $wgWellFormedXml;
-
                $this->assertEquals(
                        '<img>',
                        Html::element( 'img', null, '' ),
@@ -63,7 +61,7 @@ class HtmlTest extends MediaWikiTestCase {
                        'Close tag for empty element (array, string)'
                );
 
-               $wgWellFormedXml = true;
+               $this->setMwGlobals( 'wgWellFormedXml', true );
 
                $this->assertEquals(
                        '<img />',
@@ -90,8 +88,6 @@ class HtmlTest extends MediaWikiTestCase {
        }
 
        public function testExpandAttributesForBooleans() {
-               global $wgHtml5, $wgWellFormedXml;
-
                $this->assertEquals(
                        '',
                        Html::expandAttributes( array( 'selected' => false ) ),
@@ -114,7 +110,7 @@ class HtmlTest extends MediaWikiTestCase {
                        'Boolean attributes have no value when value is true (passed as numerical array)'
                );
 
-               $wgWellFormedXml = true;
+               $this->setMwGlobals( 'wgWellFormedXml', true );
 
                $this->assertEquals(
                        ' selected=""',
@@ -122,7 +118,7 @@ class HtmlTest extends MediaWikiTestCase {
                        'Boolean attributes have empty string value when value is true (wgWellFormedXml)'
                );
 
-               $wgHtml5 = false;
+               $this->setMwGlobals( 'wgHtml5', false );
 
                $this->assertEquals(
                        ' selected="selected"',
@@ -136,8 +132,6 @@ class HtmlTest extends MediaWikiTestCase {
         * Please note it output a string prefixed with a space!
         */
        public function testExpandAttributesVariousExpansions() {
-               global $wgWellFormedXml;
-
                ### NOT EMPTY ####
                $this->assertEquals(
                        ' empty_string=""',
@@ -160,7 +154,7 @@ class HtmlTest extends MediaWikiTestCase {
                        'Number 0 value needs no quotes'
                );
 
-               $wgWellFormedXml = true;
+               $this->setMwGlobals( 'wgWellFormedXml', true );
 
                $this->assertEquals(
                        ' empty_string=""',
index 3948e34..39673c0 100644 (file)
@@ -6,14 +6,9 @@
  * ^--- important, causes temporary tables to be used instead of the real database
  */
 class RevisionTest_ContentHandlerUseDB extends RevisionStorageTest {
-       var $saveContentHandlerNoDB = null;
 
        function setUp() {
-               global $wgContentHandlerUseDB;
-
-               $this->saveContentHandlerNoDB = $wgContentHandlerUseDB;
-
-               $wgContentHandlerUseDB = false;
+               $this->setMwGlobals( 'wgContentHandlerUseDB', false );
 
                $dbw = wfGetDB( DB_MASTER );
 
@@ -32,14 +27,6 @@ class RevisionTest_ContentHandlerUseDB extends RevisionStorageTest {
                parent::setUp();
        }
 
-       function tearDown() {
-               global $wgContentHandlerUseDB;
-
-               parent::tearDown();
-
-               $wgContentHandlerUseDB = $this->saveContentHandlerNoDB;
-       }
-
        /**
         * @covers Revision::selectFields
         */
index db0245b..9380928 100644 (file)
@@ -134,9 +134,7 @@ class RevisionTest extends MediaWikiTestCase {
 
        function testCompressRevisionTextUtf8Gzip() {
                $this->checkPHPExtension( 'zlib' );
-
-               global $wgCompressRevisions;
-               $wgCompressRevisions = true;
+               $this->setMwGlobals( 'wgCompressRevisions', true );
 
                $row = new stdClass;
                $row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
index 3422c90..4b49f63 100644 (file)
@@ -138,8 +138,8 @@ testBrowser                 = "firefox"
                $seleniumSettings = array();
                $seleniumBrowsers = array();
                $seleniumTestSuites = array();
-               global $wgSeleniumConfigFile;
-               $wgSeleniumConfigFile = '';
+               $this->setMwGlobals( 'wgSeleniumConfigFile', '' );
+
                SeleniumConfig::getSeleniumSettings( $seleniumSettings,
                        $seleniumBrowsers,
                        $seleniumTestSuites );
@@ -152,9 +152,9 @@ testBrowser                 = "firefox"
                $seleniumSettings = array();
                $seleniumBrowsers = array();
                $seleniumTestSuites = array();
-               global $wgSeleniumConfigFile;
                $this->writeToTempFile( $this->testConfig0 );
-               $wgSeleniumConfigFile = $this->tempFileName;
+               $this->setMwGlobals( 'wgSeleniumConfigFile', $this->tempFileName );
+
                SeleniumConfig::getSeleniumSettings( $seleniumSettings,
                        $seleniumBrowsers,
                        $seleniumTestSuites );
index 46f8025..d382f6f 100644 (file)
@@ -102,10 +102,12 @@ class WebRequestTest extends MediaWikiTestCase {
         * @dataProvider provideGetIP
         */
        function testGetIP( $expected, $input, $squid, $private, $description ) {
-               global $wgSquidServersNoPurge, $wgUsePrivateIPs;
                $_SERVER = $input;
-               $wgSquidServersNoPurge = $squid;
-               $wgUsePrivateIPs = $private;
+               $this->setMwGlobals( array(
+                       'wgSquidServersNoPurge' => $squid,
+                       'wgUsePrivateIPs' => $private,
+               ) );
+
                $request = new WebRequest();
                $result = $request->getIP();
                $this->assertEquals( $expected, $result, $description );
index 1d937e9..dca9910 100644 (file)
@@ -6,16 +6,10 @@
  * ^--- important, causes temporary tables to be used instead of the real database
  */
 class WikiPageTest_ContentHandlerUseDB extends WikiPageTest {
-       var $saveContentHandlerNoDB = null;
 
        function setUp() {
-               global $wgContentHandlerUseDB;
-
                parent::setUp();
-
-               $this->saveContentHandlerNoDB = $wgContentHandlerUseDB;
-
-               $wgContentHandlerUseDB = false;
+               $this->setMwGlobals( 'wgContentHandlerUseDB', false );
 
                $dbw = wfGetDB( DB_MASTER );
 
@@ -32,14 +26,6 @@ class WikiPageTest_ContentHandlerUseDB extends WikiPageTest {
                }
        }
 
-       function tearDown() {
-               global $wgContentHandlerUseDB;
-
-               $wgContentHandlerUseDB = $this->saveContentHandlerNoDB;
-
-               parent::tearDown();
-       }
-
        public function testGetContentModel() {
                $page = $this->createPage( "WikiPageTest_testGetContentModel", "some text", CONTENT_MODEL_JAVASCRIPT );
 
index 382f71a..4fc2d51 100644 (file)
@@ -211,15 +211,11 @@ class TextContentTest extends MediaWikiLangTestCase {
         * @group Database
         */
        public function testIsCountable( $text, $hasLinks, $mode, $expected ) {
-               global $wgArticleCountMethod;
-
-               $old = $wgArticleCountMethod;
-               $wgArticleCountMethod = $mode;
+               $this->setMwGlobals( 'wgArticleCountMethod', $mode );
 
                $content = $this->newContent( $text );
 
                $v = $content->isCountable( $hasLinks, $this->context->getTitle() );
-               $wgArticleCountMethod = $old;
 
                $this->assertEquals( $expected, $v, 'isCountable() returned unexpected value ' . var_export( $v, true )
                        . ' instead of ' . var_export( $expected, true ) . " in mode `$mode` for text \"$text\"" );
index f3f9c11..31d7a46 100644 (file)
@@ -8,7 +8,6 @@
 class JobQueueTest extends MediaWikiTestCase {
        protected $key;
        protected $queueRand, $queueRandTTL, $queueFifo, $queueFifoTTL;
-       protected $old = array();
 
        function __construct( $name = null, array $data = array(), $dataName = '' ) {
                parent::__construct( $name, $data, $dataName );
@@ -17,10 +16,11 @@ class JobQueueTest extends MediaWikiTestCase {
        }
 
        protected function setUp() {
-               global $wgMemc, $wgJobTypeConf;
+               global $wgJobTypeConf;
                parent::setUp();
-               $this->old['wgMemc'] = $wgMemc;
-               $wgMemc = new HashBagOStuff();
+
+               $this->setMwGlobals( 'wgMemc', new HashBagOStuff() );
+
                if ( $this->getCliArg( 'use-jobqueue=' ) ) {
                        $name = $this->getCliArg( 'use-jobqueue=' );
                        if ( !isset( $wgJobTypeConf[$name] ) ) {
@@ -51,7 +51,6 @@ class JobQueueTest extends MediaWikiTestCase {
        }
 
        protected function tearDown() {
-               global $wgMemc;
                parent::tearDown();
                foreach ( array(
                        'queueRand', 'queueRandTTL', 'queueTimestamp', 'queueTimestampTTL',
@@ -67,7 +66,6 @@ class JobQueueTest extends MediaWikiTestCase {
                        }
                        $this->$q = null;
                }
-               $wgMemc = $this->old['wgMemc'];
        }
 
        /**
index b221b83..117a072 100644 (file)
@@ -18,8 +18,6 @@ class BitmapMetadataHandlerTest extends MediaWikiTestCase {
         * translation (to en) where XMP should win.
         */
        public function testMultilingualCascade() {
-               global $wgShowEXIF;
-
                if ( !wfDl( 'exif' ) ) {
                        $this->markTestSkipped( "This test needs the exif extension." );
                }
@@ -27,7 +25,7 @@ class BitmapMetadataHandlerTest extends MediaWikiTestCase {
                        $this->markTestSkipped( "This test needs the xml extension." );
                }
 
-               $wgShowEXIF = true;
+               $this->setMwGlobals( 'wgShowEXIF', true );
 
                $meta = BitmapMetadataHandler::Jpeg( $this->filePath .
                        '/Xmp-exif-multilingual_test.jpg' );
index db29d17..d9d7a68 100644 (file)
@@ -25,21 +25,11 @@ class ExifRotationTest extends MediaWikiTestCase {
                if ( !wfDl( 'exif' ) ) {
                        $this->markTestSkipped( "This test needs the exif extension." );
                }
-               global $wgShowEXIF;
-               $this->show = $wgShowEXIF;
-               $wgShowEXIF = true;
 
-               global $wgEnableAutoRotation;
-               $this->oldAuto = $wgEnableAutoRotation;
-               $wgEnableAutoRotation = true;
-       }
-
-       protected function tearDown() {
-               global $wgShowEXIF, $wgEnableAutoRotation;
-               $wgShowEXIF = $this->show;
-               $wgEnableAutoRotation = $this->oldAuto;
-
-               parent::tearDown();
+               $this->setMwGlobals( array(
+                       'wgShowEXIF' => true,
+                       'wgEnableAutoRotation' => true,
+               ) );
        }
 
        /**
@@ -139,14 +129,11 @@ class ExifRotationTest extends MediaWikiTestCase {
         * @dataProvider provideFilesNoAutoRotate
         */
        function testMetadataNoAutoRotate( $name, $type, $info ) {
-               global $wgEnableAutoRotation;
-               $wgEnableAutoRotation = false;
+               $this->setMwGlobals( 'wgEnableAutoRotation', false );
 
                $file = $this->dataFile( $name, $type );
                $this->assertEquals( $info['width'], $file->getWidth(), "$name: width check" );
                $this->assertEquals( $info['height'], $file->getHeight(), "$name: height check" );
-
-               $wgEnableAutoRotation = true;
        }
 
        /**
@@ -154,8 +141,7 @@ class ExifRotationTest extends MediaWikiTestCase {
         * @dataProvider provideFilesNoAutoRotate
         */
        function testRotationRenderingNoAutoRotate( $name, $type, $info, $thumbs ) {
-               global $wgEnableAutoRotation;
-               $wgEnableAutoRotation = false;
+               $this->setMwGlobals( 'wgEnableAutoRotation', false );
 
                foreach ( $thumbs as $size => $out ) {
                        if ( preg_match( '/^(\d+)px$/', $size, $matches ) ) {
@@ -187,7 +173,6 @@ class ExifRotationTest extends MediaWikiTestCase {
                                $this->assertEquals( $out[1], $gis[1], "$name: thumb actual height check for $size" );
                        }
                }
-               $wgEnableAutoRotation = true;
        }
 
        public static function provideFilesNoAutoRotate() {
index 4d2d8ce..ac93aa7 100644 (file)
@@ -8,12 +8,13 @@
 class UploadFromUrlTest extends ApiTestCase {
 
        protected function setUp() {
-               global $wgEnableUploads, $wgAllowCopyUploads, $wgAllowAsyncCopyUploads;
                parent::setUp();
 
-               $wgEnableUploads = true;
-               $wgAllowCopyUploads = true;
-               $wgAllowAsyncCopyUploads = true;
+               $this->setMwGlobals( array(
+                       'wgEnableUploads' => true,
+                       'wgAllowCopyUploads' => true,
+                       'wgAllowAsyncCopyUploads' => true,
+               ) );
                wfSetupSession();
 
                if ( wfLocalFile( 'UploadFromUrlTest.png' )->exists() ) {
index 8fcaa21..7a0fea4 100644 (file)
@@ -44,8 +44,7 @@ class UploadStashTest extends MediaWikiTestCase {
        }
 
        public function testBug29408() {
-               global $wgUser;
-               $wgUser = self::$users['uploader']->user;
+               $this->setMwGlobals( 'wgUser', self::$users['uploader']->user );
 
                $repo = RepoGroup::singleton()->getLocalRepo();
                $stash = new UploadStash( $repo );
index 40d24fc..f82898f 100644 (file)
@@ -73,8 +73,6 @@ abstract class DumpTestCase extends MediaWikiLangTestCase {
         * Clears $wgUser, and reports errors from addDBData to PHPUnit
         */
        protected function setUp() {
-               global $wgUser;
-
                parent::setUp();
 
                // Check if any Exception is stored for rethrowing from addDBData
@@ -83,7 +81,7 @@ abstract class DumpTestCase extends MediaWikiLangTestCase {
                        throw $this->exceptionFromAddDBData;
                }
 
-               $wgUser = new User();
+               $this->setMwGlobals( 'wgUser', new User() );
        }
 
        /**