From 045772c641aa6f22fbf7d305097a8578c25ce47a Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Tue, 25 Jan 2011 21:26:28 +0000 Subject: [PATCH] Test uploading a file of size $wgMaxUploadSize TODO: method testMaxUploadSize() shoud be able to use differents settings. The assertion could then get moved elsewhere in a nice helper. --- tests/phpunit/includes/UploadTest.php | 36 +++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/phpunit/includes/UploadTest.php b/tests/phpunit/includes/UploadTest.php index 2401bf1200..199471c82b 100644 --- a/tests/phpunit/includes/UploadTest.php +++ b/tests/phpunit/includes/UploadTest.php @@ -75,6 +75,42 @@ class UploadTest extends MediaWikiTestCase { 'upload empty file' ); } + // Helper used to create an empty file of size $size. + private function createFileOfSize( $size ) { + $filename = '/tmp/mwuploadtest-' . posix_getpid() . '.txt' ; + + $fh = fopen( $filename, 'w' ); + fseek( $fh, $size-1, SEEK_SET); + fwrite( $fh, 0x00 ); + fclose( $fh ); + + return $filename; + } + + /** + * test uploading a 100 bytes file with wgMaxUploadSize = 100 + * + * 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; + + $filename = $this->createFileOfSize( $wgMaxUploadSize ); + $this->upload->initializePathInfo( basename($filename), $filename, 100 ); + $result = $this->upload->verifyUpload(); + unlink( $filename ); + + $this->assertEquals( + array( 'status' => UploadTestHandler::OK ), $result ); + + $wgMaxUploadSize = $savedGlobal; // restore global + } } class UploadTestHandler extends UploadBase { -- 2.20.1