Don't add strange looking space in full name if a user does not have an first or last name.

This commit is contained in:
Jan Böhmer 2020-04-08 16:18:53 +02:00
parent 0b16fd7697
commit 919e40e1a8
2 changed files with 12 additions and 2 deletions

View file

@ -506,11 +506,18 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
*/
public function getFullName(bool $including_username = false): string
{
$tmp = $this->getFirstName();
//Dont add a space, if the name has only one part (it would look strange)
if (!empty($this->getFirstName()) && !empty($this->getLastName())) {
$tmp .= ' ';
}
$tmp .= $this->getLastName();
if ($including_username) {
return sprintf('%s %s (@%s)', $this->getFirstName(), $this->getLastName(), $this->getName());
$tmp .= sprintf(' (@%s)', $this->getName());
}
return sprintf('%s %s', $this->getFirstName(), $this->getLastName());
return $tmp;
}
/**

View file

@ -58,6 +58,9 @@ class UserTest extends TestCase
$this->assertSame('John Doe', $user->getFullName(false));
$this->assertSame('John Doe (@username)', $user->getFullName(true));
$user->setLastName('');
$this->assertSame('John (@username)', $user->getFullName(true));
}
public function googleAuthenticatorEnabledDataProvider(): array