Updated Drupal to 8.6. This goes with the following updates because it's possible...
[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\Test\ConstraintValidatorTestCase;
18
19 class CurrencyValidatorTest extends ConstraintValidatorTestCase
20 {
21     protected function createValidator()
22     {
23         return new CurrencyValidator();
24     }
25
26     public function testNullIsValid()
27     {
28         $this->validator->validate(null, new Currency());
29
30         $this->assertNoViolation();
31     }
32
33     public function testEmptyStringIsValid()
34     {
35         $this->validator->validate('', new Currency());
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 Currency());
46     }
47
48     /**
49      * @dataProvider getValidCurrencies
50      */
51     public function testValidCurrencies($currency)
52     {
53         $this->validator->validate($currency, new Currency());
54
55         $this->assertNoViolation();
56     }
57
58     /**
59      * @dataProvider getValidCurrencies
60      **/
61     public function testValidCurrenciesWithCountrySpecificLocale($currency)
62     {
63         IntlTestHelper::requireFullIntl($this, false);
64
65         \Locale::setDefault('en_GB');
66
67         $this->validator->validate($currency, new Currency());
68
69         $this->assertNoViolation();
70     }
71
72     public function getValidCurrencies()
73     {
74         return array(
75             array('EUR'),
76             array('USD'),
77             array('SIT'),
78             array('AUD'),
79             array('CAD'),
80         );
81     }
82
83     /**
84      * @dataProvider getInvalidCurrencies
85      */
86     public function testInvalidCurrencies($currency)
87     {
88         $constraint = new Currency(array(
89             'message' => 'myMessage',
90         ));
91
92         $this->validator->validate($currency, $constraint);
93
94         $this->buildViolation('myMessage')
95             ->setParameter('{{ value }}', '"'.$currency.'"')
96             ->setCode(Currency::NO_SUCH_CURRENCY_ERROR)
97             ->assertRaised();
98     }
99
100     public function getInvalidCurrencies()
101     {
102         return array(
103             array('EN'),
104             array('foobar'),
105         );
106     }
107 }