[TASK] Shorten the extend class in all unit tests
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Tests / Unit / Mvc / Validation / DateRangeValidatorTest.php
1 <?php
2 namespace TYPO3\CMS\Form\Tests\Unit\Mvc\Validation;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Form\Mvc\Validation\DateRangeValidator;
18 use TYPO3\CMS\Form\Mvc\Validation\Exception\InvalidValidationOptionsException;
19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
20
21 /**
22 * Test case
23 */
24 class DateRangeValidatorTest extends UnitTestCase
25 {
26
27 /**
28 * @test
29 */
30 public function validateOptionsThrowsExceptionIfMinimumOptionIsInvalid()
31 {
32 $this->expectException(InvalidValidationOptionsException::class);
33 $this->expectExceptionCode(1521293813);
34
35 $options = ['minimum' => '1972-01', 'maximum' => ''];
36 $validator = $this->getMockBuilder(DateRangeValidator::class)
37 ->setMethods(['translateErrorMessage'])
38 ->setConstructorArgs([$options])
39 ->getMock();
40
41 $validator->validate(true);
42 }
43
44 /**
45 * @test
46 */
47 public function validateOptionsThrowsExceptionIfMaximumOptionIsInvalid()
48 {
49 $this->expectException(InvalidValidationOptionsException::class);
50 $this->expectExceptionCode(1521293814);
51
52 $options = ['minimum' => '', 'maximum' => '1972-01'];
53 $validator = $this->getMockBuilder(DateRangeValidator::class)
54 ->setMethods(['translateErrorMessage'])
55 ->setConstructorArgs([$options])
56 ->getMock();
57
58 $validator->validate(true);
59 }
60
61 /**
62 * @test
63 */
64 public function DateRangeValidatorReturnsTrueIfInputIsNoDateTime()
65 {
66 $options = ['minimum' => '2018-03-17', 'maximum' => '2018-03-17'];
67 $validator = $this->getMockBuilder(DateRangeValidator::class)
68 ->setMethods(['translateErrorMessage'])
69 ->setConstructorArgs([$options])
70 ->getMock();
71
72 $this->assertTrue($validator->validate(true)->hasErrors());
73 }
74
75 /**
76 * @test
77 */
78 public function DateRangeValidatorReturnsTrueIfInputIsLowerThanMinimumOption()
79 {
80 $input = \DateTime::createFromFormat('Y-m-d', '2018-03-17');
81 $options = ['minimum' => '2018-03-18', 'maximum' => ''];
82 $validator = $this->getMockBuilder(DateRangeValidator::class)
83 ->setMethods(['translateErrorMessage'])
84 ->setConstructorArgs([$options])
85 ->getMock();
86
87 $this->assertTrue($validator->validate($input)->hasErrors());
88 }
89
90 /**
91 * @test
92 */
93 public function DateRangeValidatorReturnsFalseIfInputIsEqualsMinimumOption()
94 {
95 $input = \DateTime::createFromFormat('Y-m-d', '2018-03-18');
96 $options = ['minimum' => '2018-03-18', 'maximum' => ''];
97 $validator = $this->getMockBuilder(DateRangeValidator::class)
98 ->setMethods(['translateErrorMessage'])
99 ->setConstructorArgs([$options])
100 ->getMock();
101
102 $this->assertFalse($validator->validate($input)->hasErrors());
103 }
104
105 /**
106 * @test
107 */
108 public function DateRangeValidatorReturnsFalseIfInputIsGreaterThanMinimumOption()
109 {
110 $input = \DateTime::createFromFormat('Y-m-d', '2018-03-19');
111 $options = ['minimum' => '2018-03-18', 'maximum' => ''];
112 $validator = $this->getMockBuilder(DateRangeValidator::class)
113 ->setMethods(['translateErrorMessage'])
114 ->setConstructorArgs([$options])
115 ->getMock();
116
117 $this->assertFalse($validator->validate($input)->hasErrors());
118 }
119
120 /**
121 * @test
122 */
123 public function DateRangeValidatorReturnsFalseIfInputIsLowerThanMaximumOption()
124 {
125 $input = \DateTime::createFromFormat('Y-m-d', '2018-03-17');
126 $options = ['maximum' => '', 'maximum' => '2018-03-18'];
127 $validator = $this->getMockBuilder(DateRangeValidator::class)
128 ->setMethods(['translateErrorMessage'])
129 ->setConstructorArgs([$options])
130 ->getMock();
131
132 $this->assertFalse($validator->validate($input)->hasErrors());
133 }
134
135 /**
136 * @test
137 */
138 public function DateRangeValidatorReturnsFalseIfInputIsEqualsMaximumOption()
139 {
140 $input = \DateTime::createFromFormat('Y-m-d', '2018-03-18');
141 $options = ['maximum' => '', 'maximum' => '2018-03-18'];
142 $validator = $this->getMockBuilder(DateRangeValidator::class)
143 ->setMethods(['translateErrorMessage'])
144 ->setConstructorArgs([$options])
145 ->getMock();
146
147 $this->assertFalse($validator->validate($input)->hasErrors());
148 }
149
150 /**
151 * @test
152 */
153 public function DateRangeValidatorReturnsTrueIfInputIsGreaterThanMaximumOption()
154 {
155 $input = \DateTime::createFromFormat('Y-m-d', '2018-03-19');
156 $options = ['maximum' => '', 'maximum' => '2018-03-18'];
157 $validator = $this->getMockBuilder(DateRangeValidator::class)
158 ->setMethods(['translateErrorMessage'])
159 ->setConstructorArgs([$options])
160 ->getMock();
161
162 $this->assertTrue($validator->validate($input)->hasErrors());
163 }
164 }