|
@@ 285-312 (lines=28) @@
|
| 282 |
|
Config::unnest(); |
| 283 |
|
} |
| 284 |
|
|
| 285 |
|
public function testAllowedSizeOnFileWithNoExtension() { |
| 286 |
|
// create tmp file |
| 287 |
|
$tmpFileName = 'UploadTest-testUpload'; |
| 288 |
|
$tmpFilePath = TEMP_FOLDER . '/' . $tmpFileName; |
| 289 |
|
$tmpFileContent = ''; |
| 290 |
|
for($i=0; $i<10000; $i++) $tmpFileContent .= '0'; |
| 291 |
|
file_put_contents($tmpFilePath, $tmpFileContent); |
| 292 |
|
|
| 293 |
|
// emulates the $_FILES array |
| 294 |
|
$tmpFile = array( |
| 295 |
|
'name' => $tmpFileName, |
| 296 |
|
'type' => 'text/plaintext', |
| 297 |
|
'size' => filesize($tmpFilePath), |
| 298 |
|
'tmp_name' => $tmpFilePath, |
| 299 |
|
'extension' => '', |
| 300 |
|
'error' => UPLOAD_ERR_OK, |
| 301 |
|
); |
| 302 |
|
|
| 303 |
|
$v = new UploadTest_Validator(); |
| 304 |
|
$v->setAllowedMaxFileSize(array('' => 10)); |
| 305 |
|
|
| 306 |
|
// test upload into default folder |
| 307 |
|
$u1 = new Upload(); |
| 308 |
|
$u1->setValidator($v); |
| 309 |
|
$result = $u1->loadIntoFile($tmpFile); |
| 310 |
|
|
| 311 |
|
$this->assertFalse($result, 'Load failed because size was too big'); |
| 312 |
|
} |
| 313 |
|
|
| 314 |
|
public function testUploadDoesNotAllowUnknownExtension() { |
| 315 |
|
// create tmp file |
|
@@ 314-341 (lines=28) @@
|
| 311 |
|
$this->assertFalse($result, 'Load failed because size was too big'); |
| 312 |
|
} |
| 313 |
|
|
| 314 |
|
public function testUploadDoesNotAllowUnknownExtension() { |
| 315 |
|
// create tmp file |
| 316 |
|
$tmpFileName = 'UploadTest-testUpload.php'; |
| 317 |
|
$tmpFilePath = TEMP_FOLDER . '/' . $tmpFileName; |
| 318 |
|
$tmpFileContent = ''; |
| 319 |
|
for($i=0; $i<10000; $i++) $tmpFileContent .= '0'; |
| 320 |
|
file_put_contents($tmpFilePath, $tmpFileContent); |
| 321 |
|
|
| 322 |
|
// emulates the $_FILES array |
| 323 |
|
$tmpFile = array( |
| 324 |
|
'name' => $tmpFileName, |
| 325 |
|
'type' => 'text/plaintext', |
| 326 |
|
'size' => filesize($tmpFilePath), |
| 327 |
|
'tmp_name' => $tmpFilePath, |
| 328 |
|
'extension' => 'php', |
| 329 |
|
'error' => UPLOAD_ERR_OK, |
| 330 |
|
); |
| 331 |
|
|
| 332 |
|
$v = new UploadTest_Validator(); |
| 333 |
|
$v->setAllowedExtensions(array('txt')); |
| 334 |
|
|
| 335 |
|
// test upload into default folder |
| 336 |
|
$u = new Upload(); |
| 337 |
|
$u->setValidator($v); |
| 338 |
|
$result = $u->loadIntoFile($tmpFile); |
| 339 |
|
|
| 340 |
|
$this->assertFalse($result, 'Load failed because extension was not accepted'); |
| 341 |
|
} |
| 342 |
|
|
| 343 |
|
public function testUploadAcceptsAllowedExtension() { |
| 344 |
|
// create tmp file |
|
@@ 343-373 (lines=31) @@
|
| 340 |
|
$this->assertFalse($result, 'Load failed because extension was not accepted'); |
| 341 |
|
} |
| 342 |
|
|
| 343 |
|
public function testUploadAcceptsAllowedExtension() { |
| 344 |
|
// create tmp file |
| 345 |
|
$tmpFileName = 'UploadTest-testUpload.txt'; |
| 346 |
|
$tmpFilePath = TEMP_FOLDER . '/' . $tmpFileName; |
| 347 |
|
$tmpFileContent = ''; |
| 348 |
|
for($i=0; $i<10000; $i++) $tmpFileContent .= '0'; |
| 349 |
|
file_put_contents($tmpFilePath, $tmpFileContent); |
| 350 |
|
|
| 351 |
|
// emulates the $_FILES array |
| 352 |
|
$tmpFile = array( |
| 353 |
|
'name' => $tmpFileName, |
| 354 |
|
'type' => 'text/plaintext', |
| 355 |
|
'size' => filesize($tmpFilePath), |
| 356 |
|
'tmp_name' => $tmpFilePath, |
| 357 |
|
'extension' => 'txt', |
| 358 |
|
'error' => UPLOAD_ERR_OK, |
| 359 |
|
); |
| 360 |
|
|
| 361 |
|
$v = new UploadTest_Validator(); |
| 362 |
|
$v->setAllowedExtensions(array('txt')); |
| 363 |
|
|
| 364 |
|
// test upload into default folder |
| 365 |
|
$u = new Upload(); |
| 366 |
|
$u->setValidator($v); |
| 367 |
|
$u->loadIntoFile($tmpFile); |
| 368 |
|
$file = $u->getFile(); |
| 369 |
|
$this->assertFileExists( |
| 370 |
|
AssetStoreTest_SpyStore::getLocalPath($file), |
| 371 |
|
'File upload to custom directory in /assets' |
| 372 |
|
); |
| 373 |
|
} |
| 374 |
|
|
| 375 |
|
public function testUploadDeniesNoExtensionFilesIfNoEmptyStringSetForValidatorExtensions() { |
| 376 |
|
// create tmp file |
|
@@ 375-402 (lines=28) @@
|
| 372 |
|
); |
| 373 |
|
} |
| 374 |
|
|
| 375 |
|
public function testUploadDeniesNoExtensionFilesIfNoEmptyStringSetForValidatorExtensions() { |
| 376 |
|
// create tmp file |
| 377 |
|
$tmpFileName = 'UploadTest-testUpload'; |
| 378 |
|
$tmpFilePath = TEMP_FOLDER . '/' . $tmpFileName; |
| 379 |
|
$tmpFileContent = ''; |
| 380 |
|
for($i=0; $i<10000; $i++) $tmpFileContent .= '0'; |
| 381 |
|
file_put_contents($tmpFilePath, $tmpFileContent); |
| 382 |
|
|
| 383 |
|
// emulates the $_FILES array |
| 384 |
|
$tmpFile = array( |
| 385 |
|
'name' => $tmpFileName, |
| 386 |
|
'type' => 'text/plaintext', |
| 387 |
|
'size' => filesize($tmpFilePath), |
| 388 |
|
'tmp_name' => $tmpFilePath, |
| 389 |
|
'extension' => '', |
| 390 |
|
'error' => UPLOAD_ERR_OK, |
| 391 |
|
); |
| 392 |
|
|
| 393 |
|
$v = new UploadTest_Validator(); |
| 394 |
|
$v->setAllowedExtensions(array('txt')); |
| 395 |
|
|
| 396 |
|
// test upload into default folder |
| 397 |
|
$u = new Upload(); |
| 398 |
|
$result = $u->loadIntoFile($tmpFile); |
| 399 |
|
|
| 400 |
|
$this->assertFalse($result, 'Load failed because extension was not accepted'); |
| 401 |
|
$this->assertEquals(1, count($u->getErrors()), 'There is a single error of the file extension'); |
| 402 |
|
} |
| 403 |
|
|
| 404 |
|
public function testUploadTarGzFileTwiceAppendsNumber() { |
| 405 |
|
// create tmp file |