Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
// $Id: month_weekdays_test.php 300728 2010-06-24 11:43:56Z quipo $
3
 
4
require_once 'simple_include.php';
5
require_once 'calendar_include.php';
6
 
7
require_once './calendar_test.php';
8
 
9
class TestOfMonthWeekdays extends TestOfCalendar {
10
    function TestOfMonthWeekdays() {
11
        $this->UnitTestCase('Test of Month Weekdays');
12
    }
13
    function setUp() {
14
        $this->cal = new Calendar_Month_Weekdays(2003, 10);
15
    }
16
    function testPrevDay () {
17
        $this->assertEqual(30,$this->cal->prevDay());
18
    }
19
    function testPrevDay_Array () {
20
        $this->assertEqual(
21
            array(
22
                'year'   => 2003,
23
                'month'  => 9,
24
                'day'    => 30,
25
                'hour'   => 0,
26
                'minute' => 0,
27
                'second' => 0),
28
            $this->cal->prevDay('array'));
29
    }
30
    function testThisDay () {
31
        $this->assertEqual(1, $this->cal->thisDay());
32
    }
33
    function testNextDay () {
34
        $this->assertEqual(2, $this->cal->nextDay());
35
    }
36
    function testPrevHour () {
37
        $this->assertEqual(23, $this->cal->prevHour());
38
    }
39
    function testThisHour () {
40
        $this->assertEqual(0, $this->cal->thisHour());
41
    }
42
    function testNextHour () {
43
        $this->assertEqual(1, $this->cal->nextHour());
44
    }
45
    function testPrevMinute () {
46
        $this->assertEqual(59, $this->cal->prevMinute());
47
    }
48
    function testThisMinute () {
49
        $this->assertEqual(0, $this->cal->thisMinute());
50
    }
51
    function testNextMinute () {
52
        $this->assertEqual(1, $this->cal->nextMinute());
53
    }
54
    function testPrevSecond () {
55
        $this->assertEqual(59, $this->cal->prevSecond());
56
    }
57
    function testThisSecond () {
58
        $this->assertEqual(0, $this->cal->thisSecond());
59
    }
60
    function testNextSecond () {
61
        $this->assertEqual(1, $this->cal->nextSecond());
62
    }
63
    function testGetTimeStamp() {
64
        $stamp = mktime(0, 0, 0, 10, 1, 2003);
65
        $this->assertEqual($stamp, $this->cal->getTimeStamp());
66
    }
67
}
68
 
69
class TestOfMonthWeekdaysBuild extends TestOfMonthWeekdays {
70
    function TestOfMonthWeekdaysBuild() {
71
        $this->UnitTestCase('Test of Month_Weekdays::build()');
72
    }
73
    function testSize() {
74
        $this->cal->build();
75
        $this->assertEqual(35, $this->cal->size());
76
    }
77
    function testFetch() {
78
        $this->cal->build();
79
        $i=0;
80
        while ($Child = $this->cal->fetch()) {
81
            $i++;
82
        }
83
        $this->assertEqual(35, $i);
84
    }
85
    function testFetchAll() {
86
        $this->cal->build();
87
        $children = array();
88
        $i = 1;
89
        while ($Child = $this->cal->fetch()) {
90
            $children[$i] = $Child;
91
            $i++;
92
        }
93
        $this->assertEqual($children,$this->cal->fetchAll());
94
    }
95
    function testSelection() {
96
        include_once CALENDAR_ROOT . 'Day.php';
97
        $selection = array(new Calendar_Day(2003, 10, 25));
98
        $this->cal->build($selection);
99
        $daysInPrevMonth = (0 == CALENDAR_FIRST_DAY_OF_WEEK) ? 3 : 2;
100
        $end = 25 + $daysInPrevMonth;
101
        $i = 1;
102
        while ($Child = $this->cal->fetch()) {
103
            if ($i == $end) {
104
                break;
105
            }
106
            $i++;
107
        }
108
        $this->assertTrue($Child->isSelected());
109
        $this->assertEqual(25, $Child->day);
110
    }
111
    function testEmptyCount() {
112
        $this->cal->build();
113
        $empty = 0;
114
        while ($Child = $this->cal->fetch()) {
115
            if ($Child->isEmpty()) {
116
                $empty++;
117
            }
118
        }
119
        $this->assertEqual(4, $empty);
120
    }
121
    function testEmptyCount2() {
122
        $this->cal = new Calendar_Month_Weekdays(2010,3);
123
        $this->cal->build();
124
        $empty = 0;
125
        while ($Child = $this->cal->fetch()) {
126
            if ($Child->isEmpty()) {
127
                $empty++;
128
            }
129
        }
130
        $this->assertEqual(4, $empty);
131
    }
132
    function testEmptyCount3() {
133
        $this->cal = new Calendar_Month_Weekdays(2010,6);
134
        $this->cal->build();
135
        $empty = 0;
136
        while ($Child = $this->cal->fetch()) {
137
            if ($Child->isEmpty()) {
138
                $empty++;
139
            }
140
        }
141
        $this->assertEqual(5, $empty);
142
    }
143
    function testEmptyDaysBefore_AfterAdjust() {
144
        $this->cal = new Calendar_Month_Weekdays(2004, 0);
145
        $this->cal->build();
146
        $expected = (CALENDAR_FIRST_DAY_OF_WEEK == 0) ? 1 : 0;
147
        $this->assertEqual($expected, $this->cal->tableHelper->getEmptyDaysBefore());
148
    }
149
    function testEmptyDaysBefore() {
150
        $this->cal = new Calendar_Month_Weekdays(2010, 3);
151
        $this->cal->build();
152
        $expected = (CALENDAR_FIRST_DAY_OF_WEEK == 0) ? 1 : 0;
153
        $this->assertEqual($expected, $this->cal->tableHelper->getEmptyDaysBefore());
154
    }
155
    function testEmptyDaysBefore2() {
156
        $this->cal = new Calendar_Month_Weekdays(2010, 6);
157
        $this->cal->build();
158
        $expected = (CALENDAR_FIRST_DAY_OF_WEEK == 0) ? 2 : 1;
159
        $this->assertEqual($expected, $this->cal->tableHelper->getEmptyDaysBefore());
160
    }
161
    function testEmptyDaysAfter() {
162
        $this->cal = new Calendar_Month_Weekdays(2010, 3);
163
        $this->cal->build();
164
        $expected = (CALENDAR_FIRST_DAY_OF_WEEK == 0) ? 30 : 31;
165
        $this->assertEqual($expected, $this->cal->tableHelper->getEmptyDaysAfter());
166
    }
167
    function testEmptyDaysAfter2() {
168
        $this->cal = new Calendar_Month_Weekdays(2010, 6);
169
        $this->cal->build();
170
        $expected = (CALENDAR_FIRST_DAY_OF_WEEK == 0) ? 30 : 31;
171
        $this->assertEqual($expected, $this->cal->tableHelper->getEmptyDaysAfter());
172
    }
173
}
174
 
175
if (!defined('TEST_RUNNING')) {
176
    define('TEST_RUNNING', true);
177
    $test = &new TestOfMonthWeekdays();
178
    $test->run(new HtmlReporter());
179
    $test = &new TestOfMonthWeekdaysBuild();
180
    $test->run(new HtmlReporter());
181
}
182
?>