adding validator tests.
This commit is contained in:
parent
8bd6d34622
commit
f8e63f313d
|
@ -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) === ''));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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'));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue