Преглед изворни кода

[ZF-7631] Zend_Validate_NotEmpty:

- allowed to check arrays for not emptyness

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@17679 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas пре 16 година
родитељ
комит
8a955cbd61
2 измењених фајлова са 7 додато и 4 уклоњено
  1. 3 3
      library/Zend/Validate/NotEmpty.php
  2. 4 1
      tests/Zend/Validate/NotEmptyTest.php

+ 3 - 3
library/Zend/Validate/NotEmpty.php

@@ -40,7 +40,7 @@ class Zend_Validate_NotEmpty extends Zend_Validate_Abstract
      */
     protected $_messageTemplates = array(
         self::IS_EMPTY => "Value is required and can't be empty",
-        self::INVALID  => "Invalid type given, value should be float, string, or integer",
+        self::INVALID  => "Invalid type given, value should be float, string, array, boolean or integer",
     );
 
     /**
@@ -53,13 +53,13 @@ class Zend_Validate_NotEmpty extends Zend_Validate_Abstract
      */
     public function isValid($value)
     {
-        if (!is_string($value) && !is_int($value) && !is_float($value) && !is_bool($value)) {
+        if (!is_string($value) && !is_int($value) && !is_float($value) && !is_bool($value) &&
+            !is_array($value)) {
             $this->_error(self::INVALID);
             return false;
         }
 
         $this->_setValue($value);
-
         if (is_string($value)
             && (('' === $value)
                 || preg_match('/^\s+$/s', $value))

+ 4 - 1
tests/Zend/Validate/NotEmptyTest.php

@@ -91,6 +91,8 @@ class Zend_Validate_NotEmptyTest extends PHPUnit_Framework_TestCase
             array(true, true),
             array(false, false),
             array(null, false),
+            array(array(), false),
+            array(array(5), true),
         );
         foreach ($valuesExpected as $i => $element) {
             $this->assertEquals($element[1], $this->_validator->isValid($element[0]),
@@ -121,7 +123,8 @@ class Zend_Validate_NotEmptyTest extends PHPUnit_Framework_TestCase
      */
     public function testNonStringValidation()
     {
-        $this->assertFalse($this->_validator->isValid(array(1 => 1)));
+        $v2 = new Zend_Validate_NotEmpty();
+        $this->assertFalse($this->_validator->isValid($v2));
     }
 }