|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
// |
|
3
|
|
|
|
|
4
|
|
|
require_once __DIR__ . '/simple_include.php'; |
|
5
|
|
|
require_once __DIR__ . '/calendar_include.php'; |
|
6
|
|
|
|
|
7
|
|
|
require_once __DIR__ . '/./calendar_test.php'; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class TestOfMonthWeekdays. |
|
11
|
|
|
*/ |
|
12
|
|
|
class TestOfMonthWeekdays extends TestOfCalendar |
|
|
|
|
|
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* TestOfMonthWeekdays constructor. |
|
16
|
|
|
*/ |
|
17
|
|
|
public function __construct() |
|
18
|
|
|
{ |
|
19
|
|
|
$this->UnitTestCase('Test of Month Weekdays'); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function setUp() |
|
23
|
|
|
{ |
|
24
|
|
|
$this->cal = new Calendar_Month_Weekdays(2003, 10); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function testPrevDay() |
|
28
|
|
|
{ |
|
29
|
|
|
$this->assertEqual(30, $this->cal->prevDay()); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testPrevDay_Array() |
|
33
|
|
|
{ |
|
34
|
|
|
$this->assertEqual([ |
|
35
|
|
|
'year' => 2003, |
|
36
|
|
|
'month' => 9, |
|
37
|
|
|
'day' => 30, |
|
38
|
|
|
'hour' => 0, |
|
39
|
|
|
'minute' => 0, |
|
40
|
|
|
'second' => 0, |
|
41
|
|
|
], $this->cal->prevDay('array')); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function testThisDay() |
|
45
|
|
|
{ |
|
46
|
|
|
$this->assertEqual(1, $this->cal->thisDay()); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function testNextDay() |
|
50
|
|
|
{ |
|
51
|
|
|
$this->assertEqual(2, $this->cal->nextDay()); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function testPrevHour() |
|
55
|
|
|
{ |
|
56
|
|
|
$this->assertEqual(23, $this->cal->prevHour()); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function testThisHour() |
|
60
|
|
|
{ |
|
61
|
|
|
$this->assertEqual(0, $this->cal->thisHour()); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function testNextHour() |
|
65
|
|
|
{ |
|
66
|
|
|
$this->assertEqual(1, $this->cal->nextHour()); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function testPrevMinute() |
|
70
|
|
|
{ |
|
71
|
|
|
$this->assertEqual(59, $this->cal->prevMinute()); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function testThisMinute() |
|
75
|
|
|
{ |
|
76
|
|
|
$this->assertEqual(0, $this->cal->thisMinute()); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function testNextMinute() |
|
80
|
|
|
{ |
|
81
|
|
|
$this->assertEqual(1, $this->cal->nextMinute()); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function testPrevSecond() |
|
85
|
|
|
{ |
|
86
|
|
|
$this->assertEqual(59, $this->cal->prevSecond()); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function testThisSecond() |
|
90
|
|
|
{ |
|
91
|
|
|
$this->assertEqual(0, $this->cal->thisSecond()); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function testNextSecond() |
|
95
|
|
|
{ |
|
96
|
|
|
$this->assertEqual(1, $this->cal->nextSecond()); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function testGetTimeStamp() |
|
100
|
|
|
{ |
|
101
|
|
|
$stamp = mktime(0, 0, 0, 10, 1, 2003); |
|
102
|
|
|
$this->assertEqual($stamp, $this->cal->getTimestamp()); |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Class TestOfMonthWeekdaysBuild. |
|
108
|
|
|
*/ |
|
109
|
|
|
class TestOfMonthWeekdaysBuild extends TestOfMonthWeekdays |
|
|
|
|
|
|
110
|
|
|
{ |
|
111
|
|
|
/** |
|
112
|
|
|
* TestOfMonthWeekdaysBuild constructor. |
|
113
|
|
|
*/ |
|
114
|
|
|
public function __construct() |
|
115
|
|
|
{ |
|
116
|
|
|
$this->UnitTestCase('Test of Month_Weekdays::build()'); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function testSize() |
|
120
|
|
|
{ |
|
121
|
|
|
$this->cal->build(); |
|
122
|
|
|
$this->assertEqual(35, $this->cal->size()); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
public function testFetch() |
|
126
|
|
|
{ |
|
127
|
|
|
$this->cal->build(); |
|
128
|
|
|
$i = 0; |
|
129
|
|
|
while ($Child = $this->cal->fetch()) { |
|
|
|
|
|
|
130
|
|
|
++$i; |
|
131
|
|
|
} |
|
132
|
|
|
$this->assertEqual(35, $i); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
public function testFetchAll() |
|
136
|
|
|
{ |
|
137
|
|
|
$this->cal->build(); |
|
138
|
|
|
$children = []; |
|
139
|
|
|
$i = 1; |
|
140
|
|
|
while ($Child = $this->cal->fetch()) { |
|
141
|
|
|
$children[$i] = $Child; |
|
142
|
|
|
++$i; |
|
143
|
|
|
} |
|
144
|
|
|
$this->assertEqual($children, $this->cal->fetchAll()); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
public function testSelection() |
|
148
|
|
|
{ |
|
149
|
|
|
require_once CALENDAR_ROOT . 'Day.php'; |
|
150
|
|
|
$selection = [new Calendar_Day(2003, 10, 25)]; |
|
151
|
|
|
$this->cal->build($selection); |
|
152
|
|
|
$daysInPrevMonth = (0 == CALENDAR_FIRST_DAY_OF_WEEK) ? 3 : 2; |
|
153
|
|
|
$end = 25 + $daysInPrevMonth; |
|
154
|
|
|
$i = 1; |
|
155
|
|
|
while ($Child = $this->cal->fetch()) { |
|
156
|
|
|
if ($i == $end) { |
|
157
|
|
|
break; |
|
158
|
|
|
} |
|
159
|
|
|
++$i; |
|
160
|
|
|
} |
|
161
|
|
|
$this->assertTrue($Child->isSelected()); |
|
162
|
|
|
$this->assertEqual(25, $Child->day); |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
public function testEmptyCount() |
|
166
|
|
|
{ |
|
167
|
|
|
$this->cal->build(); |
|
168
|
|
|
$empty = 0; |
|
169
|
|
|
while ($Child = $this->cal->fetch()) { |
|
170
|
|
|
if ($Child->isEmpty()) { |
|
171
|
|
|
++$empty; |
|
172
|
|
|
} |
|
173
|
|
|
} |
|
174
|
|
|
$this->assertEqual(4, $empty); |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
public function testEmptyCount2() |
|
178
|
|
|
{ |
|
179
|
|
|
$this->cal = new Calendar_Month_Weekdays(2010, 3); |
|
180
|
|
|
$this->cal->build(); |
|
181
|
|
|
$empty = 0; |
|
182
|
|
|
while ($Child = $this->cal->fetch()) { |
|
183
|
|
|
if ($Child->isEmpty()) { |
|
184
|
|
|
++$empty; |
|
185
|
|
|
} |
|
186
|
|
|
} |
|
187
|
|
|
$this->assertEqual(4, $empty); |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
public function testEmptyCount3() |
|
191
|
|
|
{ |
|
192
|
|
|
$this->cal = new Calendar_Month_Weekdays(2010, 6); |
|
193
|
|
|
$this->cal->build(); |
|
194
|
|
|
$empty = 0; |
|
195
|
|
|
while ($Child = $this->cal->fetch()) { |
|
196
|
|
|
if ($Child->isEmpty()) { |
|
197
|
|
|
++$empty; |
|
198
|
|
|
} |
|
199
|
|
|
} |
|
200
|
|
|
$this->assertEqual(5, $empty); |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
public function testEmptyDaysBefore_AfterAdjust() |
|
204
|
|
|
{ |
|
205
|
|
|
$this->cal = new Calendar_Month_Weekdays(2004, 0); |
|
206
|
|
|
$this->cal->build(); |
|
207
|
|
|
$expected = (CALENDAR_FIRST_DAY_OF_WEEK == 0) ? 1 : 0; |
|
208
|
|
|
$this->assertEqual($expected, $this->cal->tableHelper->getEmptyDaysBefore()); |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
public function testEmptyDaysBefore() |
|
212
|
|
|
{ |
|
213
|
|
|
$this->cal = new Calendar_Month_Weekdays(2010, 3); |
|
214
|
|
|
$this->cal->build(); |
|
215
|
|
|
$expected = (CALENDAR_FIRST_DAY_OF_WEEK == 0) ? 1 : 0; |
|
216
|
|
|
$this->assertEqual($expected, $this->cal->tableHelper->getEmptyDaysBefore()); |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
public function testEmptyDaysBefore2() |
|
220
|
|
|
{ |
|
221
|
|
|
$this->cal = new Calendar_Month_Weekdays(2010, 6); |
|
222
|
|
|
$this->cal->build(); |
|
223
|
|
|
$expected = (CALENDAR_FIRST_DAY_OF_WEEK == 0) ? 2 : 1; |
|
224
|
|
|
$this->assertEqual($expected, $this->cal->tableHelper->getEmptyDaysBefore()); |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
public function testEmptyDaysAfter() |
|
228
|
|
|
{ |
|
229
|
|
|
$this->cal = new Calendar_Month_Weekdays(2010, 3); |
|
230
|
|
|
$this->cal->build(); |
|
231
|
|
|
$expected = (CALENDAR_FIRST_DAY_OF_WEEK == 0) ? 30 : 31; |
|
232
|
|
|
$this->assertEqual($expected, $this->cal->tableHelper->getEmptyDaysAfter()); |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
public function testEmptyDaysAfter2() |
|
236
|
|
|
{ |
|
237
|
|
|
$this->cal = new Calendar_Month_Weekdays(2010, 6); |
|
238
|
|
|
$this->cal->build(); |
|
239
|
|
|
$expected = (CALENDAR_FIRST_DAY_OF_WEEK == 0) ? 30 : 31; |
|
240
|
|
|
$this->assertEqual($expected, $this->cal->tableHelper->getEmptyDaysAfter()); |
|
241
|
|
|
} |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
if (!defined('TEST_RUNNING')) { |
|
245
|
|
|
define('TEST_RUNNING', true); |
|
246
|
|
|
$test = new TestOfMonthWeekdays(); |
|
247
|
|
|
$test->run(new HtmlReporter()); |
|
|
|
|
|
|
248
|
|
|
$test = new TestOfMonthWeekdaysBuild(); |
|
249
|
|
|
$test->run(new HtmlReporter()); |
|
250
|
|
|
} |
|
251
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.