4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Validator\Tests\Constraints;
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;
19 class LanguageValidatorTest extends ConstraintValidatorTestCase
21 protected function createValidator()
23 return new LanguageValidator();
26 public function testNullIsValid()
28 $this->validator->validate(null, new Language());
30 $this->assertNoViolation();
33 public function testEmptyStringIsValid()
35 $this->validator->validate('', new Language());
37 $this->assertNoViolation();
41 * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
43 public function testExpectsStringCompatibleType()
45 $this->validator->validate(new \stdClass(), new Language());
49 * @dataProvider getValidLanguages
51 public function testValidLanguages($language)
53 $this->validator->validate($language, new Language());
55 $this->assertNoViolation();
58 public function getValidLanguages()
68 * @dataProvider getInvalidLanguages
70 public function testInvalidLanguages($language)
72 $constraint = new Language(array(
73 'message' => 'myMessage',
76 $this->validator->validate($language, $constraint);
78 $this->buildViolation('myMessage')
79 ->setParameter('{{ value }}', '"'.$language.'"')
80 ->setCode(Language::NO_SUCH_LANGUAGE_ERROR)
84 public function getInvalidLanguages()
92 public function testValidateUsingCountrySpecificLocale()
94 IntlTestHelper::requireFullIntl($this, false);
96 \Locale::setDefault('fr_FR');
97 $existingLanguage = 'en';
99 $this->validator->validate($existingLanguage, new Language(array(
100 'message' => 'aMessage',
103 $this->assertNoViolation();