5
5
6
6
class RecurrencesTest extends TestCase
7
7
{
8
-
9
8
private $ useTimeZoneWithRRules = false ;
10
9
private $ originalTimeZone = null ;
11
10
12
- public function setUp () {
11
+ public function setUp ()
12
+ {
13
13
$ this ->originalTimeZone = date_default_timezone_get ();
14
14
}
15
15
16
- public function tearDown () {
16
+ public function tearDown ()
17
+ {
17
18
date_default_timezone_set ($ this ->originalTimeZone );
18
19
}
19
20
20
- public function testYearlyFullDayTimeZoneBerlin () {
21
+ public function testYearlyFullDayTimeZoneBerlin ()
22
+ {
21
23
$ checks = array (
22
24
array ('index ' => 0 , 'dateString ' => '20000301 ' , 'message ' => '1st event, CET: ' ),
23
25
array ('index ' => 1 , 'dateString ' => '20010301T000000 ' , 'message ' => '2nd event, CET: ' ),
24
26
array ('index ' => 2 , 'dateString ' => '20020301T000000 ' , 'message ' => '3rd event, CET: ' ),
25
27
);
26
28
$ this ->assertVEVENT (
27
29
'Europe/Berlin ' ,
28
- " DTSTART;VALUE=DATE:20000301 " ,
29
- " DTEND;VALUE=DATE:20000302 " ,
30
- " RRULE:FREQ=YEARLY;WKST=SU;COUNT=3 " ,
30
+ ' DTSTART;VALUE=DATE:20000301 ' ,
31
+ ' DTEND;VALUE=DATE:20000302 ' ,
32
+ ' RRULE:FREQ=YEARLY;WKST=SU;COUNT=3 ' ,
31
33
3 ,
32
- $ checks );
34
+ $ checks
35
+ );
33
36
}
34
37
35
- public function testMonthlyFullDayTimeZoneBerlin () {
38
+ public function testMonthlyFullDayTimeZoneBerlin ()
39
+ {
36
40
$ checks = array (
37
41
array ('index ' => 0 , 'dateString ' => '20000301 ' , 'message ' => '1st event, CET: ' ),
38
42
array ('index ' => 1 , 'dateString ' => '20000401T000000 ' , 'message ' => '2nd event, CEST: ' ),
39
43
array ('index ' => 2 , 'dateString ' => '20000501T000000 ' , 'message ' => '3rd event, CEST: ' ),
40
44
);
41
45
$ this ->assertVEVENT (
42
46
'Europe/Berlin ' ,
43
- " DTSTART;VALUE=DATE:20000301 " ,
44
- " DTEND;VALUE=DATE:20000302 " ,
45
- " RRULE:FREQ=MONTHLY;BYMONTHDAY=1;WKST=SU;COUNT=3 " ,
47
+ ' DTSTART;VALUE=DATE:20000301 ' ,
48
+ ' DTEND;VALUE=DATE:20000302 ' ,
49
+ ' RRULE:FREQ=MONTHLY;BYMONTHDAY=1;WKST=SU;COUNT=3 ' ,
46
50
3 ,
47
- $ checks );
51
+ $ checks
52
+ );
48
53
}
49
54
50
- public function testMonthlyFullDayTimeZoneBerlinSummerTime () {
55
+ public function testMonthlyFullDayTimeZoneBerlinSummerTime ()
56
+ {
51
57
$ checks = array (
52
58
array ('index ' => 0 , 'dateString ' => '20180701 ' , 'message ' => '1st event, CEST: ' ),
53
59
array ('index ' => 1 , 'dateString ' => '20180801T000000 ' , 'message ' => '2nd event, CEST: ' ),
54
60
array ('index ' => 2 , 'dateString ' => '20180901T000000 ' , 'message ' => '3rd event, CEST: ' ),
55
61
);
56
62
$ this ->assertVEVENT (
57
63
'Europe/Berlin ' ,
58
- " DTSTART;VALUE=DATE:20180701 " ,
59
- " DTEND;VALUE=DATE:20180702 " ,
60
- " RRULE:FREQ=MONTHLY;BYMONTHDAY=1;WKST=SU;COUNT=3 " ,
64
+ ' DTSTART;VALUE=DATE:20180701 ' ,
65
+ ' DTEND;VALUE=DATE:20180702 ' ,
66
+ ' RRULE:FREQ=MONTHLY;BYMONTHDAY=1;WKST=SU;COUNT=3 ' ,
61
67
3 ,
62
- $ checks );
68
+ $ checks
69
+ );
63
70
}
64
71
65
- public function testMonthlyFullDayTimeZoneBerlinFromFile () {
72
+ public function testMonthlyFullDayTimeZoneBerlinFromFile ()
73
+ {
66
74
$ checks = array (
67
75
array ('index ' => 0 , 'dateString ' => '20180701 ' , 'message ' => '1st event, CEST: ' ),
68
76
array ('index ' => 1 , 'dateString ' => '20180801T000000 ' , 'message ' => '2nd event, CEST: ' ),
69
77
array ('index ' => 2 , 'dateString ' => '20180901T000000 ' , 'message ' => '3rd event, CEST: ' ),
70
78
);
71
79
$ this ->assertEventFile (
72
80
'Europe/Berlin ' ,
73
- " ./tests/ical/ical-monthly.ics " ,
81
+ ' ./tests/ical/ical-monthly.ics ' ,
74
82
25 ,
75
- $ checks );
83
+ $ checks
84
+ );
76
85
}
77
86
78
- public function testIssue196FromFile () {
87
+ public function testIssue196FromFile ()
88
+ {
79
89
$ checks = array (
80
90
array ('index ' => 0 , 'dateString ' => '20191105T190000 ' , 'timezone ' => 'Europe/Berlin ' , 'message ' => '1st event, CEST: ' ),
81
91
array ('index ' => 1 , 'dateString ' => '20191106T190000 ' , 'timezone ' => 'Europe/Berlin ' , 'message ' => '2nd event, CEST: ' ),
@@ -86,12 +96,14 @@ public function testIssue196FromFile() {
86
96
);
87
97
$ this ->assertEventFile (
88
98
'UTC ' ,
89
- " ./tests/ical/issue-196.ics " ,
99
+ ' ./tests/ical/issue-196.ics ' ,
90
100
6 ,
91
- $ checks );
101
+ $ checks
102
+ );
92
103
}
93
104
94
- public function testWeeklyFullDayTimeZoneBerlin () {
105
+ public function testWeeklyFullDayTimeZoneBerlin ()
106
+ {
95
107
$ checks = array (
96
108
array ('index ' => 0 , 'dateString ' => '20000301 ' , 'message ' => '1st event, CET: ' ),
97
109
array ('index ' => 1 , 'dateString ' => '20000308T000000 ' , 'message ' => '2nd event, CET: ' ),
@@ -102,29 +114,33 @@ public function testWeeklyFullDayTimeZoneBerlin() {
102
114
);
103
115
$ this ->assertVEVENT (
104
116
'Europe/Berlin ' ,
105
- " DTSTART;VALUE=DATE:20000301 " ,
106
- " DTEND;VALUE=DATE:20000302 " ,
107
- " RRULE:FREQ=WEEKLY;WKST=SU;COUNT=6 " ,
117
+ ' DTSTART;VALUE=DATE:20000301 ' ,
118
+ ' DTEND;VALUE=DATE:20000302 ' ,
119
+ ' RRULE:FREQ=WEEKLY;WKST=SU;COUNT=6 ' ,
108
120
6 ,
109
- $ checks );
121
+ $ checks
122
+ );
110
123
}
111
124
112
- public function testDailyFullDayTimeZoneBerlin () {
125
+ public function testDailyFullDayTimeZoneBerlin ()
126
+ {
113
127
$ checks = array (
114
128
array ('index ' => 0 , 'dateString ' => '20000301 ' , 'message ' => '1st event, CET: ' ),
115
129
array ('index ' => 1 , 'dateString ' => '20000302T000000 ' , 'message ' => '2nd event, CET: ' ),
116
130
array ('index ' => 30 , 'dateString ' => '20000331T000000 ' , 'message ' => '31st event, CEST: ' ),
117
131
);
118
132
$ this ->assertVEVENT (
119
133
'Europe/Berlin ' ,
120
- " DTSTART;VALUE=DATE:20000301 " ,
121
- " DTEND;VALUE=DATE:20000302 " ,
122
- " RRULE:FREQ=DAILY;WKST=SU;COUNT=31 " ,
134
+ ' DTSTART;VALUE=DATE:20000301 ' ,
135
+ ' DTEND;VALUE=DATE:20000302 ' ,
136
+ ' RRULE:FREQ=DAILY;WKST=SU;COUNT=31 ' ,
123
137
31 ,
124
- $ checks );
138
+ $ checks
139
+ );
125
140
}
126
141
127
- public function testWeeklyFullDayTimeZoneBerlinLocal () {
142
+ public function testWeeklyFullDayTimeZoneBerlinLocal ()
143
+ {
128
144
$ checks = array (
129
145
array ('index ' => 0 , 'dateString ' => '20000301T000000 ' , 'message ' => '1st event, CET: ' ),
130
146
array ('index ' => 1 , 'dateString ' => '20000308T000000 ' , 'message ' => '2nd event, CET: ' ),
@@ -135,68 +151,74 @@ public function testWeeklyFullDayTimeZoneBerlinLocal() {
135
151
);
136
152
$ this ->assertVEVENT (
137
153
'Europe/Berlin ' ,
138
- " DTSTART;TZID=Europe/Berlin:20000301T000000 " ,
139
- " DTEND;TZID=Europe/Berlin:20000302T000000 " ,
140
- " RRULE:FREQ=WEEKLY;WKST=SU;COUNT=6 " ,
154
+ ' DTSTART;TZID=Europe/Berlin:20000301T000000 ' ,
155
+ ' DTEND;TZID=Europe/Berlin:20000302T000000 ' ,
156
+ ' RRULE:FREQ=WEEKLY;WKST=SU;COUNT=6 ' ,
141
157
6 ,
142
- $ checks );
158
+ $ checks
159
+ );
143
160
}
144
161
145
- public function testRFCDaily10NewYork () {
146
- // (1997 9:00 AM EDT)September 2-11
162
+ public function testRFCDaily10NewYork ()
163
+ {
147
164
$ checks = array (
148
165
array ('index ' => 0 , 'dateString ' => '19970902T090000 ' , 'timezone ' => 'America/New_York ' , 'message ' => '1st event, EDT: ' ),
149
166
array ('index ' => 1 , 'dateString ' => '19970903T090000 ' , 'timezone ' => 'America/New_York ' , 'message ' => '2nd event, EDT: ' ),
150
167
array ('index ' => 9 , 'dateString ' => '19970911T090000 ' , 'timezone ' => 'America/New_York ' , 'message ' => '10th event, EDT: ' ),
151
168
);
152
169
$ this ->assertVEVENT (
153
170
'Europe/Berlin ' ,
154
- " DTSTART;TZID=America/New_York:19970902T090000 " ,
155
- "" ,
156
- " RRULE:FREQ=DAILY;COUNT=10 " ,
171
+ ' DTSTART;TZID=America/New_York:19970902T090000 ' ,
172
+ '' ,
173
+ ' RRULE:FREQ=DAILY;COUNT=10 ' ,
157
174
10 ,
158
- $ checks );
175
+ $ checks
176
+ );
159
177
}
160
178
161
- public function testRFCDaily10Berlin () {
162
- // (1997 9:00 AM CEST)September 2-11
179
+ public function testRFCDaily10Berlin ()
180
+ {
163
181
$ checks = array (
164
182
array ('index ' => 0 , 'dateString ' => '19970902T090000 ' , 'timezone ' => 'Europe/Berlin ' , 'message ' => '1st event, CEST: ' ),
165
183
array ('index ' => 1 , 'dateString ' => '19970903T090000 ' , 'timezone ' => 'Europe/Berlin ' , 'message ' => '2nd event, CEST: ' ),
166
184
array ('index ' => 9 , 'dateString ' => '19970911T090000 ' , 'timezone ' => 'Europe/Berlin ' , 'message ' => '10th event, CEST: ' ),
167
185
);
168
186
$ this ->assertVEVENT (
169
187
'Europe/Berlin ' ,
170
- " DTSTART;TZID=Europe/Berlin:19970902T090000 " ,
171
- "" ,
172
- " RRULE:FREQ=DAILY;COUNT=10 " ,
188
+ ' DTSTART;TZID=Europe/Berlin:19970902T090000 ' ,
189
+ '' ,
190
+ ' RRULE:FREQ=DAILY;COUNT=10 ' ,
173
191
10 ,
174
- $ checks );
192
+ $ checks
193
+ );
175
194
}
176
195
177
- public function testRFCDaily10BerlinFromNewYork () {
178
- // (1997 9:00 AM CEST)September 2-11
196
+ public function testRFCDaily10BerlinFromNewYork ()
197
+ {
179
198
$ checks = array (
180
199
array ('index ' => 0 , 'dateString ' => '19970902T090000 ' , 'timezone ' => 'Europe/Berlin ' , 'message ' => '1st event, CEST: ' ),
181
200
array ('index ' => 1 , 'dateString ' => '19970903T090000 ' , 'timezone ' => 'Europe/Berlin ' , 'message ' => '2nd event, CEST: ' ),
182
201
array ('index ' => 9 , 'dateString ' => '19970911T090000 ' , 'timezone ' => 'Europe/Berlin ' , 'message ' => '10th event, CEST: ' ),
183
202
);
184
203
$ this ->assertVEVENT (
185
204
'America/New_York ' ,
186
- " DTSTART;TZID=Europe/Berlin:19970902T090000 " ,
187
- "" ,
188
- " RRULE:FREQ=DAILY;COUNT=10 " ,
205
+ ' DTSTART;TZID=Europe/Berlin:19970902T090000 ' ,
206
+ '' ,
207
+ ' RRULE:FREQ=DAILY;COUNT=10 ' ,
189
208
10 ,
190
- $ checks );
209
+ $ checks
210
+ );
191
211
}
192
212
193
- /* ********************************************************************************************* */
194
-
195
- function assertVEVENT ($ defaultTimezone , $ dtstart , $ dtend , $ rrule , $ count , $ checks ) {
213
+ function assertVEVENT ($ defaultTimezone , $ dtstart , $ dtend , $ rrule , $ count , $ checks )
214
+ {
196
215
$ options = $ this ->getOptions ($ defaultTimezone );
197
- $ testIcal = $ this ->getIcalHeader () .
198
- $ this ->formatIcalEvent ($ dtstart , $ dtend , $ rrule ) .
199
- $ this ->getIcalFooter ();
216
+
217
+ $ testIcal = implode (PHP_EOL , $ this ->getIcalHeader ());
218
+ $ testIcal .= PHP_EOL ;
219
+ $ testIcal .= implode (PHP_EOL , $ this ->formatIcalEvent ($ dtstart , $ dtend , $ rrule ));
220
+ $ testIcal .= PHP_EOL ;
221
+ $ testIcal .= implode (PHP_EOL , $ this ->getIcalFooter ());
200
222
201
223
$ ical = new ICal (false , $ options );
202
224
$ ical ->initString ($ testIcal );
@@ -205,12 +227,13 @@ function assertVEVENT($defaultTimezone, $dtstart, $dtend, $rrule, $count, $check
205
227
206
228
$ this ->assertCount ($ count , $ events );
207
229
208
- foreach ($ checks as $ check ) {
230
+ foreach ($ checks as $ check ) {
209
231
$ this ->assertEvent ($ events [$ check ['index ' ]], $ check ['dateString ' ], $ check ['message ' ], isset ($ check ['timezone ' ]) ? $ check ['timezone ' ] : $ defaultTimezone );
210
232
}
211
233
}
212
234
213
- function assertEventFile ($ defaultTimezone , $ file , $ count , $ checks ) {
235
+ function assertEventFile ($ defaultTimezone , $ file , $ count , $ checks )
236
+ {
214
237
$ options = $ this ->getOptions ($ defaultTimezone );
215
238
216
239
$ ical = new ICal ($ file , $ options );
@@ -221,58 +244,70 @@ function assertEventFile($defaultTimezone, $file, $count, $checks) {
221
244
222
245
$ events = $ ical ->sortEventsWithOrder ($ events );
223
246
224
- foreach ($ checks as $ check ) {
247
+ foreach ($ checks as $ check ) {
225
248
$ this ->assertEvent ($ events [$ check ['index ' ]], $ check ['dateString ' ], $ check ['message ' ], isset ($ check ['timezone ' ]) ? $ check ['timezone ' ] : $ defaultTimezone );
226
249
}
227
250
}
228
251
229
- function assertEvent ($ event , $ expectedDateString , $ message , $ timezone = null ) {
252
+ function assertEvent ($ event , $ expectedDateString , $ message , $ timezone = null )
253
+ {
230
254
if ($ timezone !== null ) {
231
255
date_default_timezone_set ($ timezone );
232
256
}
257
+
233
258
$ expectedTimeStamp = strtotime ($ expectedDateString );
234
259
235
- $ this ->assertEquals ($ expectedTimeStamp , $ event ->dtstart_array [2 ], $ message . 'timestamp mismatch (expected ' . $ expectedDateString. ' vs actual ' . $ event ->dtstart . ') ' );
260
+ $ this ->assertEquals ($ expectedTimeStamp , $ event ->dtstart_array [2 ], $ message . 'timestamp mismatch (expected ' . $ expectedDateString . ' vs actual ' . $ event ->dtstart . ') ' );
236
261
$ this ->assertAttributeEquals ($ expectedDateString , 'dtstart ' , $ event , $ message . 'dtstart mismatch (timestamp is okay) ' );
237
262
}
238
263
239
- function getOptions ($ defaultTimezone ) {
264
+ function getOptions ($ defaultTimezone )
265
+ {
240
266
$ options = array (
241
- 'defaultSpan ' => 2 , // Default value
242
- 'defaultTimeZone ' => $ defaultTimezone , // Default value: UTC
243
- 'defaultWeekStart ' => 'MO ' , // Default value
244
- 'disableCharacterReplacement ' => false , // Default value
245
- 'skipRecurrence ' => false , // Default value
267
+ 'defaultSpan ' => 2 , // Default value
268
+ 'defaultTimeZone ' => $ defaultTimezone , // Default value: UTC
269
+ 'defaultWeekStart ' => 'MO ' , // Default value
270
+ 'disableCharacterReplacement ' => false , // Default value
271
+ 'filterDaysAfter ' => null , // Default value
272
+ 'filterDaysBefore ' => null , // Default value
273
+ 'replaceWindowsTimeZoneIds ' => false , // Default value
274
+ 'skipRecurrence ' => false , // Default value
246
275
'useTimeZoneWithRRules ' => $ this ->useTimeZoneWithRRules , // Default value: false
247
276
);
248
277
return $ options ;
249
278
}
250
279
251
- function formatIcalEvent ($ dtstart , $ dtend , $ rrule ) {
252
- return "BEGIN:VEVENT
253
- CREATED:20090213T195947Z
254
- UID:M2CD-1-1-5FB000FB-BBE4-4F3F-9E7E-217F1FF97209
255
- " . $ rrule . PHP_EOL . $ dtstart . PHP_EOL . $ dtend . PHP_EOL .
256
- "SUMMARY:test
257
- LAST-MODIFIED:20110429T222101Z
258
- DTSTAMP:20170630T105724Z
259
- SEQUENCE:0
260
- END:VEVENT
261
- " ;
280
+ function formatIcalEvent ($ dtstart , $ dtend , $ rrule )
281
+ {
282
+ return array (
283
+ 'BEGIN:VEVENT ' ,
284
+ 'CREATED:20090213T195947Z ' ,
285
+ 'UID:M2CD-1-1-5FB000FB-BBE4-4F3F-9E7E-217F1FF97209 ' ,
286
+ $ rrule ,
287
+ $ dtstart ,
288
+ $ dtend ,
289
+ 'SUMMARY:test ' ,
290
+ 'LAST-MODIFIED:20110429T222101Z ' ,
291
+ 'DTSTAMP:20170630T105724Z ' ,
292
+ 'SEQUENCE:0 ' ,
293
+ 'END:VEVENT ' ,
294
+ );
262
295
}
263
296
264
297
function getIcalHeader ()
265
298
{
266
- return "BEGIN:VCALENDAR
267
- VERSION:2.0
268
- X-WR-CALNAME:Privat
269
- X-APPLE-CALENDAR-COLOR:#FF2968
270
- X-WR-CALDESC:
271
- " ;
299
+ return array (
300
+ 'BEGIN:VCALENDAR ' ,
301
+ 'VERSION:2.0 ' ,
302
+ 'PRODID:-//Google Inc//Google Calendar 70.9054//EN ' ,
303
+ 'X-WR-CALNAME:Private ' ,
304
+ 'X-APPLE-CALENDAR-COLOR:#FF2968 ' ,
305
+ 'X-WR-CALDESC: ' ,
306
+ );
272
307
}
273
308
274
- function getIcalFooter () {
275
- return " END:VCALENDAR
276
- " ;
309
+ function getIcalFooter ()
310
+ {
311
+ return array ( ' END:VCALENDAR ' ) ;
277
312
}
278
313
}
0 commit comments