mirror of
https://github.com/vlucas/valitron.git
synced 2025-12-31 07:01:54 +00:00
added support for nested arrays in validateEquals and validateDifferent validation methods
This commit is contained in:
parent
1712b04f16
commit
7c94b2ae5a
@ -173,9 +173,9 @@ class Validator
|
|||||||
*/
|
*/
|
||||||
protected function validateEquals($field, $value, array $params)
|
protected function validateEquals($field, $value, array $params)
|
||||||
{
|
{
|
||||||
$field2 = $params[0];
|
// extract the second field value, this accounts for nested array values
|
||||||
|
list($field2Value, $multiple) = $this->getPart($this->_fields, explode('.', $params[0]));
|
||||||
return isset($this->_fields[$field2]) && $value == $this->_fields[$field2];
|
return isset($field2Value) && $value == $field2Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -189,9 +189,9 @@ class Validator
|
|||||||
*/
|
*/
|
||||||
protected function validateDifferent($field, $value, array $params)
|
protected function validateDifferent($field, $value, array $params)
|
||||||
{
|
{
|
||||||
$field2 = $params[0];
|
// extract the second field value, this accounts for nested array values
|
||||||
|
list($field2Value, $multiple) = $this->getPart($this->_fields, explode('.', $params[0]));
|
||||||
return isset($this->_fields[$field2]) && $value != $this->_fields[$field2];
|
return isset($field2Value) && $value != $field2Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1271,6 +1271,34 @@ class ValidateTest extends BaseTestCase
|
|||||||
$v2->rule('required', array('empty_text', 'null_value', 'in_array.empty_text'), true);
|
$v2->rule('required', array('empty_text', 'null_value', 'in_array.empty_text'), true);
|
||||||
$this->assertTrue($v2->validate());
|
$this->assertTrue($v2->validate());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testNestedEqualsValid()
|
||||||
|
{
|
||||||
|
$v = new Validator(array('foo' => array('one' => 'bar', 'two' => 'bar')));
|
||||||
|
$v->rule('equals', 'foo.one', 'foo.two');
|
||||||
|
$this->assertTrue($v->validate());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNestedEqualsInvalid()
|
||||||
|
{
|
||||||
|
$v = new Validator(array('foo' => array('one' => 'bar', 'two' => 'baz')));
|
||||||
|
$v->rule('equals', 'foo.one', 'foo.two');
|
||||||
|
$this->assertFalse($v->validate());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNestedDifferentValid()
|
||||||
|
{
|
||||||
|
$v = new Validator(array('foo' => array('one' => 'bar', 'two' => 'baz')));
|
||||||
|
$v->rule('different', 'foo.one', 'foo.two');
|
||||||
|
$this->assertTrue($v->validate());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNestedDifferentInvalid()
|
||||||
|
{
|
||||||
|
$v = new Validator(array('foo' => array('one' => 'baz', 'two' => 'baz')));
|
||||||
|
$v->rule('different', 'foo.one', 'foo.two');
|
||||||
|
$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