annotate vendor/sabre/vobject/tests/VObject/Component/VCardTest.php @ 7:430dbd5346f7

vendor sabre as distributed
author Charlie Root
date Sat, 13 Jan 2018 09:06:10 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
1 <?php
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
2
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
3 namespace Sabre\VObject\Component;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
4
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
5 use Sabre\VObject;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
6
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
7 class VCardTest extends \PHPUnit_Framework_TestCase {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
8
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
9 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
10 * @dataProvider validateData
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
11 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
12 function testValidate($input, $expectedWarnings, $expectedRepairedOutput) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
13
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
14 $vcard = VObject\Reader::read($input);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
15
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
16 $warnings = $vcard->validate();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
17
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
18 $warnMsg = array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
19 foreach($warnings as $warning) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
20 $warnMsg[] = $warning['message'];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
21 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
22
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
23 $this->assertEquals($expectedWarnings, $warnMsg);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
24
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
25 $vcard->validate(VObject\Component::REPAIR);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
26
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
27 $this->assertEquals(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
28 $expectedRepairedOutput,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
29 $vcard->serialize()
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
30 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
31
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
32 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
33
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
34 public function validateData() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
35
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
36 $tests = array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
37
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
38 // Correct
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
39 $tests[] = array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
40 "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:John Doe\r\nUID:foo\r\nEND:VCARD\r\n",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
41 array(),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
42 "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:John Doe\r\nUID:foo\r\nEND:VCARD\r\n",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
43 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
44
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
45 // No VERSION
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
46 $tests[] = array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
47 "BEGIN:VCARD\r\nFN:John Doe\r\nUID:foo\r\nEND:VCARD\r\n",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
48 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
49 'VERSION MUST appear exactly once in a VCARD component',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
50 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
51 "BEGIN:VCARD\r\nVERSION:3.0\r\nFN:John Doe\r\nUID:foo\r\nEND:VCARD\r\n",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
52 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
53
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
54 // Unknown version
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
55 $tests[] = array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
56 "BEGIN:VCARD\r\nVERSION:2.2\r\nFN:John Doe\r\nUID:foo\r\nEND:VCARD\r\n",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
57 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
58 'Only vcard version 4.0 (RFC6350), version 3.0 (RFC2426) or version 2.1 (icm-vcard-2.1) are supported.',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
59 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
60 "BEGIN:VCARD\r\nVERSION:2.1\r\nFN:John Doe\r\nUID:foo\r\nEND:VCARD\r\n",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
61 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
62
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
63 // No FN
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
64 $tests[] = array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
65 "BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nEND:VCARD\r\n",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
66 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
67 'The FN property must appear in the VCARD component exactly 1 time',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
68 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
69 "BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nEND:VCARD\r\n",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
70 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
71 // No FN, N fallback
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
72 $tests[] = array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
73 "BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nN:Doe;John;;;;;\r\nEND:VCARD\r\n",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
74 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
75 'The FN property must appear in the VCARD component exactly 1 time',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
76 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
77 "BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nN:Doe;John;;;;;\r\nFN:John Doe\r\nEND:VCARD\r\n",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
78 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
79 // No FN, N fallback, no first name
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
80 $tests[] = array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
81 "BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nN:Doe;;;;;;\r\nEND:VCARD\r\n",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
82 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
83 'The FN property must appear in the VCARD component exactly 1 time',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
84 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
85 "BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nN:Doe;;;;;;\r\nFN:Doe\r\nEND:VCARD\r\n",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
86 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
87
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
88 // No FN, ORG fallback
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
89 $tests[] = array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
90 "BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nORG:Acme Co.\r\nEND:VCARD\r\n",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
91 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
92 'The FN property must appear in the VCARD component exactly 1 time',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
93 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
94 "BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nORG:Acme Co.\r\nFN:Acme Co.\r\nEND:VCARD\r\n",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
95 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
96 return $tests;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
97
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
98 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
99
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
100 function testGetDocumentType() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
101
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
102 $vcard = new VCard(array(), false);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
103 $vcard->VERSION = '2.1';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
104 $this->assertEquals(VCard::VCARD21, $vcard->getDocumentType());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
105
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
106 $vcard = new VCard(array(), false);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
107 $vcard->VERSION = '3.0';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
108 $this->assertEquals(VCard::VCARD30, $vcard->getDocumentType());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
109
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
110 $vcard = new VCard(array(), false);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
111 $vcard->VERSION = '4.0';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
112 $this->assertEquals(VCard::VCARD40, $vcard->getDocumentType());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
113
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
114 $vcard = new VCard(array(), false);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
115 $this->assertEquals(VCard::UNKNOWN, $vcard->getDocumentType());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
116 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
117
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
118 function testPreferredNoPref() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
119
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
120 $vcard = <<<VCF
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
121 BEGIN:VCARD
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
122 VERSION:3.0
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
123 EMAIL:1@example.org
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
124 EMAIL:2@example.org
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
125 END:VCARD
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
126 VCF;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
127
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
128 $vcard = VObject\Reader::read($vcard);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
129 $this->assertEquals('1@example.org', $vcard->preferred('EMAIL')->getValue());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
130
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
131 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
132
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
133 function testPreferredWithPref() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
134
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
135 $vcard = <<<VCF
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
136 BEGIN:VCARD
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
137 VERSION:3.0
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
138 EMAIL:1@example.org
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
139 EMAIL;TYPE=PREF:2@example.org
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
140 END:VCARD
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
141 VCF;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
142
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
143 $vcard = VObject\Reader::read($vcard);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
144 $this->assertEquals('2@example.org', $vcard->preferred('EMAIL')->getValue());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
145
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
146 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
147
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
148 function testPreferredWith40Pref() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
149
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
150 $vcard = <<<VCF
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
151 BEGIN:VCARD
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
152 VERSION:4.0
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
153 EMAIL:1@example.org
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
154 EMAIL;PREF=3:2@example.org
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
155 EMAIL;PREF=2:3@example.org
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
156 END:VCARD
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
157 VCF;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
158
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
159 $vcard = VObject\Reader::read($vcard);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
160 $this->assertEquals('3@example.org', $vcard->preferred('EMAIL')->getValue());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
161
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
162 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
163
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
164 function testPreferredNotFound() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
165
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
166 $vcard = <<<VCF
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
167 BEGIN:VCARD
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
168 VERSION:4.0
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
169 END:VCARD
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
170 VCF;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
171
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
172 $vcard = VObject\Reader::read($vcard);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
173 $this->assertNull($vcard->preferred('EMAIL'));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
174
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
175 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
176
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
177 function testNoUIDCardDAV() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
178
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
179 $vcard = <<<VCF
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
180 BEGIN:VCARD
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
181 VERSION:4.0
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
182 FN:John Doe
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
183 END:VCARD
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
184 VCF;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
185 $this->assertValidate(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
186 $vcard,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
187 VCARD::PROFILE_CARDDAV,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
188 3,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
189 'vCards on CardDAV servers MUST have a UID property.'
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
190 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
191
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
192 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
193
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
194 function testNoUIDNoCardDAV() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
195
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
196 $vcard = <<<VCF
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
197 BEGIN:VCARD
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
198 VERSION:4.0
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
199 FN:John Doe
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
200 END:VCARD
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
201 VCF;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
202 $this->assertValidate(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
203 $vcard,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
204 0,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
205 2,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
206 'Adding a UID to a vCard property is recommended.'
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
207 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
208
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
209 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
210 function testNoUIDNoCardDAVRepair() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
211
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
212 $vcard = <<<VCF
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
213 BEGIN:VCARD
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
214 VERSION:4.0
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
215 FN:John Doe
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
216 END:VCARD
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
217 VCF;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
218 $this->assertValidate(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
219 $vcard,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
220 VCARD::REPAIR,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
221 1,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
222 'Adding a UID to a vCard property is recommended.'
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
223 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
224
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
225 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
226
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
227 function testVCard21CardDAV() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
228
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
229 $vcard = <<<VCF
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
230 BEGIN:VCARD
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
231 VERSION:2.1
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
232 FN:John Doe
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
233 UID:foo
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
234 END:VCARD
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
235 VCF;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
236 $this->assertValidate(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
237 $vcard,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
238 VCARD::PROFILE_CARDDAV,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
239 3,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
240 'CardDAV servers are not allowed to accept vCard 2.1.'
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
241 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
242
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
243 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
244
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
245 function testVCard21NoCardDAV() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
246
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
247 $vcard = <<<VCF
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
248 BEGIN:VCARD
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
249 VERSION:2.1
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
250 FN:John Doe
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
251 UID:foo
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
252 END:VCARD
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
253 VCF;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
254 $this->assertValidate(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
255 $vcard,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
256 0,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
257 0
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
258 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
259
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
260 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
261
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
262 function assertValidate($vcf, $options, $expectedLevel, $expectedMessage = null) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
263
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
264 $vcal = VObject\Reader::read($vcf);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
265 $result = $vcal->validate($options);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
266
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
267 $this->assertValidateResult($result, $expectedLevel, $expectedMessage);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
268
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
269 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
270
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
271 function assertValidateResult($input, $expectedLevel, $expectedMessage = null) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
272
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
273 $messages = array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
274 foreach($input as $warning) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
275 $messages[] = $warning['message'];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
276 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
277
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
278 if ($expectedLevel === 0) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
279 $this->assertEquals(0, count($input), 'No validation messages were expected. We got: ' . implode(', ', $messages));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
280 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
281 $this->assertEquals(1, count($input), 'We expected exactly 1 validation message, We got: ' . implode(', ', $messages));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
282
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
283 $this->assertEquals($expectedMessage, $input[0]['message']);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
284 $this->assertEquals($expectedLevel, $input[0]['level']);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
285 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
286
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
287 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
288 }