mirror of
https://github.com/vlucas/valitron.git
synced 2025-12-30 23:01:52 +00:00
Merge pull request #105 from thinkjson/foreach-discrete
Validate an array of discrete values
This commit is contained in:
commit
2e8453be81
@ -803,6 +803,11 @@ class Validator
|
||||
|
||||
protected function getPart($data, $identifiers)
|
||||
{
|
||||
// Catches the case where the field is an array of discrete values
|
||||
if (is_array($identifiers) && count($identifiers) === 0) {
|
||||
return array($data, false);
|
||||
}
|
||||
|
||||
$identifier = array_shift($identifiers);
|
||||
|
||||
// Glob match
|
||||
|
||||
@ -308,6 +308,35 @@ class ValidateTest extends BaseTestCase
|
||||
$this->assertFalse($v->validate());
|
||||
}
|
||||
|
||||
public function testForeachDiscreteValues()
|
||||
{
|
||||
$v = new Validator(array('values' => array(5, 10, 15, 20, 25)));
|
||||
$v->rule('integer', 'values.*');
|
||||
$this->assertTrue($v->validate());
|
||||
}
|
||||
|
||||
public function testForeachAssocValues()
|
||||
{
|
||||
$v = new Validator(array('values' => array(
|
||||
'foo' => 5,
|
||||
'bar' => 10,
|
||||
'baz' => 15
|
||||
)));
|
||||
$v->rule('integer', 'values.*');
|
||||
$this->assertTrue($v->validate());
|
||||
}
|
||||
|
||||
public function testForeachAssocValuesFails()
|
||||
{
|
||||
$v = new Validator(array('values' => array(
|
||||
'foo' => 5,
|
||||
'bar' => 10,
|
||||
'baz' => 'faz'
|
||||
)));
|
||||
$v->rule('integer', 'values.*');
|
||||
$this->assertFalse($v->validate());
|
||||
}
|
||||
|
||||
public function testForeachArrayAccess()
|
||||
{
|
||||
$v = new Validator(array('settings' => array(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user