ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Sabre\VObject\CliTest Class Reference

Tests the cli. More...

+ Inheritance diagram for Sabre\VObject\CliTest:
+ Collaboration diagram for Sabre\VObject\CliTest:

Public Member Functions

 setUp ()
 
 testInvalidArg ()
 
 testQuiet ()
 
 testHelp ()
 
 testFormat ()
 
 testFormatInvalid ()
 
 testInputFormatInvalid ()
 
 testNoInputFile ()
 
 testTooManyArgs ()
 
 testUnknownCommand ()
 
 testConvertJson ()
 
 testConvertJCardPretty ()
 
 testConvertJCalFail ()
 
 testConvertMimeDir ()
 
 testConvertDefaultFormats ()
 
 testConvertDefaultFormats2 ()
 
 testVCard3040 ()
 
 testVCard4030 ()
 
 testVCard4021 ()
 
 testValidate ()
 
 testValidateFail ()
 
 testValidateFail2 ()
 
 testRepair ()
 
 testRepairNothing ()
 
 testColorCalendar ()
 Note: this is a very shallow test, doesn't dig into the actual output, but just makes sure there's no errors thrown. More...
 
 testColorVCard ()
 Note: this is a very shallow test, doesn't dig into the actual output, but just makes sure there's no errors thrown. More...
 

Detailed Description

Tests the cli.

Warning: these tests are very rudimentary.

Definition at line 12 of file CliTest.php.

Member Function Documentation

◆ setUp()

Sabre\VObject\CliTest::setUp ( )

Definition at line 14 of file CliTest.php.

14  {
15 
16  $this->cli = new CliMock();
17  $this->cli->stderr = fopen('php://memory', 'r+');
18  $this->cli->stdout = fopen('php://memory', 'r+');
19 
20  }

◆ testColorCalendar()

Sabre\VObject\CliTest::testColorCalendar ( )

Note: this is a very shallow test, doesn't dig into the actual output, but just makes sure there's no errors thrown.

The colorizer is not a critical component, it's mostly a debugging tool.

This object is not valid, but it's designed to hit every part of the colorizer source.

Definition at line 542 of file CliTest.php.

542  {
543 
544  $inputStream = fopen('php://memory', 'r+');
545 
547 
552  fwrite($inputStream, <<<VCARD
553 BEGIN:VCALENDAR
554 VERSION:2.0
555 PRODID:-//Sabre//Sabre VObject {$version}//EN
556 BEGIN:VTIMEZONE
557 END:VTIMEZONE
558 BEGIN:VEVENT
559 ATTENDEE;RSVP=TRUE:mailto:foo@example.org
560 REQUEST-STATUS:5;foo
561 ATTACH:blabla
562 END:VEVENT
563 END:VCALENDAR
564 
565 VCARD
566  );
567  rewind($inputStream);
568  $this->cli->stdin = $inputStream;
569 
570  $result = $this->cli->main(['vobject', 'color', '-']);
571 
572  rewind($this->cli->stderr);
573  $error = stream_get_contents($this->cli->stderr);
574 
575  $this->assertEquals(
576  0,
577  $result,
578  "This should have been error free. stderr output:\n" . $error
579  );
580 
581  }
$result
const VERSION
Full version number.
Definition: Version.php:17
$version
Definition: build.php:27

◆ testColorVCard()

Sabre\VObject\CliTest::testColorVCard ( )

Note: this is a very shallow test, doesn't dig into the actual output, but just makes sure there's no errors thrown.

The colorizer is not a critical component, it's mostly a debugging tool.

This object is not valid, but it's designed to hit every part of the colorizer source.

Definition at line 589 of file CliTest.php.

589  {
590 
591  $inputStream = fopen('php://memory', 'r+');
592 
594 
599  fwrite($inputStream, <<<VCARD
600 BEGIN:VCARD
601 VERSION:4.0
602 PRODID:-//Sabre//Sabre VObject {$version}//EN
603 ADR:1;2;3;4a,4b;5;6
604 group.TEL:123454768
605 END:VCARD
606 
607 VCARD
608  );
609  rewind($inputStream);
610  $this->cli->stdin = $inputStream;
611 
612  $result = $this->cli->main(['vobject', 'color', '-']);
613 
614  rewind($this->cli->stderr);
615  $error = stream_get_contents($this->cli->stderr);
616 
617  $this->assertEquals(
618  0,
619  $result,
620  "This should have been error free. stderr output:\n" . $error
621  );
622 
623  }
$result
const VERSION
Full version number.
Definition: Version.php:17
$version
Definition: build.php:27

◆ testConvertDefaultFormats()

Sabre\VObject\CliTest::testConvertDefaultFormats ( )

Definition at line 282 of file CliTest.php.

282  {
283 
284  $outputFile = SABRE_TEMPDIR . 'bar.json';
285 
286  $this->assertEquals(
287  2,
288  $this->cli->main(['vobject', 'convert', 'foo.json', $outputFile])
289  );
290 
291  $this->assertEquals('json', $this->cli->inputFormat);
292  $this->assertEquals('json', $this->cli->format);
293 
294  }

◆ testConvertDefaultFormats2()

Sabre\VObject\CliTest::testConvertDefaultFormats2 ( )

Definition at line 296 of file CliTest.php.

296  {
297 
298  $outputFile = SABRE_TEMPDIR . 'bar.ics';
299 
300  $this->assertEquals(
301  2,
302  $this->cli->main(['vobject', 'convert', 'foo.ics', $outputFile])
303  );
304 
305  $this->assertEquals('mimedir', $this->cli->inputFormat);
306  $this->assertEquals('mimedir', $this->cli->format);
307 
308  }

◆ testConvertJCalFail()

Sabre\VObject\CliTest::testConvertJCalFail ( )

Definition at line 200 of file CliTest.php.

200  {
201 
202  $inputStream = fopen('php://memory', 'r+');
203 
204  fwrite($inputStream, <<<ICS
205 BEGIN:VCARD
206 VERSION:3.0
207 FN:Cowboy Henk
208 END:VCARD
209 ICS
210  );
211  rewind($inputStream);
212  $this->cli->stdin = $inputStream;
213 
214  $this->assertEquals(
215  2,
216  $this->cli->main(['vobject', 'convert', '--format=jcal', '--inputformat=mimedir', '-'])
217  );
218 
219  }

◆ testConvertJCardPretty()

Sabre\VObject\CliTest::testConvertJCardPretty ( )

Definition at line 158 of file CliTest.php.

158  {
159 
160  if (version_compare(PHP_VERSION, '5.4.0') < 0) {
161  $this->markTestSkipped('This test required PHP 5.4.0');
162  }
163 
164  $inputStream = fopen('php://memory', 'r+');
165 
166  fwrite($inputStream, <<<ICS
167 BEGIN:VCARD
168 VERSION:3.0
169 FN:Cowboy Henk
170 END:VCARD
171 ICS
172  );
173  rewind($inputStream);
174  $this->cli->stdin = $inputStream;
175 
176  $this->assertEquals(
177  0,
178  $this->cli->main(['vobject', 'convert', '--format=jcard', '--pretty', '-'])
179  );
180 
181  rewind($this->cli->stdout);
182 
183  // PHP 5.5.12 changed the output
184 
185  $expected = <<<JCARD
186 [
187  "vcard",
188  [
189  [
190  "versi
191 JCARD;
192 
193  $this->assertStringStartsWith(
194  $expected,
195  stream_get_contents($this->cli->stdout)
196  );
197 
198  }

◆ testConvertJson()

Sabre\VObject\CliTest::testConvertJson ( )

Definition at line 130 of file CliTest.php.

References $version, and Sabre\VObject\Version\VERSION.

130  {
131 
132  $inputStream = fopen('php://memory', 'r+');
133 
134  fwrite($inputStream, <<<ICS
135 BEGIN:VCARD
136 VERSION:3.0
137 FN:Cowboy Henk
138 END:VCARD
139 ICS
140  );
141  rewind($inputStream);
142  $this->cli->stdin = $inputStream;
143 
144  $this->assertEquals(
145  0,
146  $this->cli->main(['vobject', 'convert', '--format=json', '-'])
147  );
148 
149  rewind($this->cli->stdout);
151  $this->assertEquals(
152  '["vcard",[["version",{},"text","4.0"],["prodid",{},"text","-\/\/Sabre\/\/Sabre VObject ' . $version . '\/\/EN"],["fn",{},"text","Cowboy Henk"]]]',
153  stream_get_contents($this->cli->stdout)
154  );
155 
156  }
const VERSION
Full version number.
Definition: Version.php:17
$version
Definition: build.php:27

◆ testConvertMimeDir()

Sabre\VObject\CliTest::testConvertMimeDir ( )

Definition at line 221 of file CliTest.php.

221  {
222 
223  $inputStream = fopen('php://memory', 'r+');
224 
225  fwrite($inputStream, <<<JCARD
226 [
227  "vcard",
228  [
229  [
230  "version",
231  {
232 
233  },
234  "text",
235  "4.0"
236  ],
237  [
238  "prodid",
239  {
240 
241  },
242  "text",
243  "-\/\/Sabre\/\/Sabre VObject 3.1.0\/\/EN"
244  ],
245  [
246  "fn",
247  {
248 
249  },
250  "text",
251  "Cowboy Henk"
252  ]
253  ]
254 ]
255 JCARD
256  );
257  rewind($inputStream);
258  $this->cli->stdin = $inputStream;
259 
260  $this->assertEquals(
261  0,
262  $this->cli->main(['vobject', 'convert', '--format=mimedir', '--inputformat=json', '--pretty', '-'])
263  );
264 
265  rewind($this->cli->stdout);
266  $expected = <<<VCF
267 BEGIN:VCARD
268 VERSION:4.0
269 PRODID:-//Sabre//Sabre VObject 3.1.0//EN
270 FN:Cowboy Henk
271 END:VCARD
272 
273 VCF;
274 
275  $this->assertEquals(
276  strtr($expected, ["\n" => "\r\n"]),
277  stream_get_contents($this->cli->stdout)
278  );
279 
280  }

◆ testFormat()

Sabre\VObject\CliTest::testFormat ( )

Definition at line 57 of file CliTest.php.

57  {
58 
59  $this->assertEquals(
60  1,
61  $this->cli->main(['vobject', '--format=jcard'])
62  );
63 
64  rewind($this->cli->stderr);
65  $this->assertTrue(strlen(stream_get_contents($this->cli->stderr)) > 100);
66 
67  $this->assertEquals('jcard', $this->cli->format);
68 
69  }

◆ testFormatInvalid()

Sabre\VObject\CliTest::testFormatInvalid ( )

Definition at line 71 of file CliTest.php.

71  {
72 
73  $this->assertEquals(
74  1,
75  $this->cli->main(['vobject', '--format=foo'])
76  );
77 
78  rewind($this->cli->stderr);
79  $this->assertTrue(strlen(stream_get_contents($this->cli->stderr)) > 100);
80 
81  $this->assertNull($this->cli->format);
82 
83  }

◆ testHelp()

Sabre\VObject\CliTest::testHelp ( )

Definition at line 46 of file CliTest.php.

46  {
47 
48  $this->assertEquals(
49  0,
50  $this->cli->main(['vobject', '-h'])
51  );
52  rewind($this->cli->stderr);
53  $this->assertTrue(strlen(stream_get_contents($this->cli->stderr)) > 100);
54 
55  }

◆ testInputFormatInvalid()

Sabre\VObject\CliTest::testInputFormatInvalid ( )

Definition at line 85 of file CliTest.php.

85  {
86 
87  $this->assertEquals(
88  1,
89  $this->cli->main(['vobject', '--inputformat=foo'])
90  );
91 
92  rewind($this->cli->stderr);
93  $this->assertTrue(strlen(stream_get_contents($this->cli->stderr)) > 100);
94 
95  $this->assertNull($this->cli->format);
96 
97  }

◆ testInvalidArg()

Sabre\VObject\CliTest::testInvalidArg ( )

Definition at line 22 of file CliTest.php.

22  {
23 
24  $this->assertEquals(
25  1,
26  $this->cli->main(['vobject', '--hi'])
27  );
28  rewind($this->cli->stderr);
29  $this->assertTrue(strlen(stream_get_contents($this->cli->stderr)) > 100);
30 
31  }

◆ testNoInputFile()

Sabre\VObject\CliTest::testNoInputFile ( )

Definition at line 100 of file CliTest.php.

100  {
101 
102  $this->assertEquals(
103  1,
104  $this->cli->main(['vobject', 'color'])
105  );
106 
107  rewind($this->cli->stderr);
108  $this->assertTrue(strlen(stream_get_contents($this->cli->stderr)) > 100);
109 
110  }

◆ testQuiet()

Sabre\VObject\CliTest::testQuiet ( )

Definition at line 33 of file CliTest.php.

33  {
34 
35  $this->assertEquals(
36  1,
37  $this->cli->main(['vobject', '-q'])
38  );
39  $this->assertTrue($this->cli->quiet);
40 
41  rewind($this->cli->stderr);
42  $this->assertEquals(0, strlen(stream_get_contents($this->cli->stderr)));
43 
44  }

◆ testRepair()

Sabre\VObject\CliTest::testRepair ( )

Definition at line 480 of file CliTest.php.

480  {
481 
482  $inputStream = fopen('php://memory', 'r+');
483 
484  fwrite($inputStream, <<<VCARD
485 BEGIN:VCARD
486 VERSION:5.0
487 END:VCARD
488 
489 VCARD
490  );
491  rewind($inputStream);
492  $this->cli->stdin = $inputStream;
493 
494  $this->assertEquals(
495  2,
496  $this->cli->main(['vobject', 'repair', '-'])
497  );
498 
499  rewind($this->cli->stdout);
500  $this->assertRegExp("/^BEGIN:VCARD\r\nVERSION:2.1\r\nUID:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\r\nEND:VCARD\r\n$/", stream_get_contents($this->cli->stdout));
501  }

◆ testRepairNothing()

Sabre\VObject\CliTest::testRepairNothing ( )

Definition at line 503 of file CliTest.php.

503  {
504 
505  $inputStream = fopen('php://memory', 'r+');
506 
507  fwrite($inputStream, <<<VCARD
508 BEGIN:VCALENDAR
509 VERSION:2.0
510 PRODID:-//Sabre//Sabre VObject 3.1.0//EN
511 BEGIN:VEVENT
512 UID:foo
513 DTSTAMP:20140122T233226Z
514 DTSTART:20140101T120000Z
515 END:VEVENT
516 END:VCALENDAR
517 
518 VCARD
519  );
520  rewind($inputStream);
521  $this->cli->stdin = $inputStream;
522 
523  $result = $this->cli->main(['vobject', 'repair', '-']);
524 
525  rewind($this->cli->stderr);
526  $error = stream_get_contents($this->cli->stderr);
527 
528  $this->assertEquals(
529  0,
530  $result,
531  "This should have been error free. stderr output:\n" . $error
532  );
533 
534  }
$result

◆ testTooManyArgs()

Sabre\VObject\CliTest::testTooManyArgs ( )

Definition at line 112 of file CliTest.php.

112  {
113 
114  $this->assertEquals(
115  1,
116  $this->cli->main(['vobject', 'color', 'a', 'b', 'c'])
117  );
118 
119  }

◆ testUnknownCommand()

Sabre\VObject\CliTest::testUnknownCommand ( )

Definition at line 121 of file CliTest.php.

121  {
122 
123  $this->assertEquals(
124  1,
125  $this->cli->main(['vobject', 'foo', '-'])
126  );
127 
128  }

◆ testValidate()

Sabre\VObject\CliTest::testValidate ( )

Definition at line 413 of file CliTest.php.

413  {
414 
415  $inputStream = fopen('php://memory', 'r+');
416 
417  fwrite($inputStream, <<<VCARD
418 BEGIN:VCARD
419 VERSION:4.0
420 PRODID:-//Sabre//Sabre VObject 3.1.0//EN
421 UID:foo
422 FN:Cowboy Henk
423 END:VCARD
424 
425 VCARD
426  );
427  rewind($inputStream);
428  $this->cli->stdin = $inputStream;
429  $result = $this->cli->main(['vobject', 'validate', '-']);
430 
431  $this->assertEquals(
432  0,
433  $result
434  );
435 
436  }
$result

◆ testValidateFail()

Sabre\VObject\CliTest::testValidateFail ( )

Definition at line 438 of file CliTest.php.

438  {
439 
440  $inputStream = fopen('php://memory', 'r+');
441 
442  fwrite($inputStream, <<<VCARD
443 BEGIN:VCALENDAR
444 VERSION:2.0
445 END:VCARD
446 
447 VCARD
448  );
449  rewind($inputStream);
450  $this->cli->stdin = $inputStream;
451  // vCard 2.0 is not supported yet, so this returns a failure.
452  $this->assertEquals(
453  2,
454  $this->cli->main(['vobject', 'validate', '-'])
455  );
456 
457  }

◆ testValidateFail2()

Sabre\VObject\CliTest::testValidateFail2 ( )

Definition at line 459 of file CliTest.php.

459  {
460 
461  $inputStream = fopen('php://memory', 'r+');
462 
463  fwrite($inputStream, <<<VCARD
464 BEGIN:VCALENDAR
465 VERSION:5.0
466 END:VCALENDAR
467 
468 VCARD
469  );
470  rewind($inputStream);
471  $this->cli->stdin = $inputStream;
472 
473  $this->assertEquals(
474  2,
475  $this->cli->main(['vobject', 'validate', '-'])
476  );
477 
478  }

◆ testVCard3040()

Sabre\VObject\CliTest::testVCard3040 ( )

Definition at line 310 of file CliTest.php.

310  {
311 
312  $inputStream = fopen('php://memory', 'r+');
313 
314  fwrite($inputStream, <<<VCARD
315 BEGIN:VCARD
316 VERSION:3.0
317 PRODID:-//Sabre//Sabre VObject 3.1.0//EN
318 FN:Cowboy Henk
319 END:VCARD
320 
321 VCARD
322  );
323  rewind($inputStream);
324  $this->cli->stdin = $inputStream;
325 
326  $this->assertEquals(
327  0,
328  $this->cli->main(['vobject', 'convert', '--format=vcard40', '--pretty', '-'])
329  );
330 
331  rewind($this->cli->stdout);
332 
334  $expected = <<<VCF
335 BEGIN:VCARD
336 VERSION:4.0
337 PRODID:-//Sabre//Sabre VObject $version//EN
338 FN:Cowboy Henk
339 END:VCARD
340 
341 VCF;
342 
343  $this->assertEquals(
344  strtr($expected, ["\n" => "\r\n"]),
345  stream_get_contents($this->cli->stdout)
346  );
347 
348  }
const VERSION
Full version number.
Definition: Version.php:17
$version
Definition: build.php:27

◆ testVCard4021()

Sabre\VObject\CliTest::testVCard4021 ( )

Definition at line 390 of file CliTest.php.

390  {
391 
392  $inputStream = fopen('php://memory', 'r+');
393 
394  fwrite($inputStream, <<<VCARD
395 BEGIN:VCARD
396 VERSION:4.0
397 PRODID:-//Sabre//Sabre VObject 3.1.0//EN
398 FN:Cowboy Henk
399 END:VCARD
400 
401 VCARD
402  );
403  rewind($inputStream);
404  $this->cli->stdin = $inputStream;
405 
406  $this->assertEquals(
407  2,
408  $this->cli->main(['vobject', 'convert', '--format=vcard21', '--pretty', '-'])
409  );
410 
411  }

◆ testVCard4030()

Sabre\VObject\CliTest::testVCard4030 ( )

Definition at line 350 of file CliTest.php.

350  {
351 
352  $inputStream = fopen('php://memory', 'r+');
353 
354  fwrite($inputStream, <<<VCARD
355 BEGIN:VCARD
356 VERSION:4.0
357 PRODID:-//Sabre//Sabre VObject 3.1.0//EN
358 FN:Cowboy Henk
359 END:VCARD
360 
361 VCARD
362  );
363  rewind($inputStream);
364  $this->cli->stdin = $inputStream;
365 
366  $this->assertEquals(
367  0,
368  $this->cli->main(['vobject', 'convert', '--format=vcard30', '--pretty', '-'])
369  );
370 
372 
373  rewind($this->cli->stdout);
374  $expected = <<<VCF
375 BEGIN:VCARD
376 VERSION:3.0
377 PRODID:-//Sabre//Sabre VObject $version//EN
378 FN:Cowboy Henk
379 END:VCARD
380 
381 VCF;
382 
383  $this->assertEquals(
384  strtr($expected, ["\n" => "\r\n"]),
385  stream_get_contents($this->cli->stdout)
386  );
387 
388  }
const VERSION
Full version number.
Definition: Version.php:17
$version
Definition: build.php:27

The documentation for this class was generated from the following file: