Skip to content

Commit

Permalink
fix: fix VCard import without firstname (#2093)
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin authored Nov 29, 2018
1 parent 0fc6b76 commit 3ea2654
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ UNRELEASED CHANGES:

* Fix Storage page not being displayed
* Add ability to create tasks that are not linked to any contacts
* Fix VCard import without firstname
* Fix avatar display in searches

RELEASED VERSIONS:
Expand Down
6 changes: 4 additions & 2 deletions app/Services/VCard/ImportVCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,11 @@ private function importFromNICKNAME(Contact $contact, VCard $entry): void
*/
private function importFromFN(Contact $contact, VCard $entry): void
{
$fullnameParts = preg_split('/ +/', $entry->FN);
$fullnameParts = preg_split('/\s+/', $entry->FN, 2);
$contact->first_name = $this->formatValue($fullnameParts[0]);
$contact->last_name = $this->formatValue($fullnameParts[1]);
if (count($fullnameParts) > 1) {
$contact->last_name = $this->formatValue($fullnameParts[1]);
}

if (! empty($entry->NICKNAME)) {
$contact->nickname = $this->formatValue($entry->NICKNAME);
Expand Down
34 changes: 34 additions & 0 deletions tests/Unit/Services/VCard/ImportVCardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,40 @@ public function test_it_imports_names_FN_extra_space()
$this->assertEquals('Doe', $contact->last_name);
}

public function test_it_imports_name_FN()
{
$contact = new Contact;

$account = factory(Account::class)->create([]);
$importVCard = new ImportVCard($account->id);

$vcard = new VCard([
'FN' => 'John',
'N' => 'Mike;;;;',
]);
$this->invokePrivateMethod($importVCard, 'importNames', [$contact, $vcard]);

$this->assertEquals('John', $contact->first_name);
$this->assertEquals('', $contact->last_name);
}

public function test_it_imports_names_FN_multiple()
{
$contact = new Contact;

$account = factory(Account::class)->create([]);
$importVCard = new ImportVCard($account->id);

$vcard = new VCard([
'FN' => 'John Doe Marco',
'N' => 'Mike;;;;',
]);
$this->invokePrivateMethod($importVCard, 'importNames', [$contact, $vcard]);

$this->assertEquals('John', $contact->first_name);
$this->assertEquals('Doe Marco', $contact->last_name);
}

public function test_it_imports_work_information()
{
$account = factory(Account::class)->create([]);
Expand Down

0 comments on commit 3ea2654

Please sign in to comment.