From f5ed2fbe20fa4e4b1283e19cde602e9ace94800f Mon Sep 17 00:00:00 2001 From: Jeroen Desloovere Date: Mon, 12 Mar 2018 16:09:21 +0100 Subject: [PATCH] Merge PR from Jean-beru --- README.md | 1 + src/VCard.php | 22 +++++++++++++++++++++- tests/VCardTest.php | 12 ++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f4d11f2..e80ef72 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ $vcard->addEmail('info@jeroendesloovere.be'); $vcard->addPhoneNumber(1234121212, 'PREF;WORK'); $vcard->addPhoneNumber(123456789, 'WORK'); $vcard->addAddress(null, null, 'street', 'worktown', null, 'workpostcode', 'Belgium'); +$vcard->addLabel('street, worktown, workpostcode Belgium'); $vcard->addURL('http://www.jeroendesloovere.be'); $vcard->addPhoto(__DIR__ . '/landscape.jpeg'); diff --git a/src/VCard.php b/src/VCard.php index 7262dcd..abf8ee8 100644 --- a/src/VCard.php +++ b/src/VCard.php @@ -46,7 +46,8 @@ class VCard 'email', 'address', 'phoneNumber', - 'url' + 'url', + 'label' ]; /** @@ -179,6 +180,25 @@ public function addJobtitle($jobtitle) return $this; } + /** + * Add a label + * + * @param string $label + * @param string $type + * + * @return $this + */ + public function addLabel($label, $type = '') + { + $this->setProperty( + 'label', + 'LABEL' . ($type !== '' ? ';' . $type : ''), + $label + ); + + return $this; + } + /** * Add role * diff --git a/tests/VCardTest.php b/tests/VCardTest.php index 46e89a9..8a5938a 100644 --- a/tests/VCardTest.php +++ b/tests/VCardTest.php @@ -427,6 +427,18 @@ public function testSpecialFirstNameAndLastName2() $this->assertEquals('garcon-jeroen', $this->vcard->getFilename()); } + /** + * Test multiple labels + */ + public function testMultipleLabels() + { + $this->assertSame($this->vcard, $this->vcard->addLabel('My label')); + $this->assertSame($this->vcard, $this->vcard->addLabel('My work label', 'WORK')); + $this->assertSame(2, count($this->vcard->getProperties())); + $this->assertContains('LABEL:My label', $this->vcard->getOutput()); + $this->assertContains('LABEL;WORK:My work label', $this->vcard->getOutput()); + } + public function testChunkSplitUnicode() { $class_handler = new \ReflectionClass('JeroenDesloovere\VCard\VCard');