48 lines
1.4 KiB
PHP
48 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\CardDav;
|
|
|
|
use App\Services\CardDav\VCardParser;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class VCardParserTest extends TestCase
|
|
{
|
|
public function test_it_parses_contact_fields_phone_numbers_and_categories(): void
|
|
{
|
|
$vcard = <<<'VCF'
|
|
BEGIN:VCARD
|
|
VERSION:3.0
|
|
UID:contact-123
|
|
FN:Marie Durand
|
|
N:Durand;Marie;;;
|
|
ORG:AFPMA
|
|
EMAIL;TYPE=HOME:marie@example.test
|
|
TEL;TYPE=CELL,VOICE:06 11 11 00 03
|
|
TEL;TYPE=HOME:04 00 00 00 00
|
|
CATEGORIES:Benevoles,Conseil\, bureau
|
|
END:VCARD
|
|
VCF;
|
|
|
|
$contact = (new VCardParser)->parse($vcard);
|
|
|
|
$this->assertSame('contact-123', $contact->uid);
|
|
$this->assertSame('Marie Durand', $contact->fullName);
|
|
$this->assertSame('Marie', $contact->firstName);
|
|
$this->assertSame('Durand', $contact->lastName);
|
|
$this->assertSame('AFPMA', $contact->organization);
|
|
$this->assertSame('marie@example.test', $contact->email);
|
|
$this->assertCount(2, $contact->phoneNumbers);
|
|
$this->assertSame('Cell, Voice', $contact->phoneNumbers[0]->label);
|
|
$this->assertSame(['Benevoles', 'Conseil, bureau'], $contact->categories);
|
|
}
|
|
|
|
public function test_it_unfolds_multiline_values(): void
|
|
{
|
|
$vcard = "BEGIN:VCARD\r\nVERSION:3.0\r\nUID:folded\r\nFN:Association des amis\r\n du lac\r\nTEL:0611110001\r\nEND:VCARD\r\n";
|
|
|
|
$contact = (new VCardParser)->parse($vcard);
|
|
|
|
$this->assertSame('Association des amis du lac', $contact->fullName);
|
|
}
|
|
}
|