2 namespace TYPO3\CMS\Form\Tests\Unit\Validation
;
4 /***************************************************************
7 * (c) 2012 Andreas Lappe <a.lappe@kuehlhaus.com>, kuehlhaus AG
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
29 * Test case for class \TYPO3\CMS\Form\Validation\BetweenValidator.
31 * @author Andreas Lappe <a.lappe@kuehlhaus.com>
35 class BetweenValidatorTest
extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase
{
37 * @var \TYPO3\CMS\Form\Tests\Unit\Validation\Helper
42 * @var \TYPO3\CMS\Form\Validation\BetweenValidator
46 public function setUp() {
47 $this->helper
= new \TYPO3\CMS\Form\Tests\Unit\Validation\
Helper();
48 $this->fixture
= new \TYPO3\CMS\Form\Validation\
BetweenValidator(array());
51 public function tearDown() {
52 unset($this->helper
, $this->fixture
);
55 public function validNonInclusiveDataProvider() {
57 '3 < 5 < 7' => array(array(3, 5, 7)),
58 '0 < 10 < 20' => array(array(0, 10, 20)),
59 '-10 < 0 < 10' => array(array(-10, 0, 10)),
60 '-20 < -10 < 0' => array(array(-20, -10, 0)),
61 '1 < 2 < 3' => array(array(1, 2, 3)),
62 '1 < 1.01 < 1.1' => array(array(1, 1.01, 1.1)),
66 public function invalidNonInclusiveDataProvider() {
68 '1 < 1 < 2' => array(array(1, 1, 2)),
69 '1 < 2 < 2' => array(array(1, 2, 2)),
70 '1.1 < 1.1 < 1.2' => array(array(1.1, 1.1, 1.2)),
71 '1.1 < 1.2 < 1.2' => array(array(1.1, 1.2, 1.2)),
72 '-10.1234 < -10.12340 < 10' => array(array(-10.1234, -10.12340, 10)),
73 '100 < 0 < -100' => array(array(100, 0, -100))
77 public function validInclusiveDataProvider() {
79 '1 ≤ 1 ≤ 1' => array(array(1,1,1)),
80 '-10.1234 ≤ -10.12340 ≤ 10' => array(array(-10.1234, -10.12340, 10)),
81 '-10.1234 ≤ -10 ≤ 10' => array(array(-10.1234, -10.12340, 10)),
85 public function invalidInclusiveDataProvider() {
87 '-10.1234 ≤ -10.12345 ≤ 10' => array(array(-10.1234, -10.12345, 10)),
88 '100 ≤ 0 ≤ -100' => array(array(100, 0, -100))
94 * @dataProvider validNonInclusiveDataProvider
96 public function isValidWithValidInputAndWithoutInclusiveReturnsTrue($input) {
97 $this->fixture
->setMinimum($input[0]);
98 $this->fixture
->setMaximum($input[2]);
99 $this->fixture
->setFieldName('numericValue');
100 $requestHandlerMock = $this->helper
->getRequestHandler(array(
101 'numericValue' => $input[1]
103 $this->fixture
->injectRequestHandler($requestHandlerMock);
106 $this->fixture
->isValid()
112 * @dataProvider validInclusiveDataProvider
114 public function isValidWithValidInputAndWithInclusiveReturnsTrue($input) {
115 $this->fixture
->setMinimum($input[0]);
116 $this->fixture
->setMaximum($input[2]);
117 $this->fixture
->setFieldName('numericValue');
118 $this->fixture
->setInclusive(TRUE);
119 $requestHandlerMock = $this->helper
->getRequestHandler(array(
120 'numericValue' => $input[1]
122 $this->fixture
->injectRequestHandler($requestHandlerMock);
125 $this->fixture
->isValid()
131 * @dataProvider invalidNonInclusiveDataProvider
133 public function isValidWithInvalidInputAndWithoutInclusiveReturnsFalse($input) {
134 $this->fixture
->setMinimum($input[0]);
135 $this->fixture
->setMaximum($input[2]);
136 $this->fixture
->setFieldName('numericValue');
137 $requestHandlerMock = $this->helper
->getRequestHandler(array(
138 'numericValue' => $input[1]
140 $this->fixture
->injectRequestHandler($requestHandlerMock);
143 $this->fixture
->isValid()
149 * @dataProvider invalidInclusiveDataProvider
151 public function isValidWithInvalidInputAndWithInclusiveReturnsFalse($input) {
152 $this->fixture
->setMinimum($input[0]);
153 $this->fixture
->setMaximum($input[2]);
154 $this->fixture
->setFieldName('numericValue');
155 $this->fixture
->setInclusive(TRUE);
156 $requestHandlerMock = $this->helper
->getRequestHandler(array(
157 'numericValue' => $input[1]
159 $this->fixture
->injectRequestHandler($requestHandlerMock);
162 $this->fixture
->isValid()