adding validator tests.

This commit is contained in:
Taylor Otwell 2011-10-16 13:34:26 -05:00
parent 8bd6d34622
commit f8e63f313d
2 changed files with 31 additions and 1 deletions

View File

@ -208,7 +208,7 @@ protected function error($attribute, $rule, $parameters)
*/ */
protected function validate_required($attribute, $value) protected function validate_required($attribute, $value)
{ {
return (is_null($value) or (is_string($value) and trim($value) === '')); return ! (is_null($value) or (is_string($value) and trim($value) === ''));
} }
/** /**

View File

@ -0,0 +1,30 @@
<?php
use Laravel\Validation\Validator;
class ValidatorTest extends PHPUnit_Framework_TestCase {
public function test_simple_group_of_validations()
{
$rules = array(
'email' => 'required|email',
'password' => 'required|confirmed|min:6',
'name' => 'required|alpha',
);
$attributes = array(
'email' => 'taylorotwell',
'password' => 'something',
'password_confirmation' => 'something',
'name' => 'taylor5',
);
$messages = array('name_alpha' => 'The name must be alphabetic!');
$validator = Validator::make($attributes, $rules, $messages);
$this->assertFalse($validator->valid());
$this->assertFalse($validator->errors->has('password'));
}
}