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\Validation;
19 class LanguageValidatorTest extends AbstractConstraintValidatorTest
21 protected function getApiVersion()
23 return Validation::API_VERSION_2_5;
26 protected function createValidator()
28 return new LanguageValidator();
31 public function testNullIsValid()
33 $this->validator->validate(null, new Language());
35 $this->assertNoViolation();
38 public function testEmptyStringIsValid()
40 $this->validator->validate('', new Language());
42 $this->assertNoViolation();
46 * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
48 public function testExpectsStringCompatibleType()
50 $this->validator->validate(new \stdClass(), new Language());
54 * @dataProvider getValidLanguages
56 public function testValidLanguages($language)
58 $this->validator->validate($language, new Language());
60 $this->assertNoViolation();
63 public function getValidLanguages()
73 * @dataProvider getInvalidLanguages
75 public function testInvalidLanguages($language)
77 $constraint = new Language(array(
78 'message' => 'myMessage',
81 $this->validator->validate($language, $constraint);
83 $this->buildViolation('myMessage')
84 ->setParameter('{{ value }}', '"'.$language.'"')
85 ->setCode(Language::NO_SUCH_LANGUAGE_ERROR)
89 public function getInvalidLanguages()
97 public function testValidateUsingCountrySpecificLocale()
99 IntlTestHelper::requireFullIntl($this, false);
101 \Locale::setDefault('fr_FR');
102 $existingLanguage = 'en';
104 $this->validator->validate($existingLanguage, new Language(array(
105 'message' => 'aMessage',
108 $this->assertNoViolation();