r80992 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80991‎ | r80992 | r80993 >
Date:21:26, 25 January 2011
Author:hashar
Status:resolved (Comments)
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/tests/phpunit/includes/UploadTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/UploadTest.php
@@ -75,6 +75,42 @@
7676 'upload empty file' );
7777 }
7878
 79+ // Helper used to create an empty file of size $size.
 80+ private function createFileOfSize( $size ) {
 81+ $filename = '/tmp/mwuploadtest-' . posix_getpid() . '.txt' ;
 82+
 83+ $fh = fopen( $filename, 'w' );
 84+ fseek( $fh, $size-1, SEEK_SET);
 85+ fwrite( $fh, 0x00 );
 86+ fclose( $fh );
 87+
 88+ return $filename;
 89+ }
 90+
 91+ /**
 92+ * test uploading a 100 bytes file with wgMaxUploadSize = 100
 93+ *
 94+ * This method should be abstracted so we can test different settings.
 95+ */
 96+
 97+ public function testMaxUploadSize() {
 98+ global $wgMaxUploadSize;
 99+ $savedGlobal = $wgMaxUploadSize; // save global
 100+ global $wgFileExtensions;
 101+ $wgFileExtensions[] = 'txt';
 102+
 103+ $wgMaxUploadSize = 100;
 104+
 105+ $filename = $this->createFileOfSize( $wgMaxUploadSize );
 106+ $this->upload->initializePathInfo( basename($filename), $filename, 100 );
 107+ $result = $this->upload->verifyUpload();
 108+ unlink( $filename );
 109+
 110+ $this->assertEquals(
 111+ array( 'status' => UploadTestHandler::OK ), $result );
 112+
 113+ $wgMaxUploadSize = $savedGlobal; // restore global
 114+ }
79115 }
80116
81117 class UploadTestHandler extends UploadBase {

Follow-up revisions

RevisionCommit summaryAuthorDate
r81883Fix for r80992. Remove posix extension requisite. Made to work in non-Unix sy...platonides10:48, 10 February 2011

Comments

#Comment by Bryan (talk | contribs)   21:44, 25 January 2011

tempnam and wfTempDir!

Status & tagging log