Skip to content

Commit

Permalink
Merge pull request #122 from jeroendesloovere/Jean-Beru-feature/label…
Browse files Browse the repository at this point in the history
…-property

Merge PR from Jean-beru
  • Loading branch information
jeroendesloovere authored Mar 12, 2018
2 parents c52a8c6 + f5ed2fb commit 2ff9bf7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ $vcard->addEmail('[email protected]');
$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');
Expand Down
22 changes: 21 additions & 1 deletion src/VCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class VCard
'email',
'address',
'phoneNumber',
'url'
'url',
'label'
];

/**
Expand Down Expand Up @@ -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
*
Expand Down
12 changes: 12 additions & 0 deletions tests/VCardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 2ff9bf7

Please sign in to comment.