ValidatorTest.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. use Laravel\Lang;
  3. use Laravel\Validation\Validator;
  4. class ValidatorTest extends PHPUnit_Framework_TestCase {
  5. public function test_simple_group_of_validations()
  6. {
  7. $rules = array(
  8. 'email' => 'required|email',
  9. 'password' => 'required|confirmed|min:6',
  10. 'name' => 'required|alpha',
  11. 'age' => 'required',
  12. );
  13. $attributes = array(
  14. 'email' => 'taylorotwell',
  15. 'password' => 'something',
  16. 'password_confirmation' => 'something',
  17. 'name' => 'taylor5',
  18. );
  19. $messages = array('name_alpha' => 'The name must be alphabetic!');
  20. $validator = Validator::make($attributes, $rules, $messages);
  21. $this->assertFalse($validator->valid());
  22. $this->assertTrue($validator->errors->has('name'));
  23. $this->assertTrue($validator->errors->has('email'));
  24. $this->assertFalse($validator->errors->has('password'));
  25. $this->assertEquals(count($validator->errors->get('name')), 1);
  26. $this->assertEquals($validator->errors->first('name'), 'The name must be alphabetic!');
  27. $this->assertEquals($validator->errors->first('email'), Lang::line('validation.email', array('attribute' => 'email'))->get());
  28. $this->assertEquals($validator->errors->first('age'), Lang::line('validation.required', array('attribute' => 'age'))->get());
  29. }
  30. }