1c11a6bbec891f19b02bf5541a9129131e96a88a
[yaffs-website] / vendor / symfony / validator / Tests / Constraints / CurrencyValidatorTest.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\Currency;
16 use Symfony\Component\Validator\Constraints\CurrencyValidator;
17 use Symfony\Component\Validator\Validation;
18
19 class CurrencyValidatorTest extends AbstractConstraintValidatorTest
20 {
21     protected function getApiVersion()
22     {
23         return Validation::API_VERSION_2_5;
24     }
25
26     protected function createValidator()
27     {
28         return new CurrencyValidator();
29     }
30
31     public function testNullIsValid()
32     {
33         $this->validator->validate(null, new Currency());
34
35         $this->assertNoViolation();
36     }
37
38     public function testEmptyStringIsValid()
39     {
40         $this->validator->validate('', new Currency());
41
42         $this->assertNoViolation();
43     }
44
45     /**
46      * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
47      */
48     public function testExpectsStringCompatibleType()
49     {
50         $this->validator->validate(new \stdClass(), new Currency());
51     }
52
53     /**
54      * @dataProvider getValidCurrencies
55      */
56     public function testValidCurrencies($currency)
57     {
58         $this->validator->validate($currency, new Currency());
59
60         $this->assertNoViolation();
61     }
62
63     /**
64      * @dataProvider getValidCurrencies
65      **/
66     public function testValidCurrenciesWithCountrySpecificLocale($currency)
67     {
68         IntlTestHelper::requireFullIntl($this, false);
69
70         \Locale::setDefault('en_GB');
71
72         $this->validator->validate($currency, new Currency());
73
74         $this->assertNoViolation();
75     }
76
77     public function getValidCurrencies()
78     {
79         return array(
80             array('EUR'),
81             array('USD'),
82             array('SIT'),
83             array('AUD'),
84             array('CAD'),
85         );
86     }
87
88     /**
89      * @dataProvider getInvalidCurrencies
90      */
91     public function testInvalidCurrencies($currency)
92     {
93         $constraint = new Currency(array(
94             'message' => 'myMessage',
95         ));
96
97         $this->validator->validate($currency, $constraint);
98
99         $this->buildViolation('myMessage')
100             ->setParameter('{{ value }}', '"'.$currency.'"')
101             ->setCode(Currency::NO_SUCH_CURRENCY_ERROR)
102             ->assertRaised();
103     }
104
105     public function getInvalidCurrencies()
106     {
107         return array(
108             array('EN'),
109             array('foobar'),
110         );
111     }
112 }