493 |
ddelon |
1 |
<?php
|
|
|
2 |
// $Id: validator_unit_test.php,v 1.1 2005-09-30 14:58:00 ddelon Exp $
|
|
|
3 |
|
|
|
4 |
require_once('simple_include.php');
|
|
|
5 |
require_once('calendar_include.php');
|
|
|
6 |
|
|
|
7 |
Mock::generate('Calendar_Engine_Interface','Mock_Calendar_Engine');
|
|
|
8 |
Mock::generate('Calendar_Second','Mock_Calendar_Second');
|
|
|
9 |
|
|
|
10 |
class TestOfValidator extends UnitTestCase {
|
|
|
11 |
var $mockengine;
|
|
|
12 |
var $mockcal;
|
|
|
13 |
function TestOfValidator() {
|
|
|
14 |
$this->UnitTestCase('Test of Validator');
|
|
|
15 |
}
|
|
|
16 |
function setUp() {
|
|
|
17 |
$this->mockengine = new Mock_Calendar_Engine($this);
|
|
|
18 |
$this->mockengine->setReturnValue('getMinYears',1970);
|
|
|
19 |
$this->mockengine->setReturnValue('getMaxYears',2037);
|
|
|
20 |
$this->mockengine->setReturnValue('getMonthsInYear',12);
|
|
|
21 |
$this->mockengine->setReturnValue('getDaysInMonth',30);
|
|
|
22 |
$this->mockengine->setReturnValue('getHoursInDay',24);
|
|
|
23 |
$this->mockengine->setReturnValue('getMinutesInHour',60);
|
|
|
24 |
$this->mockengine->setReturnValue('getSecondsInMinute',60);
|
|
|
25 |
$this->mockcal = new Mock_Calendar_Second($this);
|
|
|
26 |
$this->mockcal->setReturnValue('getEngine',$this->mockengine);
|
|
|
27 |
}
|
|
|
28 |
function tearDown() {
|
|
|
29 |
unset ($this->mockengine);
|
|
|
30 |
unset ($this->mocksecond);
|
|
|
31 |
}
|
|
|
32 |
function testIsValidYear() {
|
|
|
33 |
$this->mockcal->setReturnValue('thisYear',2000);
|
|
|
34 |
$Validator = & new Calendar_Validator($this->mockcal);
|
|
|
35 |
$this->assertTrue($Validator->isValidYear());
|
|
|
36 |
}
|
|
|
37 |
function testIsValidYearTooSmall() {
|
|
|
38 |
$this->mockcal->setReturnValue('thisYear',1969);
|
|
|
39 |
$Validator = & new Calendar_Validator($this->mockcal);
|
|
|
40 |
$this->assertFalse($Validator->isValidYear());
|
|
|
41 |
}
|
|
|
42 |
function testIsValidYearTooLarge() {
|
|
|
43 |
$this->mockcal->setReturnValue('thisYear',2038);
|
|
|
44 |
$Validator = & new Calendar_Validator($this->mockcal);
|
|
|
45 |
$this->assertFalse($Validator->isValidYear());
|
|
|
46 |
}
|
|
|
47 |
function testIsValidMonth() {
|
|
|
48 |
$this->mockcal->setReturnValue('thisMonth',10);
|
|
|
49 |
$Validator = & new Calendar_Validator($this->mockcal);
|
|
|
50 |
$this->assertTrue($Validator->isValidMonth());
|
|
|
51 |
}
|
|
|
52 |
function testIsValidMonthTooSmall() {
|
|
|
53 |
$this->mockcal->setReturnValue('thisMonth',0);
|
|
|
54 |
$Validator = & new Calendar_Validator($this->mockcal);
|
|
|
55 |
$this->assertFalse($Validator->isValidMonth());
|
|
|
56 |
}
|
|
|
57 |
function testIsValidMonthTooLarge() {
|
|
|
58 |
$this->mockcal->setReturnValue('thisMonth',13);
|
|
|
59 |
$Validator = & new Calendar_Validator($this->mockcal);
|
|
|
60 |
$this->assertFalse($Validator->isValidMonth());
|
|
|
61 |
}
|
|
|
62 |
function testIsValidDay() {
|
|
|
63 |
$this->mockcal->setReturnValue('thisDay',10);
|
|
|
64 |
$Validator = & new Calendar_Validator($this->mockcal);
|
|
|
65 |
$this->assertTrue($Validator->isValidDay());
|
|
|
66 |
}
|
|
|
67 |
function testIsValidDayTooSmall() {
|
|
|
68 |
$this->mockcal->setReturnValue('thisDay',0);
|
|
|
69 |
$Validator = & new Calendar_Validator($this->mockcal);
|
|
|
70 |
$this->assertFalse($Validator->isValidDay());
|
|
|
71 |
}
|
|
|
72 |
function testIsValidDayTooLarge() {
|
|
|
73 |
$this->mockcal->setReturnValue('thisDay',31);
|
|
|
74 |
$Validator = & new Calendar_Validator($this->mockcal);
|
|
|
75 |
$this->assertFalse($Validator->isValidDay());
|
|
|
76 |
}
|
|
|
77 |
function testIsValidHour() {
|
|
|
78 |
$this->mockcal->setReturnValue('thisHour',10);
|
|
|
79 |
$Validator = & new Calendar_Validator($this->mockcal);
|
|
|
80 |
$this->assertTrue($Validator->isValidHour());
|
|
|
81 |
}
|
|
|
82 |
function testIsValidHourTooSmall() {
|
|
|
83 |
$this->mockcal->setReturnValue('thisHour',-1);
|
|
|
84 |
$Validator = & new Calendar_Validator($this->mockcal);
|
|
|
85 |
$this->assertFalse($Validator->isValidHour());
|
|
|
86 |
}
|
|
|
87 |
function testIsValidHourTooLarge() {
|
|
|
88 |
$this->mockcal->setReturnValue('thisHour',24);
|
|
|
89 |
$Validator = & new Calendar_Validator($this->mockcal);
|
|
|
90 |
$this->assertFalse($Validator->isValidHour());
|
|
|
91 |
}
|
|
|
92 |
function testIsValidMinute() {
|
|
|
93 |
$this->mockcal->setReturnValue('thisMinute',30);
|
|
|
94 |
$Validator = & new Calendar_Validator($this->mockcal);
|
|
|
95 |
$this->assertTrue($Validator->isValidMinute());
|
|
|
96 |
}
|
|
|
97 |
function testIsValidMinuteTooSmall() {
|
|
|
98 |
$this->mockcal->setReturnValue('thisMinute',-1);
|
|
|
99 |
$Validator = & new Calendar_Validator($this->mockcal);
|
|
|
100 |
$this->assertFalse($Validator->isValidMinute());
|
|
|
101 |
}
|
|
|
102 |
function testIsValidMinuteTooLarge() {
|
|
|
103 |
$this->mockcal->setReturnValue('thisMinute',60);
|
|
|
104 |
$Validator = & new Calendar_Validator($this->mockcal);
|
|
|
105 |
$this->assertFalse($Validator->isValidMinute());
|
|
|
106 |
}
|
|
|
107 |
function testIsValidSecond() {
|
|
|
108 |
$this->mockcal->setReturnValue('thisSecond',30);
|
|
|
109 |
$Validator = & new Calendar_Validator($this->mockcal);
|
|
|
110 |
$this->assertTrue($Validator->isValidSecond());
|
|
|
111 |
}
|
|
|
112 |
function testIsValidSecondTooSmall() {
|
|
|
113 |
$this->mockcal->setReturnValue('thisSecond',-1);
|
|
|
114 |
$Validator = & new Calendar_Validator($this->mockcal);
|
|
|
115 |
$this->assertFalse($Validator->isValidSecond());
|
|
|
116 |
}
|
|
|
117 |
function testIsValidSecondTooLarge() {
|
|
|
118 |
$this->mockcal->setReturnValue('thisSecond',60);
|
|
|
119 |
$Validator = & new Calendar_Validator($this->mockcal);
|
|
|
120 |
$this->assertFalse($Validator->isValidSecond());
|
|
|
121 |
}
|
|
|
122 |
function testIsValid() {
|
|
|
123 |
$this->mockcal->setReturnValue('thisYear',2000);
|
|
|
124 |
$this->mockcal->setReturnValue('thisMonth',5);
|
|
|
125 |
$this->mockcal->setReturnValue('thisDay',15);
|
|
|
126 |
$this->mockcal->setReturnValue('thisHour',13);
|
|
|
127 |
$this->mockcal->setReturnValue('thisMinute',30);
|
|
|
128 |
$this->mockcal->setReturnValue('thisSecond',40);
|
|
|
129 |
$Validator = & new Calendar_Validator($this->mockcal);
|
|
|
130 |
$this->assertTrue($Validator->isValid());
|
|
|
131 |
}
|
|
|
132 |
function testIsValidAllWrong() {
|
|
|
133 |
$this->mockcal->setReturnValue('thisYear',2038);
|
|
|
134 |
$this->mockcal->setReturnValue('thisMonth',13);
|
|
|
135 |
$this->mockcal->setReturnValue('thisDay',31);
|
|
|
136 |
$this->mockcal->day = 31;
|
|
|
137 |
$this->mockcal->setReturnValue('thisHour',24);
|
|
|
138 |
$this->mockcal->setReturnValue('thisMinute',60);
|
|
|
139 |
$this->mockcal->setReturnValue('thisSecond',60);
|
|
|
140 |
$Validator = & new Calendar_Validator($this->mockcal);
|
|
|
141 |
$this->assertFalse($Validator->isValid());
|
|
|
142 |
$i = 0;
|
|
|
143 |
while ( $Validator->fetch() ) {
|
|
|
144 |
$i++;
|
|
|
145 |
}
|
|
|
146 |
$this->assertEqual($i,6);
|
|
|
147 |
}
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
class TestOfValidatorLive extends UnitTestCase {
|
|
|
151 |
function TestOfValidatorLive() {
|
|
|
152 |
$this->UnitTestCase('Test of Validator Live');
|
|
|
153 |
}
|
|
|
154 |
function testYear() {
|
|
|
155 |
$Unit = new Calendar_Year(2038);
|
|
|
156 |
$Validator = & $Unit->getValidator();
|
|
|
157 |
$this->assertFalse($Validator->isValidYear());
|
|
|
158 |
}
|
|
|
159 |
function testMonth() {
|
|
|
160 |
$Unit = new Calendar_Month(2000,13);
|
|
|
161 |
$Validator = & $Unit->getValidator();
|
|
|
162 |
$this->assertFalse($Validator->isValidMonth());
|
|
|
163 |
}
|
|
|
164 |
/*
|
|
|
165 |
function testWeek() {
|
|
|
166 |
$Unit = new Calendar_Week(2000,12,7);
|
|
|
167 |
$Validator = & $Unit->getValidator();
|
|
|
168 |
$this->assertFalse($Validator->isValidWeek());
|
|
|
169 |
}
|
|
|
170 |
*/
|
|
|
171 |
function testDay() {
|
|
|
172 |
$Unit = new Calendar_Day(2000,12,32);
|
|
|
173 |
$Validator = & $Unit->getValidator();
|
|
|
174 |
$this->assertFalse($Validator->isValidDay());
|
|
|
175 |
}
|
|
|
176 |
function testHour() {
|
|
|
177 |
$Unit = new Calendar_Hour(2000,12,20,24);
|
|
|
178 |
$Validator = & $Unit->getValidator();
|
|
|
179 |
$this->assertFalse($Validator->isValidHour());
|
|
|
180 |
}
|
|
|
181 |
function testMinute() {
|
|
|
182 |
$Unit = new Calendar_Minute(2000,12,20,23,60);
|
|
|
183 |
$Validator = & $Unit->getValidator();
|
|
|
184 |
$this->assertFalse($Validator->isValidMinute());
|
|
|
185 |
}
|
|
|
186 |
function testSecond() {
|
|
|
187 |
$Unit = new Calendar_Second(2000,12,20,23,59,60);
|
|
|
188 |
$Validator = & $Unit->getValidator();
|
|
|
189 |
$this->assertFalse($Validator->isValidSecond());
|
|
|
190 |
}
|
|
|
191 |
function testAllBad() {
|
|
|
192 |
$Unit = new Calendar_Second(2000,13,32,24,60,60);
|
|
|
193 |
$this->assertFalse($Unit->isValid());
|
|
|
194 |
$Validator = & $Unit->getValidator();
|
|
|
195 |
$i = 0;
|
|
|
196 |
while ( $Validator->fetch() ) {
|
|
|
197 |
$i++;
|
|
|
198 |
}
|
|
|
199 |
$this->assertEqual($i,5);
|
|
|
200 |
}
|
|
|
201 |
}
|
|
|
202 |
|
|
|
203 |
if (!defined('TEST_RUNNING')) {
|
|
|
204 |
define('TEST_RUNNING', true);
|
|
|
205 |
$test = &new TestOfValidator();
|
|
|
206 |
$test->run(new HtmlReporter());
|
|
|
207 |
$test = &new TestOfValidatorLive();
|
|
|
208 |
$test->run(new HtmlReporter());
|
|
|
209 |
}
|
|
|
210 |
?>
|