Merge pull request #72 from thinkjson/validate-zero

Run validation is field is non-null instead of truthy. Fixes #70
This commit is contained in:
Vance Lucas 2014-05-27 14:51:00 -05:00
commit ad89c5ec35
2 changed files with 15 additions and 1 deletions

View File

@ -749,7 +749,7 @@ class Validator
$value = isset($this->_fields[$field]) ? $this->_fields[$field] : null; $value = isset($this->_fields[$field]) ? $this->_fields[$field] : null;
// Don't validate if the field is not required and the value is empty // Don't validate if the field is not required and the value is empty
if ($v['rule'] !== 'required' && !$this->hasRule('required', $field) && $value == '') { if ($v['rule'] !== 'required' && !$this->hasRule('required', $field) && (! isset($value) || $value === '')) {
continue; continue;
} }

View File

@ -727,6 +727,20 @@ class ValidateTest extends BaseTestCase
$this->assertFalse($v->validate()); $this->assertFalse($v->validate());
} }
public function testZeroStillTriggersValidation()
{
$v = new Validator(array('test' => 0));
$v->rule('min', 'test', 1);
$this->assertFalse($v->validate());
}
public function testFalseStillTriggersValidation()
{
$v = new Validator(array('test' => FALSE));
$v->rule('min', 'test', 5);
$this->assertFalse($v->validate());
}
public function testCreditCardValid() public function testCreditCardValid()
{ {
$visa = array(4539511619543489, 4532949059629052, 4024007171194938, 4929646403373269, 4539135861690622); $visa = array(4539511619543489, 4532949059629052, 4024007171194938, 4929646403373269, 4539135861690622);