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) {