Test uploading a file of size $wgMaxUploadSize
authorAntoine Musso <hashar@users.mediawiki.org>
Tue, 25 Jan 2011 21:26:28 +0000 (21:26 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Tue, 25 Jan 2011 21:26:28 +0000 (21:26 +0000)
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

index 2401bf1..199471c 100644 (file)
@@ -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 {