Skip to content

Commit

Permalink
MDL-66871 calendar: add unit test coverage for ics importing
Browse files Browse the repository at this point in the history
  • Loading branch information
lameze committed Jan 6, 2020
1 parent 5b3b975 commit eaf623c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
18 changes: 18 additions & 0 deletions calendar/tests/lib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
34 changes: 34 additions & 0 deletions lib/tests/fixtures/repeated_events.ics
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit eaf623c

Please sign in to comment.