BlankValidatorTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Tests\Component\Validator;
  11. use Symfony\Component\Validator\Constraints\Blank;
  12. use Symfony\Component\Validator\Constraints\BlankValidator;
  13. class BlankValidatorTest extends \PHPUnit_Framework_TestCase
  14. {
  15. protected $validator;
  16. protected function setUp()
  17. {
  18. $this->validator = new BlankValidator();
  19. }
  20. public function testNullIsValid()
  21. {
  22. $this->assertTrue($this->validator->isValid(null, new Blank()));
  23. }
  24. public function testBlankIsValid()
  25. {
  26. $this->assertTrue($this->validator->isValid('', new Blank()));
  27. }
  28. /**
  29. * @dataProvider getInvalidValues
  30. */
  31. public function testInvalidValues($date)
  32. {
  33. $this->assertFalse($this->validator->isValid($date, new Blank()));
  34. }
  35. public function getInvalidValues()
  36. {
  37. return array(
  38. array('foobar'),
  39. array(0),
  40. array(false),
  41. array(1234),
  42. );
  43. }
  44. public function testMessageIsSet()
  45. {
  46. $constraint = new Blank(array(
  47. 'message' => 'myMessage'
  48. ));
  49. $this->assertFalse($this->validator->isValid('foobar', $constraint));
  50. $this->assertEquals($this->validator->getMessageTemplate(), 'myMessage');
  51. $this->assertEquals($this->validator->getMessageParameters(), array(
  52. '{{ value }}' => 'foobar',
  53. ));
  54. }
  55. }