[CLEANUP] Rework/simplify copyright header and remove @package
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Validation / Validator / FloatValidatorTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Unit\Validation\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 * Testcase for the float validator
19 *
20 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
21 */
22 class FloatValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\AbstractValidatorTestcase {
23
24 protected $validatorClassName = 'TYPO3\\CMS\\Extbase\\Validation\\Validator\\FloatValidator';
25
26 public function setup() {
27 $this->validator = $this->getMock($this->validatorClassName, array('translateErrorMessage'));
28 }
29
30 /**
31 * Data provider with valid floats
32 *
33 * @return array
34 * @author Karsten Dambekalns <karsten@typo3.org>
35 */
36 public function validFloats() {
37 return array(
38 array(1029437.234726),
39 array('123.45'),
40 array('+123.45'),
41 array('-123.45'),
42 array('123.45e3'),
43 array(123450.0)
44 );
45 }
46
47 /**
48 * @author Karsten Dambekalns <karsten@typo3.org>
49 * @test
50 * @dataProvider validFloats
51 * @param mixed $float
52 */
53 public function floatValidatorReturnsNoErrorsForAValidFloat($float) {
54 $this->assertFalse($this->validator->validate($float)->hasErrors());
55 }
56
57 /**
58 * Data provider with invalid floats
59 *
60 * @return array
61 * @author Karsten Dambekalns <karsten@typo3.org>
62 */
63 public function invalidFloats() {
64 return array(
65 array(1029437),
66 array('1029437'),
67 array('not a number')
68 );
69 }
70
71 /**
72 * @author Karsten Dambekalns <karsten@typo3.org>
73 * @test
74 * @dataProvider invalidFloats
75 * @param mixed $float
76 */
77 public function floatValidatorReturnsErrorForAnInvalidFloat($float) {
78 $this->assertTrue($this->validator->validate($float)->hasErrors());
79 }
80
81 /**
82 * test
83 *
84 * @author Andreas Förthner <andreas.foerthner@netlogix.de>
85 */
86 public function floatValidatorCreatesTheCorrectErrorForAnInvalidSubject() {
87 $this->assertEquals(1, count($this->validator->validate(123456)->getErrors()));
88 }
89 }