Browse Source

ZF-12128: File Upload validator should display file name instead of field name in error message

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24959 44c647ce-9c0f-0410-b52a-842ac1e357ba
adamlundrigan 13 years ago
parent
commit
13ccb6c5c0
2 changed files with 35 additions and 9 deletions
  1. 9 9
      library/Zend/Validate/File/Upload.php
  2. 26 0
      tests/Zend/Validate/File/UploadTest.php

+ 9 - 9
library/Zend/Validate/File/Upload.php

@@ -185,40 +185,40 @@ class Zend_Validate_File_Upload extends Zend_Validate_Abstract
             switch($content['error']) {
                 case 0:
                     if (!is_uploaded_file($content['tmp_name'])) {
-                        $this->_throw($file, self::ATTACK);
+                        $this->_throw($content, self::ATTACK);
                     }
                     break;
 
                 case 1:
-                    $this->_throw($file, self::INI_SIZE);
+                    $this->_throw($content, self::INI_SIZE);
                     break;
 
                 case 2:
-                    $this->_throw($file, self::FORM_SIZE);
+                    $this->_throw($content, self::FORM_SIZE);
                     break;
 
                 case 3:
-                    $this->_throw($file, self::PARTIAL);
+                    $this->_throw($content, self::PARTIAL);
                     break;
 
                 case 4:
-                    $this->_throw($file, self::NO_FILE);
+                    $this->_throw($content, self::NO_FILE);
                     break;
 
                 case 6:
-                    $this->_throw($file, self::NO_TMP_DIR);
+                    $this->_throw($content, self::NO_TMP_DIR);
                     break;
 
                 case 7:
-                    $this->_throw($file, self::CANT_WRITE);
+                    $this->_throw($content, self::CANT_WRITE);
                     break;
 
                 case 8:
-                    $this->_throw($file, self::EXTENSION);
+                    $this->_throw($content, self::EXTENSION);
                     break;
 
                 default:
-                    $this->_throw($file, self::UNKNOWN);
+                    $this->_throw($content, self::UNKNOWN);
                     break;
             }
         }

+ 26 - 0
tests/Zend/Validate/File/UploadTest.php

@@ -274,6 +274,32 @@ class Zend_Validate_File_UploadTest extends PHPUnit_Framework_TestCase
         $this->assertEquals(array(), $validator->getFiles());
     }
 
+    /**
+     * @group ZF-12128
+     */
+    public function testErrorMessage()
+    {
+        $_FILES = array(
+            'foo' => array(
+                'name'     => 'bar',
+                'type'     => 'text',
+                'size'     => 100,
+                'tmp_name' => 'tmp_bar',
+                'error'    => 7,
+            )
+        );
+
+        $validator = new Zend_Validate_File_Upload();
+        $validator->isValid('foo');
+
+        $this->assertEquals(
+            array(
+                 'fileUploadErrorCantWrite' => "File 'bar' can't be written",
+            ),
+            $validator->getMessages()
+        );
+    }
+
 }
 
 // Call Zend_Validate_File_UploadTest::main() if this source file is executed directly.