Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional argument to addName() to set FN #173

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 22 additions & 14 deletions src/VCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,26 +325,34 @@ 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(
$lastName = '',
$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;
Expand All @@ -360,7 +368,7 @@ public function addName(
$this->setProperty(
'fullname',
'FN' . $this->getCharsetString(),
trim(implode(' ', $values))
$fullName
);
}

Expand Down Expand Up @@ -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.
Expand Down
30 changes: 29 additions & 1 deletion tests/VCardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function setUp()
$this->additional = '&';
$this->prefix = 'Mister';
$this->suffix = 'Junior';

$this->emailAddress1 = '';
$this->emailAddress2 = '';

Expand All @@ -65,6 +65,10 @@ public function setUp()

$this->firstName3 = 'Garçon';
$this->lastName3 = 'Jéroèn';

$this->firstName4 = '潤發';
$this->lastName4 = '周';
$this->fullName4 = '周潤發';
}

/**
Expand Down Expand Up @@ -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(''));
Expand Down Expand Up @@ -335,6 +362,7 @@ public function testFullBlownName()
$this->assertEquals('mister-jeroen-desloovere-junior', $this->vcard->getFilename());
}


/**
* Test multiple birthdays
*
Expand Down