diff --git a/src/VCard.php b/src/VCard.php index 29008ae..28548dd 100644 --- a/src/VCard.php +++ b/src/VCard.php @@ -325,6 +325,7 @@ private function addMediaContent($property, $content, $element) * @param string [optional] $additional * @param string [optional] $prefix * @param string [optional] $suffix + * @param string [optional] $fullName * @return $this */ public function addName( @@ -332,19 +333,26 @@ public function addName( $firstName = '', $additional = '', $prefix = '', - $suffix = '' + $suffix = '', + $fullName = '' ) { - // define values with non-empty values - $values = array_filter([ - $prefix, - $firstName, - $additional, - $lastName, - $suffix, - ]); - - // define filename - $this->setFilename($values); + + if ($fullName === '') { + // define values with non-empty values + $values = array_filter([ + $prefix, + $firstName, + $additional, + $lastName, + $suffix, + ]); + // define filename + $this->setFilename($values); + + $fullName = trim(implode(' ', $values)); + } else { + $this->setFilename($fullName); + } // set property $property = $lastName . ';' . $firstName . ';' . $additional . ';' . $prefix . ';' . $suffix; @@ -360,7 +368,7 @@ public function addName( $this->setProperty( 'fullname', 'FN' . $this->getCharsetString(), - trim(implode(' ', $values)) + $fullName ); } @@ -643,7 +651,7 @@ protected function fold($text) /** * multibyte word chunk split * @link http://php.net/manual/en/function.chunk-split.php#107711 - * + * * @param string $body The string to be chunked. * @param integer $chunklen The chunk length. * @param string $end The line ending sequence. diff --git a/tests/VCardTest.php b/tests/VCardTest.php index 0f9f839..88c3461 100644 --- a/tests/VCardTest.php +++ b/tests/VCardTest.php @@ -56,7 +56,7 @@ public function setUp() $this->additional = '&'; $this->prefix = 'Mister'; $this->suffix = 'Junior'; - + $this->emailAddress1 = ''; $this->emailAddress2 = ''; @@ -65,6 +65,10 @@ public function setUp() $this->firstName3 = 'Garçon'; $this->lastName3 = 'Jéroèn'; + + $this->firstName4 = '潤發'; + $this->lastName4 = '周'; + $this->fullName4 = '周潤發'; } /** @@ -128,6 +132,29 @@ public function testAddName() $this->assertEquals($this->vcard, $this->vcard->addName('')); } + + /** + * Test addName with fullname + */ + public function testAddNameWithFullName() + { + $return = $this->vcard->addName( + $this->lastName4, + $this->firstName4, + '', + '', + '', + $this->fullName4 + ); + + $this->assertEquals($this->vcard, $return); + + $this->assertContains($this->fullName4, $this->vcard->getOutput()); + $this->assertEquals('zhou-run-fa', $this->vcard->getFilename()); + } + + + public function testAddNote() { $this->assertEquals($this->vcard, $this->vcard->addNote('')); @@ -335,6 +362,7 @@ public function testFullBlownName() $this->assertEquals('mister-jeroen-desloovere-junior', $this->vcard->getFilename()); } + /** * Test multiple birthdays *