adding tests for nulls/not set values for nested and not nested equals and different methods

This commit is contained in:
Tom Breese 2018-02-06 23:02:03 -05:00
parent 7c94b2ae5a
commit 06d1740c32

View File

@ -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', ['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() 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', ['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() public function testAcceptedValid()
{ {
$v = new Validator(array('agree' => 'yes')); $v = new Validator(array('agree' => 'yes'));
@ -1286,6 +1346,36 @@ class ValidateTest extends BaseTestCase
$this->assertFalse($v->validate()); $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() public function testNestedDifferentValid()
{ {
$v = new Validator(array('foo' => array('one' => 'bar', 'two' => 'baz'))); $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'); $v->rule('different', 'foo.one', 'foo.two');
$this->assertFalse($v->validate()); $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) { function sampleFunctionCallback($field, $value, array $params) {