ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
VCardConverterTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Sabre\VObject;
4 
6 
7 class VCardConverterTest extends TestCase {
8 
9  use \Sabre\VObject\PHPUnitAssertions;
10 
11  function testConvert30to40() {
12 
13  $input = <<<IN
14 BEGIN:VCARD
15 VERSION:3.0
16 PRODID:foo
17 FN;CHARSET=UTF-8:Steve
18 TEL;TYPE=PREF,HOME:+1 555 666 777
19 ITEM1.TEL:+1 444 555 666
20 ITEM1.X-ABLABEL:CustomLabel
21 PHOTO;ENCODING=b;TYPE=JPEG,HOME:Zm9v
22 PHOTO;ENCODING=b;TYPE=GIF:Zm9v
23 PHOTO;X-PARAM=FOO;ENCODING=b;TYPE=PNG:Zm9v
24 PHOTO;VALUE=URI:http://example.org/foo.png
25 X-ABShowAs:COMPANY
26 END:VCARD
27 IN;
28 
29  $output = <<<OUT
30 BEGIN:VCARD
31 VERSION:4.0
32 FN:Steve
33 TEL;PREF=1;TYPE=HOME:+1 555 666 777
34 ITEM1.TEL:+1 444 555 666
35 ITEM1.X-ABLABEL:CustomLabel
36 PHOTO;TYPE=HOME:data:image/jpeg;base64,Zm9v
37 PHOTO:data:image/gif;base64,Zm9v
38 PHOTO;X-PARAM=FOO:data:image/png;base64,Zm9v
39 PHOTO:http://example.org/foo.png
40 KIND:ORG
41 END:VCARD
42 OUT;
43 
44  $vcard = Reader::read($input);
45  $vcard = $vcard->convert(Document::VCARD40);
46 
47  $this->assertVObjectEqualsVObject(
48  $output,
49  $vcard
50  );
51 
52  }
53 
54  function testConvert40to40() {
55 
56  $input = <<<IN
57 BEGIN:VCARD
58 VERSION:4.0
59 FN:Steve
60 TEL;PREF=1;TYPE=HOME:+1 555 666 777
61 PHOTO:data:image/jpeg;base64,Zm9v
62 PHOTO:data:image/gif;base64,Zm9v
63 PHOTO;X-PARAM=FOO:data:image/png;base64,Zm9v
64 PHOTO:http://example.org/foo.png
65 END:VCARD
66 
67 IN;
68 
69  $output = <<<OUT
70 BEGIN:VCARD
71 VERSION:4.0
72 FN:Steve
73 TEL;PREF=1;TYPE=HOME:+1 555 666 777
74 PHOTO:data:image/jpeg;base64,Zm9v
75 PHOTO:data:image/gif;base64,Zm9v
76 PHOTO;X-PARAM=FOO:data:image/png;base64,Zm9v
77 PHOTO:http://example.org/foo.png
78 END:VCARD
79 
80 OUT;
81 
82  $vcard = Reader::read($input);
83  $vcard = $vcard->convert(Document::VCARD40);
84 
85  $this->assertVObjectEqualsVObject(
86  $output,
87  $vcard
88  );
89 
90  }
91 
92  function testConvert21to40() {
93 
94  $input = <<<IN
95 BEGIN:VCARD
96 VERSION:2.1
97 N:Family;Johnson
98 FN:Johnson Family
99 TEL;HOME;VOICE:555-12345-345
100 ADR;HOME:;;100 Street Lane;Saubel Beach;ON;H0H0H0
101 LABEL;HOME;ENCODING=QUOTED-PRINTABLE:100 Street Lane=0D=0ASaubel Beach,
102  ON H0H0H0
103 REV:20110731T040251Z
104 UID:12345678
105 END:VCARD
106 IN;
107 
108  $output = <<<OUT
109 BEGIN:VCARD
110 VERSION:4.0
111 N:Family;Johnson;;;
112 FN:Johnson Family
113 TEL;TYPE=HOME,VOICE:555-12345-345
114 ADR;TYPE=HOME:;;100 Street Lane;Saubel Beach;ON;H0H0H0;
115 REV:20110731T040251Z
116 UID:12345678
117 END:VCARD
118 
119 OUT;
120 
121  $vcard = Reader::read($input);
122  $vcard = $vcard->convert(Document::VCARD40);
123 
124  $this->assertVObjectEqualsVObject(
125  $output,
126  $vcard
127  );
128 
129  }
130 
131  function testConvert30to30() {
132 
133  $input = <<<IN
134 BEGIN:VCARD
135 VERSION:3.0
136 PRODID:foo
137 FN;CHARSET=UTF-8:Steve
138 TEL;TYPE=PREF,HOME:+1 555 666 777
139 PHOTO;ENCODING=b;TYPE=JPEG:Zm9v
140 PHOTO;ENCODING=b;TYPE=GIF:Zm9v
141 PHOTO;X-PARAM=FOO;ENCODING=b;TYPE=PNG:Zm9v
142 PHOTO;VALUE=URI:http://example.org/foo.png
143 END:VCARD
144 
145 IN;
146 
147  $output = <<<OUT
148 BEGIN:VCARD
149 VERSION:3.0
150 PRODID:foo
151 FN;CHARSET=UTF-8:Steve
152 TEL;TYPE=PREF,HOME:+1 555 666 777
153 PHOTO;ENCODING=b;TYPE=JPEG:Zm9v
154 PHOTO;ENCODING=b;TYPE=GIF:Zm9v
155 PHOTO;X-PARAM=FOO;ENCODING=b;TYPE=PNG:Zm9v
156 PHOTO;VALUE=URI:http://example.org/foo.png
157 END:VCARD
158 
159 OUT;
160 
161  $vcard = Reader::read($input);
162  $vcard = $vcard->convert(Document::VCARD30);
163 
164  $this->assertVObjectEqualsVObject(
165  $output,
166  $vcard
167  );
168 
169  }
170 
171  function testConvert40to30() {
172 
173  $input = <<<IN
174 BEGIN:VCARD
175 VERSION:4.0
176 PRODID:foo
177 FN:Steve
178 TEL;PREF=1;TYPE=HOME:+1 555 666 777
179 PHOTO:data:image/jpeg;base64,Zm9v
180 PHOTO:data:image/gif,foo
181 PHOTO;X-PARAM=FOO:data:image/png;base64,Zm9v
182 PHOTO:http://example.org/foo.png
183 KIND:ORG
184 END:VCARD
185 
186 IN;
187 
188  $output = <<<OUT
189 BEGIN:VCARD
190 VERSION:3.0
191 FN:Steve
192 TEL;TYPE=PREF,HOME:+1 555 666 777
193 PHOTO;ENCODING=b;TYPE=JPEG:Zm9v
194 PHOTO;ENCODING=b;TYPE=GIF:Zm9v
195 PHOTO;ENCODING=b;TYPE=PNG;X-PARAM=FOO:Zm9v
196 PHOTO;VALUE=URI:http://example.org/foo.png
197 X-ABSHOWAS:COMPANY
198 END:VCARD
199 
200 OUT;
201 
202  $vcard = Reader::read($input);
203  $vcard = $vcard->convert(Document::VCARD30);
204 
205  $this->assertVObjectEqualsVObject(
206  $output,
207  $vcard
208  );
209 
210  }
211 
212  function testConvertGroupCard() {
213 
214  $input = <<<IN
215 BEGIN:VCARD
216 VERSION:3.0
217 PRODID:foo
218 X-ADDRESSBOOKSERVER-KIND:GROUP
219 END:VCARD
220 
221 IN;
222 
223  $output = <<<OUT
224 BEGIN:VCARD
225 VERSION:4.0
226 KIND:GROUP
227 END:VCARD
228 
229 OUT;
230 
231  $vcard = Reader::read($input);
232  $vcard = $vcard->convert(Document::VCARD40);
233 
234  $this->assertVObjectEqualsVObject(
235  $output,
236  $vcard
237  );
238 
239  $input = $output;
240  $output = <<<OUT
241 BEGIN:VCARD
242 VERSION:3.0
243 X-ADDRESSBOOKSERVER-KIND:GROUP
244 END:VCARD
245 
246 OUT;
247 
248  $vcard = Reader::read($input);
249  $vcard = $vcard->convert(Document::VCARD30);
250 
251  $this->assertVObjectEqualsVObject(
252  $output,
253  $vcard
254  );
255 
256  }
257 
258  function testBDAYConversion() {
259 
260  $input = <<<IN
261 BEGIN:VCARD
262 VERSION:3.0
263 PRODID:foo
264 BDAY;X-APPLE-OMIT-YEAR=1604:1604-04-16
265 END:VCARD
266 
267 IN;
268 
269  $output = <<<OUT
270 BEGIN:VCARD
271 VERSION:4.0
272 BDAY:--04-16
273 END:VCARD
274 
275 OUT;
276 
277  $vcard = Reader::read($input);
278  $vcard = $vcard->convert(Document::VCARD40);
279 
280  $this->assertVObjectEqualsVObject(
281  $output,
282  $vcard
283  );
284 
285  $input = $output;
286  $output = <<<OUT
287 BEGIN:VCARD
288 VERSION:3.0
289 BDAY;X-APPLE-OMIT-YEAR=1604:1604-04-16
290 END:VCARD
291 
292 OUT;
293 
294  $vcard = Reader::read($input);
295  $vcard = $vcard->convert(Document::VCARD30);
296 
297  $this->assertVObjectEqualsVObject(
298  $output,
299  $vcard
300  );
301 
302  }
303 
308 
309  $input = <<<IN
310 BEGIN:VCARD
311 VERSION:4.2
312 PRODID:foo
313 FN;CHARSET=UTF-8:Steve
314 TEL;TYPE=PREF,HOME:+1 555 666 777
315 ITEM1.TEL:+1 444 555 666
316 ITEM1.X-ABLABEL:CustomLabel
317 PHOTO;ENCODING=b;TYPE=JPEG,HOME:Zm9v
318 PHOTO;ENCODING=b;TYPE=GIF:Zm9v
319 PHOTO;X-PARAM=FOO;ENCODING=b;TYPE=PNG:Zm9v
320 PHOTO;VALUE=URI:http://example.org/foo.png
321 X-ABShowAs:COMPANY
322 END:VCARD
323 
324 IN;
325 
326  $vcard = Reader::read($input);
327  $vcard->convert(Document::VCARD40);
328 
329  }
330 
335 
336  $input = <<<IN
337 BEGIN:VCARD
338 VERSION:3.0
339 PRODID:foo
340 END:VCARD
341 
342 IN;
343 
344  $vcard = Reader::read($input);
345  $vcard->convert(Document::VCARD21);
346 
347  }
348 
350 
351  $input = <<<IN
352 BEGIN:VCARD
353 VERSION:4.0
354 PRODID:foo
355 KIND:INDIVIDUAL
356 END:VCARD
357 
358 IN;
359 
360  $output = <<<OUT
361 BEGIN:VCARD
362 VERSION:3.0
363 END:VCARD
364 
365 OUT;
366 
367  $vcard = Reader::read($input);
368  $vcard = $vcard->convert(Document::VCARD30);
369 
370  $this->assertVObjectEqualsVObject(
371  $output,
372  $vcard
373  );
374 
375  $input = $output;
376  $output = <<<OUT
377 BEGIN:VCARD
378 VERSION:4.0
379 END:VCARD
380 
381 OUT;
382 
383  $vcard = Reader::read($input);
384  $vcard = $vcard->convert(Document::VCARD40);
385 
386  $this->assertVObjectEqualsVObject(
387  $output,
388  $vcard
389  );
390 
391  }
392 
393  function testAnniversary() {
394 
395  $input = <<<IN
396 BEGIN:VCARD
397 VERSION:4.0
398 ITEM1.ANNIVERSARY:20081210
399 END:VCARD
400 
401 IN;
402 
403  $output = <<<'OUT'
404 BEGIN:VCARD
405 VERSION:3.0
406 ITEM1.X-ABDATE;VALUE=DATE-AND-OR-TIME:20081210
407 ITEM1.X-ABLABEL:_$!<Anniversary>!$_
408 ITEM1.X-ANNIVERSARY;VALUE=DATE-AND-OR-TIME:20081210
409 END:VCARD
410 
411 OUT;
412 
413  $vcard = Reader::read($input);
414  $vcard = $vcard->convert(Document::VCARD30);
415 
416  $this->assertVObjectEqualsVObject(
417  $output,
418  $vcard
419  );
420 
421  // Swapping input and output
422  list(
423  $input,
424  $output
425  ) = [
426  $output,
427  $input
428  ];
429 
430  $vcard = Reader::read($input);
431  $vcard = $vcard->convert(Document::VCARD40);
432 
433  $this->assertVObjectEqualsVObject(
434  $output,
435  $vcard
436  );
437 
438  }
439 
441 
442  $input = <<<IN
443 BEGIN:VCARD
444 VERSION:4.0
445 ITEM1.ANNIVERSARY:20081210
446 ITEM2.ANNIVERSARY:20091210
447 ITEM3.ANNIVERSARY:20101210
448 END:VCARD
449 
450 IN;
451 
452  $output = <<<'OUT'
453 BEGIN:VCARD
454 VERSION:3.0
455 ITEM1.X-ABDATE;VALUE=DATE-AND-OR-TIME:20081210
456 ITEM1.X-ABLABEL:_$!<Anniversary>!$_
457 ITEM1.X-ANNIVERSARY;VALUE=DATE-AND-OR-TIME:20081210
458 ITEM2.X-ABDATE;VALUE=DATE-AND-OR-TIME:20091210
459 ITEM2.X-ABLABEL:_$!<Anniversary>!$_
460 ITEM2.X-ANNIVERSARY;VALUE=DATE-AND-OR-TIME:20091210
461 ITEM3.X-ABDATE;VALUE=DATE-AND-OR-TIME:20101210
462 ITEM3.X-ABLABEL:_$!<Anniversary>!$_
463 ITEM3.X-ANNIVERSARY;VALUE=DATE-AND-OR-TIME:20101210
464 END:VCARD
465 
466 OUT;
467 
468  $vcard = Reader::read($input);
469  $vcard = $vcard->convert(Document::VCARD30);
470 
471  $this->assertVObjectEqualsVObject(
472  $output,
473  $vcard
474  );
475 
476  // Swapping input and output
477  list(
478  $input,
479  $output
480  ) = [
481  $output,
482  $input
483  ];
484 
485  $vcard = Reader::read($input);
486  $vcard = $vcard->convert(Document::VCARD40);
487 
488  $this->assertVObjectEqualsVObject(
489  $output,
490  $vcard
491  );
492 
493  }
494 
495  function testNoLabel() {
496 
497  $input = <<<VCF
498 BEGIN:VCARD
499 VERSION:3.0
500 UID:foo
501 N:Doe;John;;;
502 FN:John Doe
503 item1.X-ABDATE;type=pref:2008-12-11
504 END:VCARD
505 
506 VCF;
507 
508  $vcard = Reader::read($input);
509 
510  $this->assertInstanceOf('Sabre\\VObject\\Component\\VCard', $vcard);
511  $vcard = $vcard->convert(Document::VCARD40);
512  $vcard = $vcard->serialize();
513 
514  $converted = Reader::read($vcard);
515  $converted->validate();
516 
518 
519  $expected = <<<VCF
520 BEGIN:VCARD
521 VERSION:4.0
522 PRODID:-//Sabre//Sabre VObject $version//EN
523 UID:foo
524 N:Doe;John;;;
525 FN:John Doe
526 ITEM1.X-ABDATE;PREF=1:2008-12-11
527 END:VCARD
528 
529 VCF;
530 
531  $this->assertEquals($expected, str_replace("\r", "", $vcard));
532 
533  }
534 
535 }
if($argc< 3) $input
const VERSION
Full version number.
Definition: Version.php:17
$version
Definition: build.php:27
static http()
Fetches the global http state from ILIAS.
testUnknownTargetVCardVersion()
InvalidArgumentException
const VCARD30
vCard 3.0.
Definition: Document.php:44
testUnknownSourceVCardVersion()
InvalidArgumentException
static read($data, $options=0, $charset='UTF-8')
Parses a vCard or iCalendar object, and returns the top component.
Definition: Reader.php:42
$this data['403_header']
const VCARD21
vCard 2.1.
Definition: Document.php:39
const VCARD40
vCard 4.0.
Definition: Document.php:49