diff --git a/src/File/Crc32.php b/src/File/Crc32.php index f9236fdb9..737521c22 100644 --- a/src/File/Crc32.php +++ b/src/File/Crc32.php @@ -104,7 +104,7 @@ public function isValid($value, $file = null) $this->setValue($filename); // Is file readable ? - if (false === stream_resolve_include_path($file)) { + if (empty($file) || false === stream_resolve_include_path($file)) { $this->error(self::NOT_FOUND); return false; } diff --git a/src/File/ExcludeExtension.php b/src/File/ExcludeExtension.php index aa696c6e7..0d24b1857 100644 --- a/src/File/ExcludeExtension.php +++ b/src/File/ExcludeExtension.php @@ -59,7 +59,7 @@ public function isValid($value, $file = null) $this->setValue($filename); // Is file readable ? - if (false === stream_resolve_include_path($file)) { + if (empty($file) || false === stream_resolve_include_path($file)) { $this->error(self::NOT_FOUND); return false; } diff --git a/src/File/ExcludeMimeType.php b/src/File/ExcludeMimeType.php index 2c68bdb0b..dedcee9fc 100644 --- a/src/File/ExcludeMimeType.php +++ b/src/File/ExcludeMimeType.php @@ -54,7 +54,7 @@ public function isValid($value, $file = null) $this->setValue($filename); // Is file readable ? - if (false === stream_resolve_include_path($file)) { + if (empty($file) || false === stream_resolve_include_path($file)) { $this->error(self::NOT_READABLE); return false; } diff --git a/src/File/Extension.php b/src/File/Extension.php index 0b037ad57..2ceeebc73 100644 --- a/src/File/Extension.php +++ b/src/File/Extension.php @@ -195,7 +195,7 @@ public function isValid($value, $file = null) $this->setValue($filename); // Is file readable ? - if (false === stream_resolve_include_path($file)) { + if (empty($file) || false === stream_resolve_include_path($file)) { $this->error(self::NOT_FOUND); return false; } diff --git a/src/File/FilesSize.php b/src/File/FilesSize.php index 93991ecf5..f2d2afd0d 100644 --- a/src/File/FilesSize.php +++ b/src/File/FilesSize.php @@ -96,7 +96,7 @@ public function isValid($value, $file = null) $size = $this->getSize(); foreach ($value as $files) { // Is file readable ? - if (false === stream_resolve_include_path($files)) { + if (empty($files) || false === stream_resolve_include_path($files)) { $this->throwError($file, self::NOT_READABLE); continue; } diff --git a/src/File/Hash.php b/src/File/Hash.php index 51e450f9e..b77b1e19f 100644 --- a/src/File/Hash.php +++ b/src/File/Hash.php @@ -148,7 +148,7 @@ public function isValid($value, $file = null) $this->setValue($filename); // Is file readable ? - if (false === stream_resolve_include_path($file)) { + if (empty($file) || false === stream_resolve_include_path($file)) { $this->error(self::NOT_FOUND); return false; } diff --git a/src/File/ImageSize.php b/src/File/ImageSize.php index 616ba891b..c7714f8da 100644 --- a/src/File/ImageSize.php +++ b/src/File/ImageSize.php @@ -343,7 +343,7 @@ public function isValid($value, $file = null) $this->setValue($filename); // Is file readable ? - if (false === stream_resolve_include_path($file)) { + if (empty($file) || false === stream_resolve_include_path($file)) { $this->error(self::NOT_READABLE); return false; } diff --git a/src/File/Md5.php b/src/File/Md5.php index 5b94280e5..5d9fc34b4 100644 --- a/src/File/Md5.php +++ b/src/File/Md5.php @@ -104,7 +104,7 @@ public function isValid($value, $file = null) $this->setValue($filename); // Is file readable ? - if (false === stream_resolve_include_path($file)) { + if (empty($file) || false === stream_resolve_include_path($file)) { $this->error(self::NOT_FOUND); return false; } diff --git a/src/File/MimeType.php b/src/File/MimeType.php index f495e603f..53fb948dd 100644 --- a/src/File/MimeType.php +++ b/src/File/MimeType.php @@ -368,7 +368,7 @@ public function isValid($value, $file = null) $this->setValue($filename); // Is file readable ? - if (false === stream_resolve_include_path($file)) { + if (empty($file) || false === stream_resolve_include_path($file)) { $this->error(static::NOT_READABLE); return false; } diff --git a/src/File/Sha1.php b/src/File/Sha1.php index 8073558c7..984139450 100644 --- a/src/File/Sha1.php +++ b/src/File/Sha1.php @@ -104,7 +104,7 @@ public function isValid($value, $file = null) $this->setValue($filename); // Is file readable ? - if (false === stream_resolve_include_path($file)) { + if (empty($file) || false === stream_resolve_include_path($file)) { $this->error(self::NOT_FOUND); return false; } diff --git a/src/File/Size.php b/src/File/Size.php index 1b87fcf29..38022dd82 100644 --- a/src/File/Size.php +++ b/src/File/Size.php @@ -253,7 +253,7 @@ public function isValid($value, $file = null) $this->setValue($filename); // Is file readable ? - if (false === stream_resolve_include_path($file)) { + if (empty($file) || false === stream_resolve_include_path($file)) { $this->error(self::NOT_FOUND); return false; } diff --git a/src/File/UploadFile.php b/src/File/UploadFile.php index 5ed0d69e0..90f4d75df 100644 --- a/src/File/UploadFile.php +++ b/src/File/UploadFile.php @@ -72,7 +72,7 @@ public function isValid($value) } $this->setValue($filename); - if (false === stream_resolve_include_path($file)) { + if (empty($file) || false === stream_resolve_include_path($file)) { $this->error(self::FILE_NOT_FOUND); return false; } diff --git a/src/File/WordCount.php b/src/File/WordCount.php index 1b58a9ab6..23be65bd7 100644 --- a/src/File/WordCount.php +++ b/src/File/WordCount.php @@ -191,7 +191,7 @@ public function isValid($value, $file = null) $this->setValue($filename); // Is file readable ? - if (false === stream_resolve_include_path($file)) { + if (empty($file) || false === stream_resolve_include_path($file)) { $this->error(self::NOT_FOUND); return false; } diff --git a/test/File/Crc32Test.php b/test/File/Crc32Test.php index f5a850ecc..1c049a448 100644 --- a/test/File/Crc32Test.php +++ b/test/File/Crc32Test.php @@ -185,4 +185,23 @@ public function testZF11258() $this->assertTrue(array_key_exists('fileCrc32NotFound', $validator->getMessages())); $this->assertContains("does not exist", current($validator->getMessages())); } + + public function testEmptyFileShouldReturnFalseAndDisplayNotFoundMessage() + { + $validator = new File\Crc32(); + + $this->assertFalse($validator->isValid('')); + $this->assertArrayHasKey(File\Crc32::NOT_FOUND, $validator->getMessages()); + + $filesArray = array( + 'name' => '', + 'size' => 0, + 'tmp_name' => '', + 'error' => UPLOAD_ERR_NO_FILE, + 'type' => '', + ); + + $this->assertFalse($validator->isValid($filesArray)); + $this->assertArrayHasKey(File\Crc32::NOT_FOUND, $validator->getMessages()); + } } diff --git a/test/File/ExcludeExtensionTest.php b/test/File/ExcludeExtensionTest.php index dd6c44a03..70cecdb86 100644 --- a/test/File/ExcludeExtensionTest.php +++ b/test/File/ExcludeExtensionTest.php @@ -161,4 +161,23 @@ public function testZF11258() $this->assertTrue(array_key_exists('fileExcludeExtensionNotFound', $validator->getMessages())); $this->assertContains("does not exist", current($validator->getMessages())); } + + public function testEmptyFileShouldReturnFalseAndDisplayNotFoundMessage() + { + $validator = new File\ExcludeExtension('12345'); + + $this->assertFalse($validator->isValid('')); + $this->assertArrayHasKey(File\ExcludeExtension::NOT_FOUND, $validator->getMessages()); + + $filesArray = array( + 'name' => '', + 'size' => 0, + 'tmp_name' => '', + 'error' => UPLOAD_ERR_NO_FILE, + 'type' => '', + ); + + $this->assertFalse($validator->isValid($filesArray)); + $this->assertArrayHasKey(File\ExcludeExtension::NOT_FOUND, $validator->getMessages()); + } } diff --git a/test/File/ExcludeMimeTypeTest.php b/test/File/ExcludeMimeTypeTest.php index 205a486de..36ea8631a 100644 --- a/test/File/ExcludeMimeTypeTest.php +++ b/test/File/ExcludeMimeTypeTest.php @@ -130,4 +130,23 @@ public function testAddMimeType() $this->assertEquals('image/gif,text,jpg,to,zip,ti', $validator->getMimeType()); $this->assertEquals(array('image/gif', 'text', 'jpg', 'to', 'zip', 'ti'), $validator->getMimeType(true)); } + + public function testEmptyFileShouldReturnFalseAndDisplayNotFoundMessage() + { + $validator = new ExcludeMimeType(); + + $this->assertFalse($validator->isValid('')); + $this->assertArrayHasKey(ExcludeMimeType::NOT_READABLE, $validator->getMessages()); + + $filesArray = array( + 'name' => '', + 'size' => 0, + 'tmp_name' => '', + 'error' => UPLOAD_ERR_NO_FILE, + 'type' => '', + ); + + $this->assertFalse($validator->isValid($filesArray)); + $this->assertArrayHasKey(ExcludeMimeType::NOT_READABLE, $validator->getMessages()); + } } diff --git a/test/File/ExistsTest.php b/test/File/ExistsTest.php index 5fa248006..8561a9b4d 100644 --- a/test/File/ExistsTest.php +++ b/test/File/ExistsTest.php @@ -137,4 +137,23 @@ public function testZF11258() $this->assertTrue(array_key_exists('fileExistsDoesNotExist', $validator->getMessages())); $this->assertContains("does not exist", current($validator->getMessages())); } + + public function testEmptyFileArrayShouldReturnFalse() + { + $validator = new File\Exists(); + + $this->assertFalse($validator->isValid('')); + $this->assertArrayHasKey(File\Exists::DOES_NOT_EXIST, $validator->getMessages()); + + $filesArray = array( + 'name' => '', + 'size' => 0, + 'tmp_name' => '', + 'error' => UPLOAD_ERR_NO_FILE, + 'type' => '', + ); + + $this->assertFalse($validator->isValid($filesArray)); + $this->assertArrayHasKey(File\Exists::DOES_NOT_EXIST, $validator->getMessages()); + } } diff --git a/test/File/ExtensionTest.php b/test/File/ExtensionTest.php index 9738071e0..dba99185c 100644 --- a/test/File/ExtensionTest.php +++ b/test/File/ExtensionTest.php @@ -164,4 +164,23 @@ public function testZF11258() $this->assertTrue(array_key_exists('fileExtensionNotFound', $validator->getMessages())); $this->assertContains("does not exist", current($validator->getMessages())); } + + public function testEmptyFileShouldReturnFalseAndDisplayNotFoundMessage() + { + $validator = new File\Extension('foo'); + + $this->assertFalse($validator->isValid('')); + $this->assertArrayHasKey(File\Extension::NOT_FOUND, $validator->getMessages()); + + $filesArray = array( + 'name' => '', + 'size' => 0, + 'tmp_name' => '', + 'error' => UPLOAD_ERR_NO_FILE, + 'type' => '', + ); + + $this->assertFalse($validator->isValid($filesArray)); + $this->assertArrayHasKey(File\Extension::NOT_FOUND, $validator->getMessages()); + } } diff --git a/test/File/FilesSizeTest.php b/test/File/FilesSizeTest.php index 34ab38cb4..5f9439265 100644 --- a/test/File/FilesSizeTest.php +++ b/test/File/FilesSizeTest.php @@ -183,4 +183,23 @@ public function errorHandler($errno, $errstr) $this->multipleOptionsDetected = true; } } + + public function testEmptyFileShouldReturnFalseAndDisplayNotFoundMessage() + { + $validator = new File\FilesSize(0); + + $this->assertFalse($validator->isValid('')); + $this->assertArrayHasKey(File\FilesSize::NOT_READABLE, $validator->getMessages()); + + $filesArray = array( + 'name' => '', + 'size' => 0, + 'tmp_name' => '', + 'error' => UPLOAD_ERR_NO_FILE, + 'type' => '', + ); + + $this->assertFalse($validator->isValid($filesArray)); + $this->assertArrayHasKey(File\FilesSize::NOT_READABLE, $validator->getMessages()); + } } diff --git a/test/File/HashTest.php b/test/File/HashTest.php index cb5596492..23f584a7f 100644 --- a/test/File/HashTest.php +++ b/test/File/HashTest.php @@ -159,4 +159,23 @@ public function testZF11258() $this->assertTrue(array_key_exists('fileHashNotFound', $validator->getMessages())); $this->assertContains("does not exist", current($validator->getMessages())); } + + public function testEmptyFileShouldReturnFalseAndDisplayNotFoundMessage() + { + $validator = new File\Hash(); + + $this->assertFalse($validator->isValid('')); + $this->assertArrayHasKey(File\Hash::NOT_FOUND, $validator->getMessages()); + + $filesArray = array( + 'name' => '', + 'size' => 0, + 'tmp_name' => '', + 'error' => UPLOAD_ERR_NO_FILE, + 'type' => '', + ); + + $this->assertFalse($validator->isValid($filesArray)); + $this->assertArrayHasKey(File\Hash::NOT_FOUND, $validator->getMessages()); + } } diff --git a/test/File/ImageSizeTest.php b/test/File/ImageSizeTest.php index cc7c3d83a..e428295f9 100644 --- a/test/File/ImageSizeTest.php +++ b/test/File/ImageSizeTest.php @@ -263,4 +263,23 @@ public function testZF11258() $this->assertTrue(array_key_exists('fileImageSizeNotReadable', $validator->getMessages())); $this->assertContains("does not exist", current($validator->getMessages())); } + + public function testEmptyFileShouldReturnFalseAndDisplayNotFoundMessage() + { + $validator = new File\ImageSize(); + + $this->assertFalse($validator->isValid('')); + $this->assertArrayHasKey(File\ImageSize::NOT_READABLE, $validator->getMessages()); + + $filesArray = array( + 'name' => '', + 'size' => 0, + 'tmp_name' => '', + 'error' => UPLOAD_ERR_NO_FILE, + 'type' => '', + ); + + $this->assertFalse($validator->isValid($filesArray)); + $this->assertArrayHasKey(File\ImageSize::NOT_READABLE, $validator->getMessages()); + } } diff --git a/test/File/Md5Test.php b/test/File/Md5Test.php index b41eba332..1bb3b2070 100644 --- a/test/File/Md5Test.php +++ b/test/File/Md5Test.php @@ -199,4 +199,23 @@ public function testZF11258() $this->assertTrue(array_key_exists('fileMd5NotFound', $validator->getMessages())); $this->assertContains("does not exist", current($validator->getMessages())); } + + public function testEmptyFileShouldReturnFalseAndDisplayNotFoundMessage() + { + $validator = new File\Md5(); + + $this->assertFalse($validator->isValid('')); + $this->assertArrayHasKey(File\Md5::NOT_FOUND, $validator->getMessages()); + + $filesArray = array( + 'name' => '', + 'size' => 0, + 'tmp_name' => '', + 'error' => UPLOAD_ERR_NO_FILE, + 'type' => '', + ); + + $this->assertFalse($validator->isValid($filesArray)); + $this->assertArrayHasKey(File\Md5::NOT_FOUND, $validator->getMessages()); + } } diff --git a/test/File/MimeTypeTest.php b/test/File/MimeTypeTest.php index 942fe8add..39233cab0 100644 --- a/test/File/MimeTypeTest.php +++ b/test/File/MimeTypeTest.php @@ -221,4 +221,25 @@ public function testDisablingMagicFileByConstructor() $validator = new File\MimeType($files); $this->assertFalse($validator->getMagicFile()); } + + public function testEmptyFileShouldReturnFalseAndDisplayNotFoundMessage() + { + if (! extension_loaded('fileinfo')) { + $this->markTestSkipped('This PHP Version has no finfo installed'); + } + + $validator = new File\MimeType(); + + $this->assertFalse($validator->isValid('')); + + $filesArray = array( + 'name' => '', + 'size' => 0, + 'tmp_name' => '', + 'error' => UPLOAD_ERR_NO_FILE, + 'type' => '', + ); + + $this->assertFalse($validator->isValid($filesArray)); + } } diff --git a/test/File/Sha1Test.php b/test/File/Sha1Test.php index b15f33ed8..c567f3a9b 100644 --- a/test/File/Sha1Test.php +++ b/test/File/Sha1Test.php @@ -186,4 +186,23 @@ public function testZF11258() $this->assertTrue(array_key_exists('fileSha1NotFound', $validator->getMessages())); $this->assertContains("does not exist", current($validator->getMessages())); } + + public function testEmptyFileShouldReturnFalseAndDisplayNotFoundMessage() + { + $validator = new File\Sha1(); + + $this->assertFalse($validator->isValid('')); + $this->assertArrayHasKey(File\Sha1::NOT_FOUND, $validator->getMessages()); + + $filesArray = array( + 'name' => '', + 'size' => 0, + 'tmp_name' => '', + 'error' => UPLOAD_ERR_NO_FILE, + 'type' => '', + ); + + $this->assertFalse($validator->isValid($filesArray)); + $this->assertArrayHasKey(File\Sha1::NOT_FOUND, $validator->getMessages()); + } } diff --git a/test/File/SizeTest.php b/test/File/SizeTest.php index 1bcce680a..15fed557a 100644 --- a/test/File/SizeTest.php +++ b/test/File/SizeTest.php @@ -203,4 +203,23 @@ public function testZF11258() $this->assertTrue(array_key_exists('fileSizeNotFound', $validator->getMessages())); $this->assertContains("does not exist", current($validator->getMessages())); } + + public function testEmptyFileShouldReturnFalseAndDisplayNotFoundMessage() + { + $validator = new File\Size(); + + $this->assertFalse($validator->isValid('')); + $this->assertArrayHasKey(File\Size::NOT_FOUND, $validator->getMessages()); + + $filesArray = array( + 'name' => '', + 'size' => 0, + 'tmp_name' => '', + 'error' => UPLOAD_ERR_NO_FILE, + 'type' => '', + ); + + $this->assertFalse($validator->isValid($filesArray)); + $this->assertArrayHasKey(File\Size::NOT_FOUND, $validator->getMessages()); + } } diff --git a/test/File/UploadFileTest.php b/test/File/UploadFileTest.php index 5db211c33..b314d6b98 100644 --- a/test/File/UploadFileTest.php +++ b/test/File/UploadFileTest.php @@ -83,4 +83,23 @@ public function testZF11258() $this->assertTrue(array_key_exists('fileUploadFileErrorFileNotFound', $validator->getMessages())); $this->assertContains("not found", current($validator->getMessages())); } + + public function testEmptyFileShouldReturnFalseAndDisplayNotFoundMessage() + { + $validator = new File\UploadFile(); + + $this->assertFalse($validator->isValid('')); + $this->assertArrayHasKey(File\UploadFile::FILE_NOT_FOUND, $validator->getMessages()); + + $filesArray = array( + 'name' => '', + 'size' => 0, + 'tmp_name' => '', + 'error' => UPLOAD_ERR_NO_FILE, + 'type' => '', + ); + + $this->assertFalse($validator->isValid($filesArray)); + $this->assertArrayHasKey(File\UploadFile::FILE_NOT_FOUND, $validator->getMessages()); + } } diff --git a/test/File/WordCountTest.php b/test/File/WordCountTest.php index e5c47c101..70ba30f1c 100644 --- a/test/File/WordCountTest.php +++ b/test/File/WordCountTest.php @@ -136,4 +136,23 @@ public function testZF11258() $this->assertTrue(array_key_exists('fileWordCountNotFound', $validator->getMessages())); $this->assertContains("does not exist", current($validator->getMessages())); } + + public function testEmptyFileShouldReturnFalseAndDisplayNotFoundMessage() + { + $validator = new File\WordCount(); + + $this->assertFalse($validator->isValid('')); + $this->assertArrayHasKey(File\WordCount::NOT_FOUND, $validator->getMessages()); + + $filesArray = array( + 'name' => '', + 'size' => 0, + 'tmp_name' => '', + 'error' => UPLOAD_ERR_NO_FILE, + 'type' => '', + ); + + $this->assertFalse($validator->isValid($filesArray)); + $this->assertArrayHasKey(File\WordCount::NOT_FOUND, $validator->getMessages()); + } }