mirror of
https://github.com/vlucas/valitron.git
synced 2025-12-30 23:01:52 +00:00
Merge pull request #31 from biggingernerd/master
Added validator for boolean
This commit is contained in:
commit
add2cc92d2
@ -23,7 +23,8 @@ return array(
|
|||||||
'dateFormat' => "must be date with format '%s'",
|
'dateFormat' => "must be date with format '%s'",
|
||||||
'dateBefore' => "must be date before '%s'",
|
'dateBefore' => "must be date before '%s'",
|
||||||
'dateAfter' => "must be date after '%s'",
|
'dateAfter' => "must be date after '%s'",
|
||||||
'contains' => "must contain %s"
|
'contains' => "must contain %s",
|
||||||
|
'boolean' => "must be a boolean",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -430,6 +430,18 @@ class Validator
|
|||||||
return $vtime > $ptime;
|
return $vtime > $ptime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate that a field contains a boolean.
|
||||||
|
*
|
||||||
|
* @param string $field
|
||||||
|
* @param mixed $value
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function validateBoolean($field, $value)
|
||||||
|
{
|
||||||
|
return (is_bool($value)) ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get array of fields and data
|
* Get array of fields and data
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -640,6 +640,20 @@ class ValidateTest extends BaseTestCase
|
|||||||
$v->rule('testRule', 'name', array('foo', 'bar'))->message('Invalid name selected.');
|
$v->rule('testRule', 'name', array('foo', 'bar'))->message('Invalid name selected.');
|
||||||
$this->assertFalse($v->validate());
|
$this->assertFalse($v->validate());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testBooleanValid()
|
||||||
|
{
|
||||||
|
$v = new Validator(array('test' => true));
|
||||||
|
$v->rule('boolean', 'test');
|
||||||
|
$this->assertTrue($v->validate());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testBooleanInvalid()
|
||||||
|
{
|
||||||
|
$v = new Validator(array('test' => 'true'));
|
||||||
|
$v->rule('boolean', 'test');
|
||||||
|
$this->assertFalse($v->validate());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function sampleFunctionCallback($field, $value, array $params) {
|
function sampleFunctionCallback($field, $value, array $params) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user