From 14a467ba2470a88bf8298d8cb529f813f84fd8e6 Mon Sep 17 00:00:00 2001 From: Gabriel Caruso Date: Sat, 11 Nov 2017 02:28:10 -0200 Subject: [PATCH 01/19] Use PHPUnit\Framework\TestCase instead of PHPUnit_Framework_TestCase --- composer.json | 2 +- tests/Valitron/BaseTestCase.php | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index e3faef9..9e87dc1 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "php": ">=5.3.2" }, "require-dev": { - "phpunit/phpunit": "~4.0" + "phpunit/phpunit": "~4.8.35" }, "autoload": { "psr-0": { diff --git a/tests/Valitron/BaseTestCase.php b/tests/Valitron/BaseTestCase.php index fec8efc..ccfc736 100644 --- a/tests/Valitron/BaseTestCase.php +++ b/tests/Valitron/BaseTestCase.php @@ -1,6 +1,8 @@ Date: Sat, 2 Dec 2017 21:28:13 +0100 Subject: [PATCH 02/19] Make sure testRequiredAllowEmpty() tests 2 different usages for required rule --- tests/Valitron/ValidateTest.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/Valitron/ValidateTest.php b/tests/Valitron/ValidateTest.php index 6abdf6e..adf296e 100644 --- a/tests/Valitron/ValidateTest.php +++ b/tests/Valitron/ValidateTest.php @@ -34,7 +34,7 @@ class ValidateTest extends BaseTestCase $v->rule('required', array('name', 'email')); $this->assertFalse($v->validate()); } - + public function testRequiredSubfieldsArrayStringValue() { $v = new Validator(array('name' => 'bob')); @@ -629,7 +629,7 @@ class ValidateTest extends BaseTestCase $v->rule('slug', 'test'); $this->assertFalse($v->validate()); } - + public function testNoErrorFailOnArray() { $v = new Validator(array('test' => array())); @@ -1203,22 +1203,22 @@ class ValidateTest extends BaseTestCase public function testOptionalProvidedValid() { - $v = new Validator(array('address' => 'user@example.com')); - $v->rule('optional', 'address')->rule('email', 'address'); + $v = new Validator(array('address' => 'user@example.com')); + $v->rule('optional', 'address')->rule('email', 'address'); $this->assertTrue($v->validate()); } public function testOptionalProvidedInvalid() { - $v = new Validator(array('address' => 'userexample.com')); - $v->rule('optional', 'address')->rule('email', 'address'); + $v = new Validator(array('address' => 'userexample.com')); + $v->rule('optional', 'address')->rule('email', 'address'); $this->assertFalse($v->validate()); } public function testOptionalNotProvided() { - $v = new Validator(array()); - $v->rule('optional', 'address')->rule('email', 'address'); + $v = new Validator(array()); + $v->rule('optional', 'address')->rule('email', 'address'); $this->assertTrue($v->validate()); } @@ -1268,8 +1268,8 @@ class ValidateTest extends BaseTestCase $this->assertFalse($v1->validate()); $v2= new Validator($data); - $v2->rule('required', array('empty_text', 'null_value', 'in_array.empty_text')); - $this->assertFalse($v2->validate()); + $v2->rule('required', array('empty_text', 'null_value', 'in_array.empty_text'), true); + $this->assertTrue($v2->validate()); } } From 2438da6a999579364058e7a11092e35b4a023222 Mon Sep 17 00:00:00 2001 From: Piotr Date: Fri, 8 Dec 2017 16:00:16 +0100 Subject: [PATCH 03/19] Fix typo in docblock --- src/Valitron/Validator.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Valitron/Validator.php b/src/Valitron/Validator.php index c629ca4..76ceedf 100644 --- a/src/Valitron/Validator.php +++ b/src/Valitron/Validator.php @@ -1092,7 +1092,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. * * @param string $name @@ -1160,6 +1160,8 @@ class Validator } /** + * Add label to rule + * * @param string $value * @internal param array $labels * @return $this @@ -1173,6 +1175,8 @@ class Validator } /** + * Add labels to rules + * * @param array $labels * @return $this */ From ae7716c9009dc74b0dcc3a914be12fdda8cfe08a Mon Sep 17 00:00:00 2001 From: Jabari Hunt Date: Wed, 13 Dec 2017 12:30:45 -0600 Subject: [PATCH 04/19] Improved the email validator by making sure the domain name is valid. --- src/Valitron/Validator.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Valitron/Validator.php b/src/Valitron/Validator.php index c629ca4..13b8e6d 100644 --- a/src/Valitron/Validator.php +++ b/src/Valitron/Validator.php @@ -497,7 +497,12 @@ class Validator */ protected function validateEmail($field, $value) { - return filter_var($value, \FILTER_VALIDATE_EMAIL) !== false; + if (filter_var($value, \FILTER_VALIDATE_EMAIL) !== false) { + $domain = idn_to_ascii(ltrim(stristr($value, '@'), '@'), 0, INTL_IDNA_VARIANT_UTS46) . '.'; + if (checkdnsrr($domain, 'ANY')) {return true;} + } + + return false; } /** From 255384baa80793d06fc6222687655ab9c2bdb22c Mon Sep 17 00:00:00 2001 From: Jabari Hunt Date: Wed, 13 Dec 2017 14:52:24 -0600 Subject: [PATCH 05/19] Made the domain check an option (via third method param). --- src/Valitron/Validator.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Valitron/Validator.php b/src/Valitron/Validator.php index 13b8e6d..ecbca4e 100644 --- a/src/Valitron/Validator.php +++ b/src/Valitron/Validator.php @@ -84,7 +84,7 @@ class Validator * @param array $fields * @param string $lang * @param string $langDir - * @throws \InvalidArgumentException + * @throws emInvalidArgumentException */ public function __construct($data = array(), $fields = array(), $lang = null, $langDir = null) { @@ -495,14 +495,18 @@ class Validator * @param mixed $value * @return bool */ - protected function validateEmail($field, $value) + protected function validateEmail($field, $value, $checkDomain = false) { + $emailIsValid = false; if (filter_var($value, \FILTER_VALIDATE_EMAIL) !== false) { - $domain = idn_to_ascii(ltrim(stristr($value, '@'), '@'), 0, INTL_IDNA_VARIANT_UTS46) . '.'; - if (checkdnsrr($domain, 'ANY')) {return true;} + $emailIsValid = true; + if ($checkDomain) { + $domain = idn_to_ascii(ltrim(stristr($value, '@'), '@'), 0, INTL_IDNA_VARIANT_UTS46) . '.'; + if (!checkdnsrr($domain, 'ANY')) {$emailIsValid = false;} + } } - return false; + return $emailIsValid; } /** From 55154359dc022c380deaa1ba8569c42f854f32db Mon Sep 17 00:00:00 2001 From: Jabari Hunt Date: Wed, 13 Dec 2017 16:06:31 -0600 Subject: [PATCH 06/19] Fixed a typo that was introduces in an unrelated comment. --- src/Valitron/Validator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Valitron/Validator.php b/src/Valitron/Validator.php index ecbca4e..dfc594d 100644 --- a/src/Valitron/Validator.php +++ b/src/Valitron/Validator.php @@ -84,7 +84,7 @@ class Validator * @param array $fields * @param string $lang * @param string $langDir - * @throws emInvalidArgumentException + * @throws \InvalidArgumentException */ public function __construct($data = array(), $fields = array(), $lang = null, $langDir = null) { From c0bf6b75d8b133e672b3083c576ca3113616154c Mon Sep 17 00:00:00 2001 From: zhenwen Date: Thu, 14 Dec 2017 11:17:43 +0800 Subject: [PATCH 07/19] Update zh-cn.php --- lang/zh-cn.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lang/zh-cn.php b/lang/zh-cn.php index d154815..97835b4 100644 --- a/lang/zh-cn.php +++ b/lang/zh-cn.php @@ -24,5 +24,10 @@ return array( 'dateFormat' => "日期的格式应该为 '%s'", 'dateBefore' => "日期必须在 '%s' 之前", 'dateAfter' => "日期必须在 '%s' 之后", - 'contains' => "必须包含 %s" + 'contains' => "必须包含 %s", + 'boolean' => "必须是真或假", + 'lengthBetween' => "长度只能介于 %d 和 %d 之间", + 'creditCard' => "信用卡号码不正确", + 'lengthMin' => "长度必须大于 %d", + 'lengthMax' => "长度必须小于 %d" ); From ac79ecd1def0943eb7ee002e45bc8c6b005ba4d9 Mon Sep 17 00:00:00 2001 From: Peter elmered Date: Tue, 19 Dec 2017 18:36:40 +0100 Subject: [PATCH 08/19] Added Swedish translation --- lang/sv.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 lang/sv.php diff --git a/lang/sv.php b/lang/sv.php new file mode 100644 index 0000000..94884cf --- /dev/null +++ b/lang/sv.php @@ -0,0 +1,34 @@ + "ä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'" +); From 28ef275cde1c8738eaa8baa1b728107daeaac311 Mon Sep 17 00:00:00 2001 From: Jabari Hunt Date: Mon, 1 Jan 2018 15:11:21 -0600 Subject: [PATCH 09/19] Restored the original validateEmail() method. Created a new method called validateEmailDNS() that validates both the email address itself (using the ValidateEmail() method) as well as the domain name in the email address. --- src/Valitron/Validator.php | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/Valitron/Validator.php b/src/Valitron/Validator.php index dfc594d..f085bb5 100644 --- a/src/Valitron/Validator.php +++ b/src/Valitron/Validator.php @@ -495,18 +495,26 @@ class Validator * @param mixed $value * @return bool */ - protected function validateEmail($field, $value, $checkDomain = false) + protected function validateEmail($field, $value) { - $emailIsValid = false; - if (filter_var($value, \FILTER_VALIDATE_EMAIL) !== false) { - $emailIsValid = true; - if ($checkDomain) { - $domain = idn_to_ascii(ltrim(stristr($value, '@'), '@'), 0, INTL_IDNA_VARIANT_UTS46) . '.'; - if (!checkdnsrr($domain, 'ANY')) {$emailIsValid = 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, '@'), '@') . '.'; + return checkdnsrr($domain, 'ANY'); } - return $emailIsValid; + return false; } /** From 8603b2bec385fc6c7cfd27c73280ee06f0164d95 Mon Sep 17 00:00:00 2001 From: Jabari Date: Fri, 5 Jan 2018 22:28:47 -0600 Subject: [PATCH 10/19] Added idn_to_ascii() with a check to make sure the function itself exists as well as a check for a required constant that it needs to function. --- src/Valitron/Validator.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Valitron/Validator.php b/src/Valitron/Validator.php index f085bb5..4eae399 100644 --- a/src/Valitron/Validator.php +++ b/src/Valitron/Validator.php @@ -511,6 +511,9 @@ class Validator { 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'); } From 7dcc8a5089b0e40b492a1ebf932ee9eaa18f7285 Mon Sep 17 00:00:00 2001 From: Willem Wollebrants Date: Wed, 31 Jan 2018 16:19:05 +0100 Subject: [PATCH 11/19] add test for new emailDNS validator --- tests/Valitron/ValidateTest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/Valitron/ValidateTest.php b/tests/Valitron/ValidateTest.php index adf296e..d599cb6 100644 --- a/tests/Valitron/ValidateTest.php +++ b/tests/Valitron/ValidateTest.php @@ -560,6 +560,18 @@ class ValidateTest extends BaseTestCase $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() { $v = new Validator(array('website' => 'http://google.com')); From f8e69683afa1af97a5e6c035dbaf5452c843eb89 Mon Sep 17 00:00:00 2001 From: Willem Wollebrants Date: Wed, 31 Jan 2018 16:20:58 +0100 Subject: [PATCH 12/19] add emailDNS validator to documentation --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 0d520fd..bb7a744 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,7 @@ V::lang('ar'); * `notIn` - Negation of `in` rule (not in array of values) * `ip` - Valid IP address * `email` - Valid email address + * `emailDNS` - Valid email address with active DNS record * `url` - Valid URL * `urlActive` - Valid URL with active DNS record * `alpha` - Alphabetic characters only From 7c94b2ae5a657d5355c7a64f7c3e7bc7e82cb873 Mon Sep 17 00:00:00 2001 From: Tom Breese Date: Sun, 4 Feb 2018 13:24:47 -0500 Subject: [PATCH 13/19] added support for nested arrays in validateEquals and validateDifferent validation methods --- src/Valitron/Validator.php | 12 ++++++------ tests/Valitron/ValidateTest.php | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/Valitron/Validator.php b/src/Valitron/Validator.php index c629ca4..4be39e3 100644 --- a/src/Valitron/Validator.php +++ b/src/Valitron/Validator.php @@ -173,9 +173,9 @@ class Validator */ protected function validateEquals($field, $value, array $params) { - $field2 = $params[0]; - - return isset($this->_fields[$field2]) && $value == $this->_fields[$field2]; + // extract the second field value, this accounts for nested array values + list($field2Value, $multiple) = $this->getPart($this->_fields, explode('.', $params[0])); + return isset($field2Value) && $value == $field2Value; } /** @@ -189,9 +189,9 @@ class Validator */ protected function validateDifferent($field, $value, array $params) { - $field2 = $params[0]; - - return isset($this->_fields[$field2]) && $value != $this->_fields[$field2]; + // extract the second field value, this accounts for nested array values + list($field2Value, $multiple) = $this->getPart($this->_fields, explode('.', $params[0])); + return isset($field2Value) && $value != $field2Value; } /** diff --git a/tests/Valitron/ValidateTest.php b/tests/Valitron/ValidateTest.php index adf296e..7f07e5f 100644 --- a/tests/Valitron/ValidateTest.php +++ b/tests/Valitron/ValidateTest.php @@ -1271,6 +1271,34 @@ class ValidateTest extends BaseTestCase $v2->rule('required', array('empty_text', 'null_value', 'in_array.empty_text'), true); $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) { From fd1b55ad218d0196fd7b6f47fc7976e649b7b69e Mon Sep 17 00:00:00 2001 From: Mark Cahill Date: Mon, 5 Feb 2018 07:15:00 -0500 Subject: [PATCH 14/19] Fulfilling documentation request for numeric array validation --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 0d520fd..a4db86f 100644 --- a/README.md +++ b/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: ```php From 06d1740c3213fa846a77f554afefed1c75689e81 Mon Sep 17 00:00:00 2001 From: Tom Breese Date: Tue, 6 Feb 2018 23:02:03 -0500 Subject: [PATCH 15/19] adding tests for nulls/not set values for nested and not nested equals and different methods --- tests/Valitron/ValidateTest.php | 114 ++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) diff --git a/tests/Valitron/ValidateTest.php b/tests/Valitron/ValidateTest.php index 7f07e5f..74084b0 100644 --- a/tests/Valitron/ValidateTest.php +++ b/tests/Valitron/ValidateTest.php @@ -70,6 +70,36 @@ class ValidateTest extends BaseTestCase $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', ['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', ['bar', 'baz']); + $v->rule('equals', 'bar', 'baz'); + $this->assertFalse($v->validate()); + } + public function testDifferentValid() { $v = new Validator(array('foo' => 'bar', 'bar' => 'baz')); @@ -84,6 +114,36 @@ class ValidateTest extends BaseTestCase $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', ['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', ['bar', 'baz']); + $v->rule('equals', 'bar', 'baz'); + $this->assertFalse($v->validate()); + } + public function testAcceptedValid() { $v = new Validator(array('agree' => 'yes')); @@ -1286,6 +1346,36 @@ class ValidateTest extends BaseTestCase $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', ['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', ['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'))); @@ -1299,6 +1389,30 @@ class ValidateTest extends BaseTestCase $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', ['foo.bar', 'foo.baz']); + $v->rule('different', 'foo.bar', 'foo.baz'); + $this->assertFalse($v->validate()); + } + + public function testNestedDifferentBothUnsetRequired() + { + $v = new Validator(array('foo' => 'bar')); + $v->rule('required', ['foo.bar', 'foo.baz']); + $v->rule('different', 'foo.bar', 'foo.baz'); + $this->assertFalse($v->validate()); + } + } function sampleFunctionCallback($field, $value, array $params) { From 32dec57f69e93cc9de3312c812ecb2540864ac81 Mon Sep 17 00:00:00 2001 From: Tom Breese Date: Tue, 6 Feb 2018 23:05:25 -0500 Subject: [PATCH 16/19] adding nested different both unser required test --- tests/Valitron/ValidateTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/Valitron/ValidateTest.php b/tests/Valitron/ValidateTest.php index 74084b0..b81c308 100644 --- a/tests/Valitron/ValidateTest.php +++ b/tests/Valitron/ValidateTest.php @@ -1405,6 +1405,13 @@ class ValidateTest extends BaseTestCase $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')); From 19a1e123bdc000adc47d53a5efb489e59ed18d99 Mon Sep 17 00:00:00 2001 From: Tom Breese Date: Tue, 6 Feb 2018 23:10:20 -0500 Subject: [PATCH 17/19] updating tests for 5.3 compatible arrays --- tests/Valitron/ValidateTest.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/Valitron/ValidateTest.php b/tests/Valitron/ValidateTest.php index b81c308..04c147c 100644 --- a/tests/Valitron/ValidateTest.php +++ b/tests/Valitron/ValidateTest.php @@ -80,7 +80,7 @@ class ValidateTest extends BaseTestCase public function testEqualsBothNullRequired() { $v = new Validator(array('foo' => null, 'bar' => null)); - $v->rule('required', ['foo', 'bar']); + $v->rule('required', array('foo', 'bar')); $v->rule('equals', 'foo', 'bar'); $this->assertFalse($v->validate()); } @@ -95,7 +95,7 @@ class ValidateTest extends BaseTestCase public function testEqualsBothUnsetRequired() { $v = new Validator(array('foo' => 1)); - $v->rule('required', ['bar', 'baz']); + $v->rule('required', array('bar', 'baz')); $v->rule('equals', 'bar', 'baz'); $this->assertFalse($v->validate()); } @@ -124,7 +124,7 @@ class ValidateTest extends BaseTestCase public function testDifferentBothNullRequired() { $v = new Validator(array('foo' => null, 'bar' => null)); - $v->rule('required', ['foo', 'bar']); + $v->rule('required', array('foo', 'bar')); $v->rule('equals', 'foo', 'bar'); $this->assertFalse($v->validate()); } @@ -139,7 +139,7 @@ class ValidateTest extends BaseTestCase public function testDifferentBothUnsetRequired() { $v = new Validator(array('foo' => 1)); - $v->rule('required', ['bar', 'baz']); + $v->rule('required', array('bar', 'baz')); $v->rule('equals', 'bar', 'baz'); $this->assertFalse($v->validate()); } @@ -1356,7 +1356,7 @@ class ValidateTest extends BaseTestCase public function testNestedEqualsBothNullRequired() { $v = new Validator(array('foo' => array('bar' => null, 'baz' => null))); - $v->rule('required', ['foo.bar', 'foo.baz']); + $v->rule('required', array('foo.bar', 'foo.baz')); $v->rule('equals', 'foo.bar', 'foo.baz'); $this->assertFalse($v->validate()); } @@ -1371,7 +1371,7 @@ class ValidateTest extends BaseTestCase public function testNestedEqualsBothUnsetRequired() { $v = new Validator(array('foo' => 'bar')); - $v->rule('required', ['foo.one', 'foo.two']); + $v->rule('required', array('foo.one', 'foo.two')); $v->rule('equals', 'foo.one', 'foo.two'); $this->assertFalse($v->validate()); } @@ -1400,7 +1400,7 @@ class ValidateTest extends BaseTestCase public function testNestedDifferentBothNullRequired() { $v = new Validator(array('foo' => array('bar' => null, 'baz' => null))); - $v->rule('required', ['foo.bar', 'foo.baz']); + $v->rule('required', array('foo.bar', 'foo.baz')); $v->rule('different', 'foo.bar', 'foo.baz'); $this->assertFalse($v->validate()); } @@ -1415,7 +1415,7 @@ class ValidateTest extends BaseTestCase public function testNestedDifferentBothUnsetRequired() { $v = new Validator(array('foo' => 'bar')); - $v->rule('required', ['foo.bar', 'foo.baz']); + $v->rule('required', array('foo.bar', 'foo.baz')); $v->rule('different', 'foo.bar', 'foo.baz'); $this->assertFalse($v->validate()); } From fb8f89a519c573231961250bf9e3adbf92ec66cb Mon Sep 17 00:00:00 2001 From: Donatas Glodenis Date: Wed, 7 Feb 2018 15:33:59 +0000 Subject: [PATCH 18/19] Translation to Lithuanian --- lang/lt.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 lang/lt.php diff --git a/lang/lt.php b/lang/lt.php new file mode 100644 index 0000000..cace602 --- /dev/null +++ b/lang/lt.php @@ -0,0 +1,33 @@ + "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" +); From 4b32e6067a7f611113161b2c6f8258d85c16d0e2 Mon Sep 17 00:00:00 2001 From: Vance Lucas Date: Sat, 10 Feb 2018 16:02:11 -0600 Subject: [PATCH 19/19] Update composer license SPDX --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9e87dc1..066dda7 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "description": "Simple, elegant, stand-alone validation library with NO dependencies", "keywords": ["validation", "validator", "valid"], "homepage": "http://github.com/vlucas/valitron", - "license" : "BSD", + "license" : "BSD-3-Clause", "authors" : [ { "name": "Vance Lucas",