comparison vendor/sabre/vobject/tests/VObject/Splitter/ICalendarTest.php @ 7:430dbd5346f7

vendor sabre as distributed
author Charlie Root
date Sat, 13 Jan 2018 09:06:10 -0500
parents
children
comparison
equal deleted inserted replaced
6:cec75ba50afc 7:430dbd5346f7
1 <?php
2
3 namespace Sabre\VObject\Splitter;
4
5 use Sabre\VObject;
6
7 class ICalendarTest extends \PHPUnit_Framework_TestCase {
8
9 protected $version;
10
11 function setUp() {
12 $this->version = VObject\Version::VERSION;
13 }
14
15 function createStream($data) {
16
17 $stream = fopen('php://memory','r+');
18 fwrite($stream, $data);
19 rewind($stream);
20 return $stream;
21
22 }
23
24 function testICalendarImportValidEvent() {
25
26 $data = <<<EOT
27 BEGIN:VCALENDAR
28 BEGIN:VEVENT
29 UID:foo
30 DTSTAMP:20140122T233226Z
31 DTSTART:20140101T070000Z
32 END:VEVENT
33 END:VCALENDAR
34 EOT;
35 $tempFile = $this->createStream($data);
36
37 $objects = new ICalendar($tempFile);
38
39 $return = "";
40 while($object=$objects->getNext()) {
41 $return .= $object->serialize();
42 }
43 $this->assertEquals(array(), VObject\Reader::read($return)->validate());
44 }
45
46 /**
47 * @expectedException Sabre\VObject\ParseException
48 */
49 function testICalendarImportWrongType() {
50
51 $data = <<<EOT
52 BEGIN:VCARD
53 UID:foo1
54 END:VCARD
55 BEGIN:VCARD
56 UID:foo2
57 END:VCARD
58 EOT;
59 $tempFile = $this->createStream($data);
60
61 $objects = new ICalendar($tempFile);
62
63 }
64
65 function testICalendarImportEndOfData() {
66 $data = <<<EOT
67 BEGIN:VCALENDAR
68 BEGIN:VEVENT
69 UID:foo
70 DTSTAMP:20140122T233226Z
71 END:VEVENT
72 END:VCALENDAR
73 EOT;
74 $tempFile = $this->createStream($data);
75
76 $objects = new ICalendar($tempFile);
77
78 $return = "";
79 while($object=$objects->getNext()) {
80 $return .= $object->serialize();
81 }
82 $this->assertNull($object=$objects->getNext());
83 }
84
85 /**
86 * @expectedException Sabre\VObject\ParseException
87 */
88 function testICalendarImportInvalidEvent() {
89 $data = <<<EOT
90 EOT;
91 $tempFile = $this->createStream($data);
92 $objects = new ICalendar($tempFile);
93
94 }
95
96 function testICalendarImportMultipleValidEvents() {
97
98 $event[] = <<<EOT
99 BEGIN:VEVENT
100 UID:foo1
101 DTSTAMP:20140122T233226Z
102 DTSTART:20140101T050000Z
103 END:VEVENT
104 EOT;
105
106 $event[] = <<<EOT
107 BEGIN:VEVENT
108 UID:foo2
109 DTSTAMP:20140122T233226Z
110 DTSTART:20140101T060000Z
111 END:VEVENT
112 EOT;
113
114 $data = <<<EOT
115 BEGIN:VCALENDAR
116 $event[0]
117 $event[1]
118 END:VCALENDAR
119
120 EOT;
121 $tempFile = $this->createStream($data);
122
123 $objects = new ICalendar($tempFile);
124
125 $return = "";
126 $i = 0;
127 while($object=$objects->getNext()) {
128
129 $expected = <<<EOT
130 BEGIN:VCALENDAR
131 VERSION:2.0
132 PRODID:-//Sabre//Sabre VObject $this->version//EN
133 CALSCALE:GREGORIAN
134 $event[$i]
135 END:VCALENDAR
136
137 EOT;
138
139 $return .= $object->serialize();
140 $expected = str_replace("\n", "\r\n", $expected);
141 $this->assertEquals($expected, $object->serialize());
142 $i++;
143 }
144 $this->assertEquals(array(), VObject\Reader::read($return)->validate());
145 }
146
147 function testICalendarImportEventWithoutUID() {
148
149 $data = <<<EOT
150 BEGIN:VCALENDAR
151 VERSION:2.0
152 PRODID:-//Sabre//Sabre VObject $this->version//EN
153 CALSCALE:GREGORIAN
154 BEGIN:VEVENT
155 DTSTART:20140101T040000Z
156 DTSTAMP:20140122T233226Z
157 END:VEVENT
158 END:VCALENDAR
159
160 EOT;
161 $tempFile = $this->createStream($data);
162
163 $objects = new ICalendar($tempFile);
164
165 $return = "";
166 while($object=$objects->getNext()) {
167 $return .= $object->serialize();
168 }
169
170 $messages = VObject\Reader::read($return)->validate();
171
172 if ($messages) {
173 $messages = array_map(
174 function($item) { return $item['message']; },
175 $messages
176 );
177 $this->fail('Validation errors: ' . implode("\n", $messages));
178 } else {
179 $this->assertEquals(array(), $messages);
180 }
181 }
182
183 function testICalendarImportMultipleVTIMEZONESAndMultipleValidEvents() {
184
185 $timezones = <<<EOT
186 BEGIN:VTIMEZONE
187 TZID:Europe/Berlin
188 BEGIN:DAYLIGHT
189 TZOFFSETFROM:+0100
190 RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
191 DTSTART:19810329T020000
192 TZNAME:MESZ
193 TZOFFSETTO:+0200
194 END:DAYLIGHT
195 BEGIN:STANDARD
196 TZOFFSETFROM:+0200
197 RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
198 DTSTART:19961027T030000
199 TZNAME:MEZ
200 TZOFFSETTO:+0100
201 END:STANDARD
202 END:VTIMEZONE
203 BEGIN:VTIMEZONE
204 TZID:Europe/London
205 BEGIN:DAYLIGHT
206 TZOFFSETFROM:+0000
207 RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
208 DTSTART:19810329T010000
209 TZNAME:GMT+01:00
210 TZOFFSETTO:+0100
211 END:DAYLIGHT
212 BEGIN:STANDARD
213 TZOFFSETFROM:+0100
214 RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
215 DTSTART:19961027T020000
216 TZNAME:GMT
217 TZOFFSETTO:+0000
218 END:STANDARD
219 END:VTIMEZONE
220 EOT;
221
222 $event[] = <<<EOT
223 BEGIN:VEVENT
224 UID:foo1
225 DTSTAMP:20140122T232710Z
226 DTSTART:20140101T010000Z
227 END:VEVENT
228 EOT;
229
230 $event[] = <<<EOT
231 BEGIN:VEVENT
232 UID:foo2
233 DTSTAMP:20140122T232710Z
234 DTSTART:20140101T020000Z
235 END:VEVENT
236 EOT;
237
238 $event[] = <<<EOT
239 BEGIN:VEVENT
240 UID:foo3
241 DTSTAMP:20140122T232710Z
242 DTSTART:20140101T030000Z
243 END:VEVENT
244 EOT;
245
246 $data = <<<EOT
247 BEGIN:VCALENDAR
248 $timezones
249 $event[0]
250 $event[1]
251 $event[2]
252 END:VCALENDAR
253
254 EOT;
255 $tempFile = $this->createStream($data);
256
257 $objects = new ICalendar($tempFile);
258
259 $return = "";
260 $i = 0;
261 while($object=$objects->getNext()) {
262
263 $expected = <<<EOT
264 BEGIN:VCALENDAR
265 VERSION:2.0
266 PRODID:-//Sabre//Sabre VObject $this->version//EN
267 CALSCALE:GREGORIAN
268 $timezones
269 $event[$i]
270 END:VCALENDAR
271
272 EOT;
273 $expected = str_replace("\n", "\r\n", $expected);
274
275 $this->assertEquals($expected, $object->serialize());
276 $return .= $object->serialize();
277 $i++;
278
279 }
280
281 $this->assertEquals(array(), VObject\Reader::read($return)->validate());
282 }
283
284 function testICalendarImportWithOutVTIMEZONES() {
285
286 $data = <<<EOT
287 BEGIN:VCALENDAR
288 VERSION:2.0
289 PRODID:-//Apple Inc.//Mac OS X 10.8//EN
290 CALSCALE:GREGORIAN
291 BEGIN:VEVENT
292 CREATED:20120605T072109Z
293 UID:D6716295-C10F-4B20-82F9-E1A3026C7DCF
294 DTEND;VALUE=DATE:20120717
295 TRANSP:TRANSPARENT
296 SUMMARY:Start Vorbereitung
297 DTSTART;VALUE=DATE:20120716
298 DTSTAMP:20120605T072115Z
299 SEQUENCE:2
300 BEGIN:VALARM
301 X-WR-ALARMUID:A99EDA6A-35EB-4446-B8BC-CDA3C60C627D
302 UID:A99EDA6A-35EB-4446-B8BC-CDA3C60C627D
303 TRIGGER:-PT15H
304 X-APPLE-DEFAULT-ALARM:TRUE
305 ATTACH;VALUE=URI:Basso
306 ACTION:AUDIO
307 END:VALARM
308 END:VEVENT
309 END:VCALENDAR
310
311 EOT;
312 $tempFile = $this->createStream($data);
313
314 $objects = new ICalendar($tempFile);
315
316 $return = "";
317 while($object=$objects->getNext()) {
318 $return .= $object->serialize();
319 }
320
321 $messages = VObject\Reader::read($return)->validate();
322 $this->assertEquals(array(), $messages);
323 }
324
325 }