]> git.mxchange.org Git - friendica-addons.git/blob - dav/sabre-vobject/tests/Sabre/VObject/Component/VCardTest.php
Second part of refactoring; should be runnable again, yet not thoroughly tested
[friendica-addons.git] / dav / sabre-vobject / tests / Sabre / VObject / Component / VCardTest.php
1 <?php
2
3 namespace Sabre\VObject\Component;
4
5 use Sabre\VObject;
6
7 class VCardTest extends \PHPUnit_Framework_TestCase {
8
9     /**
10      * @dataProvider validateData
11      */
12     function testValidate($input, $expectedWarnings, $expectedRepairedOutput) {
13
14         $vcard = VObject\Reader::read($input);
15
16         $warnings = $vcard->validate();
17
18         $warnMsg = array();
19         foreach($warnings as $warning) {
20             $warnMsg[] = $warning['message'];
21         }
22
23         $this->assertEquals($expectedWarnings, $warnMsg);
24
25         $vcard->validate(VObject\Component::REPAIR);
26
27         $this->assertEquals(
28             $expectedRepairedOutput,
29             $vcard->serialize()
30         );
31
32     }
33
34     public function validateData() {
35
36         $tests = array();
37
38         // Correct
39         $tests[] = array(
40             "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:John Doe\r\nEND:VCARD\r\n",
41             array(),
42             "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:John Doe\r\nEND:VCARD\r\n",
43         );
44
45         // No VERSION
46         $tests[] = array(
47             "BEGIN:VCARD\r\nFN:John Doe\r\nEND:VCARD\r\n",
48             array(
49                 'The VERSION property must appear in the VCARD component exactly 1 time',
50             ),
51             "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:John Doe\r\nEND:VCARD\r\n",
52         );
53
54         // Unknown version
55         $tests[] = array(
56             "BEGIN:VCARD\r\nVERSION:2.2\r\nFN:John Doe\r\nEND:VCARD\r\n",
57             array(
58                 'Only vcard version 4.0 (RFC6350), version 3.0 (RFC2426) or version 2.1 (icm-vcard-2.1) are supported.',
59             ),
60             "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:John Doe\r\nEND:VCARD\r\n",
61         );
62
63         // No FN
64         $tests[] = array(
65             "BEGIN:VCARD\r\nVERSION:4.0\r\nEND:VCARD\r\n",
66             array(
67                 'The FN property must appear in the VCARD component exactly 1 time',
68             ),
69             "BEGIN:VCARD\r\nVERSION:4.0\r\nEND:VCARD\r\n",
70         );
71         // No FN, N fallback
72         $tests[] = array(
73             "BEGIN:VCARD\r\nVERSION:4.0\r\nN:Doe;John;;;;;\r\nEND:VCARD\r\n",
74             array(
75                 'The FN property must appear in the VCARD component exactly 1 time',
76             ),
77             "BEGIN:VCARD\r\nVERSION:4.0\r\nN:Doe;John;;;;;\r\nFN:John Doe\r\nEND:VCARD\r\n",
78         );
79         // No FN, N fallback, no first name
80         $tests[] = array(
81             "BEGIN:VCARD\r\nVERSION:4.0\r\nN:Doe;;;;;;\r\nEND:VCARD\r\n",
82             array(
83                 'The FN property must appear in the VCARD component exactly 1 time',
84             ),
85             "BEGIN:VCARD\r\nVERSION:4.0\r\nN:Doe;;;;;;\r\nFN:Doe\r\nEND:VCARD\r\n",
86         );
87
88         // No FN, ORG fallback
89         $tests[] = array(
90             "BEGIN:VCARD\r\nVERSION:4.0\r\nORG:Acme Co.\r\nEND:VCARD\r\n",
91             array(
92                 'The FN property must appear in the VCARD component exactly 1 time',
93             ),
94             "BEGIN:VCARD\r\nVERSION:4.0\r\nORG:Acme Co.\r\nFN:Acme Co.\r\nEND:VCARD\r\n",
95         );
96         return $tests;
97
98     }
99
100 }