Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / symfony / validator / Tests / Constraints / DateValidatorTest.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\Date;
15 use Symfony\Component\Validator\Constraints\DateValidator;
16 use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
17
18 class DateValidatorTest extends ConstraintValidatorTestCase
19 {
20     protected function createValidator()
21     {
22         return new DateValidator();
23     }
24
25     public function testNullIsValid()
26     {
27         $this->validator->validate(null, new Date());
28
29         $this->assertNoViolation();
30     }
31
32     public function testEmptyStringIsValid()
33     {
34         $this->validator->validate('', new Date());
35
36         $this->assertNoViolation();
37     }
38
39     public function testDateTimeClassIsValid()
40     {
41         $this->validator->validate(new \DateTime(), new Date());
42
43         $this->assertNoViolation();
44     }
45
46     public function testDateTimeImmutableClassIsValid()
47     {
48         $this->validator->validate(new \DateTimeImmutable(), new Date());
49
50         $this->assertNoViolation();
51     }
52
53     /**
54      * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
55      */
56     public function testExpectsStringCompatibleType()
57     {
58         $this->validator->validate(new \stdClass(), new Date());
59     }
60
61     /**
62      * @dataProvider getValidDates
63      */
64     public function testValidDates($date)
65     {
66         $this->validator->validate($date, new Date());
67
68         $this->assertNoViolation();
69     }
70
71     public function getValidDates()
72     {
73         return array(
74             array('2010-01-01'),
75             array('1955-12-12'),
76             array('2030-05-31'),
77         );
78     }
79
80     /**
81      * @dataProvider getInvalidDates
82      */
83     public function testInvalidDates($date, $code)
84     {
85         $constraint = new Date(array(
86             'message' => 'myMessage',
87         ));
88
89         $this->validator->validate($date, $constraint);
90
91         $this->buildViolation('myMessage')
92             ->setParameter('{{ value }}', '"'.$date.'"')
93             ->setCode($code)
94             ->assertRaised();
95     }
96
97     public function getInvalidDates()
98     {
99         return array(
100             array('foobar', Date::INVALID_FORMAT_ERROR),
101             array('foobar 2010-13-01', Date::INVALID_FORMAT_ERROR),
102             array('2010-13-01 foobar', Date::INVALID_FORMAT_ERROR),
103             array('2010-13-01', Date::INVALID_DATE_ERROR),
104             array('2010-04-32', Date::INVALID_DATE_ERROR),
105             array('2010-02-29', Date::INVALID_DATE_ERROR),
106         );
107     }
108 }