Permalink
Browse files

more tests.

  • Loading branch information...
1 parent 5d6eed1 commit e61dcf44ad0e066a48c64c813ff10a133846e94e @taylorotwell taylorotwell committed Jun 2, 2012
Showing with 50 additions and 2 deletions.
  1. +2 −2 src/Illuminate/Validation/Validator.php
  2. +48 −0 tests/ValidatorTest.php
@@ -274,7 +274,7 @@ protected function validateDifferent($attribute, $value, $parameters)
{
$other = $parameters[0];
- return isset($this->attributes[$other]) and $value != $this->attributes[$other];
+ return isset($this->data[$other]) and $value != $this->data[$other];
}
/**
@@ -384,7 +384,7 @@ protected function getSize($attribute, $value)
// entire length of the string will be considered the attribute size.
if (is_numeric($value) and $this->hasRule($attribute, $this->numericRules))
{
- return $this->attributes[$attribute];
+ return $this->data[$attribute];
}
elseif ($value instanceof File)
{
View
@@ -94,6 +94,54 @@ public function testValidateConfirmed()
}
+ public function testValidateSame()
+ {
+ $trans = $this->getRealTranslator();
+ $v = new Validator($trans, array('foo' => 'bar', 'baz' => 'boom'), array('foo' => 'Same:baz'));
+ $this->assertFalse($v->passes());
+
+ $v = new Validator($trans, array('foo' => 'bar'), array('foo' => 'Same:baz'));
+ $this->assertFalse($v->passes());
+
+ $v = new Validator($trans, array('foo' => 'bar', 'baz' => 'bar'), array('foo' => 'Same:baz'));
+ $this->assertTrue($v->passes());
+ }
+
+
+ public function testValidateDifferent()
+ {
+ $trans = $this->getRealTranslator();
+ $v = new Validator($trans, array('foo' => 'bar', 'baz' => 'boom'), array('foo' => 'Different:baz'));
+ $this->assertTrue($v->passes());
+
+ $v = new Validator($trans, array('foo' => 'bar'), array('foo' => 'Different:baz'));
+ $this->assertFalse($v->passes());
+
+ $v = new Validator($trans, array('foo' => 'bar', 'baz' => 'bar'), array('foo' => 'Different:baz'));
+ $this->assertFalse($v->passes());
+ }
+
+
+ public function testValidateAccepted()
+ {
+ $trans = $this->getRealTranslator();
+ $v = new Validator($trans, array('foo' => 'no'), array('foo' => 'Accepted'));
+ $this->assertFalse($v->passes());
+
+ $v = new Validator($trans, array('foo' => null), array('foo' => 'Accepted'));
+ $this->assertFalse($v->passes());
+
+ $v = new Validator($trans, array(), array('foo' => 'Accepted'));
+ $this->assertFalse($v->passes());
+
+ $v = new Validator($trans, array('foo' => 'yes'), array('foo' => 'Accepted'));
+ $this->assertTrue($v->passes());
+
+ $v = new Validator($trans, array('foo' => '1'), array('foo' => 'Accepted'));
+ $this->assertTrue($v->passes());
+ }
+
+
protected function getTranslator()
{
return m::mock('Symfony\Component\Translation\TranslatorInterface');

0 comments on commit e61dcf4

Please sign in to comment.