TYPO3 CMS  TYPO3_8-7
DateTimeValidatorTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /* *
6  * This script belongs to the Extbase framework. *
7  * *
8  * It is free software; you can redistribute it and/or modify it under *
9  * the terms of the GNU Lesser General Public License as published by the *
10  * Free Software Foundation, either version 3 of the License, or (at your *
11  * option) any later version. *
12  * *
13  * This script is distributed in the hope that it will be useful, but *
14  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
15  * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
16  * General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU Lesser General Public *
19  * License along with the script. *
20  * If not, see http://www.gnu.org/licenses/lgpl.html *
21  * *
22  * The TYPO3 project - inspiring people to share! *
23  * */
24 
27 
31 class DateTimeValidatorTest extends UnitTestCase
32 {
37  public function acceptsDateTimeValues($value)
38  {
39  $validator = new DateTimeValidator();
40  $result = $validator->validate($value);
41 
42  $this->assertFalse($result->hasErrors());
43  }
44 
48  public function dateTimeValues(): array
49  {
50  return [
51  \DateTime::class => [
52  new \DateTime(),
53  ],
54  'Extended ' . \DateTime::class => [
55  new class extends \DateTime {
56  },
57  ],
58  \DateTimeImmutable::class => [
59  new \DateTimeImmutable(),
60  ],
61  'Extended ' . \DateTimeImmutable::class => [
62  new class extends \DateTimeImmutable {
63  },
64  ],
65  ];
66  }
67 
71  public function addsErrorForInvalidValue()
72  {
73  $validator = $this->getMockBuilder(DateTimeValidator::class)
74  ->setMethods(['translateErrorMessage'])
75  ->getMock();
76  $result = $validator->validate(false);
77 
78  $this->assertTrue($result->hasErrors());
79  }
80 }