mirror of
https://github.com/vlucas/valitron.git
synced 2025-12-31 07:01:54 +00:00
Merge pull request #105 from thinkjson/foreach-discrete
Validate an array of discrete values
This commit is contained in:
commit
5bc52a8a39
@ -803,6 +803,11 @@ class Validator
|
|||||||
|
|
||||||
protected function getPart($data, $identifiers)
|
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);
|
$identifier = array_shift($identifiers);
|
||||||
|
|
||||||
// Glob match
|
// Glob match
|
||||||
|
|||||||
@ -308,6 +308,35 @@ class ValidateTest extends BaseTestCase
|
|||||||
$this->assertFalse($v->validate());
|
$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()
|
public function testForeachArrayAccess()
|
||||||
{
|
{
|
||||||
$v = new Validator(array('settings' => array(
|
$v = new Validator(array('settings' => array(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user