Index: trunk/phase3/tests/phpunit/includes/UploadTest.php |
— | — | @@ -75,6 +75,42 @@ |
76 | 76 | 'upload empty file' ); |
77 | 77 | } |
78 | 78 | |
| 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 | + } |
79 | 115 | } |
80 | 116 | |
81 | 117 | class UploadTestHandler extends UploadBase { |