diff --git a/app/Services/VCard/ExportVCard.php b/app/Services/VCard/ExportVCard.php index 357bc5b9941..873e1d9a9e9 100644 --- a/app/Services/VCard/ExportVCard.php +++ b/app/Services/VCard/ExportVCard.php @@ -250,6 +250,7 @@ private function exportContactFields(Contact $contact, VCard $vcard) $vcard->remove('TEL'); $vcard->remove('EMAIL'); $vcard->remove('socialProfile'); + $vcard->remove('URL'); foreach ($contact->contactFields as $contactField) { $type = $this->getContactFieldLabel($contactField); @@ -261,26 +262,30 @@ private function exportContactFields(Contact $contact, VCard $vcard) $vcard->add('EMAIL', $this->escape($contactField->data), $type); break; default: - break; - } - switch ($contactField->contactFieldType->name) { - // See https://tools.ietf.org/id/draft-george-vcarddav-vcard-extension-02.html - case 'Facebook': - $vcard->add('socialProfile', $this->escape('https://www.facebook.com/'.$contactField->data), ['type' => 'facebook']); - break; - case 'Twitter': - $vcard->add('socialProfile', $this->escape('https://twitter.com/'.$contactField->data), ['type' => 'twitter']); - break; - case 'Whatsapp': - $vcard->add('socialProfile', $this->escape('https://wa.me/'.$contactField->data), ['type' => 'whatsapp']); - break; - case 'Telegram': - $vcard->add('socialProfile', $this->escape('http://t.me/'.$contactField->data), ['type' => 'telegram']); - break; - case 'LinkedIn': - $vcard->add('socialProfile', $this->escape('http://www.linkedin.com/in/'.$contactField->data), ['type' => 'linkedin']); - break; - default: + switch ($contactField->contactFieldType->name) { + // See https://tools.ietf.org/id/draft-george-vcarddav-vcard-extension-02.html + case 'Facebook': + $vcard->add('socialProfile', $this->escape('https://www.facebook.com/'.$contactField->data), ['type' => 'facebook']); + break; + case 'Twitter': + $vcard->add('socialProfile', $this->escape('https://twitter.com/'.$contactField->data), ['type' => 'twitter']); + break; + case 'Whatsapp': + $vcard->add('socialProfile', $this->escape('https://wa.me/'.$contactField->data), ['type' => 'whatsapp']); + break; + case 'Telegram': + $vcard->add('socialProfile', $this->escape('http://t.me/'.$contactField->data), ['type' => 'telegram']); + break; + case 'LinkedIn': + $vcard->add('socialProfile', $this->escape('http://www.linkedin.com/in/'.$contactField->data), ['type' => 'linkedin']); + break; + default: + // If field isn't a supported social profile, but still has a protocol, then export it as a url. + if (! empty($contactField->contactFieldType->protocol)) { + $vcard->add('URL', $this->escape($contactField->contactFieldType->protocol.$contactField->data)); + } + break; + } break; } } diff --git a/tests/Unit/Services/VCard/ExportVCardTest.php b/tests/Unit/Services/VCard/ExportVCardTest.php index 7264ae97091..49cae3a4dfe 100644 --- a/tests/Unit/Services/VCard/ExportVCardTest.php +++ b/tests/Unit/Services/VCard/ExportVCardTest.php @@ -482,6 +482,42 @@ public function socialProfileProvider() ]; } + /** + * @test + * @dataProvider contactUrlProvider + */ + public function vcard_add_contact_url($name, $protocol, $data, $result) + { + $account = factory(Account::class)->create(); + $contact = factory(Contact::class)->create(['account_id' => $account->id]); + $vCard = new VCard(); + + $contactFieldType = factory(ContactFieldType::class)->create([ + 'account_id' => $account->id, + 'name' => $name, + 'protocol' => $protocol, + 'type' => 'URL', + ]); + factory(ContactField::class)->create([ + 'contact_id' => $contact->id, + 'account_id' => $account->id, + 'contact_field_type_id' => $contactFieldType->id, + 'data' => $data, + ]); + + $exportVCard = app(ExportVCard::class); + $this->invokePrivateMethod($exportVCard, 'exportContactFields', [$contact, $vCard]); + $this->assertStringContainsString($result, $vCard->serialize()); + } + + public function contactUrlProvider() + { + return [ + ['Discord', 'https://www.discord.app/user/', 'test123', 'URL;VALUE=URI:https://www.discord.app/user/test123'], + ['Facebook Profile', 'https://www.facebook.com/', 'test123', 'URL;VALUE=URI:https://www.facebook.com/test123'], + ]; + } + /** @test */ public function vcard_add_addresses_empty() {