mirror of
https://github.com/vlucas/valitron.git
synced 2025-12-30 23:01:52 +00:00
Merge remote-tracking branch 'remotes/upstream/master' into validators-patch
This commit is contained in:
commit
48dcdc7248
14
README.md
14
README.md
@ -86,6 +86,19 @@ if($v->validate()) {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Or use dot syntax to validate all members of a numeric array:
|
||||||
|
|
||||||
|
```php
|
||||||
|
$v = new Valitron\Validator(array('values' => array(50, 90)));
|
||||||
|
$v->rule('max', 'values.*', 100);
|
||||||
|
if($v->validate()) {
|
||||||
|
echo "Yay! We're all good!";
|
||||||
|
} else {
|
||||||
|
// Errors
|
||||||
|
print_r($v->errors());
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
Setting language and language dir globally:
|
Setting language and language dir globally:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
@ -121,6 +134,7 @@ V::lang('ar');
|
|||||||
* `notIn` - Negation of `in` rule (not in array of values)
|
* `notIn` - Negation of `in` rule (not in array of values)
|
||||||
* `ip` - Valid IP address
|
* `ip` - Valid IP address
|
||||||
* `email` - Valid email address
|
* `email` - Valid email address
|
||||||
|
* `emailDNS` - Valid email address with active DNS record
|
||||||
* `url` - Valid URL
|
* `url` - Valid URL
|
||||||
* `urlActive` - Valid URL with active DNS record
|
* `urlActive` - Valid URL with active DNS record
|
||||||
* `alpha` - Alphabetic characters only
|
* `alpha` - Alphabetic characters only
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
"description": "Simple, elegant, stand-alone validation library with NO dependencies",
|
"description": "Simple, elegant, stand-alone validation library with NO dependencies",
|
||||||
"keywords": ["validation", "validator", "valid"],
|
"keywords": ["validation", "validator", "valid"],
|
||||||
"homepage": "http://github.com/vlucas/valitron",
|
"homepage": "http://github.com/vlucas/valitron",
|
||||||
"license" : "BSD",
|
"license" : "BSD-3-Clause",
|
||||||
"authors" : [
|
"authors" : [
|
||||||
{
|
{
|
||||||
"name": "Vance Lucas",
|
"name": "Vance Lucas",
|
||||||
@ -16,7 +16,7 @@
|
|||||||
"php": ">=5.3.2"
|
"php": ">=5.3.2"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "~4.0"
|
"phpunit/phpunit": "~4.8.35"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-0": {
|
"psr-0": {
|
||||||
|
|||||||
33
lang/lt.php
Normal file
33
lang/lt.php
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
return array(
|
||||||
|
'required' => "yra privalomas",
|
||||||
|
'equals' => "reikšmė turi būti tokia pati, kaip „%s“",
|
||||||
|
'different' => "turi būti kitokia, nei „%s“",
|
||||||
|
'accepted' => "turi būti priimta",
|
||||||
|
'numeric' => "turi būti sveikasis skaičius",
|
||||||
|
'integer' => "turi būti skaičius",
|
||||||
|
'length' => "turi būti %d ženklų ilgio",
|
||||||
|
'min' => "turi būti bent %s",
|
||||||
|
'max' => "turi būti ne daugiau kaip %s",
|
||||||
|
'in' => "turi neteisingą vertę",
|
||||||
|
'notIn' => "turi neteisingą vertę",
|
||||||
|
'ip' => "nėra teisingas IP adresas",
|
||||||
|
'email' => "nėra teisingas el. pašto adresas",
|
||||||
|
'url' => "nėra teisingas URL",
|
||||||
|
'urlActive' => "turi būti aktyvus domenas",
|
||||||
|
'alpha' => "turi turėti tik raides a-ž",
|
||||||
|
'alphaNum' => "turi turėti tik raides a-ž ir/ar skaičius 0-9",
|
||||||
|
'slug' => "turi turėti tik raides a-ž, skaičius 0-9, brukšnelius ir apatinius brukšnelius",
|
||||||
|
'regex' => "yra neteisingų ženklų",
|
||||||
|
'date' => "nėra teisinga data",
|
||||||
|
'dateFormat' => "turi būti „%s“ formato data",
|
||||||
|
'dateBefore' => "turi būti data, ankstesnė nei „%s“",
|
||||||
|
'dateAfter' => "turi būti data, vėlesnė nei „%s“",
|
||||||
|
'contains' => "turi turėti %s",
|
||||||
|
'boolean' => "turi būti būlio (taip/ne) tipo",
|
||||||
|
'lengthBetween' => "turi būti nuo %d iki %d ilgio",
|
||||||
|
'creditCard' => "turi būti teisingas kreditinės kortelės numeris",
|
||||||
|
'lengthMin' => "turi būti bent %d ženklų ilgio",
|
||||||
|
'lengthMax' => "turi būti ne ilgesnis nei %d ženklų",
|
||||||
|
'instanceOf' => "turi būti „%s“ atvejis"
|
||||||
|
);
|
||||||
34
lang/sv.php
Normal file
34
lang/sv.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'required' => "är obligatorisk",
|
||||||
|
'equals' => "måste vara samma som '%s'",
|
||||||
|
'different' => "får inte vara samma som '%s'",
|
||||||
|
'accepted' => "måste accepteras",
|
||||||
|
'numeric' => "måste vara numerisk",
|
||||||
|
'integer' => "måste vara ett heltal",
|
||||||
|
'length' => "måste vara %d tecken långt",
|
||||||
|
'min' => "måste vara minst %s",
|
||||||
|
'max' => "får inte vara mer än %s",
|
||||||
|
'in' => "innehåller ogiltigt värde",
|
||||||
|
'notIn' => "innehåller ogiltigt värde",
|
||||||
|
'ip' => "är inte en giltlig IP-adress",
|
||||||
|
'email' => "är inte en giltlig e-postadress",
|
||||||
|
'url' => "är inte en giltlig URL",
|
||||||
|
'urlActive' => "måste vara ett aktivt domännamn",
|
||||||
|
'alpha' => "får bara inehålla bokstäver a-z",
|
||||||
|
'alphaNum' => "får bara inehålla bokstäver a-z och/eller siffror 0-9",
|
||||||
|
'slug' => "får bara inehålla bokstäver a-z och/eller siffror 0-9, bindesträck og understräck",
|
||||||
|
'regex' => "inehåller ogiltliga tecken",
|
||||||
|
'date' => "är inte ett giltligt datum",
|
||||||
|
'dateFormat' => "måste vara ett datum med formatet '%s'",
|
||||||
|
'dateBefore' => "måste vara ett datum före '%s'",
|
||||||
|
'dateAfter' => "måste vara ett datum efter '%s'",
|
||||||
|
'contains' => "måste innehålla %s",
|
||||||
|
'boolean' => "måste vara ett booleskt värde",
|
||||||
|
'lengthBetween' => "måste vara mellan %d och %d tecken långt",
|
||||||
|
'creditCard' => "måste vara et gyldig kredittkortnummer",
|
||||||
|
'lengthMin' => "måste vara minst %d tecken långt",
|
||||||
|
'lengthMax' => "får itne överstiga %d tecken",
|
||||||
|
'instanceOf' => "måste vara en instans av '%s'"
|
||||||
|
);
|
||||||
@ -24,5 +24,10 @@ return array(
|
|||||||
'dateFormat' => "日期的格式应该为 '%s'",
|
'dateFormat' => "日期的格式应该为 '%s'",
|
||||||
'dateBefore' => "日期必须在 '%s' 之前",
|
'dateBefore' => "日期必须在 '%s' 之前",
|
||||||
'dateAfter' => "日期必须在 '%s' 之后",
|
'dateAfter' => "日期必须在 '%s' 之后",
|
||||||
'contains' => "必须包含 %s"
|
'contains' => "必须包含 %s",
|
||||||
|
'boolean' => "必须是真或假",
|
||||||
|
'lengthBetween' => "长度只能介于 %d 和 %d 之间",
|
||||||
|
'creditCard' => "信用卡号码不正确",
|
||||||
|
'lengthMin' => "长度必须大于 %d",
|
||||||
|
'lengthMax' => "长度必须小于 %d"
|
||||||
);
|
);
|
||||||
|
|||||||
@ -172,9 +172,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -187,9 +187,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -529,6 +529,26 @@ class Validator
|
|||||||
return filter_var($value, \FILTER_VALIDATE_EMAIL) !== false;
|
return filter_var($value, \FILTER_VALIDATE_EMAIL) !== false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate that a field is a valid e-mail address and the domain name is active
|
||||||
|
*
|
||||||
|
* @param string $field
|
||||||
|
* @param mixed $value
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function validateEmailDNS($field, $value)
|
||||||
|
{
|
||||||
|
if ($this->validateEmail($field, $value)) {
|
||||||
|
$domain = ltrim(stristr($value, '@'), '@') . '.';
|
||||||
|
if (function_exists('idn_to_ascii') && defined('INTL_IDNA_VARIANT_UTS46')) {
|
||||||
|
$domain = idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46);
|
||||||
|
}
|
||||||
|
return checkdnsrr($domain, 'ANY');
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate that a field is a valid URL by syntax
|
* Validate that a field is a valid URL by syntax
|
||||||
*
|
*
|
||||||
@ -1120,7 +1140,7 @@ class Validator
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if either a valdiator with the given name has been
|
* Returns true if either a validator with the given name has been
|
||||||
* registered or there is a default validator by that name.
|
* registered or there is a default validator by that name.
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
@ -1188,6 +1208,8 @@ class Validator
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Add label to rule
|
||||||
|
*
|
||||||
* @param string $value
|
* @param string $value
|
||||||
* @return Validator
|
* @return Validator
|
||||||
*/
|
*/
|
||||||
@ -1200,6 +1222,8 @@ class Validator
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Add labels to rules
|
||||||
|
*
|
||||||
* @param array $labels
|
* @param array $labels
|
||||||
* @return Validator
|
* @return Validator
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class BaseTestCase extends \PHPUnit_Framework_TestCase
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class BaseTestCase extends TestCase
|
||||||
{
|
{
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -34,7 +34,7 @@ class ValidateTest extends BaseTestCase
|
|||||||
$v->rule('required', array('name', 'email'));
|
$v->rule('required', array('name', 'email'));
|
||||||
$this->assertFalse($v->validate());
|
$this->assertFalse($v->validate());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRequiredSubfieldsArrayStringValue()
|
public function testRequiredSubfieldsArrayStringValue()
|
||||||
{
|
{
|
||||||
$v = new Validator(array('name' => 'bob'));
|
$v = new Validator(array('name' => 'bob'));
|
||||||
@ -70,6 +70,36 @@ class ValidateTest extends BaseTestCase
|
|||||||
$this->assertFalse($v->validate());
|
$this->assertFalse($v->validate());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testEqualsBothNull()
|
||||||
|
{
|
||||||
|
$v = new Validator(array('foo' => null, 'bar' => null));
|
||||||
|
$v->rule('equals', 'foo', 'bar');
|
||||||
|
$this->assertTrue($v->validate());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testEqualsBothNullRequired()
|
||||||
|
{
|
||||||
|
$v = new Validator(array('foo' => null, 'bar' => null));
|
||||||
|
$v->rule('required', array('foo', 'bar'));
|
||||||
|
$v->rule('equals', 'foo', 'bar');
|
||||||
|
$this->assertFalse($v->validate());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testEqualsBothUnset()
|
||||||
|
{
|
||||||
|
$v = new Validator(array('foo' => 1));
|
||||||
|
$v->rule('equals', 'bar', 'baz');
|
||||||
|
$this->assertTrue($v->validate());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testEqualsBothUnsetRequired()
|
||||||
|
{
|
||||||
|
$v = new Validator(array('foo' => 1));
|
||||||
|
$v->rule('required', array('bar', 'baz'));
|
||||||
|
$v->rule('equals', 'bar', 'baz');
|
||||||
|
$this->assertFalse($v->validate());
|
||||||
|
}
|
||||||
|
|
||||||
public function testDifferentValid()
|
public function testDifferentValid()
|
||||||
{
|
{
|
||||||
$v = new Validator(array('foo' => 'bar', 'bar' => 'baz'));
|
$v = new Validator(array('foo' => 'bar', 'bar' => 'baz'));
|
||||||
@ -84,6 +114,36 @@ class ValidateTest extends BaseTestCase
|
|||||||
$this->assertFalse($v->validate());
|
$this->assertFalse($v->validate());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDifferentBothNull()
|
||||||
|
{
|
||||||
|
$v = new Validator(array('foo' => null, 'bar' => null));
|
||||||
|
$v->rule('equals', 'foo', 'bar');
|
||||||
|
$this->assertTrue($v->validate());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDifferentBothNullRequired()
|
||||||
|
{
|
||||||
|
$v = new Validator(array('foo' => null, 'bar' => null));
|
||||||
|
$v->rule('required', array('foo', 'bar'));
|
||||||
|
$v->rule('equals', 'foo', 'bar');
|
||||||
|
$this->assertFalse($v->validate());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDifferentBothUnset()
|
||||||
|
{
|
||||||
|
$v = new Validator(array('foo' => 1));
|
||||||
|
$v->rule('equals', 'bar', 'baz');
|
||||||
|
$this->assertTrue($v->validate());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDifferentBothUnsetRequired()
|
||||||
|
{
|
||||||
|
$v = new Validator(array('foo' => 1));
|
||||||
|
$v->rule('required', array('bar', 'baz'));
|
||||||
|
$v->rule('equals', 'bar', 'baz');
|
||||||
|
$this->assertFalse($v->validate());
|
||||||
|
}
|
||||||
|
|
||||||
public function testAcceptedValid()
|
public function testAcceptedValid()
|
||||||
{
|
{
|
||||||
$v = new Validator(array('agree' => 'yes'));
|
$v = new Validator(array('agree' => 'yes'));
|
||||||
@ -560,6 +620,18 @@ class ValidateTest extends BaseTestCase
|
|||||||
$this->assertFalse($v->validate());
|
$this->assertFalse($v->validate());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testEmailDnsValid(){
|
||||||
|
$v = new Validator(array('name' => 'Chester Tester', 'email' => 'chester@tester.com'));
|
||||||
|
$v->rule('emailDNS', 'email');
|
||||||
|
$this->assertTrue($v->validate());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testEmailDnsInvalid(){
|
||||||
|
$v = new Validator(array('name' => 'Chester Tester', 'email' => 'chester@tester.zyx'));
|
||||||
|
$v->rule('emailDNS', 'email');
|
||||||
|
$this->assertFalse($v->validate());
|
||||||
|
}
|
||||||
|
|
||||||
public function testUrlValid()
|
public function testUrlValid()
|
||||||
{
|
{
|
||||||
$v = new Validator(array('website' => 'http://google.com'));
|
$v = new Validator(array('website' => 'http://google.com'));
|
||||||
@ -629,7 +701,7 @@ class ValidateTest extends BaseTestCase
|
|||||||
$v->rule('slug', 'test');
|
$v->rule('slug', 'test');
|
||||||
$this->assertFalse($v->validate());
|
$this->assertFalse($v->validate());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNoErrorFailOnArray()
|
public function testNoErrorFailOnArray()
|
||||||
{
|
{
|
||||||
$v = new Validator(array('test' => array()));
|
$v = new Validator(array('test' => array()));
|
||||||
@ -1287,22 +1359,22 @@ class ValidateTest extends BaseTestCase
|
|||||||
|
|
||||||
public function testOptionalProvidedValid()
|
public function testOptionalProvidedValid()
|
||||||
{
|
{
|
||||||
$v = new Validator(array('address' => 'user@example.com'));
|
$v = new Validator(array('address' => 'user@example.com'));
|
||||||
$v->rule('optional', 'address')->rule('email', 'address');
|
$v->rule('optional', 'address')->rule('email', 'address');
|
||||||
$this->assertTrue($v->validate());
|
$this->assertTrue($v->validate());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testOptionalProvidedInvalid()
|
public function testOptionalProvidedInvalid()
|
||||||
{
|
{
|
||||||
$v = new Validator(array('address' => 'userexample.com'));
|
$v = new Validator(array('address' => 'userexample.com'));
|
||||||
$v->rule('optional', 'address')->rule('email', 'address');
|
$v->rule('optional', 'address')->rule('email', 'address');
|
||||||
$this->assertFalse($v->validate());
|
$this->assertFalse($v->validate());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testOptionalNotProvided()
|
public function testOptionalNotProvided()
|
||||||
{
|
{
|
||||||
$v = new Validator(array());
|
$v = new Validator(array());
|
||||||
$v->rule('optional', 'address')->rule('email', 'address');
|
$v->rule('optional', 'address')->rule('email', 'address');
|
||||||
$this->assertTrue($v->validate());
|
$this->assertTrue($v->validate());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1353,9 +1425,98 @@ class ValidateTest extends BaseTestCase
|
|||||||
$this->assertFalse($v1->validate());
|
$this->assertFalse($v1->validate());
|
||||||
|
|
||||||
$v2 = new Validator($data);
|
$v2 = new Validator($data);
|
||||||
$v2->rule('required', array('empty_text', 'null_value', 'in_array.empty_text'));
|
$v2->rule('required', array('empty_text', 'null_value', 'in_array.empty_text'), true);
|
||||||
$this->assertFalse($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 testNestedEqualsBothNull()
|
||||||
|
{
|
||||||
|
$v = new Validator(array('foo' => array('bar' => null, 'baz' => null)));
|
||||||
|
$v->rule('equals', 'foo.bar', 'foo.baz');
|
||||||
|
$this->assertTrue($v->validate());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNestedEqualsBothNullRequired()
|
||||||
|
{
|
||||||
|
$v = new Validator(array('foo' => array('bar' => null, 'baz' => null)));
|
||||||
|
$v->rule('required', array('foo.bar', 'foo.baz'));
|
||||||
|
$v->rule('equals', 'foo.bar', 'foo.baz');
|
||||||
|
$this->assertFalse($v->validate());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNestedEqualsBothUnset()
|
||||||
|
{
|
||||||
|
$v = new Validator(array('foo' => 'bar'));
|
||||||
|
$v->rule('equals', 'foo.one', 'foo.two');
|
||||||
|
$this->assertTrue($v->validate());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNestedEqualsBothUnsetRequired()
|
||||||
|
{
|
||||||
|
$v = new Validator(array('foo' => 'bar'));
|
||||||
|
$v->rule('required', array('foo.one', 'foo.two'));
|
||||||
|
$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());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNestedDifferentBothNull()
|
||||||
|
{
|
||||||
|
$v = new Validator(array('foo' => array('bar' => null, 'baz' => null)));
|
||||||
|
$v->rule('different', 'foo.bar', 'foo.baz');
|
||||||
|
$this->assertTrue($v->validate());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNestedDifferentBothNullRequired()
|
||||||
|
{
|
||||||
|
$v = new Validator(array('foo' => array('bar' => null, 'baz' => null)));
|
||||||
|
$v->rule('required', array('foo.bar', 'foo.baz'));
|
||||||
|
$v->rule('different', 'foo.bar', 'foo.baz');
|
||||||
|
$this->assertFalse($v->validate());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNestedDifferentBothUnset()
|
||||||
|
{
|
||||||
|
$v = new Validator(array('foo' => 'bar'));
|
||||||
|
$v->rule('different', 'foo.bar', 'foo.baz');
|
||||||
|
$this->assertTrue($v->validate());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNestedDifferentBothUnsetRequired()
|
||||||
|
{
|
||||||
|
$v = new Validator(array('foo' => 'bar'));
|
||||||
|
$v->rule('required', array('foo.bar', 'foo.baz'));
|
||||||
|
$v->rule('different', 'foo.bar', 'foo.baz');
|
||||||
|
$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