From eaf623c5bfaef20a24361f9465165532193c44c6 Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Mon, 16 Dec 2019 08:36:56 +0800 Subject: [PATCH] MDL-66871 calendar: add unit test coverage for ics importing --- calendar/tests/lib_test.php | 18 ++++++++++++++ lib/tests/fixtures/repeated_events.ics | 34 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 lib/tests/fixtures/repeated_events.ics diff --git a/calendar/tests/lib_test.php b/calendar/tests/lib_test.php index 96af6075ba85e..94a3cb4c9f4d0 100644 --- a/calendar/tests/lib_test.php +++ b/calendar/tests/lib_test.php @@ -227,6 +227,24 @@ public function test_add_subscription() { calendar_import_icalendar_events($ical, null, $sub->id); $count = $DB->count_records('event', array('subscriptionid' => $sub->id)); $this->assertEquals($count, 1); + + // Test for ICS file with repeated events. + $subscription = new stdClass(); + $subscription->name = 'Repeated events'; + $subscription->importfrom = CALENDAR_IMPORT_FROM_FILE; + $subscription->eventtype = 'site'; + $id = calendar_add_subscription($subscription); + $calendar = file_get_contents($CFG->dirroot . '/lib/tests/fixtures/repeated_events.ics'); + $ical = new iCalendar(); + $ical->unserialize($calendar); + $this->assertEquals($ical->parser_errors, []); + + $sub = calendar_get_subscription($id); + $output = calendar_import_icalendar_events($ical, null, $sub->id); + $this->assertStringNotContainsString('Events deleted: 17', $output); + $this->assertStringContainsString('Events imported: 1', $output); + $this->assertStringContainsString('Events skipped: 0', $output); + $this->assertStringContainsString('Events updated: 0', $output); } /** diff --git a/lib/tests/fixtures/repeated_events.ics b/lib/tests/fixtures/repeated_events.ics new file mode 100644 index 0000000000000..7157007a5a2f7 --- /dev/null +++ b/lib/tests/fixtures/repeated_events.ics @@ -0,0 +1,34 @@ +BEGIN:VCALENDAR +PRODID:QIS-LSF HIS eG +VERSION:2.0 +BEGIN:VTIMEZONE +TZID:Europe/Berlin +X-LIC-LOCATION:Europe/Berlin +BEGIN:DAYLIGHT +TZOFFSETFROM:+0100 +TZOFFSETTO:+0200 +TZNAME:CEST +DTSTART:19700329T020000 +RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3 +END:DAYLIGHT +BEGIN:STANDARD +TZOFFSETFROM:+0200 +TZOFFSETTO:+0100 +TZNAME:CET +DTSTART:19701025T030000 +RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10 +END:STANDARD +END:VTIMEZONE +METHOD:PUBLISH +BEGIN:VEVENT +DTSTART;TZID=Europe/Berlin:20191015T160000 +DTEND;TZID=Europe/Berlin:20191015T180000 +RRULE:FREQ=WEEKLY;UNTIL=20200211T235900Z;INTERVAL=1;BYDAY=TU +LOCATION:O27 - 122 +DTSTAMP:20191002T151421Z +UID:115808212972 +DESCRIPTION: +SUMMARY:CS6307.000 - Introduction to Computer Science (for Non-Computer Scientists) +CATEGORIES:Vorlesung/ Übung +END:VEVENT +END:VCALENDAR