|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
// |
|
3
|
|
|
|
|
4
|
|
|
require_once __DIR__ . '/simple_include.php'; |
|
5
|
|
|
require_once __DIR__ . '/calendar_include.php'; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class TestOfPearDateEngine. |
|
9
|
|
|
*/ |
|
10
|
|
|
class TestOfPearDateEngine extends UnitTestCase |
|
|
|
|
|
|
11
|
|
|
{ |
|
12
|
|
|
public $engine; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* TestOfPearDateEngine constructor. |
|
16
|
|
|
*/ |
|
17
|
|
|
public function __construct() |
|
18
|
|
|
{ |
|
19
|
|
|
parent::__construct('Test of Calendar_Engine_PearDate'); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function setUp() |
|
23
|
|
|
{ |
|
24
|
|
|
$this->engine = new Calendar_Engine_PearDate(); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function testGetSecondsInMinute() |
|
28
|
|
|
{ |
|
29
|
|
|
$this->assertEqual($this->engine->getSecondsInMinute(), _EXTCAL_TS_MINUTE); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testGetMinutesInHour() |
|
33
|
|
|
{ |
|
34
|
|
|
$this->assertEqual($this->engine->getMinutesInHour(), _EXTCAL_TS_MINUTE); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function testGetHoursInDay() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->assertEqual($this->engine->getHoursInDay(), 24); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function testGetFirstDayOfWeek() |
|
43
|
|
|
{ |
|
44
|
|
|
$this->assertEqual($this->engine->getFirstDayOfWeek(), 1); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testGetWeekDays() |
|
48
|
|
|
{ |
|
49
|
|
|
$this->assertEqual($this->engine->getWeekDays(), [0, 1, 2, 3, 4, 5, 6]); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function testGetDaysInWeek() |
|
53
|
|
|
{ |
|
54
|
|
|
$this->assertEqual($this->engine->getDaysInWeek(), 7); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function testGetWeekNInYear() |
|
58
|
|
|
{ |
|
59
|
|
|
$this->assertEqual($this->engine->getWeekNInYear(2003, 11, 3), 45); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function testGetWeekNInMonth() |
|
63
|
|
|
{ |
|
64
|
|
|
$this->assertEqual($this->engine->getWeekNInMonth(2003, 11, 3), 2); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function testGetWeeksInMonth0() |
|
68
|
|
|
{ |
|
69
|
|
|
$this->assertEqual($this->engine->getWeeksInMonth(2003, 11, 0), 6); //week starts on sunday |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function testGetWeeksInMonth1() |
|
73
|
|
|
{ |
|
74
|
|
|
$this->assertEqual($this->engine->getWeeksInMonth(2003, 11, 1), 5); //week starts on monday |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function testGetWeeksInMonth2() |
|
78
|
|
|
{ |
|
79
|
|
|
$this->assertEqual($this->engine->getWeeksInMonth(2003, 2, 6), 4); //week starts on saturday |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function testGetWeeksInMonth3() |
|
83
|
|
|
{ |
|
84
|
|
|
// Unusual cases that can cause fails (shows up with example 21.php) |
|
85
|
|
|
$this->assertEqual($this->engine->getWeeksInMonth(2004, 2, 1), 5); |
|
86
|
|
|
$this->assertEqual($this->engine->getWeeksInMonth(2004, 8, 1), 6); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function testGetDayOfWeek() |
|
90
|
|
|
{ |
|
91
|
|
|
$this->assertEqual($this->engine->getDayOfWeek(2003, 11, 18), 2); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function testGetFirstDayInMonth() |
|
95
|
|
|
{ |
|
96
|
|
|
$this->assertEqual($this->engine->getFirstDayInMonth(2003, 10), 3); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function testGetDaysInMonth() |
|
100
|
|
|
{ |
|
101
|
|
|
$this->assertEqual($this->engine->getDaysInMonth(2003, 10), 31); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function testGetMinYears() |
|
105
|
|
|
{ |
|
106
|
|
|
$this->assertEqual($this->engine->getMinYears(), 0); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function testGetMaxYears() |
|
110
|
|
|
{ |
|
111
|
|
|
$this->assertEqual($this->engine->getMaxYears(), 9999); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
public function testDateToStamp() |
|
115
|
|
|
{ |
|
116
|
|
|
$stamp = '2003-10-15 13:30:45'; |
|
117
|
|
|
$this->assertEqual($this->engine->dateToStamp(2003, 10, 15, 13, 30, 45), $stamp); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public function testStampToSecond() |
|
121
|
|
|
{ |
|
122
|
|
|
$stamp = '2003-10-15 13:30:45'; |
|
123
|
|
|
$this->assertEqual($this->engine->stampToSecond($stamp), 45); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
public function testStampToMinute() |
|
127
|
|
|
{ |
|
128
|
|
|
$stamp = '2003-10-15 13:30:45'; |
|
129
|
|
|
$this->assertEqual($this->engine->stampToMinute($stamp), 30); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
public function testStampToHour() |
|
133
|
|
|
{ |
|
134
|
|
|
$stamp = '2003-10-15 13:30:45'; |
|
135
|
|
|
$this->assertEqual($this->engine->stampToHour($stamp), 13); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
public function testStampToDay() |
|
139
|
|
|
{ |
|
140
|
|
|
$stamp = '2003-10-15 13:30:45'; |
|
141
|
|
|
$this->assertEqual($this->engine->stampToDay($stamp), 15); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
public function testStampToMonth() |
|
145
|
|
|
{ |
|
146
|
|
|
$stamp = '2003-10-15 13:30:45'; |
|
147
|
|
|
$this->assertEqual($this->engine->stampToMonth($stamp), 10); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
public function testStampToYear() |
|
151
|
|
|
{ |
|
152
|
|
|
$stamp = '2003-10-15 13:30:45'; |
|
153
|
|
|
$this->assertEqual($this->engine->stampToYear($stamp), 2003); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
public function testAdjustDate() |
|
157
|
|
|
{ |
|
158
|
|
|
$stamp = '2004-01-01 13:30:45'; |
|
159
|
|
|
$y = $this->engine->stampToYear($stamp); |
|
160
|
|
|
$m = $this->engine->stampToMonth($stamp); |
|
161
|
|
|
$d = $this->engine->stampToDay($stamp); |
|
162
|
|
|
|
|
163
|
|
|
//the first day of the month should be thursday |
|
164
|
|
|
$this->assertEqual($this->engine->getDayOfWeek($y, $m, $d), 4); |
|
165
|
|
|
|
|
166
|
|
|
--$m; // 2004-00-01 => 2003-12-01 |
|
|
|
|
|
|
167
|
|
|
$this->engine->adjustDate($y, $m, $d, $dummy, $dummy, $dummy); |
|
|
|
|
|
|
168
|
|
|
|
|
169
|
|
|
$this->assertEqual($y, 2003); |
|
170
|
|
|
$this->assertEqual($m, 12); |
|
171
|
|
|
$this->assertEqual($d, 1); |
|
172
|
|
|
|
|
173
|
|
|
// get last day and check if it's wednesday |
|
174
|
|
|
$d = $this->engine->getDaysInMonth($y, $m); |
|
175
|
|
|
|
|
176
|
|
|
$this->assertEqual($this->engine->getDayOfWeek($y, $m, $d), 3); |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
public function testIsToday() |
|
180
|
|
|
{ |
|
181
|
|
|
$stamp = date('Y-m-d H:i:s'); |
|
182
|
|
|
$this->assertTrue($this->engine->isToday($stamp)); |
|
183
|
|
|
$stamp = date('Y-m-d H:i:s', time() + 1000000000); |
|
184
|
|
|
$this->assertFalse($this->engine->isToday($stamp)); |
|
185
|
|
|
} |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
if (!defined('TEST_RUNNING')) { |
|
189
|
|
|
define('TEST_RUNNING', true); |
|
190
|
|
|
$test = new TestOfPearDateEngine(); |
|
191
|
|
|
$test->run(new HtmlReporter()); |
|
|
|
|
|
|
192
|
|
|
} |
|
193
|
|
|
|
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.