MDL-66871 calendar: add unit test coverage for ics importing
authorSimey Lameze <simey@moodle.com>
Mon, 16 Dec 2019 00:36:56 +0000 (08:36 +0800)
committerSimey Lameze <simey@moodle.com>
Mon, 6 Jan 2020 02:36:35 +0000 (10:36 +0800)
calendar/tests/lib_test.php
lib/tests/fixtures/repeated_events.ics [new file with mode: 0644]

index 96af607..94a3cb4 100644 (file)
@@ -227,6 +227,24 @@ class core_calendar_lib_testcase extends advanced_testcase {
         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 (file)
index 0000000..7157007
--- /dev/null
@@ -0,0 +1,34 @@
+BEGIN:VCALENDAR\r
+PRODID:QIS-LSF HIS eG\r
+VERSION:2.0\r
+BEGIN:VTIMEZONE\r
+TZID:Europe/Berlin\r
+X-LIC-LOCATION:Europe/Berlin\r
+BEGIN:DAYLIGHT\r
+TZOFFSETFROM:+0100\r
+TZOFFSETTO:+0200\r
+TZNAME:CEST\r
+DTSTART:19700329T020000\r
+RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3\r
+END:DAYLIGHT\r
+BEGIN:STANDARD\r
+TZOFFSETFROM:+0200\r
+TZOFFSETTO:+0100\r
+TZNAME:CET\r
+DTSTART:19701025T030000\r
+RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10\r
+END:STANDARD\r
+END:VTIMEZONE\r
+METHOD:PUBLISH\r
+BEGIN:VEVENT\r
+DTSTART;TZID=Europe/Berlin:20191015T160000\r
+DTEND;TZID=Europe/Berlin:20191015T180000\r
+RRULE:FREQ=WEEKLY;UNTIL=20200211T235900Z;INTERVAL=1;BYDAY=TU\r
+LOCATION:O27 - 122\r
+DTSTAMP:20191002T151421Z\r
+UID:115808212972\r
+DESCRIPTION:\r
+SUMMARY:CS6307.000 - Introduction to Computer Science (for Non-Computer Scientists)\r
+CATEGORIES:Vorlesung/ Übung\r
+END:VEVENT\r
+END:VCALENDAR\r