ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Sabre\VObject\Component\VCardTest Class Reference
+ Inheritance diagram for Sabre\VObject\Component\VCardTest:
+ Collaboration diagram for Sabre\VObject\Component\VCardTest:

Public Member Functions

 testValidate ($input, $expectedWarnings, $expectedRepairedOutput)
 @dataProvider validateData More...
 
 validateData ()
 
 testGetDocumentType ()
 
 testGetByType ()
 
 testPreferredNoPref ()
 
 testPreferredWithPref ()
 
 testPreferredWith40Pref ()
 
 testPreferredNotFound ()
 
 testNoUIDCardDAV ()
 
 testNoUIDNoCardDAV ()
 
 testNoUIDNoCardDAVRepair ()
 
 testVCard21CardDAV ()
 
 testVCard21NoCardDAV ()
 
 assertValidate ($vcf, $options, $expectedLevel, $expectedMessage=null)
 
 assertValidateResult ($input, $expectedLevel, $expectedMessage=null)
 

Detailed Description

Definition at line 8 of file VCardTest.php.

Member Function Documentation

◆ assertValidate()

Sabre\VObject\Component\VCardTest::assertValidate (   $vcf,
  $options,
  $expectedLevel,
  $expectedMessage = null 
)

Definition at line 286 of file VCardTest.php.

286 {
287
289 $result = $vcal->validate($options);
290
291 $this->assertValidateResult($result, $expectedLevel, $expectedMessage);
292
293 }
$result
assertValidateResult($input, $expectedLevel, $expectedMessage=null)
Definition: VCardTest.php:295
static read($data, $options=0, $charset='UTF-8')
Parses a vCard or iCalendar object, and returns the top component.
Definition: Reader.php:42

References PHPMailer\PHPMailer\$options, $result, $vcal, Sabre\VObject\Component\VCardTest\assertValidateResult(), and Sabre\VObject\Reader\read().

Referenced by Sabre\VObject\Component\VCardTest\testNoUIDCardDAV(), Sabre\VObject\Component\VCardTest\testNoUIDNoCardDAV(), Sabre\VObject\Component\VCardTest\testNoUIDNoCardDAVRepair(), Sabre\VObject\Component\VCardTest\testVCard21CardDAV(), and Sabre\VObject\Component\VCardTest\testVCard21NoCardDAV().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ assertValidateResult()

Sabre\VObject\Component\VCardTest::assertValidateResult (   $input,
  $expectedLevel,
  $expectedMessage = null 
)

Definition at line 295 of file VCardTest.php.

295 {
296
297 $messages = [];
298 foreach ($input as $warning) {
299 $messages[] = $warning['message'];
300 }
301
302 if ($expectedLevel === 0) {
303 $this->assertEquals(0, count($input), 'No validation messages were expected. We got: ' . implode(', ', $messages));
304 } else {
305 $this->assertEquals(1, count($input), 'We expected exactly 1 validation message, We got: ' . implode(', ', $messages));
306
307 $this->assertEquals($expectedMessage, $input[0]['message']);
308 $this->assertEquals($expectedLevel, $input[0]['level']);
309 }
310
311 }
$warning
Definition: X509warning.php:13
count()
Returns the number of elements.
Definition: Node.php:177
$messages
Definition: en.php:5
foreach($paths as $path) if($argc< 3) $input

References Sabre\VObject\$input, $messages, $warning, and Sabre\VObject\Node\count().

Referenced by Sabre\VObject\Component\VCardTest\assertValidate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testGetByType()

Sabre\VObject\Component\VCardTest::testGetByType ( )

Definition at line 126 of file VCardTest.php.

126 {
127 $vcard = <<<VCF
128BEGIN:VCARD
129VERSION:3.0
130EMAIL;TYPE=home:1@example.org
131EMAIL;TYPE=work:2@example.org
132END:VCARD
133VCF;
134
135 $vcard = VObject\Reader::read($vcard);
136 $this->assertEquals('1@example.org', $vcard->getByType('EMAIL', 'home')->getValue());
137 $this->assertEquals('2@example.org', $vcard->getByType('EMAIL', 'work')->getValue());
138 $this->assertNull($vcard->getByType('EMAIL', 'non-existant'));
139 $this->assertNull($vcard->getByType('ADR', 'non-existant'));
140 }

References Sabre\VObject\Reader\read().

+ Here is the call graph for this function:

◆ testGetDocumentType()

Sabre\VObject\Component\VCardTest::testGetDocumentType ( )

Definition at line 108 of file VCardTest.php.

108 {
109
110 $vcard = new VCard([], false);
111 $vcard->VERSION = '2.1';
112 $this->assertEquals(VCard::VCARD21, $vcard->getDocumentType());
113
114 $vcard = new VCard([], false);
115 $vcard->VERSION = '3.0';
116 $this->assertEquals(VCard::VCARD30, $vcard->getDocumentType());
117
118 $vcard = new VCard([], false);
119 $vcard->VERSION = '4.0';
120 $this->assertEquals(VCard::VCARD40, $vcard->getDocumentType());
121
122 $vcard = new VCard([], false);
123 $this->assertEquals(VCard::UNKNOWN, $vcard->getDocumentType());
124 }
const VCARD30
vCard 3.0.
Definition: Document.php:44
const UNKNOWN
Unknown document type.
Definition: Document.php:24
const VCARD21
vCard 2.1.
Definition: Document.php:39
const VCARD40
vCard 4.0.
Definition: Document.php:49

References Sabre\VObject\Document\UNKNOWN, Sabre\VObject\Document\VCARD21, Sabre\VObject\Document\VCARD30, and Sabre\VObject\Document\VCARD40.

◆ testNoUIDCardDAV()

Sabre\VObject\Component\VCardTest::testNoUIDCardDAV ( )

Definition at line 201 of file VCardTest.php.

201 {
202
203 $vcard = <<<VCF
204BEGIN:VCARD
205VERSION:4.0
206FN:John Doe
207END:VCARD
208VCF;
209 $this->assertValidate(
210 $vcard,
211 VCARD::PROFILE_CARDDAV,
212 3,
213 'vCards on CardDAV servers MUST have a UID property.'
214 );
215
216 }
assertValidate($vcf, $options, $expectedLevel, $expectedMessage=null)
Definition: VCardTest.php:286

References Sabre\VObject\Component\VCardTest\assertValidate().

+ Here is the call graph for this function:

◆ testNoUIDNoCardDAV()

Sabre\VObject\Component\VCardTest::testNoUIDNoCardDAV ( )

Definition at line 218 of file VCardTest.php.

218 {
219
220 $vcard = <<<VCF
221BEGIN:VCARD
222VERSION:4.0
223FN:John Doe
224END:VCARD
225VCF;
226 $this->assertValidate(
227 $vcard,
228 0,
229 2,
230 'Adding a UID to a vCard property is recommended.'
231 );
232
233 }

References Sabre\VObject\Component\VCardTest\assertValidate().

+ Here is the call graph for this function:

◆ testNoUIDNoCardDAVRepair()

Sabre\VObject\Component\VCardTest::testNoUIDNoCardDAVRepair ( )

Definition at line 234 of file VCardTest.php.

234 {
235
236 $vcard = <<<VCF
237BEGIN:VCARD
238VERSION:4.0
239FN:John Doe
240END:VCARD
241VCF;
242 $this->assertValidate(
243 $vcard,
244 VCARD::REPAIR,
245 1,
246 'Adding a UID to a vCard property is recommended.'
247 );
248
249 }

References Sabre\VObject\Component\VCardTest\assertValidate().

+ Here is the call graph for this function:

◆ testPreferredNoPref()

Sabre\VObject\Component\VCardTest::testPreferredNoPref ( )

Definition at line 142 of file VCardTest.php.

142 {
143
144 $vcard = <<<VCF
145BEGIN:VCARD
146VERSION:3.0
147EMAIL:1@example.org
148EMAIL:2@example.org
149END:VCARD
150VCF;
151
152 $vcard = VObject\Reader::read($vcard);
153 $this->assertEquals('1@example.org', $vcard->preferred('EMAIL')->getValue());
154
155 }

References Sabre\VObject\Reader\read().

+ Here is the call graph for this function:

◆ testPreferredNotFound()

Sabre\VObject\Component\VCardTest::testPreferredNotFound ( )

Definition at line 188 of file VCardTest.php.

188 {
189
190 $vcard = <<<VCF
191BEGIN:VCARD
192VERSION:4.0
193END:VCARD
194VCF;
195
196 $vcard = VObject\Reader::read($vcard);
197 $this->assertNull($vcard->preferred('EMAIL'));
198
199 }

References Sabre\VObject\Reader\read().

+ Here is the call graph for this function:

◆ testPreferredWith40Pref()

Sabre\VObject\Component\VCardTest::testPreferredWith40Pref ( )

Definition at line 172 of file VCardTest.php.

172 {
173
174 $vcard = <<<VCF
175BEGIN:VCARD
176VERSION:4.0
177EMAIL:1@example.org
178EMAIL;PREF=3:2@example.org
179EMAIL;PREF=2:3@example.org
180END:VCARD
181VCF;
182
183 $vcard = VObject\Reader::read($vcard);
184 $this->assertEquals('3@example.org', $vcard->preferred('EMAIL')->getValue());
185
186 }

References Sabre\VObject\Reader\read().

+ Here is the call graph for this function:

◆ testPreferredWithPref()

Sabre\VObject\Component\VCardTest::testPreferredWithPref ( )

Definition at line 157 of file VCardTest.php.

157 {
158
159 $vcard = <<<VCF
160BEGIN:VCARD
161VERSION:3.0
162EMAIL:1@example.org
163EMAIL;TYPE=PREF:2@example.org
164END:VCARD
165VCF;
166
167 $vcard = VObject\Reader::read($vcard);
168 $this->assertEquals('2@example.org', $vcard->preferred('EMAIL')->getValue());
169
170 }

References Sabre\VObject\Reader\read().

+ Here is the call graph for this function:

◆ testValidate()

Sabre\VObject\Component\VCardTest::testValidate (   $input,
  $expectedWarnings,
  $expectedRepairedOutput 
)

@dataProvider validateData

Definition at line 13 of file VCardTest.php.

13 {
14
16
17 $warnings = $vcard->validate();
18
19 $warnMsg = [];
20 foreach ($warnings as $warning) {
21 $warnMsg[] = $warning['message'];
22 }
23
24 $this->assertEquals($expectedWarnings, $warnMsg);
25
26 $vcard->validate(VObject\Component::REPAIR);
27
28 $this->assertEquals(
29 $expectedRepairedOutput,
30 $vcard->serialize()
31 );
32
33 }
const REPAIR
The following constants are used by the validate() method.
Definition: Node.php:27

References Sabre\VObject\$input, $warning, $warnings, Sabre\VObject\Reader\read(), and Sabre\VObject\Node\REPAIR.

+ Here is the call graph for this function:

◆ testVCard21CardDAV()

Sabre\VObject\Component\VCardTest::testVCard21CardDAV ( )

Definition at line 251 of file VCardTest.php.

251 {
252
253 $vcard = <<<VCF
254BEGIN:VCARD
255VERSION:2.1
256FN:John Doe
257UID:foo
258END:VCARD
259VCF;
260 $this->assertValidate(
261 $vcard,
262 VCARD::PROFILE_CARDDAV,
263 3,
264 'CardDAV servers are not allowed to accept vCard 2.1.'
265 );
266
267 }

References Sabre\VObject\Component\VCardTest\assertValidate().

+ Here is the call graph for this function:

◆ testVCard21NoCardDAV()

Sabre\VObject\Component\VCardTest::testVCard21NoCardDAV ( )

Definition at line 269 of file VCardTest.php.

269 {
270
271 $vcard = <<<VCF
272BEGIN:VCARD
273VERSION:2.1
274FN:John Doe
275UID:foo
276END:VCARD
277VCF;
278 $this->assertValidate(
279 $vcard,
280 0,
281 0
282 );
283
284 }

References Sabre\VObject\Component\VCardTest\assertValidate().

+ Here is the call graph for this function:

◆ validateData()

Sabre\VObject\Component\VCardTest::validateData ( )

Definition at line 35 of file VCardTest.php.

35 {
36
37 $tests = [];
38
39 // Correct
40 $tests[] = [
41 "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:John Doe\r\nUID:foo\r\nEND:VCARD\r\n",
42 [],
43 "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:John Doe\r\nUID:foo\r\nEND:VCARD\r\n",
44 ];
45
46 // No VERSION
47 $tests[] = [
48 "BEGIN:VCARD\r\nFN:John Doe\r\nUID:foo\r\nEND:VCARD\r\n",
49 [
50 'VERSION MUST appear exactly once in a VCARD component',
51 ],
52 "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:John Doe\r\nUID:foo\r\nEND:VCARD\r\n",
53 ];
54
55 // Unknown version
56 $tests[] = [
57 "BEGIN:VCARD\r\nVERSION:2.2\r\nFN:John Doe\r\nUID:foo\r\nEND:VCARD\r\n",
58 [
59 'Only vcard version 4.0 (RFC6350), version 3.0 (RFC2426) or version 2.1 (icm-vcard-2.1) are supported.',
60 ],
61 "BEGIN:VCARD\r\nVERSION:2.1\r\nFN:John Doe\r\nUID:foo\r\nEND:VCARD\r\n",
62 ];
63
64 // No FN
65 $tests[] = [
66 "BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nEND:VCARD\r\n",
67 [
68 'The FN property must appear in the VCARD component exactly 1 time',
69 ],
70 "BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nEND:VCARD\r\n",
71 ];
72 // No FN, N fallback
73 $tests[] = [
74 "BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nN:Doe;John;;;;;\r\nEND:VCARD\r\n",
75 [
76 'The FN property must appear in the VCARD component exactly 1 time',
77 ],
78 "BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nN:Doe;John;;;;;\r\nFN:John Doe\r\nEND:VCARD\r\n",
79 ];
80 // No FN, N fallback, no first name
81 $tests[] = [
82 "BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nN:Doe;;;;;;\r\nEND:VCARD\r\n",
83 [
84 'The FN property must appear in the VCARD component exactly 1 time',
85 ],
86 "BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nN:Doe;;;;;;\r\nFN:Doe\r\nEND:VCARD\r\n",
87 ];
88 // No FN, ORG fallback
89 $tests[] = [
90 "BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nORG:Acme Co.\r\nEND:VCARD\r\n",
91 [
92 'The FN property must appear in the VCARD component exactly 1 time',
93 ],
94 "BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nORG:Acme Co.\r\nFN:Acme Co.\r\nEND:VCARD\r\n",
95 ];
96 // No FN, EMAIL fallback
97 $tests[] = [
98 "BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nEMAIL:1@example.org\r\nEND:VCARD\r\n",
99 [
100 'The FN property must appear in the VCARD component exactly 1 time',
101 ],
102 "BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nEMAIL:1@example.org\r\nFN:1@example.org\r\nEND:VCARD\r\n",
103 ];
104 return $tests;
105
106 }
$tests
Definition: bench.php:104

References $tests.


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