Security update for Core, with self-updated composer
[yaffs-website] / vendor / symfony / validator / Tests / Constraints / LocaleValidatorTest.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\Locale;
15 use Symfony\Component\Validator\Constraints\LocaleValidator;
16 use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
17
18 class LocaleValidatorTest extends ConstraintValidatorTestCase
19 {
20     protected function createValidator()
21     {
22         return new LocaleValidator();
23     }
24
25     public function testNullIsValid()
26     {
27         $this->validator->validate(null, new Locale());
28
29         $this->assertNoViolation();
30     }
31
32     public function testEmptyStringIsValid()
33     {
34         $this->validator->validate('', new Locale());
35
36         $this->assertNoViolation();
37     }
38
39     /**
40      * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
41      */
42     public function testExpectsStringCompatibleType()
43     {
44         $this->validator->validate(new \stdClass(), new Locale());
45     }
46
47     /**
48      * @dataProvider getValidLocales
49      */
50     public function testValidLocales($locale)
51     {
52         $this->validator->validate($locale, new Locale());
53
54         $this->assertNoViolation();
55     }
56
57     public function getValidLocales()
58     {
59         return array(
60             array('en'),
61             array('en_US'),
62             array('pt'),
63             array('pt_PT'),
64             array('zh_Hans'),
65             array('fil_PH'),
66         );
67     }
68
69     /**
70      * @dataProvider getInvalidLocales
71      */
72     public function testInvalidLocales($locale)
73     {
74         $constraint = new Locale(array(
75             'message' => 'myMessage',
76         ));
77
78         $this->validator->validate($locale, $constraint);
79
80         $this->buildViolation('myMessage')
81             ->setParameter('{{ value }}', '"'.$locale.'"')
82             ->setCode(Locale::NO_SUCH_LOCALE_ERROR)
83             ->assertRaised();
84     }
85
86     public function getInvalidLocales()
87     {
88         return array(
89             array('EN'),
90             array('foobar'),
91         );
92     }
93 }