From f8e63f313d2a469e183d93a8c1c9f6dc35a1fcfc Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 16 Oct 2011 13:34:26 -0500 Subject: [PATCH] adding validator tests. --- laravel/validation/validator.php | 2 +- tests/Cases/ValidatorTest.php | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/Cases/ValidatorTest.php diff --git a/laravel/validation/validator.php b/laravel/validation/validator.php index 48b1192e..539ffe6a 100644 --- a/laravel/validation/validator.php +++ b/laravel/validation/validator.php @@ -208,7 +208,7 @@ protected function error($attribute, $rule, $parameters) */ 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) === '')); } /** diff --git a/tests/Cases/ValidatorTest.php b/tests/Cases/ValidatorTest.php new file mode 100644 index 00000000..190139fa --- /dev/null +++ b/tests/Cases/ValidatorTest.php @@ -0,0 +1,30 @@ + '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')); + } + +} \ No newline at end of file