UploadBaseTest: Use setMwGlobals() instead of juggling globals
authorTimo Tijhof <krinklemail@gmail.com>
Tue, 7 Oct 2014 03:13:32 +0000 (05:13 +0200)
committerTimo Tijhof <krinklemail@gmail.com>
Tue, 7 Oct 2014 03:13:32 +0000 (05:13 +0200)
Abstracts the logic for restoration into the built-in teardown()
handler.

Also purify the test configuration by setting wgHooks and
wgFileExtensions to otherwise empty arrays instead of extending
existing ones.

Change-Id: Ied65ee62f658dd650c603a54e72cd19965867a8f

tests/phpunit/includes/upload/UploadBaseTest.php

index 41d8dee..f23b264 100644 (file)
@@ -9,21 +9,17 @@ class UploadBaseTest extends MediaWikiTestCase {
        protected $upload;
 
        protected function setUp() {
-               global $wgHooks;
                parent::setUp();
 
                $this->upload = new UploadTestHandler;
-               $this->hooks = $wgHooks;
-               $wgHooks['InterwikiLoadPrefix'][] = function ( $prefix, &$data ) {
-                       return false;
-               };
-       }
-
-       protected function tearDown() {
-               global $wgHooks;
-               $wgHooks = $this->hooks;
 
-               parent::tearDown();
+               $this->setMwGlobals( 'wgHooks', array(
+                       'InterwikiLoadPrefix' => array(
+                               function ( $prefix, &$data ) {
+                                       return false;
+                               }
+                       ),
+               ) );
        }
 
        /**
@@ -112,22 +108,22 @@ class UploadBaseTest extends MediaWikiTestCase {
         * This method should be abstracted so we can test different settings.
         */
        public function testMaxUploadSize() {
-               global $wgMaxUploadSize;
-               $savedGlobal = $wgMaxUploadSize; // save global
-               global $wgFileExtensions;
-               $wgFileExtensions[] = 'txt';
-
-               $wgMaxUploadSize = 100;
+               $this->setMwGlobals( array(
+                       'wgMaxUploadSize' => 100,
+                       'wgFileExtensions' => array(
+                               'txt',
+                       ),
+               ) );
 
-               $filename = $this->createFileOfSize( $wgMaxUploadSize );
+               $filename = $this->createFileOfSize( 100 );
                $this->upload->initializePathInfo( basename( $filename ) . '.txt', $filename, 100 );
                $result = $this->upload->verifyUpload();
                unlink( $filename );
 
                $this->assertEquals(
-                       array( 'status' => UploadBase::OK ), $result );
-
-               $wgMaxUploadSize = $savedGlobal; // restore global
+                       array( 'status' => UploadBase::OK ),
+                       $result
+               );
        }