Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

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