[FEATURE] Add several testcases for validators
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Tests / Unit / Validation / FileMinimumSizeValidatorTest.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\FileMinimumSizeValidator.
28 *
29 * @author Andreas Lappe <a.lappe@kuehlhaus.com>
30 * @package TYPO3
31 * @subpackage form
32 */
33 class FileMinimumSizeValidatorTest 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\FileMinimumSizeValidator
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\FileMinimumSizeValidator(array());
47 }
48
49 public function tearDown() {
50 unset($this->helper, $this->fixture);
51 }
52
53 public function validSizesProvider() {
54 return array(
55 '12B for min. 11B' => array(array(11, 12)),
56 '12B for min. 12B' => array(array(12, 12))
57 );
58 }
59
60 public function invalidSizesProvider() {
61 return array(
62 '11B for min. 12B' => array(array(12, 11))
63 );
64 }
65
66 /**
67 * @test
68 * @dataProvider validSizesProvider
69 */
70 public function isValidForValidInputReturnsTrue($input) {
71 $this->fixture->setFieldName('myFile');
72 $this->fixture->setMinimum($input[0]);
73 $requestHandlerMock = $this->helper->getRequestHandler(array(
74 'myFile' => array('size' => $input[1])
75 ));
76 $this->fixture->injectRequestHandler($requestHandlerMock);
77
78 $this->assertTrue(
79 $this->fixture->isValid()
80 );
81 }
82
83 /**
84 * @test
85 * @dataProvider invalidSizesProvider
86 */
87 public function isValidForInvalidInputReturnsFalse($input) {
88 $this->fixture->setFieldName('myFile');
89 $this->fixture->setMinimum($input[0]);
90 $requestHandlerMock = $this->helper->getRequestHandler(array(
91 'myFile' => array('size' => $input[1])
92 ));
93 $this->fixture->injectRequestHandler($requestHandlerMock);
94
95 $this->assertFalse(
96 $this->fixture->isValid()
97 );
98 }
99 }
100 ?>