From dba0bdeaed732c0b88022b93ead3aea5af2abbf5 Mon Sep 17 00:00:00 2001 From: sasezaki Date: Tue, 14 May 2013 00:55:17 +0900 Subject: [PATCH] sync svn r24807 - ZF-12128: File Upload validator should display file name instead of field name in error --- library/Zend/Validator/File/Upload.php | 18 +++++++------- tests/ZendTest/Validator/File/UploadTest.php | 26 ++++++++++++++++++++ 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/library/Zend/Validator/File/Upload.php b/library/Zend/Validator/File/Upload.php index b3cd005ba97..482fb1f63f9 100644 --- a/library/Zend/Validator/File/Upload.php +++ b/library/Zend/Validator/File/Upload.php @@ -163,40 +163,40 @@ public function isValid($value, $file = null) switch ($content['error']) { case 0: if (!is_uploaded_file($content['tmp_name'])) { - $this->throwError($file, self::ATTACK); + $this->throwError($content, self::ATTACK); } break; case 1: - $this->throwError($file, self::INI_SIZE); + $this->throwError($content, self::INI_SIZE); break; case 2: - $this->throwError($file, self::FORM_SIZE); + $this->throwError($content, self::FORM_SIZE); break; case 3: - $this->throwError($file, self::PARTIAL); + $this->throwError($content, self::PARTIAL); break; case 4: - $this->throwError($file, self::NO_FILE); + $this->throwError($content, self::NO_FILE); break; case 6: - $this->throwError($file, self::NO_TMP_DIR); + $this->throwError($content, self::NO_TMP_DIR); break; case 7: - $this->throwError($file, self::CANT_WRITE); + $this->throwError($content, self::CANT_WRITE); break; case 8: - $this->throwError($file, self::EXTENSION); + $this->throwError($content, self::EXTENSION); break; default: - $this->throwError($file, self::UNKNOWN); + $this->throwError($content, self::UNKNOWN); break; } } diff --git a/tests/ZendTest/Validator/File/UploadTest.php b/tests/ZendTest/Validator/File/UploadTest.php index abfc096c561..367f39cf195 100644 --- a/tests/ZendTest/Validator/File/UploadTest.php +++ b/tests/ZendTest/Validator/File/UploadTest.php @@ -249,4 +249,30 @@ public function testZF11258() $this->assertTrue(array_key_exists('fileUploadErrorFileNotFound', $validator->getMessages())); $this->assertContains("nofile.mo'", current($validator->getMessages())); } + + /** + * @group ZF-12128 + */ + public function testErrorMessage() + { + $_FILES = array( + 'foo' => array( + 'name' => 'bar', + 'type' => 'text', + 'size' => 100, + 'tmp_name' => 'tmp_bar', + 'error' => 7, + ) + ); + + $validator = new File\Upload; + $validator->isValid('foo'); + + $this->assertEquals( + array( + 'fileUploadErrorCantWrite' => "File 'bar' can't be written", + ), + $validator->getMessages() + ); + } }