c028596b04c209a35dd3da2ae2816ba697104034
[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\Validation;
17
18 class LocaleValidatorTest 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 LocaleValidator();
28     }
29
30     public function testNullIsValid()
31     {
32         $this->validator->validate(null, new Locale());
33
34         $this->assertNoViolation();
35     }
36
37     public function testEmptyStringIsValid()
38     {
39         $this->validator->validate('', new Locale());
40
41         $this->assertNoViolation();
42     }
43
44     /**
45      * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
46      */
47     public function testExpectsStringCompatibleType()
48     {
49         $this->validator->validate(new \stdClass(), new Locale());
50     }
51
52     /**
53      * @dataProvider getValidLocales
54      */
55     public function testValidLocales($locale)
56     {
57         $this->validator->validate($locale, new Locale());
58
59         $this->assertNoViolation();
60     }
61
62     public function getValidLocales()
63     {
64         return array(
65             array('en'),
66             array('en_US'),
67             array('pt'),
68             array('pt_PT'),
69             array('zh_Hans'),
70             array('fil_PH'),
71         );
72     }
73
74     /**
75      * @dataProvider getInvalidLocales
76      */
77     public function testInvalidLocales($locale)
78     {
79         $constraint = new Locale(array(
80             'message' => 'myMessage',
81         ));
82
83         $this->validator->validate($locale, $constraint);
84
85         $this->buildViolation('myMessage')
86             ->setParameter('{{ value }}', '"'.$locale.'"')
87             ->setCode(Locale::NO_SUCH_LOCALE_ERROR)
88             ->assertRaised();
89     }
90
91     public function getInvalidLocales()
92     {
93         return array(
94             array('EN'),
95             array('foobar'),
96         );
97     }
98 }