[FEATURE] Add several testcases for validators
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Tests / Unit / Validation / GreaterThanValidatorTest.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2012 Andreas Lappe <a.lappe@kuehlhaus.com>, kuehlhaus AG
6 *
7 * All rights reserved
8 *
9 * This script is part of the TYPO3 project. The TYPO3 project is
10 * free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * The GNU General Public License can be found at
16 * http://www.gnu.org/copyleft/gpl.html.
17 *
18 * This script is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * This copyright notice MUST APPEAR in all copies of the script!
24 ***************************************************************/
25
26 /**
27 * Test case for class \TYPO3\CMS\Form\Validation\GreaterThanValidator.
28 *
29 * @author Andreas Lappe <a.lappe@kuehlhaus.com>
30 * @package TYPO3
31 * @subpackage form
32 */
33 class GreaterThanValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
34 /**
35 * @var \TYPO3\CMS\Form\Tests\Unit\Validation\Helper
36 */
37 protected $helper;
38
39 /**
40 * @var \TYPO3\CMS\Form\Validation\GreaterThanValidator
41 */
42 protected $fixture;
43
44 public function setUp() {
45 $this->helper = new \TYPO3\CMS\Form\Tests\Unit\Validation\Helper();
46 $this->fixture = new \TYPO3\CMS\Form\Validation\GreaterThanValidator(array());
47 }
48
49 public function tearDown() {
50 unset($this->helper, $this->fixture);
51 }
52
53 public function validNumberProvider() {
54 return array(
55 '13 > 12' => array(array(12, 13)),
56 );
57 }
58
59 public function invalidNumberProvider() {
60 return array(
61 '12.1 > 12' => array(array(12, 12.1)),
62 '12 > 12' => array(array(12, 12)),
63 '11.99 > 12' => array(array(12, 11.99))
64 );
65 }
66
67 /**
68 * @test
69 * @dataProvider validNumberProvider
70 */
71 public function isValidForValidInputReturnsTrue($input) {
72 $this->fixture->setFieldName('myFile');
73 $this->fixture->setMinimum($input[0]);
74 $requestHandlerMock = $this->helper->getRequestHandler(array(
75 'myFile' => $input[1]
76 ));
77 $this->fixture->injectRequestHandler($requestHandlerMock);
78
79 $this->assertTrue(
80 $this->fixture->isValid()
81 );
82 }
83
84 /**
85 * @test
86 * @dataProvider invalidNumberProvider
87 */
88 public function isValidForInvalidInputReturnsFalse($input) {
89 $this->fixture->setFieldName('myFile');
90 $this->fixture->setMinimum($input[0]);
91 $requestHandlerMock = $this->helper->getRequestHandler(array(
92 'myFile' => $input[1]
93 ));
94 $this->fixture->injectRequestHandler($requestHandlerMock);
95
96 $this->assertFalse(
97 $this->fixture->isValid()
98 );
99 }
100 }
101 ?>