Security update for Core, with self-updated composer
[yaffs-website] / vendor / symfony / validator / Tests / Constraints / LanguageValidatorTest.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\Intl\Util\IntlTestHelper;
15 use Symfony\Component\Validator\Constraints\Language;
16 use Symfony\Component\Validator\Constraints\LanguageValidator;
17 use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
18
19 class LanguageValidatorTest extends ConstraintValidatorTestCase
20 {
21     protected function createValidator()
22     {
23         return new LanguageValidator();
24     }
25
26     public function testNullIsValid()
27     {
28         $this->validator->validate(null, new Language());
29
30         $this->assertNoViolation();
31     }
32
33     public function testEmptyStringIsValid()
34     {
35         $this->validator->validate('', new Language());
36
37         $this->assertNoViolation();
38     }
39
40     /**
41      * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
42      */
43     public function testExpectsStringCompatibleType()
44     {
45         $this->validator->validate(new \stdClass(), new Language());
46     }
47
48     /**
49      * @dataProvider getValidLanguages
50      */
51     public function testValidLanguages($language)
52     {
53         $this->validator->validate($language, new Language());
54
55         $this->assertNoViolation();
56     }
57
58     public function getValidLanguages()
59     {
60         return array(
61             array('en'),
62             array('en_US'),
63             array('my'),
64         );
65     }
66
67     /**
68      * @dataProvider getInvalidLanguages
69      */
70     public function testInvalidLanguages($language)
71     {
72         $constraint = new Language(array(
73             'message' => 'myMessage',
74         ));
75
76         $this->validator->validate($language, $constraint);
77
78         $this->buildViolation('myMessage')
79             ->setParameter('{{ value }}', '"'.$language.'"')
80             ->setCode(Language::NO_SUCH_LANGUAGE_ERROR)
81             ->assertRaised();
82     }
83
84     public function getInvalidLanguages()
85     {
86         return array(
87             array('EN'),
88             array('foobar'),
89         );
90     }
91
92     public function testValidateUsingCountrySpecificLocale()
93     {
94         IntlTestHelper::requireFullIntl($this, false);
95
96         \Locale::setDefault('fr_FR');
97         $existingLanguage = 'en';
98
99         $this->validator->validate($existingLanguage, new Language(array(
100             'message' => 'aMessage',
101         )));
102
103         $this->assertNoViolation();
104     }
105 }