From 9afa605dc3564d1fc580c1f67565ca6b9146c907 Mon Sep 17 00:00:00 2001 From: Willem Wollebrants Date: Mon, 22 Feb 2016 12:13:02 +0100 Subject: [PATCH] Add tests for 'optional' rule --- tests/Valitron/ValidateTest.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/Valitron/ValidateTest.php b/tests/Valitron/ValidateTest.php index 9834d2e..996c4a2 100644 --- a/tests/Valitron/ValidateTest.php +++ b/tests/Valitron/ValidateTest.php @@ -1085,6 +1085,27 @@ class ValidateTest extends BaseTestCase ), ); } + + public function testOptionalProvidedValid() + { + $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'); + $this->assertFalse($v->validate()); + } + + public function testOptionalNotProvided() + { + $v = new Validator(array()); + $v->rule('optional', 'address')->rule('email', 'address'); + $this->assertTrue($v->validate()); + } } function sampleFunctionCallback($field, $value, array $params) {