‪TYPO3CMS  9.5
DateRangeValidatorTest.php
Go to the documentation of this file.
1 <?php
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 
19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
20 
24 class ‪DateRangeValidatorTest extends UnitTestCase
25 {
26 
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 
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 
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 
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 
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 
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 
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 
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 
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 }
‪TYPO3\CMS\Form\Mvc\Validation\Exception\InvalidValidationOptionsException
Definition: InvalidValidationOptionsException.php:23
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Validation\DateRangeValidatorTest\DateRangeValidatorReturnsFalseIfInputIsGreaterThanMinimumOption
‪DateRangeValidatorReturnsFalseIfInputIsGreaterThanMinimumOption()
Definition: DateRangeValidatorTest.php:108
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Validation\DateRangeValidatorTest\DateRangeValidatorReturnsFalseIfInputIsEqualsMinimumOption
‪DateRangeValidatorReturnsFalseIfInputIsEqualsMinimumOption()
Definition: DateRangeValidatorTest.php:93
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Validation
Definition: CountValidatorTest.php:2
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Validation\DateRangeValidatorTest\DateRangeValidatorReturnsFalseIfInputIsEqualsMaximumOption
‪DateRangeValidatorReturnsFalseIfInputIsEqualsMaximumOption()
Definition: DateRangeValidatorTest.php:138
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Validation\DateRangeValidatorTest
Definition: DateRangeValidatorTest.php:25
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Validation\DateRangeValidatorTest\DateRangeValidatorReturnsFalseIfInputIsLowerThanMaximumOption
‪DateRangeValidatorReturnsFalseIfInputIsLowerThanMaximumOption()
Definition: DateRangeValidatorTest.php:123
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Validation\DateRangeValidatorTest\DateRangeValidatorReturnsTrueIfInputIsLowerThanMinimumOption
‪DateRangeValidatorReturnsTrueIfInputIsLowerThanMinimumOption()
Definition: DateRangeValidatorTest.php:78
‪$validator
‪if(isset($args['d'])) $validator
Definition: validateRstFiles.php:218
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Validation\DateRangeValidatorTest\validateOptionsThrowsExceptionIfMinimumOptionIsInvalid
‪validateOptionsThrowsExceptionIfMinimumOptionIsInvalid()
Definition: DateRangeValidatorTest.php:30
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Validation\DateRangeValidatorTest\validateOptionsThrowsExceptionIfMaximumOptionIsInvalid
‪validateOptionsThrowsExceptionIfMaximumOptionIsInvalid()
Definition: DateRangeValidatorTest.php:47
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Validation\DateRangeValidatorTest\DateRangeValidatorReturnsTrueIfInputIsNoDateTime
‪DateRangeValidatorReturnsTrueIfInputIsNoDateTime()
Definition: DateRangeValidatorTest.php:64
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Validation\DateRangeValidatorTest\DateRangeValidatorReturnsTrueIfInputIsGreaterThanMaximumOption
‪DateRangeValidatorReturnsTrueIfInputIsGreaterThanMaximumOption()
Definition: DateRangeValidatorTest.php:153
‪TYPO3\CMS\Form\Mvc\Validation\DateRangeValidator
Definition: DateRangeValidator.php:27