Skip to content

Commit 805cdf8

Browse files
committed
RE: #209, #210 and #211 - use correct line endings in test iCal strings
Update options to define all possible values Only use double quotes when necessary
1 parent d4a1c36 commit 805cdf8

File tree

4 files changed

+608
-534
lines changed

4 files changed

+608
-534
lines changed

tests/RecurrencesTest.php

Lines changed: 129 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -5,77 +5,87 @@
55

66
class RecurrencesTest extends TestCase
77
{
8-
98
private $useTimeZoneWithRRules = false;
109
private $originalTimeZone = null;
1110

12-
public function setUp() {
11+
public function setUp()
12+
{
1313
$this->originalTimeZone = date_default_timezone_get();
1414
}
1515

16-
public function tearDown() {
16+
public function tearDown()
17+
{
1718
date_default_timezone_set($this->originalTimeZone);
1819
}
1920

20-
public function testYearlyFullDayTimeZoneBerlin() {
21+
public function testYearlyFullDayTimeZoneBerlin()
22+
{
2123
$checks = array(
2224
array('index' => 0, 'dateString' => '20000301', 'message' => '1st event, CET: '),
2325
array('index' => 1, 'dateString' => '20010301T000000', 'message' => '2nd event, CET: '),
2426
array('index' => 2, 'dateString' => '20020301T000000', 'message' => '3rd event, CET: '),
2527
);
2628
$this->assertVEVENT(
2729
'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',
3133
3,
32-
$checks);
34+
$checks
35+
);
3336
}
3437

35-
public function testMonthlyFullDayTimeZoneBerlin() {
38+
public function testMonthlyFullDayTimeZoneBerlin()
39+
{
3640
$checks = array(
3741
array('index' => 0, 'dateString' => '20000301', 'message' => '1st event, CET: '),
3842
array('index' => 1, 'dateString' => '20000401T000000', 'message' => '2nd event, CEST: '),
3943
array('index' => 2, 'dateString' => '20000501T000000', 'message' => '3rd event, CEST: '),
4044
);
4145
$this->assertVEVENT(
4246
'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',
4650
3,
47-
$checks);
51+
$checks
52+
);
4853
}
4954

50-
public function testMonthlyFullDayTimeZoneBerlinSummerTime() {
55+
public function testMonthlyFullDayTimeZoneBerlinSummerTime()
56+
{
5157
$checks = array(
5258
array('index' => 0, 'dateString' => '20180701', 'message' => '1st event, CEST: '),
5359
array('index' => 1, 'dateString' => '20180801T000000', 'message' => '2nd event, CEST: '),
5460
array('index' => 2, 'dateString' => '20180901T000000', 'message' => '3rd event, CEST: '),
5561
);
5662
$this->assertVEVENT(
5763
'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',
6167
3,
62-
$checks);
68+
$checks
69+
);
6370
}
6471

65-
public function testMonthlyFullDayTimeZoneBerlinFromFile() {
72+
public function testMonthlyFullDayTimeZoneBerlinFromFile()
73+
{
6674
$checks = array(
6775
array('index' => 0, 'dateString' => '20180701', 'message' => '1st event, CEST: '),
6876
array('index' => 1, 'dateString' => '20180801T000000', 'message' => '2nd event, CEST: '),
6977
array('index' => 2, 'dateString' => '20180901T000000', 'message' => '3rd event, CEST: '),
7078
);
7179
$this->assertEventFile(
7280
'Europe/Berlin',
73-
"./tests/ical/ical-monthly.ics",
81+
'./tests/ical/ical-monthly.ics',
7482
25,
75-
$checks);
83+
$checks
84+
);
7685
}
7786

78-
public function testIssue196FromFile() {
87+
public function testIssue196FromFile()
88+
{
7989
$checks = array(
8090
array('index' => 0, 'dateString' => '20191105T190000', 'timezone' => 'Europe/Berlin', 'message' => '1st event, CEST: '),
8191
array('index' => 1, 'dateString' => '20191106T190000', 'timezone' => 'Europe/Berlin', 'message' => '2nd event, CEST: '),
@@ -86,12 +96,14 @@ public function testIssue196FromFile() {
8696
);
8797
$this->assertEventFile(
8898
'UTC',
89-
"./tests/ical/issue-196.ics",
99+
'./tests/ical/issue-196.ics',
90100
6,
91-
$checks);
101+
$checks
102+
);
92103
}
93104

94-
public function testWeeklyFullDayTimeZoneBerlin() {
105+
public function testWeeklyFullDayTimeZoneBerlin()
106+
{
95107
$checks = array(
96108
array('index' => 0, 'dateString' => '20000301', 'message' => '1st event, CET: '),
97109
array('index' => 1, 'dateString' => '20000308T000000', 'message' => '2nd event, CET: '),
@@ -102,29 +114,33 @@ public function testWeeklyFullDayTimeZoneBerlin() {
102114
);
103115
$this->assertVEVENT(
104116
'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',
108120
6,
109-
$checks);
121+
$checks
122+
);
110123
}
111124

112-
public function testDailyFullDayTimeZoneBerlin() {
125+
public function testDailyFullDayTimeZoneBerlin()
126+
{
113127
$checks = array(
114128
array('index' => 0, 'dateString' => '20000301', 'message' => '1st event, CET: '),
115129
array('index' => 1, 'dateString' => '20000302T000000', 'message' => '2nd event, CET: '),
116130
array('index' => 30, 'dateString' => '20000331T000000', 'message' => '31st event, CEST: '),
117131
);
118132
$this->assertVEVENT(
119133
'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',
123137
31,
124-
$checks);
138+
$checks
139+
);
125140
}
126141

127-
public function testWeeklyFullDayTimeZoneBerlinLocal() {
142+
public function testWeeklyFullDayTimeZoneBerlinLocal()
143+
{
128144
$checks = array(
129145
array('index' => 0, 'dateString' => '20000301T000000', 'message' => '1st event, CET: '),
130146
array('index' => 1, 'dateString' => '20000308T000000', 'message' => '2nd event, CET: '),
@@ -135,68 +151,74 @@ public function testWeeklyFullDayTimeZoneBerlinLocal() {
135151
);
136152
$this->assertVEVENT(
137153
'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',
141157
6,
142-
$checks);
158+
$checks
159+
);
143160
}
144161

145-
public function testRFCDaily10NewYork() {
146-
// (1997 9:00 AM EDT)September 2-11
162+
public function testRFCDaily10NewYork()
163+
{
147164
$checks = array(
148165
array('index' => 0, 'dateString' => '19970902T090000', 'timezone' => 'America/New_York', 'message' => '1st event, EDT: '),
149166
array('index' => 1, 'dateString' => '19970903T090000', 'timezone' => 'America/New_York', 'message' => '2nd event, EDT: '),
150167
array('index' => 9, 'dateString' => '19970911T090000', 'timezone' => 'America/New_York', 'message' => '10th event, EDT: '),
151168
);
152169
$this->assertVEVENT(
153170
'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',
157174
10,
158-
$checks);
175+
$checks
176+
);
159177
}
160178

161-
public function testRFCDaily10Berlin() {
162-
// (1997 9:00 AM CEST)September 2-11
179+
public function testRFCDaily10Berlin()
180+
{
163181
$checks = array(
164182
array('index' => 0, 'dateString' => '19970902T090000', 'timezone' => 'Europe/Berlin', 'message' => '1st event, CEST: '),
165183
array('index' => 1, 'dateString' => '19970903T090000', 'timezone' => 'Europe/Berlin', 'message' => '2nd event, CEST: '),
166184
array('index' => 9, 'dateString' => '19970911T090000', 'timezone' => 'Europe/Berlin', 'message' => '10th event, CEST: '),
167185
);
168186
$this->assertVEVENT(
169187
'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',
173191
10,
174-
$checks);
192+
$checks
193+
);
175194
}
176195

177-
public function testRFCDaily10BerlinFromNewYork() {
178-
// (1997 9:00 AM CEST)September 2-11
196+
public function testRFCDaily10BerlinFromNewYork()
197+
{
179198
$checks = array(
180199
array('index' => 0, 'dateString' => '19970902T090000', 'timezone' => 'Europe/Berlin', 'message' => '1st event, CEST: '),
181200
array('index' => 1, 'dateString' => '19970903T090000', 'timezone' => 'Europe/Berlin', 'message' => '2nd event, CEST: '),
182201
array('index' => 9, 'dateString' => '19970911T090000', 'timezone' => 'Europe/Berlin', 'message' => '10th event, CEST: '),
183202
);
184203
$this->assertVEVENT(
185204
'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',
189208
10,
190-
$checks);
209+
$checks
210+
);
191211
}
192212

193-
/* ********************************************************************************************* */
194-
195-
function assertVEVENT($defaultTimezone, $dtstart, $dtend, $rrule, $count, $checks) {
213+
function assertVEVENT($defaultTimezone, $dtstart, $dtend, $rrule, $count, $checks)
214+
{
196215
$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());
200222

201223
$ical = new ICal(false, $options);
202224
$ical->initString($testIcal);
@@ -205,12 +227,13 @@ function assertVEVENT($defaultTimezone, $dtstart, $dtend, $rrule, $count, $check
205227

206228
$this->assertCount($count, $events);
207229

208-
foreach($checks as $check) {
230+
foreach ($checks as $check) {
209231
$this->assertEvent($events[$check['index']], $check['dateString'], $check['message'], isset($check['timezone']) ? $check['timezone'] : $defaultTimezone);
210232
}
211233
}
212234

213-
function assertEventFile($defaultTimezone, $file, $count, $checks) {
235+
function assertEventFile($defaultTimezone, $file, $count, $checks)
236+
{
214237
$options = $this->getOptions($defaultTimezone);
215238

216239
$ical = new ICal($file, $options);
@@ -221,58 +244,70 @@ function assertEventFile($defaultTimezone, $file, $count, $checks) {
221244

222245
$events = $ical->sortEventsWithOrder($events);
223246

224-
foreach($checks as $check) {
247+
foreach ($checks as $check) {
225248
$this->assertEvent($events[$check['index']], $check['dateString'], $check['message'], isset($check['timezone']) ? $check['timezone'] : $defaultTimezone);
226249
}
227250
}
228251

229-
function assertEvent($event, $expectedDateString, $message, $timezone = null) {
252+
function assertEvent($event, $expectedDateString, $message, $timezone = null)
253+
{
230254
if ($timezone !== null) {
231255
date_default_timezone_set($timezone);
232256
}
257+
233258
$expectedTimeStamp = strtotime($expectedDateString);
234259

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 . ')');
236261
$this->assertAttributeEquals($expectedDateString, 'dtstart', $event, $message . 'dtstart mismatch (timestamp is okay)');
237262
}
238263

239-
function getOptions($defaultTimezone) {
264+
function getOptions($defaultTimezone)
265+
{
240266
$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
246275
'useTimeZoneWithRRules' => $this->useTimeZoneWithRRules, // Default value: false
247276
);
248277
return $options;
249278
}
250279

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+
);
262295
}
263296

264297
function getIcalHeader()
265298
{
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+
);
272307
}
273308

274-
function getIcalFooter() {
275-
return "END:VCALENDAR
276-
";
309+
function getIcalFooter()
310+
{
311+
return array('END:VCALENDAR');
277312
}
278313
}

0 commit comments

Comments
 (0)