ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ReaderTest.php
Go to the documentation of this file.
1<?php
2
3namespace Sabre\VObject;
4
5use PHPUnit\Framework\TestCase;
6
7class ReaderTest extends TestCase {
8
9 function testReadComponent() {
10
11 $data = "BEGIN:VCALENDAR\r\nEND:VCALENDAR";
12
14
15 $this->assertInstanceOf('Sabre\\VObject\\Component', $result);
16 $this->assertEquals('VCALENDAR', $result->name);
17 $this->assertEquals(0, count($result->children()));
18
19 }
20
21 function testReadStream() {
22
23 $data = "BEGIN:VCALENDAR\r\nEND:VCALENDAR";
24
25 $stream = fopen('php://memory', 'r+');
26 fwrite($stream, $data);
27 rewind($stream);
28
30
31 $this->assertInstanceOf('Sabre\\VObject\\Component', $result);
32 $this->assertEquals('VCALENDAR', $result->name);
33 $this->assertEquals(0, count($result->children()));
34
35 }
36
38
39 $data = "BEGIN:VCALENDAR\nEND:VCALENDAR";
40
42
43 $this->assertInstanceOf('Sabre\\VObject\\Component', $result);
44 $this->assertEquals('VCALENDAR', $result->name);
45 $this->assertEquals(0, count($result->children()));
46
47 }
48
50
51 $data = "BEGIN:\r\n\tVCALENDAR\r\nE\r\n ND:VCALENDAR";
52
54
55 $this->assertInstanceOf('Sabre\\VObject\\Component', $result);
56 $this->assertEquals('VCALENDAR', $result->name);
57 $this->assertEquals(0, count($result->children()));
58
59 }
60
65
66 $data = "BEGIN:VCALENDAR\r\nEND:FOO";
67
69
70 }
71
76
77 $data = "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nEND:FOO\r\nEND:VCALENDAR";
78
80
81 }
82
83 function testReadProperty() {
84
85 $data = "BEGIN:VCALENDAR\r\nSUMMARY:propValue\r\nEND:VCALENDAR";
87
88 $result = $result->SUMMARY;
89 $this->assertInstanceOf('Sabre\\VObject\\Property', $result);
90 $this->assertEquals('SUMMARY', $result->name);
91 $this->assertEquals('propValue', $result->getValue());
92
93 }
94
96
97 $data = "BEGIN:VCALENDAR\r\nSUMMARY:Line1\\nLine2\\NLine3\\\\Not the 4th line!\r\nEND:VCALENDAR";
99
100 $result = $result->SUMMARY;
101 $this->assertInstanceOf('Sabre\\VObject\\Property', $result);
102 $this->assertEquals('SUMMARY', $result->name);
103 $this->assertEquals("Line1\nLine2\nLine3\\Not the 4th line!", $result->getValue());
104
105 }
106
108
109 $data = "BEGIN:VCALENDAR\r\nDTSTART:20110529\r\nEND:VCALENDAR";
111
112 $result = $result->DTSTART;
113 $this->assertInstanceOf('Sabre\\VObject\\Property\\ICalendar\\DateTime', $result);
114 $this->assertEquals('DTSTART', $result->name);
115 $this->assertEquals('20110529', $result->getValue());
116
117 }
118
120
121 $data = "BEGIN:VCALENDAR\r\nfoo.DTSTART:20110529\r\nEND:VCALENDAR";
123
124 $result = $result->DTSTART;
125 $this->assertInstanceOf('Sabre\\VObject\\Property\\ICalendar\\DateTime', $result);
126 $this->assertEquals('DTSTART', $result->name);
127 $this->assertEquals('20110529', $result->getValue());
128
129 }
130
135
136 $data = "BEGIN:VCALENDAR\r\nPROPNAME;propValue";
138
139 }
140
142
143 $data = [
144 "BEGIN:VCALENDAR",
145 "PROPNAME:propValue",
146 "END:VCALENDAR"
147 ];
148
149 $result = Reader::read(implode("\r\n", $data));
150
151 $this->assertInstanceOf('Sabre\\VObject\\Component', $result);
152 $this->assertEquals('VCALENDAR', $result->name);
153 $this->assertEquals(1, count($result->children()));
154 $this->assertInstanceOf('Sabre\\VObject\\Property', $result->children()[0]);
155 $this->assertEquals('PROPNAME', $result->children()[0]->name);
156 $this->assertEquals('propValue', $result->children()[0]->getValue());
157
158 }
159
161
162 $data = [
163 "BEGIN:VCALENDAR",
164 "BEGIN:VTIMEZONE",
165 "BEGIN:DAYLIGHT",
166 "END:DAYLIGHT",
167 "END:VTIMEZONE",
168 "END:VCALENDAR"
169 ];
170
171 $result = Reader::read(implode("\r\n", $data));
172
173 $this->assertInstanceOf('Sabre\\VObject\\Component', $result);
174 $this->assertEquals('VCALENDAR', $result->name);
175 $this->assertEquals(1, count($result->children()));
176 $this->assertInstanceOf('Sabre\\VObject\\Component', $result->children()[0]);
177 $this->assertEquals('VTIMEZONE', $result->children()[0]->name);
178 $this->assertEquals(1, count($result->children()[0]->children()));
179 $this->assertInstanceOf('Sabre\\VObject\\Component', $result->children()[0]->children()[0]);
180 $this->assertEquals('DAYLIGHT', $result->children()[0]->children()[0]->name);
181
182
183 }
184
186
187 $data = "BEGIN:VCALENDAR\r\nPROPNAME;PARAMNAME=paramvalue:propValue\r\nEND:VCALENDAR";
189
190 $result = $result->PROPNAME;
191
192 $this->assertInstanceOf('Sabre\\VObject\\Property', $result);
193 $this->assertEquals('PROPNAME', $result->name);
194 $this->assertEquals('propValue', $result->getValue());
195 $this->assertEquals(1, count($result->parameters()));
196 $this->assertEquals('PARAMNAME', $result->parameters['PARAMNAME']->name);
197 $this->assertEquals('paramvalue', $result->parameters['PARAMNAME']->getValue());
198
199 }
200
202
203 $data = "BEGIN:VCALENDAR\r\nPROPNAME;N=1;N=2;N=3,4;N=\"5\",6;N=\"7,8\";N=9,10;N=^'11^':propValue\r\nEND:VCALENDAR";
205
206 $result = $result->PROPNAME;
207
208 $this->assertInstanceOf('Sabre\\VObject\\Property', $result);
209 $this->assertEquals('PROPNAME', $result->name);
210 $this->assertEquals('propValue', $result->getValue());
211 $this->assertEquals(1, count($result->parameters()));
212 $this->assertEquals('N', $result->parameters['N']->name);
213 $this->assertEquals('1,2,3,4,5,6,7,8,9,10,"11"', $result->parameters['N']->getValue());
214 $this->assertEquals([1, 2, 3, 4, 5, 6, "7,8", 9, 10, '"11"'], $result->parameters['N']->getParts());
215
216 }
217
219
220 $data = "BEGIN:VCALENDAR\r\nPROPNAME;WORK;VOICE;PREF:propValue\r\nEND:VCALENDAR";
222
223 $result = $result->PROPNAME;
224
225 $this->assertInstanceOf('Sabre\\VObject\\Property', $result);
226 $this->assertEquals('PROPNAME', $result->name);
227 $this->assertEquals('propValue', $result->getValue());
228 $this->assertEquals(1, count($result->parameters()));
229 $this->assertEquals('TYPE', $result->parameters['TYPE']->name);
230 $this->assertEquals('WORK,VOICE,PREF', $result->parameters['TYPE']->getValue());
231 $this->assertEquals(['WORK', 'VOICE', 'PREF'], $result->parameters['TYPE']->getParts());
232
233 }
234
236
237 $data = "BEGIN:VCALENDAR\r\nPROPNAME;PRODIGY:propValue\r\nEND:VCALENDAR";
239
240 $result = $result->PROPNAME;
241
242 $this->assertInstanceOf('Sabre\\VObject\\Property', $result);
243 $this->assertEquals('PROPNAME', $result->name);
244 $this->assertEquals('propValue', $result->getValue());
245 $this->assertEquals(1, count($result->parameters()));
246 $this->assertEquals('TYPE', $result->parameters['TYPE']->name);
247 $this->assertTrue($result->parameters['TYPE']->noName);
248 $this->assertEquals('PRODIGY', $result->parameters['TYPE']);
249
250 }
251
253
254 $data = "BEGIN:VCALENDAR\r\nPROPNAME;PARAMNAME=paramvalue:propValue:anotherrandomstring\r\nEND:VCALENDAR";
256
257 $result = $result->PROPNAME;
258
259 $this->assertInstanceOf('Sabre\\VObject\\Property', $result);
260 $this->assertEquals('PROPNAME', $result->name);
261 $this->assertEquals('propValue:anotherrandomstring', $result->getValue());
262 $this->assertEquals(1, count($result->parameters()));
263 $this->assertEquals('PARAMNAME', $result->parameters['PARAMNAME']->name);
264 $this->assertEquals('paramvalue', $result->parameters['PARAMNAME']->getValue());
265
266 }
267
269
270 $data = "BEGIN:VCALENDAR\r\nPROPNAME;PARAMNAME=paramvalue;PARAMNAME2=paramvalue2:propValue\r\nEND:VCALENDAR";
272
273 $result = $result->PROPNAME;
274
275 $this->assertInstanceOf('Sabre\\VObject\\Property', $result);
276 $this->assertEquals('PROPNAME', $result->name);
277 $this->assertEquals('propValue', $result->getValue());
278 $this->assertEquals(2, count($result->parameters()));
279 $this->assertEquals('PARAMNAME', $result->parameters['PARAMNAME']->name);
280 $this->assertEquals('paramvalue', $result->parameters['PARAMNAME']->getValue());
281 $this->assertEquals('PARAMNAME2', $result->parameters['PARAMNAME2']->name);
282 $this->assertEquals('paramvalue2', $result->parameters['PARAMNAME2']->getValue());
283
284 }
285
287
288 $data = "BEGIN:VCALENDAR\r\nPROPNAME;PARAMNAME=\"paramvalue\":propValue\r\nEND:VCALENDAR";
290
291 $result = $result->PROPNAME;
292
293 $this->assertInstanceOf('Sabre\\VObject\\Property', $result);
294 $this->assertEquals('PROPNAME', $result->name);
295 $this->assertEquals('propValue', $result->getValue());
296 $this->assertEquals(1, count($result->parameters()));
297 $this->assertEquals('PARAMNAME', $result->parameters['PARAMNAME']->name);
298 $this->assertEquals('paramvalue', $result->parameters['PARAMNAME']->getValue());
299
300 }
301
303
304 $data = "BEGIN:VCALENDAR\r\nPROPNAME;PARAMNAME=paramvalue1^nvalue2^^nvalue3:propValue\r\nEND:VCALENDAR";
306
307 $result = $result->PROPNAME;
308
309 $this->assertInstanceOf('Sabre\\VObject\\Property', $result);
310 $this->assertEquals('PROPNAME', $result->name);
311 $this->assertEquals('propValue', $result->getValue());
312
313 $this->assertEquals(1, count($result->parameters()));
314 $this->assertEquals('PARAMNAME', $result->parameters['PARAMNAME']->name);
315 $this->assertEquals("paramvalue1\nvalue2^nvalue3", $result->parameters['PARAMNAME']->getValue());
316
317 }
318
320
321 $data = "BEGIN:VCALENDAR\r\nPROPNAME;PARAMNAME=\"param:value\":propValue\r\nEND:VCALENDAR";
323 $result = $result->PROPNAME;
324
325 $this->assertInstanceOf('Sabre\\VObject\\Property', $result);
326 $this->assertEquals('PROPNAME', $result->name);
327 $this->assertEquals('propValue', $result->getValue());
328 $this->assertEquals(1, count($result->parameters()));
329 $this->assertEquals('PARAMNAME', $result->parameters['PARAMNAME']->name);
330 $this->assertEquals('param:value', $result->parameters['PARAMNAME']->getValue());
331
332 }
333
334 function testReadForgiving() {
335
336 $data = [
337 "BEGIN:VCALENDAR",
338 "X_PROP:propValue",
339 "END:VCALENDAR"
340 ];
341
342 $caught = false;
343 try {
344 $result = Reader::read(implode("\r\n", $data));
345 } catch (ParseException $e) {
346 $caught = true;
347 }
348
349 $this->assertEquals(true, $caught);
350
352
353 $expected = implode("\r\n", [
354 "BEGIN:VCALENDAR",
355 "X_PROP:propValue",
356 "END:VCALENDAR",
357 ""
358 ]);
359
360 $this->assertEquals($expected, $result->serialize());
361
362 }
363
365
366 $data = [
367 "BEGIN:VCALENDAR",
368 "DESCRIPTION:propValue",
369 "Yes, we've actually seen a file with non-idented property values on multiple lines",
370 "END:VCALENDAR"
371 ];
372
373 $caught = false;
374 try {
375 $result = Reader::read(implode("\r\n", $data));
376 } catch (ParseException $e) {
377 $caught = true;
378 }
379
380 $this->assertEquals(true, $caught);
381
383
384 $expected = implode("\r\n", [
385 "BEGIN:VCALENDAR",
386 "DESCRIPTION:propValue",
387 "END:VCALENDAR",
388 ""
389 ]);
390
391 $this->assertEquals($expected, $result->serialize());
392
393 }
394
401
402 $input = <<<ICS
403BEGIN:VCALENDAR
404VERSION:1.0
405BEGIN:VEVENT
406X-FUNAMBOL-FOLDER:DEFAULT_FOLDER
407X-FUNAMBOL-ALLDAY:0
408DTSTART:20111017T110000Z
409DTEND:20111017T123000Z
410X-MICROSOFT-CDO-BUSYSTATUS:BUSY
411CATEGORIES:
412LOCATION;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:Netviewer Meeting
413PRIORITY:1
414STATUS:3
415X-MICROSOFT-CDO-REPLYTIME:20111017T064200Z
416SUMMARY;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:Kopieren: test
417CLASS:PUBLIC
418AALARM:
419RRULE:
420X-FUNAMBOL-BILLINGINFO:
421X-FUNAMBOL-COMPANIES:
422X-FUNAMBOL-MILEAGE:
423X-FUNAMBOL-NOAGING:0
424ATTENDEE;STATUS=NEEDS ACTION;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:'Heino' heino@test.com
425ATTENDEE;STATUS=NEEDS ACTION;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:'Markus' test@test.com
426ATTENDEE;STATUS=NEEDS AC
427ICS;
428
430
431 }
432
437
438 Reader::read(false);
439
440 }
441
442 function testReadBOM() {
443
444 $data = chr(0xef) . chr(0xbb) . chr(0xbf) . "BEGIN:VCALENDAR\r\nEND:VCALENDAR";
446
447 $this->assertInstanceOf('Sabre\\VObject\\Component', $result);
448 $this->assertEquals('VCALENDAR', $result->name);
449 $this->assertEquals(0, count($result->children()));
450
451 }
452
454
455 $data = <<<XML
456<?xml version="1.0" encoding="utf-8"?>
457<icalendar xmlns="urn:ietf:params:xml:ns:icalendar-2.0">
458 <vcalendar>
459 </vcalendar>
460</icalendar>
461XML;
462
464
465 $this->assertInstanceOf('Sabre\\VObject\\Component', $result);
466 $this->assertEquals('VCALENDAR', $result->name);
467 $this->assertEquals(0, count($result->children()));
468
469 }
470
471 function testReadXMLStream() {
472
473 $data = <<<XML
474<?xml version="1.0" encoding="utf-8"?>
475<icalendar xmlns="urn:ietf:params:xml:ns:icalendar-2.0">
476 <vcalendar>
477 </vcalendar>
478</icalendar>
479XML;
480
481 $stream = fopen('php://memory', 'r+');
482 fwrite($stream, $data);
483 rewind($stream);
484
486
487 $this->assertInstanceOf('Sabre\\VObject\\Component', $result);
488 $this->assertEquals('VCALENDAR', $result->name);
489 $this->assertEquals(0, count($result->children()));
490
491 }
492
493}
$result
test()
Definition: build.php:107
An exception for terminatinating execution or to throw for unit testing.
Exception thrown by Reader if an invalid object was attempted to be parsed.
testReadBrokenLine()
@expectedException Sabre\VObject\ParseException
Definition: ReaderTest.php:134
testReadPropertyRepeatingNamelessGuessedParameter()
Definition: ReaderTest.php:218
testReadIncompleteFile()
Reported as Issue 32.
Definition: ReaderTest.php:400
testReadCorruptSubComponent()
@expectedException Sabre\VObject\ParseException
Definition: ReaderTest.php:75
testReadBrokenInput()
@expectedException \InvalidArgumentException
Definition: ReaderTest.php:436
testReadCorruptComponent()
@expectedException Sabre\VObject\ParseException
Definition: ReaderTest.php:64
static read($data, $options=0, $charset='UTF-8')
Parses a vCard or iCalendar object, and returns the top component.
Definition: Reader.php:42
const OPTION_FORGIVING
If this option is passed to the reader, it will be less strict about the validity of the lines.
Definition: Reader.php:21
const OPTION_IGNORE_INVALID_LINES
If this option is turned on, any lines we cannot parse will be ignored by the reader.
Definition: Reader.php:27
static readXML($data, $options=0)
Parses a xCard or xCal object, and returns the top component.
Definition: Reader.php:89
$stream
PHP stream implementation.
foreach($paths as $path) if($argc< 3) $input
$data
Definition: bench.php:6