3b3456b0b3353453184f3ffeb21875479b36debb
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Tests / Unit / Validator / BetweenValidatorTest.php
1 <?php
2 namespace TYPO3\CMS\Form\Tests\Unit\Validator;
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 /**
18 * Test case
19 */
20 class BetweenValidatorTest extends AbstractValidatorTest
21 {
22 /**
23 * @var string
24 */
25 protected $subjectClassName = \TYPO3\CMS\Form\Domain\Validator\BetweenValidator::class;
26
27 /**
28 * @return array
29 */
30 public function validNonInclusiveDataProvider()
31 {
32 return [
33 '3 < 5 < 7' => [[3, 5, 7]],
34 '0 < 10 < 20' => [[0, 10, 20]],
35 '-10 < 0 < 10' => [[-10, 0, 10]],
36 '-20 < -10 < 0' => [[-20, -10, 0]],
37 '1 < 2 < 3' => [[1, 2, 3]],
38 '1 < 1.01 < 1.1' => [[1, 1.01, 1.1]],
39 ];
40 }
41
42 /**
43 * @return array
44 */
45 public function invalidNonInclusiveDataProvider()
46 {
47 return [
48 '1 < 1 < 2' => [[1, 1, 2]],
49 '1 < 2 < 2' => [[1, 2, 2]],
50 '1.1 < 1.1 < 1.2' => [[1.1, 1.1, 1.2]],
51 '1.1 < 1.2 < 1.2' => [[1.1, 1.2, 1.2]],
52 '-10.1234 < -10.12340 < 10' => [[-10.1234, -10.12340, 10]],
53 '100 < 0 < -100' => [[100, 0, -100]]
54 ];
55 }
56
57 /**
58 * @return array
59 */
60 public function validInclusiveDataProvider()
61 {
62 return [
63 '1 ≤ 1 ≤ 1' => [[1,1,1]],
64 '-10.1234 ≤ -10.12340 ≤ 10' => [[-10.1234, -10.12340, 10]],
65 '-10.1234 ≤ -10 ≤ 10' => [[-10.1234, -10.12340, 10]],
66 ];
67 }
68
69 public function invalidInclusiveDataProvider()
70 {
71 return [
72 '-10.1234 ≤ -10.12345 ≤ 10' => [[-10.1234, -10.12345, 10]],
73 '100 ≤ 0 ≤ -100' => [[100, 0, -100]]
74 ];
75 }
76
77 /**
78 * @param array $input
79 * @test
80 * @dataProvider validNonInclusiveDataProvider
81 */
82 public function validateWithValidInputAndWithoutInclusiveHasEmptyErrorResult($input)
83 {
84 $options = ['element' => uniqid('test'), 'errorMessage' => uniqid('error')];
85 $options['minimum'] = $input[0];
86 $options['maximum'] = $input[2];
87 $subject = $this->createSubject($options);
88
89 $this->assertEmpty(
90 $subject->validate($input[1])->getErrors()
91 );
92 }
93
94 /**
95 * @param array $input
96 * @test
97 * @dataProvider validInclusiveDataProvider
98 */
99 public function validateWithValidInputAndWithInclusiveHasEmptyErrorResult($input)
100 {
101 $options = ['element' => uniqid('test'), 'errorMessage' => uniqid('error')];
102 $options['minimum'] = $input[0];
103 $options['maximum'] = $input[2];
104 $options['inclusive'] = true;
105 $subject = $this->createSubject($options);
106
107 $this->assertEmpty(
108 $subject->validate($input[1])->getErrors()
109 );
110 }
111
112 /**
113 * @param array $input
114 * @test
115 * @dataProvider invalidNonInclusiveDataProvider
116 */
117 public function validateWithInvalidInputAndWithoutInclusiveHasNotEmptyErrorResult($input)
118 {
119 $options = ['element' => uniqid('test'), 'errorMessage' => uniqid('error')];
120 $options['minimum'] = $input[0];
121 $options['maximum'] = $input[2];
122 $subject = $this->createSubject($options);
123
124 $this->assertNotEmpty(
125 $subject->validate($input[1])->getErrors()
126 );
127 }
128
129 /**
130 * @param array $input
131 * @test
132 * @dataProvider invalidInclusiveDataProvider
133 */
134 public function validateWithInvalidInputAndWithInclusiveHasNotEmptyErrorResult($input)
135 {
136 $options = ['element' => uniqid('test'), 'errorMessage' => uniqid('error')];
137 $options['minimum'] = $input[0];
138 $options['maximum'] = $input[2];
139 $options['inclusive'] = true;
140 $subject = $this->createSubject($options);
141
142 $this->assertNotEmpty(
143 $subject->validate($input[1])->getErrors()
144 );
145 }
146 }