Skip to content

Commit 238b84c

Browse files
committed
Update list of multiple properties
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
1 parent a8809f0 commit 238b84c

File tree

2 files changed

+86
-15
lines changed

2 files changed

+86
-15
lines changed

apps/dav/lib/CardDAV/AddressBookImpl.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -259,19 +259,7 @@ protected function vCard2Array($uri, VCard $vCard, $withTypes = false) {
259259
]) . '?photo';
260260

261261
$result['PHOTO'] = 'VALUE=uri:' . $url;
262-
} elseif ($property->name === 'X-SOCIALPROFILE') {
263-
$type = $this->getTypeFromProperty($property);
264-
265-
// Type is the social network, when it's empty we don't need this.
266-
if ($type !== null) {
267-
if (!isset($result[$property->name])) {
268-
$result[$property->name] = [];
269-
}
270-
$result[$property->name][$type] = $property->getValue();
271-
}
272-
273-
// The following properties can be set multiple times
274-
} elseif (in_array($property->name, ['CLOUD', 'EMAIL', 'IMPP', 'TEL', 'URL', 'X-ADDRESSBOOKSERVER-MEMBER'])) {
262+
} elseif (in_array($property->name, ['URL', 'GEO', 'CLOUD', 'ADR', 'EMAIL', 'IMPP', 'TEL', 'X-SOCIALPROFILE', 'RELATED', 'LANG', 'X-ADDRESSBOOKSERVER-MEMBER'])) {
275263
if (!isset($result[$property->name])) {
276264
$result[$property->name] = [];
277265
}

apps/dav/tests/unit/CardDAV/AddressBookImplTest.php

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,9 @@ public function testVCard2Array() {
321321
$property = $vCard->createProperty('X-SOCIALPROFILE', 'tw-example');
322322
$property->add('TYPE', 'twitter');
323323
$vCard->add($property);
324+
$property = $vCard->createProperty('X-SOCIALPROFILE', 'tw-example-2');
325+
$property->add('TYPE', 'twitter');
326+
$vCard->add($property);
324327
$property = $vCard->createProperty('X-SOCIALPROFILE', 'fb-example');
325328
$property->add('TYPE', 'facebook');
326329
$vCard->add($property);
@@ -355,8 +358,88 @@ public function testVCard2Array() {
355358
],
356359

357360
'X-SOCIALPROFILE' => [
358-
'twitter'=> 'tw-example',
359-
'facebook'=> 'fb-example',
361+
'tw-example',
362+
'tw-example-2',
363+
'fb-example',
364+
],
365+
366+
'isLocalSystemBook' => true,
367+
], $array);
368+
}
369+
370+
public function testVCard2ArrayWithTypes() {
371+
$vCard = new VCard();
372+
373+
$vCard->add($vCard->createProperty('FN', 'Full Name'));
374+
375+
// Multi-value properties
376+
$vCard->add($vCard->createProperty('CLOUD', 'cloud-user1@localhost'));
377+
$vCard->add($vCard->createProperty('CLOUD', 'cloud-user2@example.tld'));
378+
379+
$property = $vCard->createProperty('EMAIL', 'email-user1@localhost');
380+
$property->add('TYPE', 'HOME');
381+
$vCard->add($property);
382+
$property = $vCard->createProperty('EMAIL', 'email-user2@example.tld');
383+
$property->add('TYPE', 'WORK');
384+
$vCard->add($property);
385+
386+
$vCard->add($vCard->createProperty('IMPP', 'impp-user1@localhost'));
387+
$vCard->add($vCard->createProperty('IMPP', 'impp-user2@example.tld'));
388+
389+
$property = $vCard->createProperty('TEL', '+49 123456789');
390+
$property->add('TYPE', 'HOME,VOICE');
391+
$vCard->add($property);
392+
$property = $vCard->createProperty('TEL', '+1 555 123456789');
393+
$property->add('TYPE', 'WORK');
394+
$vCard->add($property);
395+
396+
$vCard->add($vCard->createProperty('URL', 'https://localhost'));
397+
$vCard->add($vCard->createProperty('URL', 'https://example.tld'));
398+
399+
// Type depending properties
400+
$property = $vCard->createProperty('X-SOCIALPROFILE', 'tw-example');
401+
$property->add('TYPE', 'twitter');
402+
$vCard->add($property);
403+
$property = $vCard->createProperty('X-SOCIALPROFILE', 'tw-example-2');
404+
$property->add('TYPE', 'twitter');
405+
$vCard->add($property);
406+
$property = $vCard->createProperty('X-SOCIALPROFILE', 'fb-example');
407+
$property->add('TYPE', 'facebook');
408+
$vCard->add($property);
409+
410+
$array = $this->invokePrivate($this->addressBookImpl, 'vCard2Array', ['uri', $vCard, true]);
411+
unset($array['PRODID']);
412+
unset($array['UID']);
413+
414+
$this->assertEquals([
415+
'URI' => 'uri',
416+
'VERSION' => '4.0',
417+
'FN' => 'Full Name',
418+
'CLOUD' => [
419+
['type' => '', 'value' => 'cloud-user1@localhost'],
420+
['type' => '', 'value' => 'cloud-user2@example.tld'],
421+
],
422+
'EMAIL' => [
423+
['type' => 'HOME', 'value' => 'email-user1@localhost'],
424+
['type' => 'WORK', 'value' => 'email-user2@example.tld'],
425+
],
426+
'IMPP' => [
427+
['type' => '', 'value' => 'impp-user1@localhost'],
428+
['type' => '', 'value' => 'impp-user2@example.tld'],
429+
],
430+
'TEL' => [
431+
['type' => 'HOME,VOICE', 'value' => '+49 123456789'],
432+
['type' => 'WORK', 'value' => '+1 555 123456789'],
433+
],
434+
'URL' => [
435+
['type' => '', 'value' => 'https://localhost'],
436+
['type' => '', 'value' => 'https://example.tld'],
437+
],
438+
439+
'X-SOCIALPROFILE' => [
440+
['type' => 'twitter', 'value' => 'tw-example'],
441+
['type' => 'twitter', 'value' => 'tw-example-2'],
442+
['type' => 'facebook', 'value' => 'fb-example'],
360443
],
361444

362445
'isLocalSystemBook' => true,

0 commit comments

Comments
 (0)