TYPO3 CMS  TYPO3_6-2
BetweenValidatorTest.php
Go to the documentation of this file.
1 <?php
3 
21 
25  protected $helper;
26 
30  protected $subject;
31 
32  public function setUp() {
33  $this->helper = new \TYPO3\CMS\Form\Tests\Unit\Validation\Helper();
34  $this->subject = $this->getMock('TYPO3\\CMS\\Form\\Validation\\BetweenValidator', array('dummy'), array(), '', FALSE);
35  }
36 
37  public function validNonInclusiveDataProvider() {
38  return array(
39  '3 < 5 < 7' => array(array(3, 5, 7)),
40  '0 < 10 < 20' => array(array(0, 10, 20)),
41  '-10 < 0 < 10' => array(array(-10, 0, 10)),
42  '-20 < -10 < 0' => array(array(-20, -10, 0)),
43  '1 < 2 < 3' => array(array(1, 2, 3)),
44  '1 < 1.01 < 1.1' => array(array(1, 1.01, 1.1)),
45  );
46  }
47 
48  public function invalidNonInclusiveDataProvider() {
49  return array(
50  '1 < 1 < 2' => array(array(1, 1, 2)),
51  '1 < 2 < 2' => array(array(1, 2, 2)),
52  '1.1 < 1.1 < 1.2' => array(array(1.1, 1.1, 1.2)),
53  '1.1 < 1.2 < 1.2' => array(array(1.1, 1.2, 1.2)),
54  '-10.1234 < -10.12340 < 10' => array(array(-10.1234, -10.12340, 10)),
55  '100 < 0 < -100' => array(array(100, 0, -100))
56  );
57  }
58 
59  public function validInclusiveDataProvider() {
60  return array(
61  '1 ≤ 1 ≤ 1' => array(array(1,1,1)),
62  '-10.1234 ≤ -10.12340 ≤ 10' => array(array(-10.1234, -10.12340, 10)),
63  '-10.1234 ≤ -10 ≤ 10' => array(array(-10.1234, -10.12340, 10)),
64  );
65  }
66 
67  public function invalidInclusiveDataProvider() {
68  return array(
69  '-10.1234 ≤ -10.12345 ≤ 10' => array(array(-10.1234, -10.12345, 10)),
70  '100 ≤ 0 ≤ -100' => array(array(100, 0, -100))
71  );
72  }
73 
79  $this->subject->setMinimum($input[0]);
80  $this->subject->setMaximum($input[2]);
81  $this->subject->setFieldName('numericValue');
82  $requestHandlerMock = $this->helper->getRequestHandler(array(
83  'numericValue' => $input[1]
84  ));
85  $this->subject->injectRequestHandler($requestHandlerMock);
86 
87  $this->assertTrue(
88  $this->subject->isValid()
89  );
90  }
91 
97  $this->subject->setMinimum($input[0]);
98  $this->subject->setMaximum($input[2]);
99  $this->subject->setFieldName('numericValue');
100  $this->subject->setInclusive(TRUE);
101  $requestHandlerMock = $this->helper->getRequestHandler(array(
102  'numericValue' => $input[1]
103  ));
104  $this->subject->injectRequestHandler($requestHandlerMock);
105 
106  $this->assertTrue(
107  $this->subject->isValid()
108  );
109  }
110 
116  $this->subject->setMinimum($input[0]);
117  $this->subject->setMaximum($input[2]);
118  $this->subject->setFieldName('numericValue');
119  $requestHandlerMock = $this->helper->getRequestHandler(array(
120  'numericValue' => $input[1]
121  ));
122  $this->subject->injectRequestHandler($requestHandlerMock);
123 
124  $this->assertFalse(
125  $this->subject->isValid()
126  );
127  }
128 
134  $this->subject->setMinimum($input[0]);
135  $this->subject->setMaximum($input[2]);
136  $this->subject->setFieldName('numericValue');
137  $this->subject->setInclusive(TRUE);
138  $requestHandlerMock = $this->helper->getRequestHandler(array(
139  'numericValue' => $input[1]
140  ));
141  $this->subject->injectRequestHandler($requestHandlerMock);
142 
143  $this->assertFalse(
144  $this->subject->isValid()
145  );
146  }
147 }