mirror of
https://github.com/vlucas/valitron.git
synced 2025-12-31 07:01:54 +00:00
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:
commit
ad89c5ec35
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user