mirror of
https://github.com/vlucas/valitron.git
synced 2025-12-30 23:01:52 +00:00
Run validation is field is non-null instead of truthy. Fixes #70
This commit is contained in:
parent
2120bacaf5
commit
272fe84b15
@ -698,7 +698,7 @@ class Validator
|
||||
$value = isset($this->_fields[$field]) ? $this->_fields[$field] : null;
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
||||
@ -727,6 +727,20 @@ class ValidateTest extends BaseTestCase
|
||||
$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()
|
||||
{
|
||||
$visa = array(4539511619543489, 4532949059629052, 4024007171194938, 4929646403373269, 4539135861690622);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user