Version 1
[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\Validation;
17
18 class NotBlankValidatorTest extends AbstractConstraintValidatorTest
19 {
20     protected function getApiVersion()
21     {
22         return Validation::API_VERSION_2_5;
23     }
24
25     protected function createValidator()
26     {
27         return new NotBlankValidator();
28     }
29
30     /**
31      * @dataProvider getValidValues
32      */
33     public function testValidValues($value)
34     {
35         $this->validator->validate($value, new NotBlank());
36
37         $this->assertNoViolation();
38     }
39
40     public function getValidValues()
41     {
42         return array(
43             array('foobar'),
44             array(0),
45             array(0.0),
46             array('0'),
47             array(1234),
48         );
49     }
50
51     public function testNullIsInvalid()
52     {
53         $constraint = new NotBlank(array(
54             'message' => 'myMessage',
55         ));
56
57         $this->validator->validate(null, $constraint);
58
59         $this->buildViolation('myMessage')
60             ->setParameter('{{ value }}', 'null')
61             ->setCode(NotBlank::IS_BLANK_ERROR)
62             ->assertRaised();
63     }
64
65     public function testBlankIsInvalid()
66     {
67         $constraint = new NotBlank(array(
68             'message' => 'myMessage',
69         ));
70
71         $this->validator->validate('', $constraint);
72
73         $this->buildViolation('myMessage')
74             ->setParameter('{{ value }}', '""')
75             ->setCode(NotBlank::IS_BLANK_ERROR)
76             ->assertRaised();
77     }
78
79     public function testFalseIsInvalid()
80     {
81         $constraint = new NotBlank(array(
82             'message' => 'myMessage',
83         ));
84
85         $this->validator->validate(false, $constraint);
86
87         $this->buildViolation('myMessage')
88             ->setParameter('{{ value }}', 'false')
89             ->setCode(NotBlank::IS_BLANK_ERROR)
90             ->assertRaised();
91     }
92
93     public function testEmptyArrayIsInvalid()
94     {
95         $constraint = new NotBlank(array(
96             'message' => 'myMessage',
97         ));
98
99         $this->validator->validate(array(), $constraint);
100
101         $this->buildViolation('myMessage')
102             ->setParameter('{{ value }}', 'array')
103             ->setCode(NotBlank::IS_BLANK_ERROR)
104             ->assertRaised();
105     }
106 }