Skip to content

Commit 23b3c93

Browse files
author
Coby Tamayo
committed
Test more cases
1 parent 1d1b0e4 commit 23b3c93

File tree

1 file changed

+96
-2
lines changed

1 file changed

+96
-2
lines changed

test/unit/CalendarTest.php

Lines changed: 96 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,12 +320,11 @@ public function test_recurrences_with_overrides() {
320320
],
321321
[
322322
'start' => '11:30:00',
323-
'end' => '17:30:00', // TODO different duration
323+
'end' => '17:30:00',
324324
'BYDAY' => ['SA', 'SU'],
325325
],
326326
],
327327
],
328-
'recurrence_description' => 'Thrice.',
329328
],
330329
];
331330

@@ -351,6 +350,101 @@ public function test_recurrences_with_overrides() {
351350
], $starts);
352351
}
353352

353+
public function test_recurrences_with_overrides_weekly() {
354+
// single event series:
355+
// - 3/1 - 3/7 M/W/F 10am - 3pm, Sat/Sun 11:30am - 4:30pm
356+
$events = [
357+
[
358+
'start' => '2021-03-01 10:00:00',
359+
'end' => '2021-03-01 15:00:00',
360+
'title' => 'Three Times',
361+
'recurrence' => [
362+
'until' => '2021-03-07 15:00:00',
363+
'frequency' => 'Weekly',
364+
'exceptions' => [],
365+
'overrides' => [
366+
[
367+
'start' => '10:00:00',
368+
'end' => '15:00:00',
369+
'BYDAY' => ['MO', 'WE', 'FR'],
370+
],
371+
[
372+
'start' => '11:30:00',
373+
'end' => '17:30:00',
374+
'BYDAY' => ['SA', 'SU'],
375+
],
376+
],
377+
],
378+
],
379+
];
380+
381+
$calendar = new Calendar($events);
382+
383+
$starts = array_map(function(array $recurrence) {
384+
return sprintf(
385+
'%s - %s',
386+
$recurrence['start'],
387+
gmdate('H:i:s', strtotime($recurrence['end']))
388+
);
389+
}, $calendar->recurrences());
390+
391+
$this->assertEquals([
392+
'2021-03-01 10:00:00 - 15:00:00',
393+
'2021-03-03 10:00:00 - 15:00:00',
394+
'2021-03-05 10:00:00 - 15:00:00',
395+
'2021-03-06 11:30:00 - 17:30:00',
396+
'2021-03-07 11:30:00 - 17:30:00',
397+
], $starts);
398+
}
399+
400+
public function test_recurrences_with_overrides_monthly() {
401+
// single event series:
402+
// - 3/1 - 5/17 every 1st Mon at 5pm & every 3rd Mon at 3pm
403+
$events = [
404+
[
405+
'start' => '2021-03-01 10:00:00',
406+
'end' => '2021-03-01 15:00:00',
407+
'title' => 'Three Times',
408+
'recurrence' => [
409+
'until' => '2021-05-17 15:00:00',
410+
'frequency' => 'Monthly',
411+
'exceptions' => [],
412+
'overrides' => [
413+
[
414+
'start' => '17:00:00',
415+
'end' => '18:00:00',
416+
'BYDAY' => '1MO',
417+
],
418+
[
419+
'start' => '15:00:00',
420+
'end' => '16:00:00',
421+
'BYDAY' => '3MO',
422+
],
423+
],
424+
],
425+
],
426+
];
427+
428+
$calendar = new Calendar($events);
429+
430+
$starts = array_map(function(array $recurrence) {
431+
return sprintf(
432+
'%s - %s',
433+
$recurrence['start'],
434+
gmdate('H:i:s', strtotime($recurrence['end']))
435+
);
436+
}, $calendar->recurrences());
437+
438+
$this->assertEquals([
439+
'2021-03-01 17:00:00 - 18:00:00',
440+
'2021-03-15 15:00:00 - 16:00:00',
441+
'2021-04-05 17:00:00 - 18:00:00',
442+
'2021-04-19 15:00:00 - 16:00:00',
443+
'2021-05-03 17:00:00 - 18:00:00',
444+
'2021-05-17 15:00:00 - 16:00:00',
445+
], $starts);
446+
}
447+
354448
/**
355449
* Test sorting issue: https://github.com/sitecrafting/greg/issues/4
356450
*/

0 commit comments

Comments
 (0)