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