fd92febf9b29b96c31975ab7f67b4217db9d3f92
[yaffs-website] / vendor / symfony / validator / Tests / Constraints / NotBlankValidatorTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\Validator\Tests\Constraints;
13
14 use Symfony\Component\Validator\Constraints\NotBlank;
15 use Symfony\Component\Validator\Constraints\NotBlankValidator;
16 use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
17
18 class NotBlankValidatorTest extends ConstraintValidatorTestCase
19 {
20     protected function createValidator()
21     {
22         return new NotBlankValidator();
23     }
24
25     /**
26      * @dataProvider getValidValues
27      */
28     public function testValidValues($value)
29     {
30         $this->validator->validate($value, new NotBlank());
31
32         $this->assertNoViolation();
33     }
34
35     public function getValidValues()
36     {
37         return array(
38             array('foobar'),
39             array(0),
40             array(0.0),
41             array('0'),
42             array(1234),
43         );
44     }
45
46     public function testNullIsInvalid()
47     {
48         $constraint = new NotBlank(array(
49             'message' => 'myMessage',
50         ));
51
52         $this->validator->validate(null, $constraint);
53
54         $this->buildViolation('myMessage')
55             ->setParameter('{{ value }}', 'null')
56             ->setCode(NotBlank::IS_BLANK_ERROR)
57             ->assertRaised();
58     }
59
60     public function testBlankIsInvalid()
61     {
62         $constraint = new NotBlank(array(
63             'message' => 'myMessage',
64         ));
65
66         $this->validator->validate('', $constraint);
67
68         $this->buildViolation('myMessage')
69             ->setParameter('{{ value }}', '""')
70             ->setCode(NotBlank::IS_BLANK_ERROR)
71             ->assertRaised();
72     }
73
74     public function testFalseIsInvalid()
75     {
76         $constraint = new NotBlank(array(
77             'message' => 'myMessage',
78         ));
79
80         $this->validator->validate(false, $constraint);
81
82         $this->buildViolation('myMessage')
83             ->setParameter('{{ value }}', 'false')
84             ->setCode(NotBlank::IS_BLANK_ERROR)
85             ->assertRaised();
86     }
87
88     public function testEmptyArrayIsInvalid()
89     {
90         $constraint = new NotBlank(array(
91             'message' => 'myMessage',
92         ));
93
94         $this->validator->validate(array(), $constraint);
95
96         $this->buildViolation('myMessage')
97             ->setParameter('{{ value }}', 'array')
98             ->setCode(NotBlank::IS_BLANK_ERROR)
99             ->assertRaised();
100     }
101 }