Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

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