This repository has been archived by the owner on Jan 8, 2020. It is now read-only.
/
StepTest.php
151 lines (134 loc) · 3.86 KB
/
StepTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Validator
*/
namespace ZendTest\Validator;
use Zend\Validator;
/**
* @category Zend
* @package Zend_Validator
* @subpackage UnitTests
* @group Zend_Validator
*/
class StepTest extends \PHPUnit_Framework_TestCase
{
/**
* Step object
*
* @var \Zend\Validator\Step
*/
protected $_validator;
/**
* Creates a new Zend\Validator\Step object for each test method
*
* @return void
*/
public function setUp()
{
$this->_validator = new Validator\Step();
}
/**
* Ensures that the validator follows expected behavior
*
* @return void
*/
public function testBasic()
{
// By default, baseValue == 0 and step == 1
$valuesExpected = array(
array(1.00, true),
array(0.00, true),
array(2, true),
array(3, true),
array(2.1, false),
array('2', true),
array('1', true),
array('1.2', false),
array(1.01, false),
array('not a scalar', false)
);
foreach ($valuesExpected as $element) {
$this->assertEquals($element[1], $this->_validator->isValid($element[0]),
'Test failed with ' . var_export($element, 1));
}
}
public function testDecimalBaseValue()
{
$valuesExpected = array(
array(1.1, false),
array(0.1, true),
array(2.1, true),
array(3.1, false),
array('2.1', true),
array('1.1', false),
array(1.11, false),
array('not a scalar', false)
);
$validator = new Validator\Step(array(
'baseValue' => 0.1,
'step' => 2
));
foreach ($valuesExpected as $element) {
$this->assertEquals($element[1], $validator->isValid($element[0]),
'Test failed with ' . var_export($element, 1));
}
}
public function testDecimalStep()
{
$valuesExpected = array(
array(1.1, false),
array(0.1, false),
array(2.1, true),
array(3.1, false),
array(10.5, true),
array('2.1', true),
array('1.1', false),
array(1.11, false),
array('not a scalar', false)
);
$validator = new Validator\Step(array(
'baseValue' => 0,
'step' => 2.1
));
foreach ($valuesExpected as $element) {
$this->assertEquals($element[1], $validator->isValid($element[0]),
'Test failed with ' . var_export($element, 1));
}
}
/**
* Ensures that getMessages() returns expected default value
*
* @return void
*/
public function testGetMessages()
{
$this->assertEquals(array(), $this->_validator->getMessages());
}
/**
* Ensures that set/getBaseValue() works
*/
public function testCanSetBaseValue()
{
$this->_validator->setBaseValue(2);
$this->assertEquals('2', $this->_validator->getBaseValue());
}
/**
* Ensures that set/getStep() works
*/
public function testCanSetStepValue()
{
$this->_validator->setStep(2);
$this->assertEquals('2', $this->_validator->getStep());
}
public function testEqualsMessageTemplates()
{
$validator = new Validator\Step();
$this->assertAttributeEquals($validator->getOption('messageTemplates'),
'messageTemplates', $validator);
}
}