summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/upload/UploadBaseTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/phpunit/includes/upload/UploadBaseTest.php')
-rw-r--r--tests/phpunit/includes/upload/UploadBaseTest.php41
1 files changed, 18 insertions, 23 deletions
diff --git a/tests/phpunit/includes/upload/UploadBaseTest.php b/tests/phpunit/includes/upload/UploadBaseTest.php
index 3d3b0068..9441b77f 100644
--- a/tests/phpunit/includes/upload/UploadBaseTest.php
+++ b/tests/phpunit/includes/upload/UploadBaseTest.php
@@ -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;
+ }
+ ),
+ ) );
}
/**
@@ -97,7 +93,7 @@ class UploadBaseTest extends MediaWikiTestCase {
// Helper used to create an empty file of size $size.
private function createFileOfSize( $size ) {
- $filename = tempnam( wfTempDir(), "mwuploadtest" );
+ $filename = $this->getNewTempFile();
$fh = fopen( $filename, 'w' );
ftruncate( $fh, $size );
@@ -112,22 +108,21 @@ 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
+ );
}