Skip to content

Commit

Permalink
fix: fix vcard company import (#5616)
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin committed Oct 17, 2021
1 parent 8eed44e commit 0dd4b23
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/Services/VCard/ImportVCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,10 @@ private function importWorkInformation(Contact $contact, VCard $entry): void
];

if ($entry->ORG) {
$request['company'] = $this->formatValue($entry->ORG);
$parts = $entry->ORG->getParts();
if ($company = Arr::get($parts, '0')) {
$request['company'] = $this->formatValue($company);
}
}

if ($entry->ROLE) {
Expand Down
19 changes: 19 additions & 0 deletions database/migrations/2021_10_14_212144_v_card_company.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

use Illuminate\Support\Facades\DB;
use Illuminate\Database\Migrations\Migration;

class VCardCompany extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
DB::table('contacts')
->where('company', ';')
->update(['company' => null]);
}
}
36 changes: 36 additions & 0 deletions tests/Unit/Services/VCard/ImportVCardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Carbon\Carbon;
use Tests\TestCase;
use App\Models\User\User;
use Sabre\VObject\Reader;
use App\Models\Contact\Tag;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -49,6 +50,41 @@ public function it_can_not_import_because_no_firstname_in_vcard()
$this->assertFalse($this->invokePrivateMethod($importVCard, 'canImportCurrentEntry', [$vcard]));
}

/** @test */
public function it_can_not_import_because_empty_firstname_in_vcard()
{
$account = factory(Account::class)->create([]);
$importVCard = new ImportVCard;

$vcard = new VCard([
'N' => ';;;;',
]);

$this->assertFalse($this->invokePrivateMethod($importVCard, 'canImportCurrentEntry', [$vcard]));
}

/** @test */
public function it_can_not_import_vcard()
{
$account = factory(Account::class)->create([]);
$importVCard = new ImportVCard;

$vcard = Reader::read('
BEGIN:VCARD
VERSION:3.0
N:;;;;
FN:
ORG:;
EMAIL;TYPE=home;TYPE=pref:mail@example.org
NOTE:
NICKNAME:
TITLE:
REV:20210900T000102Z
END:VCARD', Reader::OPTION_FORGIVING + Reader::OPTION_IGNORE_INVALID_LINES);

$this->assertFalse($this->invokePrivateMethod($importVCard, 'canImportCurrentEntry', [$vcard]));
}

/** @test */
public function it_can_not_import_because_empty_nickname_in_vcard()
{
Expand Down

0 comments on commit 0dd4b23

Please sign in to comment.