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)
 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.

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().

286  {
287 
288  $vcal = VObject\Reader::read($vcf);
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
+ 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.

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

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

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  }
if($argc< 3) $input
$messages
Definition: en.php:5
$warning
Definition: X509warning.php:13
count()
Returns the number of elements.
Definition: Node.php:177
+ 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.

References Sabre\VObject\Reader\read().

126  {
127  $vcard = <<<VCF
128 BEGIN:VCARD
129 VERSION:3.0
130 EMAIL;TYPE=home:1@example.org
131 EMAIL;TYPE=work:2@example.org
132 END:VCARD
133 VCF;
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  }
static read($data, $options=0, $charset='UTF-8')
Parses a vCard or iCalendar object, and returns the top component.
Definition: Reader.php:42
+ Here is the call graph for this function:

◆ testGetDocumentType()

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

Definition at line 108 of file VCardTest.php.

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

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

◆ testNoUIDCardDAV()

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

Definition at line 201 of file VCardTest.php.

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

201  {
202 
203  $vcard = <<<VCF
204 BEGIN:VCARD
205 VERSION:4.0
206 FN:John Doe
207 END:VCARD
208 VCF;
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
+ Here is the call graph for this function:

◆ testNoUIDNoCardDAV()

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

Definition at line 218 of file VCardTest.php.

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

218  {
219 
220  $vcard = <<<VCF
221 BEGIN:VCARD
222 VERSION:4.0
223 FN:John Doe
224 END:VCARD
225 VCF;
226  $this->assertValidate(
227  $vcard,
228  0,
229  2,
230  'Adding a UID to a vCard property is recommended.'
231  );
232 
233  }
assertValidate($vcf, $options, $expectedLevel, $expectedMessage=null)
Definition: VCardTest.php:286
+ Here is the call graph for this function:

◆ testNoUIDNoCardDAVRepair()

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

Definition at line 234 of file VCardTest.php.

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

234  {
235 
236  $vcard = <<<VCF
237 BEGIN:VCARD
238 VERSION:4.0
239 FN:John Doe
240 END:VCARD
241 VCF;
242  $this->assertValidate(
243  $vcard,
244  VCARD::REPAIR,
245  1,
246  'Adding a UID to a vCard property is recommended.'
247  );
248 
249  }
assertValidate($vcf, $options, $expectedLevel, $expectedMessage=null)
Definition: VCardTest.php:286
+ Here is the call graph for this function:

◆ testPreferredNoPref()

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

Definition at line 142 of file VCardTest.php.

References Sabre\VObject\Reader\read().

142  {
143 
144  $vcard = <<<VCF
145 BEGIN:VCARD
146 VERSION:3.0
147 EMAIL:1@example.org
148 EMAIL:2@example.org
149 END:VCARD
150 VCF;
151 
152  $vcard = VObject\Reader::read($vcard);
153  $this->assertEquals('1@example.org', $vcard->preferred('EMAIL')->getValue());
154 
155  }
static read($data, $options=0, $charset='UTF-8')
Parses a vCard or iCalendar object, and returns the top component.
Definition: Reader.php:42
+ Here is the call graph for this function:

◆ testPreferredNotFound()

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

Definition at line 188 of file VCardTest.php.

References Sabre\VObject\Reader\read().

188  {
189 
190  $vcard = <<<VCF
191 BEGIN:VCARD
192 VERSION:4.0
193 END:VCARD
194 VCF;
195 
196  $vcard = VObject\Reader::read($vcard);
197  $this->assertNull($vcard->preferred('EMAIL'));
198 
199  }
static read($data, $options=0, $charset='UTF-8')
Parses a vCard or iCalendar object, and returns the top component.
Definition: Reader.php:42
+ Here is the call graph for this function:

◆ testPreferredWith40Pref()

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

Definition at line 172 of file VCardTest.php.

References Sabre\VObject\Reader\read().

172  {
173 
174  $vcard = <<<VCF
175 BEGIN:VCARD
176 VERSION:4.0
177 EMAIL:1@example.org
178 EMAIL;PREF=3:2@example.org
179 EMAIL;PREF=2:3@example.org
180 END:VCARD
181 VCF;
182 
183  $vcard = VObject\Reader::read($vcard);
184  $this->assertEquals('3@example.org', $vcard->preferred('EMAIL')->getValue());
185 
186  }
static read($data, $options=0, $charset='UTF-8')
Parses a vCard or iCalendar object, and returns the top component.
Definition: Reader.php:42
+ Here is the call graph for this function:

◆ testPreferredWithPref()

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

Definition at line 157 of file VCardTest.php.

References Sabre\VObject\Reader\read().

157  {
158 
159  $vcard = <<<VCF
160 BEGIN:VCARD
161 VERSION:3.0
162 EMAIL:1@example.org
163 EMAIL;TYPE=PREF:2@example.org
164 END:VCARD
165 VCF;
166 
167  $vcard = VObject\Reader::read($vcard);
168  $this->assertEquals('2@example.org', $vcard->preferred('EMAIL')->getValue());
169 
170  }
static read($data, $options=0, $charset='UTF-8')
Parses a vCard or iCalendar object, and returns the top component.
Definition: Reader.php:42
+ Here is the call graph for this function:

◆ testValidate()

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

validateData

Definition at line 13 of file VCardTest.php.

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

13  {
14 
15  $vcard = VObject\Reader::read($input);
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  }
if($argc< 3) $input
$warning
Definition: X509warning.php:13
const REPAIR
The following constants are used by the validate() method.
Definition: Node.php:27
static read($data, $options=0, $charset='UTF-8')
Parses a vCard or iCalendar object, and returns the top component.
Definition: Reader.php:42
+ Here is the call graph for this function:

◆ testVCard21CardDAV()

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

Definition at line 251 of file VCardTest.php.

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

251  {
252 
253  $vcard = <<<VCF
254 BEGIN:VCARD
255 VERSION:2.1
256 FN:John Doe
257 UID:foo
258 END:VCARD
259 VCF;
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  }
assertValidate($vcf, $options, $expectedLevel, $expectedMessage=null)
Definition: VCardTest.php:286
+ Here is the call graph for this function:

◆ testVCard21NoCardDAV()

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

Definition at line 269 of file VCardTest.php.

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

269  {
270 
271  $vcard = <<<VCF
272 BEGIN:VCARD
273 VERSION:2.1
274 FN:John Doe
275 UID:foo
276 END:VCARD
277 VCF;
278  $this->assertValidate(
279  $vcard,
280  0,
281  0
282  );
283 
284  }
assertValidate($vcf, $options, $expectedLevel, $expectedMessage=null)
Definition: VCardTest.php:286
+ Here is the call graph for this function:

◆ validateData()

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

Definition at line 35 of file VCardTest.php.

References $tests.

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

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