BlankValidatorTest.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace Symfony\Tests\Component\Validator;
  3. use Symfony\Component\Validator\Constraints\Blank;
  4. use Symfony\Component\Validator\Constraints\BlankValidator;
  5. class BlankValidatorTest extends \PHPUnit_Framework_TestCase
  6. {
  7. protected $validator;
  8. protected function setUp()
  9. {
  10. $this->validator = new BlankValidator();
  11. }
  12. public function testNullIsValid()
  13. {
  14. $this->assertTrue($this->validator->isValid(null, new Blank()));
  15. }
  16. public function testBlankIsValid()
  17. {
  18. $this->assertTrue($this->validator->isValid('', new Blank()));
  19. }
  20. /**
  21. * @dataProvider getInvalidValues
  22. */
  23. public function testInvalidValues($date)
  24. {
  25. $this->assertFalse($this->validator->isValid($date, new Blank()));
  26. }
  27. public function getInvalidValues()
  28. {
  29. return array(
  30. array('foobar'),
  31. array(0),
  32. array(false),
  33. array(1234),
  34. );
  35. }
  36. public function testMessageIsSet()
  37. {
  38. $constraint = new Blank(array(
  39. 'message' => 'myMessage'
  40. ));
  41. $this->assertFalse($this->validator->isValid('foobar', $constraint));
  42. $this->assertEquals($this->validator->getMessageTemplate(), 'myMessage');
  43. $this->assertEquals($this->validator->getMessageParameters(), array(
  44. '{{ value }}' => 'foobar',
  45. ));
  46. }
  47. }