From ccdf630c9da867fe3874ce9bfc6cc844ba31e45e Mon Sep 17 00:00:00 2001 From: ve3 Date: Tue, 10 Dec 2024 14:11:25 +0700 Subject: [PATCH] Fix `E_USER_ERROR` deprecated on PHP 8.4 --- .gitignore | 3 +- Rundiz/Upload/Upload.php | 6 +- phpunit.xml | 37 +- tests/phpunit/PHP70/ThrowErrorTest.php | 130 ------ tests/phpunit/PHP70/UploadTest.php | 421 ------------------ .../phpunit/PHP70/ValidatePropertiesTest.php | 180 -------- .../{PHP72 => PHP84}/ThrowErrorTest.php | 25 +- tests/phpunit/{PHP72 => PHP84}/UploadTest.php | 5 +- .../ValidatePropertiesTest.php | 2 +- tests/phpunit/PHPB70/ThrowErrorTest.php | 115 ----- tests/phpunit/PHPB70/UploadTest.php | 421 ------------------ .../phpunit/PHPB70/ValidatePropertiesTest.php | 180 -------- 12 files changed, 36 insertions(+), 1489 deletions(-) delete mode 100644 tests/phpunit/PHP70/ThrowErrorTest.php delete mode 100644 tests/phpunit/PHP70/UploadTest.php delete mode 100644 tests/phpunit/PHP70/ValidatePropertiesTest.php rename tests/phpunit/{PHP72 => PHP84}/ThrowErrorTest.php (82%) rename tests/phpunit/{PHP72 => PHP84}/UploadTest.php (99%) rename tests/phpunit/{PHP72 => PHP84}/ValidatePropertiesTest.php (99%) delete mode 100644 tests/phpunit/PHPB70/ThrowErrorTest.php delete mode 100644 tests/phpunit/PHPB70/UploadTest.php delete mode 100644 tests/phpunit/PHPB70/ValidatePropertiesTest.php diff --git a/.gitignore b/.gitignore index 143c426..eef84e3 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.phpunit.result.cache \ No newline at end of file +.phpunit.result.cache +.phpunit.cache \ No newline at end of file diff --git a/Rundiz/Upload/Upload.php b/Rundiz/Upload/Upload.php index 5dc1181..1622533 100644 --- a/Rundiz/Upload/Upload.php +++ b/Rundiz/Upload/Upload.php @@ -647,6 +647,7 @@ protected function setErrorMessage( * Or you can call this method in case that you want to process the other uploaded file next to previous one. * * @param string $input_file_name The name of input file. + * @throws \InvalidArgumentException Throw errors if invalid argument type. */ public function setInputFileName($input_file_name) { @@ -780,6 +781,7 @@ protected function setWebSafeFileName() * @link http://php.net/manual/en/function.finfo-file.php More info about finfo_file() function. * @param string $input_file_name The input file name. This support only one file upload. * @return string Return file's mime type or error message. + * @throws \InvalidArgumentException Throw errors if invalid argument type. */ public function testGetUploadedMimetype($input_file_name = null) { @@ -1305,7 +1307,7 @@ protected function validateImageDimension() /** * Validate that these options properties has properly set in the correct type. * - * @throws Exception Throw errors on invalid property type. + * @throws \DomainException Throw errors when `move_uploaded_to` property was not set. */ protected function validateOptionsProperties() { @@ -1356,7 +1358,7 @@ protected function validateOptionsProperties() } if (empty($this->move_uploaded_to)) { - trigger_error('The move_uploaded_to property was not set', E_USER_ERROR); + throw new \DomainException('The move_uploaded_to property was not set', 1); } if (!is_string($this->new_file_name) && $this->new_file_name != null) { diff --git a/phpunit.xml b/phpunit.xml index 52cb7d4..4cf17fa 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,21 +1,20 @@ - - - - ./tests/phpunit/PHPB70 - ./tests/phpunit/PHP70 - ./tests/phpunit/PHP70 - ./tests/phpunit/PHP72 - - - \ No newline at end of file + + + + + + ./tests/phpunit/PHP84 + + + diff --git a/tests/phpunit/PHP70/ThrowErrorTest.php b/tests/phpunit/PHP70/ThrowErrorTest.php deleted file mode 100644 index 4b7270e..0000000 --- a/tests/phpunit/PHP70/ThrowErrorTest.php +++ /dev/null @@ -1,130 +0,0 @@ -temp_folder) || stripos($this->temp_folder, DIRECTORY_SEPARATOR . 'temp') === false) { - // on error, the temp folder property will not set, do nothing here. - return ; - } - - $files = glob($this->temp_folder.'*.*'); - if (is_array($files)) { - foreach ($files as $file) { - if (is_file($file) && is_writable($file) && strpos($file, '.gitkeep') === false) { - unlink($file); - } - } - unset($file); - } - unset($files); - }// __destruct - - - private $asset_folder; - private $temp_folder; - private $file_text; - - - public function setUp() - { - if ( - class_exists('\PHPUnit_Runner_Version') && - method_exists('\PHPUnit_Runner_Version', 'id') && - version_compare(\PHPUnit_Runner_Version::id(), '6.0', '<') - ) { - $this->markTestSkipped('Require PHPUnit v6.0.x'); - } elseif ( - class_exists('\PHPUnit\Runner\Version') && - method_exists('\PHPUnit\Runner\Version', 'id') && - version_compare(\PHPUnit\Runner\Version::id(), '6.0', '<') - ) { - $this->markTestSkipped('Require PHPUnit v6.0.x'); - } - - $this->asset_folder = \Rundiz\Upload\Tests\CommonConfig::getAssetsDir(); - $this->temp_folder = \Rundiz\Upload\Tests\CommonConfig::getTempDir(); - - // copy files from assets folder to temp to prevent file deletion while set it to $_FILES. - $files = glob($this->asset_folder.'*.*'); - if (is_array($files)) { - foreach ($files as $file) { - $destination = str_replace($this->asset_folder, $this->temp_folder, $file); - copy($file, $destination); - unset($destination); - } - unset($file); - } - unset($files); - - // setup file same as it is in $_FILES. - $this->file_text['filename'] = array( - 'name' => 'text.txt', - 'type' => 'text/plain', - 'tmp_name' => $this->temp_folder.'text.txt', - 'error' => 0, - 'size' => filesize($this->temp_folder.'text.txt'), - ); - }// setUp - - - public function tearDown() - { - $this->file_text = null; - $_FILES = array(); - }// tearDown - - - /** - * @expectedException InvalidArgumentException - */ - public function testInvalidInputFileNameType() - { - $_FILES = $this->file_text; - - $Upload = new \Rundiz\Upload\Upload(array('filename')); - $Upload->move_uploaded_to = $this->temp_folder; - $Upload->upload(); - - unset($Upload); - }// testInvalidInputFileNameType - - - /** - * @expectedException InvalidArgumentException - */ - public function testInvalidInputFileNameTypeForGetUploadedMimeType() - { - $_FILES = $this->file_text; - - $Upload = new \Rundiz\Upload\Upload('filename'); - $Upload->testGetUploadedMimetype(array('filename')); - - unset($Upload); - }// testInvalidInputFileNameTypeForGetUploadedMimeType - - - /** - * @expectedException PHPUnit\Framework\Error - */ - public function testMoveUploadedToError() - { - $this->expectException(\PHPUnit\Framework\Error\Error::class); - $_FILES = $this->file_text; - - $Upload = new \Rundiz\Upload\Upload('filename'); - $Upload->move_uploaded_to = null; - $Upload->upload(); - - unset($Upload); - }// testMoveUploadedToError - - -} \ No newline at end of file diff --git a/tests/phpunit/PHP70/UploadTest.php b/tests/phpunit/PHP70/UploadTest.php deleted file mode 100644 index 737a331..0000000 --- a/tests/phpunit/PHP70/UploadTest.php +++ /dev/null @@ -1,421 +0,0 @@ -temp_folder) || stripos($this->temp_folder, DIRECTORY_SEPARATOR . 'temp') === false) { - // on error, the temp folder property will not set, do nothing here. - return ; - } - - $files = glob($this->temp_folder.'*.*'); - if (is_array($files)) { - foreach ($files as $file) { - if (is_file($file) && is_writable($file) && strpos($file, '.gitkeep') === false) { - unlink($file); - } - } - unset($file); - } - unset($files); - }// __destruct - - - private $asset_folder; - private $temp_folder; - private $file_text; - private $file_dangertext; - private $file_falseimage; - private $file_51kbimage; - private $file_fakejpg_butpng; - private $files_multiple; - - - public function setUp() - { - $this->asset_folder = \Rundiz\Upload\Tests\CommonConfig::getAssetsDir(); - $this->temp_folder = \Rundiz\Upload\Tests\CommonConfig::getTempDir(); - - // copy files from assets folder to temp to prevent file deletion while set it to $_FILES. - $files = glob($this->asset_folder.'*.*'); - if (is_array($files)) { - foreach ($files as $file) { - $destination = str_replace($this->asset_folder, $this->temp_folder, $file); - copy($file, $destination); - unset($destination); - } - unset($file); - } - unset($files); - - // setup file same as it is in $_FILES. - $this->file_text['filename'] = array( - 'name' => 'text.txt', - 'type' => 'text/plain', - 'tmp_name' => $this->temp_folder.'text.txt', - 'error' => 0, - 'size' => filesize($this->temp_folder.'text.txt'), - ); - $this->file_dangertext['filename'] = array( - 'name' => 'not-safe-text.txt', - 'type' => 'text/plain', - 'tmp_name' => $this->temp_folder.'not-safe-text.txt', - 'error' => 0, - 'size' => filesize($this->temp_folder.'not-safe-text.txt'), - ); - $this->file_falseimage['filename'] = array( - 'name' => 'false-image.jpg', - 'type' => 'image/jpeg', - 'tmp_name' => $this->temp_folder.'false-image.jpg', - 'error' => 0, - 'size' => filesize($this->temp_folder.'false-image.jpg'), - ); - $this->file_51kbimage['filename'] = array( - 'name' => '51KB-image.jpg', - 'type' => 'image/jpeg', - 'tmp_name' => $this->temp_folder.'51KB-image.jpg', - 'error' => 0, - 'size' => filesize($this->temp_folder.'51KB-image.jpg'), - ); - $this->file_fakejpg_butpng['filename'] = array( - 'name' => 'fakepng-butjpg.png', - 'type' => 'image/jpeg', - 'tmp_name' => $this->temp_folder.'fakepng-butjpg.png', - 'error' => 0, - 'size' => filesize($this->temp_folder.'fakepng-butjpg.png'), - ); - $this->files_multiple['filename'] = array( - 'name' => array( - 0 => 'text.txt', - 1 => 'not-safe-text.txt', - 2 => 'false-image.jpg', - 3 => '51KB-image.jpg', - 4 => 'fakepng-butjpg.png', - ), - 'type' => array( - 0 => 'text/plain', - 1 => 'text/plain', - 2 => 'image/jpeg', - 3 => 'image/jpeg', - 4 => 'image/png', - ), - 'tmp_name' => array( - 0 => $this->temp_folder.'text.txt', - 1 => $this->temp_folder.'not-safe-text.txt', - 2 => $this->temp_folder.'false-image.jpg', - 3 => $this->temp_folder.'51KB-image.jpg', - 4 => $this->temp_folder.'fakepng-butjpg.png', - ), - 'error' => array( - 0 => 0, - 1 => 0, - 2 => 0, - 3 => 0, - 4 => 0, - ), - 'size' => array( - 0 => filesize($this->temp_folder.'text.txt'), - 1 => filesize($this->temp_folder.'not-safe-text.txt'), - 2 => filesize($this->temp_folder.'false-image.jpg'), - 3 => filesize($this->temp_folder.'51KB-image.jpg'), - 4 => filesize($this->temp_folder.'fakepng-butjpg.png'), - ), - ); - }// setUp - - - public function tearDown() - { - $this->file_51kbimage = null; - $this->file_fakejpg_butpng = null; - $this->file_dangertext = null; - $this->file_falseimage = null; - $this->file_text = null; - $this->files_multiple = null; - $_FILES = array(); - }// tearDown - - - public function testGetDefaultFileExtensionsMimeTypes() - { - $Upload = new \Rundiz\Upload\Upload('filename'); - - $this->assertTrue(is_array($Upload->getDefaultFileExtensionsMimeTypes())); - $this->assertArraySubset(array('txt' => array('text/plain')), $Upload->getDefaultFileExtensionsMimeTypes()); - - unset($Upload); - }// testGetDefaultFileExtensionsMimeTypes - - - public function testGetUploadMimeType() - { - $Upload = new \Rundiz\Upload\Upload('filename'); - - $_FILES = $this->file_text; - $this->assertTrue(false !== strpos($Upload->testGetUploadedMimetype('filename'), 'text/plain')); - $_FILES = $this->file_dangertext; - $this->assertTrue(false !== strpos($Upload->testGetUploadedMimetype('filename'), 'text/plain')); - $_FILES = $this->file_falseimage; - $this->assertTrue(false !== strpos($Upload->testGetUploadedMimetype('filename'), 'text/plain')); - $_FILES = $this->file_51kbimage; - $this->assertTrue(false !== strpos($Upload->testGetUploadedMimetype('filename'), 'image/jpeg')); - - unset($Upload); - }// testGetUploadMimeType - - - public function testAllowedExtensionAndMimeType() - { - $Upload = new \Rundiz\Upload\Tests\ExtendedUploadForTest('filename'); - $default_mime_types_file = 'file-extensions-mime-types.php'; - if (is_file(\Rundiz\Upload\Tests\CommonConfig::getRundizUploadClassDir().$default_mime_types_file)) { - $Upload->file_extensions_mime_types = include \Rundiz\Upload\Tests\CommonConfig::getRundizUploadClassDir().$default_mime_types_file; - } - unset($default_mime_types_file); - - $_FILES = $this->file_text; - $Upload->setFilesPropertyForCheck(); - $Upload->allowed_file_extensions = array('txt'); - $this->assertTrue($Upload->validateExtensionAndMimeType()); - $_FILES = $this->file_dangertext; - $Upload->setFilesPropertyForCheck(); - $Upload->allowed_file_extensions = array('txt'); - $this->assertTrue($Upload->validateExtensionAndMimeType()); - $_FILES = $this->file_falseimage; - $Upload->setFilesPropertyForCheck(); - $Upload->allowed_file_extensions = array('jpg'); - $this->assertFalse($Upload->validateExtensionAndMimeType()); - $_FILES = $this->file_51kbimage; - $Upload->setFilesPropertyForCheck(); - $Upload->allowed_file_extensions = array('jpg'); - $this->assertTrue($Upload->validateExtensionAndMimeType()); - - unset($Upload); - }// testAllowedExtensionAndMimeType - - - public function testMaxFileSize() - { - $Upload = new \Rundiz\Upload\Tests\ExtendedUploadForTest('filename'); - - $_FILES = $this->file_text; - $Upload->setFilesPropertyForCheck(); - $Upload->max_file_size = 1500; - $this->assertTrue($Upload->validateFileSize()); - $_FILES = $this->file_dangertext; - $Upload->setFilesPropertyForCheck(); - $Upload->max_file_size = 1500; - $this->assertTrue($Upload->validateFileSize()); - $_FILES = $this->file_falseimage; - $Upload->setFilesPropertyForCheck(); - $Upload->max_file_size = 1500; - $this->assertTrue($Upload->validateFileSize()); - $_FILES = $this->file_51kbimage; - $Upload->setFilesPropertyForCheck(); - $Upload->max_file_size = 50000; - $this->assertFalse($Upload->validateFileSize()); - - unset($Upload); - }// testMaxFileSize - - - public function testMaxImageDimension() - { - $Upload = new \Rundiz\Upload\Tests\ExtendedUploadForTest('filename'); - - $_FILES = $this->file_51kbimage; - $Upload->setFilesPropertyForCheck(); - $Upload->max_image_dimensions = array(500, 400); - $this->assertTrue($Upload->validateImageDimension()); - $Upload->max_image_dimensions = array(400, 400); - $this->assertFalse($Upload->validateImageDimension()); - $Upload->max_image_dimensions = array(500, 300); - $this->assertFalse($Upload->validateImageDimension()); - $Upload->clear(); - - $_FILES = $this->file_text; - $Upload->setInputFileName('filename'); - $Upload->setFilesPropertyForCheck(); - $Upload->max_image_dimensions = array(500, 400); - $this->assertTrue($Upload->validateImageDimension()); - - $_FILES = $this->file_falseimage; - $Upload->setInputFileName('filename'); - $Upload->setFilesPropertyForCheck(); - $Upload->max_image_dimensions = array(500, 400); - $this->assertTrue($Upload->validateImageDimension()); - - unset($Upload); - }// testMaxImageDimension - - - public function testNewFileName() - { - $Upload = new \Rundiz\Upload\Tests\ExtendedUploadForTest('filename'); - $the_new_file_name = 'TEST -= !@#$%^&*()_+ []\\ {}| ;\' :" ,./ <>? `~'; - $expect_new_file_name = 'TEST -= #$^&()_+ [] {} ;\' ,. `~'; - - $_FILES = $this->file_text; - $Upload->setFilesPropertyForCheck(); - $Upload->new_file_name = $the_new_file_name; - $Upload->setNewFileName(); - $this->assertEquals($expect_new_file_name, $Upload->new_file_name); - - unset($Upload); - }// testNewFileName - - - public function testSecurityScan() - { - $Upload = new \Rundiz\Upload\Tests\ExtendedUploadForTest('filename'); - - $_FILES = $this->file_text; - $Upload->setFilesPropertyForCheck(); - $this->assertTrue($Upload->securityScan()); - $_FILES = $this->file_dangertext; - $Upload->setFilesPropertyForCheck(); - $this->assertFalse($Upload->securityScan()); - $_FILES = $this->file_falseimage; - $Upload->setFilesPropertyForCheck(); - $this->assertTrue($Upload->securityScan()); - $_FILES = $this->file_51kbimage; - $Upload->setFilesPropertyForCheck(); - $this->assertTrue($Upload->securityScan()); - - unset($Upload); - }// testSecurityScan - - - /** - * @group upmultiple - */ - public function testUploadMultiple() - { - $_FILES = $this->files_multiple; - - $Upload = new \Rundiz\Upload\Tests\ExtendedUploadForTest('filename'); - $Upload->allowed_file_extensions = array('jpg', 'png', 'txt'); - $Upload->max_file_size = 60000; - $default_mime_types_file = 'file-extensions-mime-types.php'; - if (is_file(\Rundiz\Upload\Tests\CommonConfig::getRundizUploadClassDir().$default_mime_types_file)) { - $Upload->file_extensions_mime_types = include \Rundiz\Upload\Tests\CommonConfig::getRundizUploadClassDir().$default_mime_types_file; - } - unset($default_mime_types_file); - $Upload->move_uploaded_to = $this->temp_folder; - $Upload->overwrite = false; - $Upload->security_scan = true; - $Upload->stop_on_failed_upload_multiple = false; - $Upload->web_safe_file_name = true; - $upload_result = $Upload->upload(); - - $this->assertCount(5, $_FILES['filename']); - $this->assertTrue($upload_result); - $this->assertGreaterThanOrEqual(3, count($Upload->error_messages));// not-safe-text.txt false-image.jpg fakepng-butjpg.png - - $Upload->clear(); - - $Upload->setInputFileName('filename'); - $Upload->allowed_file_extensions = array('jpg', 'png', 'txt'); - $Upload->file_extensions_mime_types = array(); - $Upload->max_file_size = 60000; - $Upload->move_uploaded_to = $this->temp_folder; - $Upload->overwrite = false; - $Upload->security_scan = false; - $Upload->stop_on_failed_upload_multiple = false; - $Upload->web_safe_file_name = true; - $upload_result = $Upload->upload(); - - $this->assertTrue($upload_result); - $this->assertEquals(0, count($Upload->error_messages)); - - unset($Upload, $upload_result); - }// testUploadMultiple - - - public function testUploadNotSet() - { - // will not set $_FILES and must not contains any error. - unset($_FILES); - - $Upload = new \Rundiz\Upload\Tests\ExtendedUploadForTest('filename'); - $Upload->upload(); - - $expect = array( - array( - 'code' => 'RDU_4', - ) - ); - $this->assertArraySubset($expect, $Upload->error_codes); - }// testUploadNotSet - - - public function testUploadSingle() - { - $_FILES = $this->file_51kbimage; - - $Upload = new \Rundiz\Upload\Tests\ExtendedUploadForTest('filename'); - $Upload->setInputFileName('filename'); - $Upload->allowed_file_extensions = array('jpg'); - $Upload->max_file_size = 60000; - $default_mime_types_file = 'file-extensions-mime-types.php'; - if (is_file(\Rundiz\Upload\Tests\CommonConfig::getRundizUploadClassDir().$default_mime_types_file)) { - $Upload->file_extensions_mime_types = include \Rundiz\Upload\Tests\CommonConfig::getRundizUploadClassDir().$default_mime_types_file; - } - unset($default_mime_types_file); - $Upload->move_uploaded_to = $this->temp_folder; - $Upload->overwrite = false; - $Upload->security_scan = true; - $Upload->web_safe_file_name = true; - $upload_result = $Upload->upload(); - - $this->assertTrue($upload_result); - $this->assertEquals(0, count($Upload->error_messages)); - - unset($Upload, $upload_result); - }// testUploadSingle - - - public function testWebSafeFileName() - { - $Upload = new \Rundiz\Upload\Tests\ExtendedUploadForTest('filename'); - $the_new_file_name = 'TEST -= !@#$%^&*()_+ []\\ {}| ;\' :" ,./ <>? `~'; - $expect_new_file_name = 'TEST-_-'; - - $_FILES = $this->file_text; - $Upload->setFilesPropertyForCheck(); - $Upload->new_file_name = $the_new_file_name; - $Upload->setNewFileName(); - $Upload->setWebSafeFileName(); - $this->assertEquals($expect_new_file_name, $Upload->new_file_name); - - unset($expect_new_file_name, $the_new_file_name, $Upload); - - $Upload = new \Rundiz\Upload\Tests\ExtendedUploadForTest('filename'); - $_FILES = array( - 'filename' => array( - 'name' => 'ชื่อไฟล์ภาษาไทย.jpg', - 'type' => 'image/jpeg', - 'tmp_name' => \Rundiz\Upload\Tests\CommonConfig::getTempDir() . 'ชื่อไฟล์ภาษาไทย.jpg', - 'error' => 0, - 'size' => 51000, - ), - ); - $Upload->setFilesPropertyForCheck(); - $Upload->new_file_name = ''; - $Upload->setNewFileName(); - $Upload->setWebSafeFileName(); - $this->assertNotSame('', $Upload->new_file_name); - - unset($Upload); - }// testWebSafeFileName - - -} diff --git a/tests/phpunit/PHP70/ValidatePropertiesTest.php b/tests/phpunit/PHP70/ValidatePropertiesTest.php deleted file mode 100644 index eef0a37..0000000 --- a/tests/phpunit/PHP70/ValidatePropertiesTest.php +++ /dev/null @@ -1,180 +0,0 @@ -temp_folder) || stripos($this->temp_folder, DIRECTORY_SEPARATOR . 'temp') === false) { - // on error, the temp folder property will not set, do nothing here. - return ; - } - - $files = glob($this->temp_folder.'*.*'); - if (is_array($files)) { - foreach ($files as $file) { - if (is_file($file) && is_writable($file) && strpos($file, '.gitkeep') === false) { - unlink($file); - } - } - unset($file); - } - unset($files); - }// __destruct - - - private $asset_folder; - private $temp_folder; - private $file_text; - private $file_51kbimage; - - - public function setUp() - { - $this->asset_folder = \Rundiz\Upload\Tests\CommonConfig::getAssetsDir(); - $this->temp_folder = \Rundiz\Upload\Tests\CommonConfig::getTempDir(); - - // copy files from assets folder to temp to prevent file deletion while set it to $_FILES. - $files = glob($this->asset_folder.'*.*'); - if (is_array($files)) { - foreach ($files as $file) { - $destination = str_replace($this->asset_folder, $this->temp_folder, $file); - copy($file, $destination); - unset($destination); - } - unset($file); - } - unset($files); - - // setup file same as it is in $_FILES. - $this->file_text['filename'] = array( - 'name' => 'text.txt', - 'type' => 'text/plain', - 'tmp_name' => $this->temp_folder.'text.txt', - 'error' => 0, - 'size' => filesize($this->temp_folder.'text.txt'), - ); - $this->file_51kbimage['filename'] = array( - 'name' => '51KB-image.JPG', - 'type' => 'image/jpeg', - 'tmp_name' => $this->temp_folder.'51KB-image.JPG', - 'error' => 0, - 'size' => filesize($this->temp_folder.'51KB-image.JPG'), - ); - }// setUp - - - public function testAllowedFileExtension() - { - $_FILES = $this->file_text; - - $Upload = new \Rundiz\Upload\Tests\ExtendedUploadForTest('filename'); - - $Upload->allowed_file_extensions = 'invalidType'; - $Upload->validateOptionsProperties(); - $this->assertEquals(array('invalidType'), $Upload->allowed_file_extensions); - - $Upload->allowed_file_extensions = null; - $Upload->validateOptionsProperties(); - $this->assertNull($Upload->allowed_file_extensions); - - unset($Upload); - }// testAllowedFileExtension - - - public function testFileExtensionsMimeTypes() - { - $_FILES = $this->file_text; - - $Upload = new \Rundiz\Upload\Tests\ExtendedUploadForTest('filename'); - - $Upload->file_extensions_mime_types = 'invalidType'; - $Upload->validateOptionsProperties(); - $this->assertNull($Upload->file_extensions_mime_types); - - $Upload->file_extensions_mime_types = null; - $Upload->validateOptionsProperties(); - $this->assertNull($Upload->file_extensions_mime_types); - - unset($Upload); - }// testFileExtensionsMimeTypes - - - public function testMaxFileSize() - { - $_FILES = $this->file_text; - - $Upload = new \Rundiz\Upload\Tests\ExtendedUploadForTest('filename'); - - $Upload->max_file_size = '2.5'; - $Upload->validateOptionsProperties(); - $this->assertEquals(2, $Upload->max_file_size); - - $Upload->max_file_size = 'invalidType'; - $Upload->validateOptionsProperties(); - $this->assertNull($Upload->max_file_size); - - unset($Upload); - }// testMaxFileSize - - - public function testMaxImageDimension() - { - $_FILES = $this->file_text; - - $Upload = new \Rundiz\Upload\Tests\ExtendedUploadForTest('filename'); - - $Upload->max_image_dimensions = 'invalidType'; - $Upload->validateOptionsProperties(); - $this->assertEquals(array(), $Upload->max_image_dimensions); - - $Upload->max_image_dimensions = array(500); - $Upload->validateOptionsProperties(); - $this->assertEquals(array(), $Upload->max_image_dimensions); - - $Upload->max_image_dimensions = array(500, 300); - $Upload->validateOptionsProperties(); - $this->assertEquals(array(500, 300), $Upload->max_image_dimensions); - - $Upload->max_image_dimensions = array(500, 300, 200); - $Upload->validateOptionsProperties(); - $this->assertEquals(array(), $Upload->max_image_dimensions); - - $Upload->max_image_dimensions = array('string', 300); - $Upload->validateOptionsProperties(); - $this->assertEquals(array(), $Upload->max_image_dimensions); - - $Upload->max_image_dimensions = array(500, 300, array(200, 100)); - $Upload->validateOptionsProperties(); - $this->assertEquals(array(), $Upload->max_image_dimensions); - - unset($Upload); - }// testMaxImageDimension - - - public function testNewFileName() - { - $_FILES = $this->file_text; - - $Upload = new \Rundiz\Upload\Tests\ExtendedUploadForTest('filename'); - - $Upload->new_file_name = array('newFileName'); - $Upload->validateOptionsProperties(); - $this->assertIsString($Upload->new_file_name); - $this->assertEmpty($Upload->new_file_name); - - $Upload->new_file_name = 'newFileName'; - $Upload->validateOptionsProperties(); - $this->assertEquals('newFileName', $Upload->new_file_name); - - unset($Upload); - }// testNewFileName - - -} \ No newline at end of file diff --git a/tests/phpunit/PHP72/ThrowErrorTest.php b/tests/phpunit/PHP84/ThrowErrorTest.php similarity index 82% rename from tests/phpunit/PHP72/ThrowErrorTest.php rename to tests/phpunit/PHP84/ThrowErrorTest.php index 14a3ca9..f1b7245 100644 --- a/tests/phpunit/PHP72/ThrowErrorTest.php +++ b/tests/phpunit/PHP84/ThrowErrorTest.php @@ -1,7 +1,7 @@ =') - ) { - $this->expectError(\PHPUnit\Framework\Error\Error::class); - } else { - $this->expectException(\PHPUnit\Framework\Error\Error::class); - } - $_FILES = $this->file_text; + try { + $_FILES = $this->file_text; - $Upload = new \Rundiz\Upload\Upload('filename'); - $Upload->move_uploaded_to = null; - $Upload->upload(); + $Upload = new \Rundiz\Upload\Upload('filename'); + $Upload->move_uploaded_to = null; + $Upload->upload(); - unset($Upload); + unset($Upload); + } catch(\Exception $ex) { + $this->assertEquals('The move_uploaded_to property was not set', $ex->getMessage()); + } }// testMoveUploadedToError diff --git a/tests/phpunit/PHP72/UploadTest.php b/tests/phpunit/PHP84/UploadTest.php similarity index 99% rename from tests/phpunit/PHP72/UploadTest.php rename to tests/phpunit/PHP84/UploadTest.php index 498b364..1ea4780 100644 --- a/tests/phpunit/PHP72/UploadTest.php +++ b/tests/phpunit/PHP84/UploadTest.php @@ -1,7 +1,7 @@ files_multiple; diff --git a/tests/phpunit/PHP72/ValidatePropertiesTest.php b/tests/phpunit/PHP84/ValidatePropertiesTest.php similarity index 99% rename from tests/phpunit/PHP72/ValidatePropertiesTest.php rename to tests/phpunit/PHP84/ValidatePropertiesTest.php index 5ca90e1..fd709f4 100644 --- a/tests/phpunit/PHP72/ValidatePropertiesTest.php +++ b/tests/phpunit/PHP84/ValidatePropertiesTest.php @@ -1,7 +1,7 @@ temp_folder) || stripos($this->temp_folder, DIRECTORY_SEPARATOR . 'temp') === false) { - // on error, the temp folder property will not set, do nothing here. - return ; - } - - $files = glob($this->temp_folder.'*.*'); - if (is_array($files)) { - foreach ($files as $file) { - if (is_file($file) && is_writable($file) && strpos($file, '.gitkeep') === false) { - unlink($file); - } - } - unset($file); - } - unset($files); - }// __destruct - - - private $asset_folder; - private $temp_folder; - private $file_text; - - - public function setUp() - { - $this->asset_folder = \Rundiz\Upload\Tests\CommonConfig::getAssetsDir(); - $this->temp_folder = \Rundiz\Upload\Tests\CommonConfig::getTempDir(); - - // copy files from assets folder to temp to prevent file deletion while set it to $_FILES. - $files = glob($this->asset_folder.'*.*'); - if (is_array($files)) { - foreach ($files as $file) { - $destination = str_replace($this->asset_folder, $this->temp_folder, $file); - copy($file, $destination); - unset($destination); - } - unset($file); - } - unset($files); - - // setup file same as it is in $_FILES. - $this->file_text['filename'] = array( - 'name' => 'text.txt', - 'type' => 'text/plain', - 'tmp_name' => $this->temp_folder.'text.txt', - 'error' => 0, - 'size' => filesize($this->temp_folder.'text.txt'), - ); - }// setUp - - - public function tearDown() - { - $this->file_text = null; - $_FILES = array(); - }// tearDown - - - /** - * @expectedException InvalidArgumentException - */ - public function testInvalidInputFileNameType() - { - $_FILES = $this->file_text; - - $Upload = new \Rundiz\Upload\Upload(array('filename')); - $Upload->move_uploaded_to = $this->temp_folder; - $Upload->upload(); - - unset($Upload); - }// testInvalidInputFileNameType - - - /** - * @expectedException InvalidArgumentException - */ - public function testInvalidInputFileNameTypeForGetUploadedMimeType() - { - $_FILES = $this->file_text; - - $Upload = new \Rundiz\Upload\Upload('filename'); - $Upload->testGetUploadedMimetype(array('filename')); - - unset($Upload); - }// testInvalidInputFileNameTypeForGetUploadedMimeType - - - /** - * @expectedException PHPUnit_Framework_Error - */ - public function testMoveUploadedToError() - { - $_FILES = $this->file_text; - - $Upload = new \Rundiz\Upload\Upload('filename'); - $Upload->move_uploaded_to = null; - $Upload->upload(); - - unset($Upload); - }// testMoveUploadedToError - - -} \ No newline at end of file diff --git a/tests/phpunit/PHPB70/UploadTest.php b/tests/phpunit/PHPB70/UploadTest.php deleted file mode 100644 index 6f9876d..0000000 --- a/tests/phpunit/PHPB70/UploadTest.php +++ /dev/null @@ -1,421 +0,0 @@ -temp_folder) || stripos($this->temp_folder, DIRECTORY_SEPARATOR . 'temp') === false) { - // on error, the temp folder property will not set, do nothing here. - return ; - } - - $files = glob($this->temp_folder.'*.*'); - if (is_array($files)) { - foreach ($files as $file) { - if (is_file($file) && is_writable($file) && strpos($file, '.gitkeep') === false) { - unlink($file); - } - } - unset($file); - } - unset($files); - }// __destruct - - - private $asset_folder; - private $temp_folder; - private $file_text; - private $file_dangertext; - private $file_falseimage; - private $file_51kbimage; - private $file_fakejpg_butpng; - private $files_multiple; - - - public function setUp() - { - $this->asset_folder = \Rundiz\Upload\Tests\CommonConfig::getAssetsDir(); - $this->temp_folder = \Rundiz\Upload\Tests\CommonConfig::getTempDir(); - - // copy files from assets folder to temp to prevent file deletion while set it to $_FILES. - $files = glob($this->asset_folder.'*.*'); - if (is_array($files)) { - foreach ($files as $file) { - $destination = str_replace($this->asset_folder, $this->temp_folder, $file); - copy($file, $destination); - unset($destination); - } - unset($file); - } - unset($files); - - // setup file same as it is in $_FILES. - $this->file_text['filename'] = array( - 'name' => 'text.txt', - 'type' => 'text/plain', - 'tmp_name' => $this->temp_folder.'text.txt', - 'error' => 0, - 'size' => filesize($this->temp_folder.'text.txt'), - ); - $this->file_dangertext['filename'] = array( - 'name' => 'not-safe-text.txt', - 'type' => 'text/plain', - 'tmp_name' => $this->temp_folder.'not-safe-text.txt', - 'error' => 0, - 'size' => filesize($this->temp_folder.'not-safe-text.txt'), - ); - $this->file_falseimage['filename'] = array( - 'name' => 'false-image.jpg', - 'type' => 'image/jpeg', - 'tmp_name' => $this->temp_folder.'false-image.jpg', - 'error' => 0, - 'size' => filesize($this->temp_folder.'false-image.jpg'), - ); - $this->file_51kbimage['filename'] = array( - 'name' => '51KB-image.jpg', - 'type' => 'image/jpeg', - 'tmp_name' => $this->temp_folder.'51KB-image.jpg', - 'error' => 0, - 'size' => filesize($this->temp_folder.'51KB-image.jpg'), - ); - $this->file_fakejpg_butpng['filename'] = array( - 'name' => 'fakepng-butjpg.png', - 'type' => 'image/jpeg', - 'tmp_name' => $this->temp_folder.'fakepng-butjpg.png', - 'error' => 0, - 'size' => filesize($this->temp_folder.'fakepng-butjpg.png'), - ); - $this->files_multiple['filename'] = array( - 'name' => array( - 0 => 'text.txt', - 1 => 'not-safe-text.txt', - 2 => 'false-image.jpg', - 3 => '51KB-image.jpg', - 4 => 'fakepng-butjpg.png', - ), - 'type' => array( - 0 => 'text/plain', - 1 => 'text/plain', - 2 => 'image/jpeg', - 3 => 'image/jpeg', - 4 => 'image/png', - ), - 'tmp_name' => array( - 0 => $this->temp_folder.'text.txt', - 1 => $this->temp_folder.'not-safe-text.txt', - 2 => $this->temp_folder.'false-image.jpg', - 3 => $this->temp_folder.'51KB-image.jpg', - 4 => $this->temp_folder.'fakepng-butjpg.png', - ), - 'error' => array( - 0 => 0, - 1 => 0, - 2 => 0, - 3 => 0, - 4 => 0, - ), - 'size' => array( - 0 => filesize($this->temp_folder.'text.txt'), - 1 => filesize($this->temp_folder.'not-safe-text.txt'), - 2 => filesize($this->temp_folder.'false-image.jpg'), - 3 => filesize($this->temp_folder.'51KB-image.jpg'), - 4 => filesize($this->temp_folder.'fakepng-butjpg.png'), - ), - ); - }// setUp - - - public function tearDown() - { - $this->file_51kbimage = null; - $this->file_fakejpg_butpng = null; - $this->file_dangertext = null; - $this->file_falseimage = null; - $this->file_text = null; - $this->files_multiple = null; - $_FILES = array(); - }// tearDown - - - public function testGetDefaultFileExtensionsMimeTypes() - { - $Upload = new \Rundiz\Upload\Upload('filename'); - - $this->assertTrue(is_array($Upload->getDefaultFileExtensionsMimeTypes())); - $this->assertArraySubset(array('txt' => array('text/plain')), $Upload->getDefaultFileExtensionsMimeTypes()); - - unset($Upload); - }// testGetDefaultFileExtensionsMimeTypes - - - public function testGetUploadMimeType() - { - $Upload = new \Rundiz\Upload\Upload('filename'); - - $_FILES = $this->file_text; - $this->assertTrue(false !== strpos($Upload->testGetUploadedMimetype('filename'), 'text/plain')); - $_FILES = $this->file_dangertext; - $this->assertTrue(false !== strpos($Upload->testGetUploadedMimetype('filename'), 'text/plain')); - $_FILES = $this->file_falseimage; - $this->assertTrue(false !== strpos($Upload->testGetUploadedMimetype('filename'), 'text/plain')); - $_FILES = $this->file_51kbimage; - $this->assertTrue(false !== strpos($Upload->testGetUploadedMimetype('filename'), 'image/jpeg')); - - unset($Upload); - }// testGetUploadMimeType - - - public function testAllowedExtensionAndMimeType() - { - $Upload = new \Rundiz\Upload\Tests\ExtendedUploadForTest('filename'); - $default_mime_types_file = 'file-extensions-mime-types.php'; - if (is_file(\Rundiz\Upload\Tests\CommonConfig::getRundizUploadClassDir().$default_mime_types_file)) { - $Upload->file_extensions_mime_types = include \Rundiz\Upload\Tests\CommonConfig::getRundizUploadClassDir().$default_mime_types_file; - } - unset($default_mime_types_file); - - $_FILES = $this->file_text; - $Upload->setFilesPropertyForCheck(); - $Upload->allowed_file_extensions = array('txt'); - $this->assertTrue($Upload->validateExtensionAndMimeType()); - $_FILES = $this->file_dangertext; - $Upload->setFilesPropertyForCheck(); - $Upload->allowed_file_extensions = array('txt'); - $this->assertTrue($Upload->validateExtensionAndMimeType()); - $_FILES = $this->file_falseimage; - $Upload->setFilesPropertyForCheck(); - $Upload->allowed_file_extensions = array('jpg'); - $this->assertFalse($Upload->validateExtensionAndMimeType()); - $_FILES = $this->file_51kbimage; - $Upload->setFilesPropertyForCheck(); - $Upload->allowed_file_extensions = array('jpg'); - $this->assertTrue($Upload->validateExtensionAndMimeType()); - - unset($Upload); - }// testAllowedExtensionAndMimeType - - - public function testMaxFileSize() - { - $Upload = new \Rundiz\Upload\Tests\ExtendedUploadForTest('filename'); - - $_FILES = $this->file_text; - $Upload->setFilesPropertyForCheck(); - $Upload->max_file_size = 1500; - $this->assertTrue($Upload->validateFileSize()); - $_FILES = $this->file_dangertext; - $Upload->setFilesPropertyForCheck(); - $Upload->max_file_size = 1500; - $this->assertTrue($Upload->validateFileSize()); - $_FILES = $this->file_falseimage; - $Upload->setFilesPropertyForCheck(); - $Upload->max_file_size = 1500; - $this->assertTrue($Upload->validateFileSize()); - $_FILES = $this->file_51kbimage; - $Upload->setFilesPropertyForCheck(); - $Upload->max_file_size = 50000; - $this->assertFalse($Upload->validateFileSize()); - - unset($Upload); - }// testMaxFileSize - - - public function testMaxImageDimension() - { - $Upload = new \Rundiz\Upload\Tests\ExtendedUploadForTest('filename'); - - $_FILES = $this->file_51kbimage; - $Upload->setFilesPropertyForCheck(); - $Upload->max_image_dimensions = array(500, 400); - $this->assertTrue($Upload->validateImageDimension()); - $Upload->max_image_dimensions = array(400, 400); - $this->assertFalse($Upload->validateImageDimension()); - $Upload->max_image_dimensions = array(500, 300); - $this->assertFalse($Upload->validateImageDimension()); - $Upload->clear(); - - $_FILES = $this->file_text; - $Upload->setInputFileName('filename'); - $Upload->setFilesPropertyForCheck(); - $Upload->max_image_dimensions = array(500, 400); - $this->assertTrue($Upload->validateImageDimension()); - - $_FILES = $this->file_falseimage; - $Upload->setInputFileName('filename'); - $Upload->setFilesPropertyForCheck(); - $Upload->max_image_dimensions = array(500, 400); - $this->assertTrue($Upload->validateImageDimension()); - - unset($Upload); - }// testMaxImageDimension - - - public function testNewFileName() - { - $Upload = new \Rundiz\Upload\Tests\ExtendedUploadForTest('filename'); - $the_new_file_name = 'TEST -= !@#$%^&*()_+ []\\ {}| ;\' :" ,./ <>? `~'; - $expect_new_file_name = 'TEST -= #$^&()_+ [] {} ;\' ,. `~'; - - $_FILES = $this->file_text; - $Upload->setFilesPropertyForCheck(); - $Upload->new_file_name = $the_new_file_name; - $Upload->setNewFileName(); - $this->assertEquals($expect_new_file_name, $Upload->new_file_name); - - unset($Upload); - }// testNewFileName - - - public function testSecurityScan() - { - $Upload = new \Rundiz\Upload\Tests\ExtendedUploadForTest('filename'); - - $_FILES = $this->file_text; - $Upload->setFilesPropertyForCheck(); - $this->assertTrue($Upload->securityScan()); - $_FILES = $this->file_dangertext; - $Upload->setFilesPropertyForCheck(); - $this->assertFalse($Upload->securityScan()); - $_FILES = $this->file_falseimage; - $Upload->setFilesPropertyForCheck(); - $this->assertTrue($Upload->securityScan()); - $_FILES = $this->file_51kbimage; - $Upload->setFilesPropertyForCheck(); - $this->assertTrue($Upload->securityScan()); - - unset($Upload); - }// testSecurityScan - - - /** - * @group upmultiple - */ - public function testUploadMultiple() - { - $_FILES = $this->files_multiple; - - $Upload = new \Rundiz\Upload\Tests\ExtendedUploadForTest('filename'); - $Upload->allowed_file_extensions = array('jpg', 'png', 'txt'); - $Upload->max_file_size = 60000; - $default_mime_types_file = 'file-extensions-mime-types.php'; - if (is_file(\Rundiz\Upload\Tests\CommonConfig::getRundizUploadClassDir().$default_mime_types_file)) { - $Upload->file_extensions_mime_types = include \Rundiz\Upload\Tests\CommonConfig::getRundizUploadClassDir().$default_mime_types_file; - } - unset($default_mime_types_file); - $Upload->move_uploaded_to = $this->temp_folder; - $Upload->overwrite = false; - $Upload->security_scan = true; - $Upload->stop_on_failed_upload_multiple = false; - $Upload->web_safe_file_name = true; - $upload_result = $Upload->upload(); - - $this->assertCount(5, $_FILES['filename']); - $this->assertTrue($upload_result); - $this->assertGreaterThanOrEqual(3, count($Upload->error_messages));// not-safe-text.txt false-image.jpg fakepng-butjpg.png - - $Upload->clear(); - - $Upload->setInputFileName('filename'); - $Upload->allowed_file_extensions = array('jpg', 'png', 'txt'); - $Upload->file_extensions_mime_types = array(); - $Upload->max_file_size = 60000; - $Upload->move_uploaded_to = $this->temp_folder; - $Upload->overwrite = false; - $Upload->security_scan = false; - $Upload->stop_on_failed_upload_multiple = false; - $Upload->web_safe_file_name = true; - $upload_result = $Upload->upload(); - - $this->assertTrue($upload_result); - $this->assertEquals(0, count($Upload->error_messages)); - - unset($Upload, $upload_result); - }// testUploadMultiple - - - public function testUploadNotSet() - { - // will not set $_FILES and must not contains any error. - unset($_FILES); - - $Upload = new \Rundiz\Upload\Tests\ExtendedUploadForTest('filename'); - $Upload->upload(); - - $expect = array( - array( - 'code' => 'RDU_4', - ) - ); - $this->assertArraySubset($expect, $Upload->error_codes); - }// testUploadNotSet - - - public function testUploadSingle() - { - $_FILES = $this->file_51kbimage; - - $Upload = new \Rundiz\Upload\Tests\ExtendedUploadForTest('filename'); - $Upload->setInputFileName('filename'); - $Upload->allowed_file_extensions = array('jpg'); - $Upload->max_file_size = 60000; - $default_mime_types_file = 'file-extensions-mime-types.php'; - if (is_file(\Rundiz\Upload\Tests\CommonConfig::getRundizUploadClassDir().$default_mime_types_file)) { - $Upload->file_extensions_mime_types = include \Rundiz\Upload\Tests\CommonConfig::getRundizUploadClassDir().$default_mime_types_file; - } - unset($default_mime_types_file); - $Upload->move_uploaded_to = $this->temp_folder; - $Upload->overwrite = false; - $Upload->security_scan = true; - $Upload->web_safe_file_name = true; - $upload_result = $Upload->upload(); - - $this->assertTrue($upload_result); - $this->assertEquals(0, count($Upload->error_messages)); - - unset($Upload, $upload_result); - }// testUploadSingle - - - public function testWebSafeFileName() - { - $Upload = new \Rundiz\Upload\Tests\ExtendedUploadForTest('filename'); - $the_new_file_name = 'TEST -= !@#$%^&*()_+ []\\ {}| ;\' :" ,./ <>? `~'; - $expect_new_file_name = 'TEST-_-'; - - $_FILES = $this->file_text; - $Upload->setFilesPropertyForCheck(); - $Upload->new_file_name = $the_new_file_name; - $Upload->setNewFileName(); - $Upload->setWebSafeFileName(); - $this->assertEquals($expect_new_file_name, $Upload->new_file_name); - - unset($expect_new_file_name, $the_new_file_name, $Upload); - - $Upload = new \Rundiz\Upload\Tests\ExtendedUploadForTest('filename'); - $_FILES = array( - 'filename' => array( - 'name' => 'ชื่อไฟล์ภาษาไทย.jpg', - 'type' => 'image/jpeg', - 'tmp_name' => \Rundiz\Upload\Tests\CommonConfig::getTempDir() . 'ชื่อไฟล์ภาษาไทย.jpg', - 'error' => 0, - 'size' => 51000, - ), - ); - $Upload->setFilesPropertyForCheck(); - $Upload->new_file_name = ''; - $Upload->setNewFileName(); - $Upload->setWebSafeFileName(); - $this->assertNotSame('', $Upload->new_file_name); - - unset($Upload); - }// testWebSafeFileName - - -} diff --git a/tests/phpunit/PHPB70/ValidatePropertiesTest.php b/tests/phpunit/PHPB70/ValidatePropertiesTest.php deleted file mode 100644 index 6634bd4..0000000 --- a/tests/phpunit/PHPB70/ValidatePropertiesTest.php +++ /dev/null @@ -1,180 +0,0 @@ -temp_folder) || stripos($this->temp_folder, DIRECTORY_SEPARATOR . 'temp') === false) { - // on error, the temp folder property will not set, do nothing here. - return ; - } - - $files = glob($this->temp_folder.'*.*'); - if (is_array($files)) { - foreach ($files as $file) { - if (is_file($file) && is_writable($file) && strpos($file, '.gitkeep') === false) { - unlink($file); - } - } - unset($file); - } - unset($files); - }// __destruct - - - private $asset_folder; - private $temp_folder; - private $file_text; - private $file_51kbimage; - - - public function setUp() - { - $this->asset_folder = \Rundiz\Upload\Tests\CommonConfig::getAssetsDir(); - $this->temp_folder = \Rundiz\Upload\Tests\CommonConfig::getTempDir(); - - // copy files from assets folder to temp to prevent file deletion while set it to $_FILES. - $files = glob($this->asset_folder.'*.*'); - if (is_array($files)) { - foreach ($files as $file) { - $destination = str_replace($this->asset_folder, $this->temp_folder, $file); - copy($file, $destination); - unset($destination); - } - unset($file); - } - unset($files); - - // setup file same as it is in $_FILES. - $this->file_text['filename'] = array( - 'name' => 'text.txt', - 'type' => 'text/plain', - 'tmp_name' => $this->temp_folder.'text.txt', - 'error' => 0, - 'size' => filesize($this->temp_folder.'text.txt'), - ); - $this->file_51kbimage['filename'] = array( - 'name' => '51KB-image.JPG', - 'type' => 'image/jpeg', - 'tmp_name' => $this->temp_folder.'51KB-image.JPG', - 'error' => 0, - 'size' => filesize($this->temp_folder.'51KB-image.JPG'), - ); - }// setUp - - - public function testAllowedFileExtension() - { - $_FILES = $this->file_text; - - $Upload = new \Rundiz\Upload\Tests\ExtendedUploadForTest('filename'); - - $Upload->allowed_file_extensions = 'invalidType'; - $Upload->validateOptionsProperties(); - $this->assertEquals(array('invalidType'), $Upload->allowed_file_extensions); - - $Upload->allowed_file_extensions = null; - $Upload->validateOptionsProperties(); - $this->assertNull($Upload->allowed_file_extensions); - - unset($Upload); - }// testAllowedFileExtension - - - public function testFileExtensionsMimeTypes() - { - $_FILES = $this->file_text; - - $Upload = new \Rundiz\Upload\Tests\ExtendedUploadForTest('filename'); - - $Upload->file_extensions_mime_types = 'invalidType'; - $Upload->validateOptionsProperties(); - $this->assertNull($Upload->file_extensions_mime_types); - - $Upload->file_extensions_mime_types = null; - $Upload->validateOptionsProperties(); - $this->assertNull($Upload->file_extensions_mime_types); - - unset($Upload); - }// testFileExtensionsMimeTypes - - - public function testMaxFileSize() - { - $_FILES = $this->file_text; - - $Upload = new \Rundiz\Upload\Tests\ExtendedUploadForTest('filename'); - - $Upload->max_file_size = '2.5'; - $Upload->validateOptionsProperties(); - $this->assertEquals(2, $Upload->max_file_size); - - $Upload->max_file_size = 'invalidType'; - $Upload->validateOptionsProperties(); - $this->assertNull($Upload->max_file_size); - - unset($Upload); - }// testMaxFileSize - - - public function testMaxImageDimension() - { - $_FILES = $this->file_text; - - $Upload = new \Rundiz\Upload\Tests\ExtendedUploadForTest('filename'); - - $Upload->max_image_dimensions = 'invalidType'; - $Upload->validateOptionsProperties(); - $this->assertEquals(array(), $Upload->max_image_dimensions); - - $Upload->max_image_dimensions = array(500); - $Upload->validateOptionsProperties(); - $this->assertEquals(array(), $Upload->max_image_dimensions); - - $Upload->max_image_dimensions = array(500, 300); - $Upload->validateOptionsProperties(); - $this->assertEquals(array(500, 300), $Upload->max_image_dimensions); - - $Upload->max_image_dimensions = array(500, 300, 200); - $Upload->validateOptionsProperties(); - $this->assertEquals(array(), $Upload->max_image_dimensions); - - $Upload->max_image_dimensions = array('string', 300); - $Upload->validateOptionsProperties(); - $this->assertEquals(array(), $Upload->max_image_dimensions); - - $Upload->max_image_dimensions = array(500, 300, array(200, 100)); - $Upload->validateOptionsProperties(); - $this->assertEquals(array(), $Upload->max_image_dimensions); - - unset($Upload); - }// testMaxImageDimension - - - public function testNewFileName() - { - $_FILES = $this->file_text; - - $Upload = new \Rundiz\Upload\Tests\ExtendedUploadForTest('filename'); - - $Upload->new_file_name = array('newFileName'); - $Upload->validateOptionsProperties(); - $this->assertIsString($Upload->new_file_name); - $this->assertEmpty($Upload->new_file_name); - - $Upload->new_file_name = 'newFileName'; - $Upload->validateOptionsProperties(); - $this->assertEquals('newFileName', $Upload->new_file_name); - - unset($Upload); - }// testNewFileName - - -} \ No newline at end of file