-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from Astrotomic/address
Add support for Address / Adr
- Loading branch information
Showing
7 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace Astrotomic\Vcard\Properties; | ||
|
||
class Adr extends Property | ||
{ | ||
public const HOME = 'HOME'; | ||
public const WORK = 'WORK'; | ||
public const PREF = 'PREF'; | ||
|
||
public function __construct( | ||
protected string $poBox, | ||
protected string $extendedAddress, | ||
protected string $streetAddress, | ||
protected string $locality, | ||
protected string $region, | ||
protected string $postalCode, | ||
protected string $countryName, | ||
protected array $types | ||
) { | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
$types = implode(';', array_map( | ||
fn (string $type): string => "TYPE={$type}", | ||
$this->types | ||
)); | ||
|
||
$parameters = implode(';', [ | ||
$this->poBox, | ||
$this->extendedAddress, | ||
$this->streetAddress, | ||
$this->locality, | ||
$this->region, | ||
$this->postalCode, | ||
$this->countryName, | ||
]); | ||
|
||
return "ADR;{$types}:{$parameters}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
namespace Astrotomic\Vcard\Tests; | ||
|
||
use Astrotomic\Vcard\Properties\Adr; | ||
use Astrotomic\Vcard\Properties\Email; | ||
use Astrotomic\Vcard\Properties\Gender; | ||
use Astrotomic\Vcard\Properties\Kind; | ||
|
@@ -29,6 +30,7 @@ public function vcard_full(): void | |
->url('https://company.com') | ||
->bday(Carbon::parse('1990-06-24')) | ||
->photo('data:image/jpeg;base64,'.base64_encode(file_get_contents(__DIR__.'/stubs/photo.jpg'))) | ||
->adr('', '', '1600 Pennsylvania Ave NW', 'Washington', 'DC', '20500-0003', 'USA') | ||
); | ||
} | ||
|
||
|
@@ -203,4 +205,26 @@ public function vcard_with_fn_member_uuid_and_mail(): void | |
->member('[email protected]', '550e8400-e29b-11d4-a716-446655440000') | ||
); | ||
} | ||
|
||
/** @test */ | ||
public function vcard_with_work_address(): void | ||
{ | ||
$this->assertMatchesVcardSnapshot( | ||
Vcard::make() | ||
->fullName('John Adam Smith') | ||
->adr('', '', '1600 Pennsylvania Ave NW', 'Washington', 'DC', '20500-0003', 'USA', [Adr::WORK]) | ||
); | ||
} | ||
|
||
/** @test */ | ||
public function vcard_with_work_and_home_address(): void | ||
{ | ||
$this->assertMatchesVcardSnapshot( | ||
Vcard::make() | ||
->fullName('John Adam Smith') | ||
->adr('', '', '1600 Pennsylvania Ave NW', 'Washington', 'DC', '20500-0003', 'USA', | ||
[Adr::WORK, Adr::PREF]) | ||
->adr('', '', '1640 Riverside Drive', ' Hill Valley', 'CA', '', 'USA', [Adr::HOME]) | ||
); | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
tests/__snapshots__/VcardTest__vcard_with_work_address__1.vcf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
BEGIN:VCARD | ||
VERSION:4.0 | ||
FN;CHARSET=UTF-8:John Adam Smith | ||
ADR;TYPE=WORK:;;1600 Pennsylvania Ave NW;Washington;DC;20500-0003;USA | ||
REV:2021-02-25T10:30:45.000000Z | ||
PRODID:-//Astrotomic vCard | ||
END:VCARD |
8 changes: 8 additions & 0 deletions
8
tests/__snapshots__/VcardTest__vcard_with_work_and_home_address__1.vcf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
BEGIN:VCARD | ||
VERSION:4.0 | ||
FN;CHARSET=UTF-8:John Adam Smith | ||
ADR;TYPE=WORK;TYPE=PREF:;;1600 Pennsylvania Ave NW;Washington;DC;20500-0003;USA | ||
ADR;TYPE=HOME:;;1640 Riverside Drive; Hill Valley;CA;;USA | ||
REV:2021-02-25T10:30:45.000000Z | ||
PRODID:-//Astrotomic vCard | ||
END:VCARD |