annotate plugins/libcalendaring/tests/libvcalendar.php @ 4:888e774ee983

libcalendar plugin as distributed
author Charlie Root
date Sat, 13 Jan 2018 08:57:56 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1 <?php
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
2
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
3 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
4 * libcalendaring plugin's iCalendar functions tests
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
5 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
6 * @author Thomas Bruederli <bruederli@kolabsys.com>
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
7 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
8 * Copyright (C) 2014, Kolab Systems AG <contact@kolabsys.com>
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
9 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
10 * This program is free software: you can redistribute it and/or modify
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
11 * it under the terms of the GNU Affero General Public License as
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
12 * published by the Free Software Foundation, either version 3 of the
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
13 * License, or (at your option) any later version.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
14 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
15 * This program is distributed in the hope that it will be useful,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
18 * GNU Affero General Public License for more details.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
19 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
20 * You should have received a copy of the GNU Affero General Public License
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
22 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
23
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
24 class libvcalendar_test extends PHPUnit_Framework_TestCase
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
25 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
26 function setUp()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
27 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
28 require_once __DIR__ . '/../libvcalendar.php';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
29 require_once __DIR__ . '/../libcalendaring.php';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
30 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
31
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
32 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
33 * Simple iCal parsing test
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
34 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
35 function test_import()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
36 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
37 $ical = new libvcalendar();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
38 $ics = file_get_contents(__DIR__ . '/resources/snd.ics');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
39 $events = $ical->import($ics, 'UTF-8');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
40
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
41 $this->assertEquals(1, count($events));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
42 $event = $events[0];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
43
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
44 $this->assertInstanceOf('DateTime', $event['created'], "'created' property is DateTime object");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
45 $this->assertInstanceOf('DateTime', $event['changed'], "'changed' property is DateTime object");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
46 $this->assertEquals('UTC', $event['created']->getTimezone()->getName(), "'created' date is in UTC");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
47
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
48 $this->assertInstanceOf('DateTime', $event['start'], "'start' property is DateTime object");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
49 $this->assertInstanceOf('DateTime', $event['end'], "'end' property is DateTime object");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
50 $this->assertEquals('08-01', $event['start']->format('m-d'), "Start date is August 1st");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
51 $this->assertTrue($event['allday'], "All-day event flag");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
52
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
53 $this->assertEquals('B968B885-08FB-40E5-B89E-6DA05F26AA79', $event['uid'], "Event UID");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
54 $this->assertEquals('Swiss National Day', $event['title'], "Event title");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
55 $this->assertEquals('http://en.wikipedia.org/wiki/Swiss_National_Day', $event['url'], "URL property");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
56 $this->assertEquals(2, $event['sequence'], "Sequence number");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
57
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
58 $desclines = explode("\n", $event['description']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
59 $this->assertEquals(4, count($desclines), "Multiline description");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
60 $this->assertEquals("French: FĂȘte nationale Suisse", rtrim($desclines[1]), "UTF-8 encoding");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
61 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
62
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
63 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
64 * Test parsing from files
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
65 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
66 function test_import_from_file()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
67 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
68 $ical = new libvcalendar();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
69
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
70 $events = $ical->import_from_file(__DIR__ . '/resources/multiple.ics', 'UTF-8');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
71 $this->assertEquals(2, count($events));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
72
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
73 $events = $ical->import_from_file(__DIR__ . '/resources/invalid.txt', 'UTF-8');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
74 $this->assertEmpty($events);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
75 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
76
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
77 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
78 * Test parsing from files with multiple VCALENDAR blocks (#2884)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
79 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
80 function test_import_from_file_multiple()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
81 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
82 $ical = new libvcalendar();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
83 $ical->fopen(__DIR__ . '/resources/multiple-rdate.ics', 'UTF-8');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
84 $events = array();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
85 foreach ($ical as $event) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
86 $events[] = $event;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
87 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
88
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
89 $this->assertEquals(2, count($events));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
90 $this->assertEquals("AAAA6A8C3CCE4EE2C1257B5C00FFFFFF-Lotus_Notes_Generated", $events[0]['uid']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
91 $this->assertEquals("AAAA1C572093EC3FC125799C004AFFFF-Lotus_Notes_Generated", $events[1]['uid']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
92 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
93
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
94 function test_invalid_dates()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
95 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
96 $ical = new libvcalendar();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
97 $events = $ical->import_from_file(__DIR__ . '/resources/invalid-dates.ics', 'UTF-8');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
98 $event = $events[0];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
99
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
100 $this->assertEquals(1, count($events), "Import event data");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
101 $this->assertInstanceOf('DateTime', $event['created'], "Created date field");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
102 $this->assertFalse(array_key_exists('changed', $event), "No changed date field");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
103 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
104
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
105 function test_invalid_vevent()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
106 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
107 $this->setExpectedException('\Sabre\VObject\ParseException');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
108
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
109 $ical = new libvcalendar();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
110 $events = $ical->import_from_file(__DIR__ . '/resources/invalid-event.ics', 'UTF-8', true);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
111 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
112
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
113 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
114 * Test some extended ical properties such as attendees, recurrence rules, alarms and attachments
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
115 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
116 function test_extended()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
117 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
118 $ical = new libvcalendar();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
119
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
120 $events = $ical->import_from_file(__DIR__ . '/resources/itip.ics', 'UTF-8');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
121 $event = $events[0];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
122 $this->assertEquals('REQUEST', $ical->method, "iTip method");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
123
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
124 // attendees
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
125 $this->assertEquals(3, count($event['attendees']), "Attendees list (including organizer)");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
126 $organizer = $event['attendees'][0];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
127 $this->assertEquals('ORGANIZER', $organizer['role'], 'Organizer ROLE');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
128 $this->assertEquals('Rolf Test', $organizer['name'], 'Organizer name');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
129
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
130 $attendee = $event['attendees'][1];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
131 $this->assertEquals('REQ-PARTICIPANT', $attendee['role'], 'Attendee ROLE');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
132 $this->assertEquals('NEEDS-ACTION', $attendee['status'], 'Attendee STATUS');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
133 $this->assertEquals('rolf2@mykolab.com', $attendee['email'], 'Attendee mailto:');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
134 $this->assertEquals('carl@mykolab.com', $attendee['delegated-from'], 'Attendee delegated-from');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
135 $this->assertTrue($attendee['rsvp'], 'Attendee RSVP');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
136
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
137 $delegator = $event['attendees'][2];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
138 $this->assertEquals('NON-PARTICIPANT', $delegator['role'], 'Delegator ROLE');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
139 $this->assertEquals('DELEGATED', $delegator['status'], 'Delegator STATUS');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
140 $this->assertEquals('INDIVIDUAL', $delegator['cutype'], 'Delegator CUTYPE');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
141 $this->assertEquals('carl@mykolab.com', $delegator['email'], 'Delegator mailto:');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
142 $this->assertEquals('rolf2@mykolab.com', $delegator['delegated-to'], 'Delegator delegated-to');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
143 $this->assertFalse($delegator['rsvp'], 'Delegator RSVP');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
144
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
145 // attachments
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
146 $this->assertEquals(1, count($event['attachments']), "Embedded attachments");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
147 $attachment = $event['attachments'][0];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
148 $this->assertEquals('text/html', $attachment['mimetype'], "Attachment mimetype attribute");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
149 $this->assertEquals('calendar.html', $attachment['name'], "Attachment filename (X-LABEL) attribute");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
150 $this->assertContains('<title>Kalender</title>', $attachment['data'], "Attachment content (decoded)");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
151
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
152 // recurrence rules
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
153 $events = $ical->import_from_file(__DIR__ . '/resources/recurring.ics', 'UTF-8');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
154 $event = $events[0];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
155
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
156 $this->assertTrue(is_array($event['recurrence']), 'Recurrences rule as hash array');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
157 $rrule = $event['recurrence'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
158 $this->assertEquals('MONTHLY', $rrule['FREQ'], "Recurrence frequency");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
159 $this->assertEquals('1', $rrule['INTERVAL'], "Recurrence interval");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
160 $this->assertEquals('3WE', $rrule['BYDAY'], "Recurrence frequency");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
161 $this->assertInstanceOf('DateTime', $rrule['UNTIL'], "Recurrence end date");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
162
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
163 $this->assertEquals(2, count($rrule['EXDATE']), "Recurrence EXDATEs");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
164 $this->assertInstanceOf('DateTime', $rrule['EXDATE'][0], "Recurrence EXDATE as DateTime");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
165
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
166 $this->assertTrue(is_array($rrule['EXCEPTIONS']));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
167 $this->assertEquals(1, count($rrule['EXCEPTIONS']), "Recurrence Exceptions");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
168
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
169 $exception = $rrule['EXCEPTIONS'][0];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
170 $this->assertEquals($event['uid'], $event['uid'], "Exception UID");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
171 $this->assertEquals('Recurring Test (Exception)', $exception['title'], "Exception title");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
172 $this->assertInstanceOf('DateTime', $exception['start'], "Exception start");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
173
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
174 // categories, class
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
175 $this->assertEquals('libcalendaring tests', join(',', (array)$event['categories']), "Event categories");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
176 $this->assertEquals('confidential', $event['sensitivity'], "Class/sensitivity = confidential");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
177
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
178 // parse a recurrence chain instance
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
179 $events = $ical->import_from_file(__DIR__ . '/resources/recurrence-id.ics', 'UTF-8');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
180 $this->assertEquals(1, count($events), "Fall back to Component::getComponents() when getBaseComponents() is empty");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
181 $this->assertInstanceOf('DateTime', $events[0]['recurrence_date'], "Recurrence-ID as date");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
182 $this->assertTrue($events[0]['thisandfuture'], "Range=THISANDFUTURE");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
183
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
184 $this->assertEquals(count($events[0]['exceptions']), 1, "Second VEVENT as exception");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
185 $this->assertEquals($events[0]['exceptions'][0]['uid'], $events[0]['uid'], "Exception UID match");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
186 $this->assertEquals($events[0]['exceptions'][0]['sequence'], '2', "Exception sequence");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
187 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
188
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
189 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
190 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
191 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
192 function test_alarms()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
193 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
194 $ical = new libvcalendar();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
195
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
196 $events = $ical->import_from_file(__DIR__ . '/resources/recurring.ics', 'UTF-8');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
197 $event = $events[0];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
198
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
199 $this->assertEquals('-12H:DISPLAY', $event['alarms'], "Serialized alarms string");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
200 $alarm = libcalendaring::parse_alarm_value($event['alarms']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
201 $this->assertEquals('12', $alarm[0], "Alarm value");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
202 $this->assertEquals('-H', $alarm[1], "Alarm unit");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
203
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
204 $this->assertEquals('DISPLAY', $event['valarms'][0]['action'], "Full alarm item (action)");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
205 $this->assertEquals('-PT12H', $event['valarms'][0]['trigger'], "Full alarm item (trigger)");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
206 $this->assertEquals('END', $event['valarms'][0]['related'], "Full alarm item (related)");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
207
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
208 // alarm trigger with 0 values
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
209 $events = $ical->import_from_file(__DIR__ . '/resources/alarms.ics', 'UTF-8');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
210 $event = $events[0];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
211
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
212 $this->assertEquals('-30M:DISPLAY', $event['alarms'], "Stripped alarm string");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
213 $alarm = libcalendaring::parse_alarm_value($event['alarms']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
214 $this->assertEquals('30', $alarm[0], "Alarm value");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
215 $this->assertEquals('-M', $alarm[1], "Alarm unit");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
216 $this->assertEquals('-30M', $alarm[2], "Alarm string");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
217 $this->assertEquals('-PT30M', $alarm[3], "Unified alarm string (stripped zero-values)");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
218
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
219 $this->assertEquals('DISPLAY', $event['valarms'][0]['action'], "First alarm action");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
220 $this->assertEquals('', $event['valarms'][0]['related'], "First alarm related property");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
221 $this->assertEquals('This is the first event reminder', $event['valarms'][0]['description'], "First alarm text");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
222
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
223 $this->assertEquals(3, count($event['valarms']), "List all VALARM blocks");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
224
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
225 $valarm = $event['valarms'][1];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
226 $this->assertEquals(1, count($valarm['attendees']), "Email alarm attendees");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
227 $this->assertEquals('EMAIL', $valarm['action'], "Second alarm item (action)");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
228 $this->assertEquals('-P1D', $valarm['trigger'], "Second alarm item (trigger)");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
229 $this->assertEquals('This is the reminder message', $valarm['summary'], "Email alarm text");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
230 $this->assertInstanceOf('DateTime', $event['valarms'][2]['trigger'], "Absolute trigger date/time");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
231
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
232 // test alarms export
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
233 $ics = $ical->export(array($event));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
234 $this->assertContains('ACTION:DISPLAY', $ics, "Display alarm block");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
235 $this->assertContains('ACTION:EMAIL', $ics, "Email alarm block");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
236 $this->assertContains('DESCRIPTION:This is the first event reminder', $ics, "Alarm description");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
237 $this->assertContains('SUMMARY:This is the reminder message', $ics, "Email alarm summary");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
238 $this->assertContains('ATTENDEE:mailto:reminder-recipient@example.org', $ics, "Email alarm recipient");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
239 $this->assertContains('TRIGGER;VALUE=DATE-TIME:20130812', $ics, "Date-Time trigger");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
240 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
241
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
242 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
243 * @depends test_import_from_file
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
244 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
245 function test_attachment()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
246 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
247 $ical = new libvcalendar();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
248
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
249 $events = $ical->import_from_file(__DIR__ . '/resources/attachment.ics', 'UTF-8');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
250 $event = $events[0];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
251
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
252 $this->assertEquals(2, count($events));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
253 $this->assertEquals(1, count($event['attachments']));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
254 $this->assertEquals('image/png', $event['attachments'][0]['mimetype']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
255 $this->assertEquals('500px-Opensource.svg.png', $event['attachments'][0]['name']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
256 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
257
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
258 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
259 * @depends test_import
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
260 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
261 function test_apple_alarms()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
262 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
263 $ical = new libvcalendar();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
264 $events = $ical->import_from_file(__DIR__ . '/resources/apple-alarms.ics', 'UTF-8');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
265 $event = $events[0];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
266
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
267 // alarms
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
268 $this->assertEquals('-45M:AUDIO', $event['alarms'], "Relative alarm string");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
269 $alarm = libcalendaring::parse_alarm_value($event['alarms']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
270 $this->assertEquals('45', $alarm[0], "Alarm value");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
271 $this->assertEquals('-M', $alarm[1], "Alarm unit");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
272
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
273 $this->assertEquals(1, count($event['valarms']), "Ignore invalid alarm blocks");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
274 $this->assertEquals('AUDIO', $event['valarms'][0]['action'], "Full alarm item (action)");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
275 $this->assertEquals('-PT45M', $event['valarms'][0]['trigger'], "Full alarm item (trigger)");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
276 $this->assertEquals('Basso', $event['valarms'][0]['uri'], "Full alarm item (attachment)");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
277 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
278
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
279 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
280 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
281 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
282 function test_escaped_values()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
283 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
284 $ical = new libvcalendar();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
285 $events = $ical->import_from_file(__DIR__ . '/resources/escaped.ics', 'UTF-8');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
286 $event = $events[0];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
287
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
288 $this->assertEquals("House, Street, Zip Place", $event['location'], "Decode escaped commas in location value");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
289 $this->assertEquals("Me, meets Them\nThem, meet Me", $event['description'], "Decode description value");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
290 $this->assertEquals("Kolab, Thomas", $event['attendees'][3]['name'], "Unescaped");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
291
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
292 $ics = $ical->export($events);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
293 $this->assertContains('ATTENDEE;CN="Kolab, Thomas";PARTSTAT=', $ics, "Quoted attendee parameters");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
294 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
295
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
296 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
297 * Parse RDATE properties (#2885)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
298 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
299 function test_rdate()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
300 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
301 $ical = new libvcalendar();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
302 $events = $ical->import_from_file(__DIR__ . '/resources/multiple-rdate.ics', 'UTF-8');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
303 $event = $events[0];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
304
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
305 $this->assertEquals(9, count($event['recurrence']['RDATE']));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
306 $this->assertInstanceOf('DateTime', $event['recurrence']['RDATE'][0]);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
307 $this->assertInstanceOf('DateTime', $event['recurrence']['RDATE'][1]);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
308 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
309
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
310 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
311 * @depends test_import
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
312 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
313 function test_freebusy()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
314 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
315 $ical = new libvcalendar();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
316 $ical->import_from_file(__DIR__ . '/resources/freebusy.ifb', 'UTF-8');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
317 $freebusy = $ical->freebusy;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
318
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
319 $this->assertInstanceOf('DateTime', $freebusy['start'], "'start' property is DateTime object");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
320 $this->assertInstanceOf('DateTime', $freebusy['end'], "'end' property is DateTime object");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
321 $this->assertEquals(11, count($freebusy['periods']), "Number of freebusy periods defined");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
322 $periods = $ical->get_busy_periods();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
323 $this->assertEquals(9, count($periods), "Number of busy periods found");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
324 $this->assertEquals('BUSY-TENTATIVE', $periods[8][2], "FBTYPE=BUSY-TENTATIVE");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
325 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
326
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
327 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
328 * @depends test_import
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
329 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
330 function test_freebusy_dummy()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
331 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
332 $ical = new libvcalendar();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
333 $ical->import_from_file(__DIR__ . '/resources/dummy.ifb', 'UTF-8');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
334 $freebusy = $ical->freebusy;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
335
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
336 $this->assertEquals(0, count($freebusy['periods']), "Ignore 0-length freebudy periods");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
337 $this->assertContains('dummy', $freebusy['comment'], "Parse comment");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
338 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
339
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
340 function test_vtodo()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
341 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
342 $ical = new libvcalendar();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
343 $tasks = $ical->import_from_file(__DIR__ . '/resources/vtodo.ics', 'UTF-8', true);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
344 $task = $tasks[0];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
345
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
346 $this->assertInstanceOf('DateTime', $task['start'], "'start' property is DateTime object");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
347 $this->assertInstanceOf('DateTime', $task['due'], "'due' property is DateTime object");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
348 $this->assertEquals('-1D:DISPLAY', $task['alarms'], "Taks alarm value");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
349 $this->assertEquals('IN-PROCESS', $task['status'], "Task status property");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
350 $this->assertEquals(1, count($task['x-custom']), "Custom properties");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
351 $this->assertEquals(4, count($task['categories']));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
352 $this->assertEquals('1234567890-12345678-PARENT', $task['parent_id'], "Parent Relation");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
353
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
354 $completed = $tasks[1];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
355 $this->assertEquals('COMPLETED', $completed['status'], "Task status=completed when COMPLETED property is present");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
356 $this->assertEquals(100, $completed['complete'], "Task percent complete value");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
357
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
358 $ics = $ical->export(array($completed));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
359 $this->assertRegExp('/COMPLETED(;VALUE=DATE-TIME)?:[0-9TZ]+/', $ics, "Export COMPLETED property");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
360 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
361
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
362 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
363 * Test for iCal export from internal hash array representation
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
364 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
365 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
366 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
367 function test_export()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
368 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
369 $ical = new libvcalendar();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
370
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
371 $events = $ical->import_from_file(__DIR__ . '/resources/itip.ics', 'UTF-8');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
372 $event = $events[0];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
373 $events = $ical->import_from_file(__DIR__ . '/resources/recurring.ics', 'UTF-8');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
374 $event += $events[0];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
375
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
376 $this->attachment_data = $event['attachments'][0]['data'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
377 unset($event['attachments'][0]['data']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
378 $event['attachments'][0]['id'] = '1';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
379 $event['description'] = '*Exported by libvcalendar*';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
380
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
381 $event['start']->setTimezone(new DateTimezone('America/Montreal'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
382 $event['end']->setTimezone(new DateTimezone('Europe/Berlin'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
383
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
384 $ics = $ical->export(array($event), 'REQUEST', false, array($this, 'get_attachment_data'), true);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
385
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
386 $this->assertContains('BEGIN:VCALENDAR', $ics, "VCALENDAR encapsulation BEGIN");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
387
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
388 $this->assertContains('BEGIN:VTIMEZONE', $ics, "VTIMEZONE encapsulation BEGIN");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
389 $this->assertContains('TZID:Europe/Berlin', $ics, "Timezone ID");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
390 $this->assertContains('TZOFFSETFROM:+0100', $ics, "Timzone transition FROM");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
391 $this->assertContains('TZOFFSETTO:+0200', $ics, "Timzone transition TO");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
392 $this->assertContains('TZOFFSETFROM:-0400', $ics, "TZOFFSETFROM with negative offset (Bug T428)");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
393 $this->assertContains('TZOFFSETTO:-0500', $ics, "TZOFFSETTO with negative offset (Bug T428)");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
394 $this->assertContains('END:VTIMEZONE', $ics, "VTIMEZONE encapsulation END");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
395
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
396 $this->assertContains('BEGIN:VEVENT', $ics, "VEVENT encapsulation BEGIN");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
397 $this->assertSame(2, substr_count($ics, 'DTSTAMP'), "Duplicate DTSTAMP (T1148)");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
398 $this->assertContains('UID:ac6b0aee-2519-4e5c-9a25-48c57064c9f0', $ics, "Event UID");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
399 $this->assertContains('SEQUENCE:' . $event['sequence'], $ics, "Export Sequence number");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
400 $this->assertContains('CLASS:CONFIDENTIAL', $ics, "Sensitivity => Class");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
401 $this->assertContains('DESCRIPTION:*Exported by', $ics, "Export Description");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
402 $this->assertContains('ORGANIZER;CN=Rolf Test:mailto:rolf@', $ics, "Export organizer");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
403 $this->assertRegExp('/ATTENDEE.*;ROLE=REQ-PARTICIPANT/', $ics, "Export Attendee ROLE");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
404 $this->assertRegExp('/ATTENDEE.*;PARTSTAT=NEEDS-ACTION/', $ics, "Export Attendee Status");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
405 $this->assertRegExp('/ATTENDEE.*;RSVP=TRUE/', $ics, "Export Attendee RSVP");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
406 $this->assertRegExp('/:mailto:rolf2@/', $ics, "Export Attendee mailto:");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
407
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
408 $rrule = $event['recurrence'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
409 $this->assertRegExp('/RRULE:.*FREQ='.$rrule['FREQ'].'/', $ics, "Export Recurrence Frequence");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
410 $this->assertRegExp('/RRULE:.*INTERVAL='.$rrule['INTERVAL'].'/', $ics, "Export Recurrence Interval");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
411 $this->assertRegExp('/RRULE:.*UNTIL=20140718T215959Z/', $ics, "Export Recurrence End date");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
412 $this->assertRegExp('/RRULE:.*BYDAY='.$rrule['BYDAY'].'/', $ics, "Export Recurrence BYDAY");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
413 $this->assertRegExp('/EXDATE.*:20131218/', $ics, "Export Recurrence EXDATE");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
414
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
415 $this->assertContains('BEGIN:VALARM', $ics, "Export VALARM");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
416 $this->assertContains('TRIGGER;RELATED=END:-PT12H', $ics, "Export Alarm trigger");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
417
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
418 $this->assertRegExp('/ATTACH.*;VALUE=BINARY/', $ics, "Embed attachment");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
419 $this->assertRegExp('/ATTACH.*;ENCODING=BASE64/', $ics, "Attachment B64 encoding");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
420 $this->assertRegExp('!ATTACH.*;FMTTYPE=text/html!', $ics, "Attachment mimetype");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
421 $this->assertRegExp('!ATTACH.*;X-LABEL=calendar.html!', $ics, "Attachment filename with X-LABEL");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
422
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
423 $this->assertContains('END:VEVENT', $ics, "VEVENT encapsulation END");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
424 $this->assertContains('END:VCALENDAR', $ics, "VCALENDAR encapsulation END");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
425 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
426
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
427 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
428 * @depends test_extended
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
429 * @depends test_export
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
430 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
431 function test_export_multiple()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
432 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
433 $ical = new libvcalendar();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
434 $events = array_merge(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
435 $ical->import_from_file(__DIR__ . '/resources/snd.ics', 'UTF-8'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
436 $ical->import_from_file(__DIR__ . '/resources/multiple.ics', 'UTF-8')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
437 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
438
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
439 $num = count($events);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
440 $ics = $ical->export($events, null, false);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
441
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
442 $this->assertContains('BEGIN:VCALENDAR', $ics, "VCALENDAR encapsulation BEGIN");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
443 $this->assertContains('END:VCALENDAR', $ics, "VCALENDAR encapsulation END");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
444 $this->assertEquals($num, substr_count($ics, 'BEGIN:VEVENT'), "VEVENT encapsulation BEGIN");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
445 $this->assertEquals($num, substr_count($ics, 'END:VEVENT'), "VEVENT encapsulation END");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
446 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
447
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
448 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
449 * @depends test_export
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
450 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
451 function test_export_recurrence_exceptions()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
452 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
453 $ical = new libvcalendar();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
454 $events = $ical->import_from_file(__DIR__ . '/resources/recurring.ics', 'UTF-8');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
455
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
456 // add exceptions
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
457 $event = $events[0];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
458 unset($event['recurrence']['EXCEPTIONS']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
459
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
460 $exception1 = $event;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
461 $exception1['start'] = clone $event['start'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
462 $exception1['start']->setDate(2013, 8, 14);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
463 $exception1['end'] = clone $event['end'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
464 $exception1['end']->setDate(2013, 8, 14);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
465
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
466 $exception2 = $event;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
467 $exception2['start'] = clone $event['start'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
468 $exception2['start']->setDate(2013, 11, 13);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
469 $exception2['end'] = clone $event['end'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
470 $exception2['end']->setDate(2013, 11, 13);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
471 $exception2['title'] = 'Recurring Exception';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
472
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
473 $events[0]['recurrence']['EXCEPTIONS'] = array($exception1, $exception2);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
474
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
475 $ics = $ical->export($events, null, false);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
476
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
477 $num = count($events[0]['recurrence']['EXCEPTIONS']) + 1;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
478 $this->assertEquals($num, substr_count($ics, 'BEGIN:VEVENT'), "VEVENT encapsulation BEGIN");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
479 $this->assertEquals($num, substr_count($ics, 'UID:'.$event['uid']), "Recurrence Exceptions with same UID");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
480 $this->assertEquals($num, substr_count($ics, 'END:VEVENT'), "VEVENT encapsulation END");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
481
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
482 $this->assertContains('RECURRENCE-ID;TZID=Europe/Zurich:20130814', $ics, "Recurrence-ID (1) being the exception date");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
483 $this->assertContains('RECURRENCE-ID;TZID=Europe/Zurich:20131113', $ics, "Recurrence-ID (2) being the exception date");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
484 $this->assertContains('SUMMARY:'.$exception2['title'], $ics, "Exception title");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
485 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
486
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
487 function test_export_valid_rrules()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
488 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
489 $event = array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
490 'uid' => '1234567890',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
491 'start' => new DateTime('now'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
492 'end' => new DateTime('now + 30min'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
493 'title' => 'test_export_valid_rrules',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
494 'recurrence' => array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
495 'FREQ' => 'DAILY',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
496 'COUNT' => 5,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
497 'EXDATE' => array(),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
498 'RDATE' => array(),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
499 ),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
500 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
501 $ical = new libvcalendar();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
502 $ics = $ical->export(array($event), null, false, null, false);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
503
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
504 $this->assertNotContains('EXDATE=', $ics);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
505 $this->assertNotContains('RDATE=', $ics);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
506 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
507
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
508 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
509 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
510 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
511 function test_export_rdate()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
512 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
513 $ical = new libvcalendar();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
514 $events = $ical->import_from_file(__DIR__ . '/resources/multiple-rdate.ics', 'UTF-8');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
515 $ics = $ical->export($events, null, false);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
516
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
517 $this->assertContains('RDATE:20140520T020000Z', $ics, "VALUE=PERIOD is translated into single DATE-TIME values");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
518 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
519
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
520 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
521 * @depends test_export
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
522 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
523 function test_export_direct()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
524 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
525 $ical = new libvcalendar();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
526 $events = $ical->import_from_file(__DIR__ . '/resources/multiple.ics', 'UTF-8');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
527 $num = count($events);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
528
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
529 ob_start();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
530 $return = $ical->export($events, null, true);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
531 $output = ob_get_contents();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
532 ob_end_clean();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
533
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
534 $this->assertTrue($return, "Return true on successful writing");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
535 $this->assertContains('BEGIN:VCALENDAR', $output, "VCALENDAR encapsulation BEGIN");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
536 $this->assertContains('END:VCALENDAR', $output, "VCALENDAR encapsulation END");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
537 $this->assertEquals($num, substr_count($output, 'BEGIN:VEVENT'), "VEVENT encapsulation BEGIN");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
538 $this->assertEquals($num, substr_count($output, 'END:VEVENT'), "VEVENT encapsulation END");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
539 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
540
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
541 function test_datetime()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
542 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
543 $ical = new libvcalendar();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
544 $cal = new \Sabre\VObject\Component\VCalendar();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
545 $localtime = $ical->datetime_prop($cal, 'DTSTART', new DateTime('2013-09-01 12:00:00', new DateTimeZone('Europe/Berlin')));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
546 $localdate = $ical->datetime_prop($cal, 'DTSTART', new DateTime('2013-09-01', new DateTimeZone('Europe/Berlin')), false, true);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
547 $utctime = $ical->datetime_prop($cal, 'DTSTART', new DateTime('2013-09-01 12:00:00', new DateTimeZone('UTC')));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
548 $asutctime = $ical->datetime_prop($cal, 'DTSTART', new DateTime('2013-09-01 12:00:00', new DateTimeZone('Europe/Berlin')), true);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
549
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
550 $this->assertContains('TZID=Europe/Berlin', $localtime->serialize());
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
551 $this->assertContains('VALUE=DATE', $localdate->serialize());
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
552 $this->assertContains('20130901T120000Z', $utctime->serialize());
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
553 $this->assertContains('20130901T100000Z', $asutctime->serialize());
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
554 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
555
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
556 function test_get_vtimezone()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
557 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
558 $vtz = libvcalendar::get_vtimezone('Europe/Berlin', strtotime('2014-08-22T15:00:00+02:00'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
559 $this->assertInstanceOf('\Sabre\VObject\Component', $vtz, "VTIMEZONE is a Component object");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
560 $this->assertEquals('Europe/Berlin', $vtz->TZID);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
561 $this->assertEquals('4', $vtz->{'X-MICROSOFT-CDO-TZID'});
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
562
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
563 // check for transition to daylight saving time which is BEFORE the given date
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
564 $dst = reset($vtz->select('DAYLIGHT'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
565 $this->assertEquals('DAYLIGHT', $dst->name);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
566 $this->assertEquals('20140330T010000', $dst->DTSTART);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
567 $this->assertEquals('+0100', $dst->TZOFFSETFROM);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
568 $this->assertEquals('+0200', $dst->TZOFFSETTO);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
569 $this->assertEquals('CEST', $dst->TZNAME);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
570
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
571 // check (last) transition to standard time which is AFTER the given date
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
572 $std = end($vtz->select('STANDARD'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
573 $this->assertEquals('STANDARD', $std->name);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
574 $this->assertEquals('20141026T010000', $std->DTSTART);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
575 $this->assertEquals('+0200', $std->TZOFFSETFROM);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
576 $this->assertEquals('+0100', $std->TZOFFSETTO);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
577 $this->assertEquals('CET', $std->TZNAME);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
578
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
579 // unknown timezone
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
580 $vtz = libvcalendar::get_vtimezone('America/Foo Bar');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
581 $this->assertEquals(false, $vtz);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
582
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
583 // invalid input data
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
584 $vtz = libvcalendar::get_vtimezone(new DateTime());
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
585 $this->assertEquals(false, $vtz);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
586
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
587 // DateTimezone as input data
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
588 $vtz = libvcalendar::get_vtimezone(new DateTimezone('Pacific/Chatham'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
589 $this->assertInstanceOf('\Sabre\VObject\Component', $vtz);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
590 $this->assertContains('TZOFFSETFROM:+1245', $vtz->serialize());
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
591 $this->assertContains('TZOFFSETTO:+1345', $vtz->serialize());
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
592 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
593
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
594 function get_attachment_data($id, $event)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
595 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
596 return $this->attachment_data;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
597 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
598 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
599