[~CONFIGURATION] Extbase: Set lockType to empty string instead of 'system'.
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Validation / Validator / IntegerValidator_testcase.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
6 * All rights reserved
7 *
8 * This class is a backport of the corresponding class of FLOW3.
9 * All credits go to the v5 team.
10 *
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.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 *
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.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * Testcase for the integer validator
30 *
31 * @package Extbase
32 * @subpackage extbase
33 * @version $Id$
34 */
35 class Tx_Extbase_Validation_Validator_IntegerValidator_testcase extends Tx_Extbase_BaseTestCase {
36
37 /**
38 * An array of valid floating point numbers addresses
39 * @var array
40 */
41 protected $validIntegerNumbers;
42
43 /**
44 * An array of invalid floating point numbers addresses
45 * @var array
46 */
47 protected $invalidIntegerNumbers;
48
49 public function setUp() {
50 $this->validIntegerNumbers = array(
51 1029437,
52 '12345',
53 '+12345',
54 '-12345'
55 );
56
57 $this->invalidIntegerNumbers = array(
58 'not a number',
59 3.1415,
60 '12345.987'
61 );
62 }
63
64 /**
65 * @test
66 * @dataProvider validIntegers
67 */
68 public function integerValidatorReturnsTrueForAValidInteger() {
69 $integerValidator = new Tx_Extbase_Validation_Validator_IntegerValidator();
70 foreach ($this->validIntegerNumbers as $integerNumber) {
71 $this->assertTrue($integerValidator->isValid($integerNumber), "$integerNumber was declared to be invalid, but it is valid.");
72 }
73 }
74
75 /**
76 * Data provider with invalid email addresses
77 *
78 * @return array
79 */
80 public function invalidIntegers() {
81 return array(
82 array('not a number'),
83 array(3.1415),
84 array('12345.987')
85 );
86 }
87
88 /**
89 * @test
90 * @dataProvider invalidIntegers
91 */
92 public function integerValidatorReturnsTrueForAnInvalidInteger() {
93 $integerValidator = $this->getMock('Tx_Extbase_Validation_Validator_IntegerValidator', array('addError'), array(), '', FALSE);
94 foreach ($this->invalidIntegerNumbers as $integerNumber) {
95 $this->assertFalse($integerValidator->isValid($integerNumber), "$integerNumber was declared to be valid, but it is invalid.");
96 }
97 }
98
99 /**
100 * @test
101 */
102 public function integerValidatorCreatesTheCorrectErrorForAnInvalidSubject() {
103 $integerValidator = $this->getMock('Tx_Extbase_Validation_Validator_IntegerValidator', array('addError'), array(), '', FALSE);
104 $integerValidator->expects($this->once())->method('addError')->with('The given subject was not a valid integer.', 1221560494);
105 $integerValidator->isValid('not a number');
106 }
107
108 }
109
110 ?>