1 | <?php |
---|
2 | // $Id: week_firstday_0_test.php,v 1.1 2005/10/20 18:57:52 quipo Exp $ |
---|
3 | define('CALENDAR_FIRST_DAY_OF_WEEK', 0); //force firstDay = Sunday |
---|
4 | |
---|
5 | require_once('simple_include.php'); |
---|
6 | require_once('calendar_include.php'); |
---|
7 | |
---|
8 | require_once('./calendar_test.php'); |
---|
9 | |
---|
10 | class TestOfWeek_firstday_0 extends TestOfCalendar { |
---|
11 | function TestOfWeek_firstday_0() { |
---|
12 | $this->UnitTestCase('Test of Week - Week Starting on Sunday'); |
---|
13 | } |
---|
14 | function setUp() { |
---|
15 | $this->cal = Calendar_Factory::create('Week', 2003, 10, 9); |
---|
16 | //print_r($this->cal); |
---|
17 | } |
---|
18 | function testPrevDay () { |
---|
19 | $this->assertEqual(8, $this->cal->prevDay()); |
---|
20 | } |
---|
21 | function testPrevDay_Array () { |
---|
22 | $this->assertEqual( |
---|
23 | array( |
---|
24 | 'year' => 2003, |
---|
25 | 'month' => 10, |
---|
26 | 'day' => 8, |
---|
27 | 'hour' => 0, |
---|
28 | 'minute' => 0, |
---|
29 | 'second' => 0), |
---|
30 | $this->cal->prevDay('array')); |
---|
31 | } |
---|
32 | function testThisDay () { |
---|
33 | $this->assertEqual(9, $this->cal->thisDay()); |
---|
34 | } |
---|
35 | function testNextDay () { |
---|
36 | $this->assertEqual(10, $this->cal->nextDay()); |
---|
37 | } |
---|
38 | function testPrevHour () { |
---|
39 | $this->assertEqual(23, $this->cal->prevHour()); |
---|
40 | } |
---|
41 | function testThisHour () { |
---|
42 | $this->assertEqual(0, $this->cal->thisHour()); |
---|
43 | } |
---|
44 | function testNextHour () { |
---|
45 | $this->assertEqual(1, $this->cal->nextHour()); |
---|
46 | } |
---|
47 | function testPrevMinute () { |
---|
48 | $this->assertEqual(59, $this->cal->prevMinute()); |
---|
49 | } |
---|
50 | function testThisMinute () { |
---|
51 | $this->assertEqual(0, $this->cal->thisMinute()); |
---|
52 | } |
---|
53 | function testNextMinute () { |
---|
54 | $this->assertEqual(1, $this->cal->nextMinute()); |
---|
55 | } |
---|
56 | function testPrevSecond () { |
---|
57 | $this->assertEqual(59, $this->cal->prevSecond()); |
---|
58 | } |
---|
59 | function testThisSecond () { |
---|
60 | $this->assertEqual(0, $this->cal->thisSecond()); |
---|
61 | } |
---|
62 | function testNextSecond () { |
---|
63 | $this->assertEqual(1, $this->cal->nextSecond()); |
---|
64 | } |
---|
65 | function testGetTimeStamp() { |
---|
66 | $stamp = mktime(0,0,0,10,9,2003); |
---|
67 | $this->assertEqual($stamp,$this->cal->getTimeStamp()); |
---|
68 | } |
---|
69 | function testNewTimeStamp() { |
---|
70 | $stamp = mktime(0,0,0,7,28,2004); |
---|
71 | $this->cal->setTimestamp($stamp); |
---|
72 | $this->assertEqual('29 2004', date('W Y', $this->cal->prevWeek(true))); |
---|
73 | $this->assertEqual('30 2004', date('W Y', $this->cal->thisWeek(true))); |
---|
74 | $this->assertEqual('31 2004', date('W Y', $this->cal->nextWeek(true))); |
---|
75 | } |
---|
76 | function testPrevWeekInMonth() { |
---|
77 | $this->assertEqual(1, $this->cal->prevWeek()); |
---|
78 | $stamp = mktime(0,0,0,2,3,2005); |
---|
79 | $this->cal->setTimestamp($stamp); |
---|
80 | $this->assertEqual(0, $this->cal->prevWeek()); |
---|
81 | } |
---|
82 | function testThisWeekInMonth() { |
---|
83 | $this->assertEqual(2, $this->cal->thisWeek()); |
---|
84 | $stamp = mktime(0,0,0,2,3,2005); |
---|
85 | $this->cal->setTimestamp($stamp); |
---|
86 | $this->assertEqual(1, $this->cal->thisWeek()); |
---|
87 | $stamp = mktime(0,0,0,1,1,2005); |
---|
88 | $this->cal->setTimestamp($stamp); |
---|
89 | $this->assertEqual(1, $this->cal->thisWeek()); |
---|
90 | $stamp = mktime(0,0,0,1,3,2005); |
---|
91 | $this->cal->setTimestamp($stamp); |
---|
92 | $this->assertEqual(2, $this->cal->thisWeek()); |
---|
93 | } |
---|
94 | function testNextWeekInMonth() { |
---|
95 | $this->assertEqual(3, $this->cal->nextWeek()); |
---|
96 | $stamp = mktime(0,0,0,2,3,2005); |
---|
97 | $this->cal->setTimestamp($stamp); |
---|
98 | $this->assertEqual(2, $this->cal->nextWeek()); |
---|
99 | } |
---|
100 | function testPrevWeekInYear() { |
---|
101 | $this->assertEqual(date('W', $this->cal->prevWeek('timestamp')), $this->cal->prevWeek('n_in_year')); |
---|
102 | $stamp = mktime(0,0,0,1,1,2004); |
---|
103 | $this->cal->setTimestamp($stamp); |
---|
104 | $this->assertEqual(date('W', $this->cal->nextWeek('timestamp')), $this->cal->nextWeek('n_in_year')); |
---|
105 | } |
---|
106 | function testThisWeekInYear() { |
---|
107 | $this->assertEqual(date('W', $this->cal->thisWeek('timestamp')), $this->cal->thisWeek('n_in_year')); |
---|
108 | $stamp = mktime(0,0,0,1,1,2004); |
---|
109 | $this->cal->setTimestamp($stamp); |
---|
110 | $this->assertEqual(date('W', $this->cal->thisWeek('timestamp')), $this->cal->thisWeek('n_in_year')); |
---|
111 | } |
---|
112 | function testFirstWeekInYear() { |
---|
113 | $stamp = mktime(0,0,0,1,4,2004); |
---|
114 | $this->cal->setTimestamp($stamp); |
---|
115 | $this->assertEqual(1, $this->cal->thisWeek('n_in_year')); |
---|
116 | } |
---|
117 | function testNextWeekInYear() { |
---|
118 | $this->assertEqual(date('W', $this->cal->nextWeek('timestamp')), $this->cal->nextWeek('n_in_year')); |
---|
119 | } |
---|
120 | function testPrevWeekArray() { |
---|
121 | $testArray = array( |
---|
122 | 'year'=>2003, |
---|
123 | 'month'=>9, |
---|
124 | 'day'=>28, |
---|
125 | 'hour'=>0, |
---|
126 | 'minute'=>0, |
---|
127 | 'second'=>0 |
---|
128 | ); |
---|
129 | $this->assertEqual($testArray, $this->cal->prevWeek('array')); |
---|
130 | } |
---|
131 | function testThisWeekArray() { |
---|
132 | $testArray = array( |
---|
133 | 'year'=>2003, |
---|
134 | 'month'=>10, |
---|
135 | 'day'=>5, |
---|
136 | 'hour'=>0, |
---|
137 | 'minute'=>0, |
---|
138 | 'second'=>0 |
---|
139 | ); |
---|
140 | $this->assertEqual($testArray, $this->cal->thisWeek('array')); |
---|
141 | } |
---|
142 | function testNextWeekArray() { |
---|
143 | $testArray = array( |
---|
144 | 'year'=>2003, |
---|
145 | 'month'=>10, |
---|
146 | 'day'=>12, |
---|
147 | 'hour'=>0, |
---|
148 | 'minute'=>0, |
---|
149 | 'second'=>0 |
---|
150 | ); |
---|
151 | $this->assertEqual($testArray, $this->cal->nextWeek('array')); |
---|
152 | } |
---|
153 | function testPrevWeekObject() { |
---|
154 | $testWeek = Calendar_Factory::create('Week', 2003,9,28); |
---|
155 | $Week = $this->cal->prevWeek('object'); |
---|
156 | $this->assertEqual($testWeek->getTimeStamp(),$Week->getTimeStamp()); |
---|
157 | } |
---|
158 | function testThisWeekObject() { |
---|
159 | $testWeek = Calendar_Factory::create('Week', 2003,10,5); |
---|
160 | $Week = $this->cal->thisWeek('object'); |
---|
161 | $this->assertEqual($testWeek->getTimeStamp(),$Week->getTimeStamp()); |
---|
162 | } |
---|
163 | function testNextWeekObject() { |
---|
164 | $testWeek = Calendar_Factory::create('Week', 2003,10,12); |
---|
165 | $Week = $this->cal->nextWeek('object'); |
---|
166 | $this->assertEqual($testWeek->getTimeStamp(),$Week->getTimeStamp()); |
---|
167 | } |
---|
168 | } |
---|
169 | |
---|
170 | class TestOfWeek_firstday_0_Build extends TestOfWeek_firstday_0 { |
---|
171 | function TestOfWeek_firstday_0_Build() { |
---|
172 | $this->UnitTestCase('Test of Week::build() - FirstDay = Sunday'); |
---|
173 | } |
---|
174 | function testSize() { |
---|
175 | $this->cal->build(); |
---|
176 | $this->assertEqual(7, $this->cal->size()); |
---|
177 | } |
---|
178 | |
---|
179 | function testFetch() { |
---|
180 | $this->cal->build(); |
---|
181 | $i=0; |
---|
182 | while ($Child = $this->cal->fetch()) { |
---|
183 | $i++; |
---|
184 | } |
---|
185 | $this->assertEqual(7, $i); |
---|
186 | } |
---|
187 | function testFetchAll() { |
---|
188 | $this->cal->build(); |
---|
189 | $children = array(); |
---|
190 | $i = 1; |
---|
191 | while ( $Child = $this->cal->fetch() ) { |
---|
192 | $children[$i]=$Child; |
---|
193 | $i++; |
---|
194 | } |
---|
195 | $this->assertEqual($children,$this->cal->fetchAll()); |
---|
196 | } |
---|
197 | |
---|
198 | function testSelection() { |
---|
199 | require_once(CALENDAR_ROOT . 'Day.php'); |
---|
200 | $selection = array(Calendar_Factory::create('Day', 2003, 10, 6)); |
---|
201 | $this->cal->build($selection); |
---|
202 | $i = 1; |
---|
203 | while ($Child = $this->cal->fetch()) { |
---|
204 | if ($i == 2) { |
---|
205 | break; //06-10-2003 is the 2nd day of the week |
---|
206 | } |
---|
207 | $i++; |
---|
208 | } |
---|
209 | $this->assertTrue($Child->isSelected()); |
---|
210 | } |
---|
211 | function testSelectionCornerCase() { |
---|
212 | require_once(CALENDAR_ROOT . 'Day.php'); |
---|
213 | $selectedDays = array( |
---|
214 | Calendar_Factory::create('Day', 2003, 12, 28), |
---|
215 | Calendar_Factory::create('Day', 2003, 12, 29), |
---|
216 | Calendar_Factory::create('Day', 2003, 12, 30), |
---|
217 | Calendar_Factory::create('Day', 2003, 12, 31), |
---|
218 | Calendar_Factory::create('Day', 2004, 01, 01), |
---|
219 | Calendar_Factory::create('Day', 2004, 01, 02), |
---|
220 | Calendar_Factory::create('Day', 2004, 01, 03) |
---|
221 | ); |
---|
222 | $this->cal = Calendar_Factory::create('Week', 2003, 12, 31, 0); |
---|
223 | $this->cal->build($selectedDays); |
---|
224 | while ($Day = $this->cal->fetch()) { |
---|
225 | $this->assertTrue($Day->isSelected()); |
---|
226 | } |
---|
227 | $this->cal = Calendar_Factory::create('Week', 2004, 1, 1, 0); |
---|
228 | $this->cal->build($selectedDays); |
---|
229 | while ($Day = $this->cal->fetch()) { |
---|
230 | $this->assertTrue($Day->isSelected()); |
---|
231 | } |
---|
232 | } |
---|
233 | } |
---|
234 | if (!defined('TEST_RUNNING')) { |
---|
235 | define('TEST_RUNNING', true); |
---|
236 | $test = &new TestOfWeek_firstday_0(); |
---|
237 | $test->run(new HtmlReporter()); |
---|
238 | $test = &new TestOfWeek_firstday_0_Build(); |
---|
239 | $test->run(new HtmlReporter()); |
---|
240 | } |
---|
241 | ?> |
---|