UploadBaseTest: Use setMwGlobals() instead of juggling globals
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
This commit is contained in:
parent
17adab6135
commit
dabd389220
1 changed files with 17 additions and 21 deletions
|
|
@ -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';
|
||||
$this->setMwGlobals( array(
|
||||
'wgMaxUploadSize' => 100,
|
||||
'wgFileExtensions' => array(
|
||||
'txt',
|
||||
),
|
||||
) );
|
||||
|
||||
$wgMaxUploadSize = 100;
|
||||
|
||||
$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
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue