|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
// |
|
3
|
|
|
|
|
4
|
|
|
require_once __DIR__ . '/simple_include.php'; |
|
5
|
|
|
require_once __DIR__ . '/calendar_include.php'; |
|
6
|
|
|
|
|
7
|
|
|
require_once __DIR__ . '/./decorator_test.php'; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class TestOfUtilTextual. |
|
11
|
|
|
*/ |
|
12
|
|
|
class TestOfUtilTextual extends UnitTestCase |
|
|
|
|
|
|
13
|
|
|
{ |
|
14
|
|
|
public $mockengine; |
|
15
|
|
|
public $mockcal; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* TestOfUtilTextual constructor. |
|
19
|
|
|
*/ |
|
20
|
|
|
public function __construct() |
|
21
|
|
|
{ |
|
22
|
|
|
parent::__construct('Test of Calendar_Util_Textual'); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function setUp() |
|
26
|
|
|
{ |
|
27
|
|
|
$this->mockengine = new Mock_Calendar_Engine($this); |
|
|
|
|
|
|
28
|
|
|
$this->mockcal = new Mock_Calendar_Second($this); |
|
|
|
|
|
|
29
|
|
|
$this->mockcal->setReturnValue('prevYear', 2002); |
|
30
|
|
|
$this->mockcal->setReturnValue('thisYear', 2003); |
|
31
|
|
|
$this->mockcal->setReturnValue('nextYear', 2004); |
|
32
|
|
|
$this->mockcal->setReturnValue('prevMonth', 9); |
|
33
|
|
|
$this->mockcal->setReturnValue('thisMonth', 10); |
|
34
|
|
|
$this->mockcal->setReturnValue('nextMonth', 11); |
|
35
|
|
|
$this->mockcal->setReturnValue('prevDay', 14); |
|
36
|
|
|
$this->mockcal->setReturnValue('thisDay', 15); |
|
37
|
|
|
$this->mockcal->setReturnValue('nextDay', 16); |
|
38
|
|
|
$this->mockcal->setReturnValue('prevHour', 12); |
|
39
|
|
|
$this->mockcal->setReturnValue('thisHour', 13); |
|
40
|
|
|
$this->mockcal->setReturnValue('nextHour', 14); |
|
41
|
|
|
$this->mockcal->setReturnValue('prevMinute', 29); |
|
42
|
|
|
$this->mockcal->setReturnValue('thisMinute', 30); |
|
43
|
|
|
$this->mockcal->setReturnValue('nextMinute', 31); |
|
44
|
|
|
$this->mockcal->setReturnValue('prevSecond', 44); |
|
45
|
|
|
$this->mockcal->setReturnValue('thisSecond', 45); |
|
46
|
|
|
$this->mockcal->setReturnValue('nextSecond', 46); |
|
47
|
|
|
$this->mockcal->setReturnValue('getEngine', $this->mockengine); |
|
48
|
|
|
$this->mockcal->setReturnValue('getTimestamp', 12345); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function tearDown() |
|
52
|
|
|
{ |
|
53
|
|
|
unset($this->engine, $this->mockcal); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function testMonthNamesLong() |
|
57
|
|
|
{ |
|
58
|
|
|
$monthNames = [ |
|
59
|
|
|
1 => 'January', |
|
60
|
|
|
2 => 'February', |
|
61
|
|
|
3 => 'March', |
|
62
|
|
|
4 => 'April', |
|
63
|
|
|
5 => 'May', |
|
64
|
|
|
6 => 'June', |
|
65
|
|
|
7 => 'July', |
|
66
|
|
|
8 => 'August', |
|
67
|
|
|
9 => 'September', |
|
68
|
|
|
10 => 'October', |
|
69
|
|
|
11 => 'November', |
|
70
|
|
|
12 => 'December', |
|
71
|
|
|
]; |
|
72
|
|
|
$this->assertEqual($monthNames, Calendar_Util_Textual::monthNames()); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function testMonthNamesShort() |
|
76
|
|
|
{ |
|
77
|
|
|
$monthNames = [ |
|
78
|
|
|
1 => 'Jan', |
|
79
|
|
|
2 => 'Feb', |
|
80
|
|
|
3 => 'Mar', |
|
81
|
|
|
4 => 'Apr', |
|
82
|
|
|
5 => 'May', |
|
83
|
|
|
6 => 'Jun', |
|
84
|
|
|
7 => 'Jul', |
|
85
|
|
|
8 => 'Aug', |
|
86
|
|
|
9 => 'Sep', |
|
87
|
|
|
10 => 'Oct', |
|
88
|
|
|
11 => 'Nov', |
|
89
|
|
|
12 => 'Dec', |
|
90
|
|
|
]; |
|
91
|
|
|
$this->assertEqual($monthNames, Calendar_Util_Textual::monthNames('short')); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function testMonthNamesTwo() |
|
95
|
|
|
{ |
|
96
|
|
|
$monthNames = [ |
|
97
|
|
|
1 => 'Ja', |
|
98
|
|
|
2 => 'Fe', |
|
99
|
|
|
3 => 'Ma', |
|
100
|
|
|
4 => 'Ap', |
|
101
|
|
|
5 => 'Ma', |
|
102
|
|
|
6 => 'Ju', |
|
103
|
|
|
7 => 'Ju', |
|
104
|
|
|
8 => 'Au', |
|
105
|
|
|
9 => 'Se', |
|
106
|
|
|
10 => 'Oc', |
|
107
|
|
|
11 => 'No', |
|
108
|
|
|
12 => 'De', |
|
109
|
|
|
]; |
|
110
|
|
|
$this->assertEqual($monthNames, Calendar_Util_Textual::monthNames('two')); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
public function testMonthNamesOne() |
|
114
|
|
|
{ |
|
115
|
|
|
$monthNames = [ |
|
116
|
|
|
1 => 'J', |
|
117
|
|
|
2 => 'F', |
|
118
|
|
|
3 => 'M', |
|
119
|
|
|
4 => 'A', |
|
120
|
|
|
5 => 'M', |
|
121
|
|
|
6 => 'J', |
|
122
|
|
|
7 => 'J', |
|
123
|
|
|
8 => 'A', |
|
124
|
|
|
9 => 'S', |
|
125
|
|
|
10 => 'O', |
|
126
|
|
|
11 => 'N', |
|
127
|
|
|
12 => 'D', |
|
128
|
|
|
]; |
|
129
|
|
|
$this->assertEqual($monthNames, Calendar_Util_Textual::monthNames('one')); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
public function testWeekdayNamesLong() |
|
133
|
|
|
{ |
|
134
|
|
|
$weekdayNames = [ |
|
135
|
|
|
0 => 'Sunday', |
|
136
|
|
|
1 => 'Monday', |
|
137
|
|
|
2 => 'Tuesday', |
|
138
|
|
|
3 => 'Wednesday', |
|
139
|
|
|
4 => 'Thursday', |
|
140
|
|
|
5 => 'Friday', |
|
141
|
|
|
6 => 'Saturday', |
|
142
|
|
|
]; |
|
143
|
|
|
$this->assertEqual($weekdayNames, Calendar_Util_Textual::weekdayNames()); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
public function testWeekdayNamesShort() |
|
147
|
|
|
{ |
|
148
|
|
|
$weekdayNames = [ |
|
149
|
|
|
0 => 'Sun', |
|
150
|
|
|
1 => 'Mon', |
|
151
|
|
|
2 => 'Tue', |
|
152
|
|
|
3 => 'Wed', |
|
153
|
|
|
4 => 'Thu', |
|
154
|
|
|
5 => 'Fri', |
|
155
|
|
|
6 => 'Sat', |
|
156
|
|
|
]; |
|
157
|
|
|
$this->assertEqual($weekdayNames, Calendar_Util_Textual::weekdayNames('short')); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
public function testWeekdayNamesTwo() |
|
161
|
|
|
{ |
|
162
|
|
|
$weekdayNames = [ |
|
163
|
|
|
0 => 'Su', |
|
164
|
|
|
1 => 'Mo', |
|
165
|
|
|
2 => 'Tu', |
|
166
|
|
|
3 => 'We', |
|
167
|
|
|
4 => 'Th', |
|
168
|
|
|
5 => 'Fr', |
|
169
|
|
|
6 => 'Sa', |
|
170
|
|
|
]; |
|
171
|
|
|
$this->assertEqual($weekdayNames, Calendar_Util_Textual::weekdayNames('two')); |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
public function testWeekdayNamesOne() |
|
175
|
|
|
{ |
|
176
|
|
|
$weekdayNames = [ |
|
177
|
|
|
0 => 'S', |
|
178
|
|
|
1 => 'M', |
|
179
|
|
|
2 => 'T', |
|
180
|
|
|
3 => 'W', |
|
181
|
|
|
4 => 'T', |
|
182
|
|
|
5 => 'F', |
|
183
|
|
|
6 => 'S', |
|
184
|
|
|
]; |
|
185
|
|
|
$this->assertEqual($weekdayNames, Calendar_Util_Textual::weekdayNames('one')); |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
public function testPrevMonthNameShort() |
|
189
|
|
|
{ |
|
190
|
|
|
$this->assertEqual('Sep', Calendar_Util_Textual::prevMonthName($this->mockcal, 'short')); |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
public function testThisMonthNameShort() |
|
194
|
|
|
{ |
|
195
|
|
|
$this->assertEqual('Oct', Calendar_Util_Textual::thisMonthName($this->mockcal, 'short')); |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
public function testNextMonthNameShort() |
|
199
|
|
|
{ |
|
200
|
|
|
$this->assertEqual('Nov', Calendar_Util_Textual::nextMonthName($this->mockcal, 'short')); |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
public function testThisDayNameShort() |
|
204
|
|
|
{ |
|
205
|
|
|
$this->assertEqual('Wed', Calendar_Util_Textual::thisDayName($this->mockcal, 'short')); |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
public function testOrderedWeekdaysShort() |
|
209
|
|
|
{ |
|
210
|
|
|
$weekdayNames = [ |
|
211
|
|
|
0 => 'Sun', |
|
212
|
|
|
1 => 'Mon', |
|
213
|
|
|
2 => 'Tue', |
|
214
|
|
|
3 => 'Wed', |
|
215
|
|
|
4 => 'Thu', |
|
216
|
|
|
5 => 'Fri', |
|
217
|
|
|
6 => 'Sat', |
|
218
|
|
|
]; |
|
219
|
|
|
$nShifts = CALENDAR_FIRST_DAY_OF_WEEK; |
|
220
|
|
|
while ($nShifts-- > 0) { |
|
221
|
|
|
$day = array_shift($weekdayNames); |
|
222
|
|
|
array_push($weekdayNames, $day); |
|
223
|
|
|
} |
|
224
|
|
|
$this->assertEqual($weekdayNames, Calendar_Util_Textual::orderedWeekdays($this->mockcal, 'short')); |
|
225
|
|
|
} |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
if (!defined('TEST_RUNNING')) { |
|
229
|
|
|
define('TEST_RUNNING', true); |
|
230
|
|
|
$test = new TestOfUtilTextual(); |
|
231
|
|
|
$test->run(new HtmlReporter()); |
|
|
|
|
|
|
232
|
|
|
} |
|
233
|
|
|
|
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.