Fixed #5067 - account for only one name in generateFormattedNameFromFullName

This commit is contained in:
snipe 2018-02-22 14:10:58 -08:00
parent a85b38850c
commit cbd8409611
2 changed files with 28 additions and 10 deletions

View file

@ -330,6 +330,15 @@ class User extends SnipeModel implements AuthenticatableContract, CanResetPasswo
public static function generateFormattedNameFromFullName($format = 'filastname', $users_name)
{
// If there was only one name given
if (strpos($users_name, ' ') === false) {
$first_name = $users_name;
$last_name = '';
$username = $users_name;
} else {
list($first_name, $last_name) = explode(" ", $users_name, 2);
// Assume filastname by default
@ -344,6 +353,7 @@ class User extends SnipeModel implements AuthenticatableContract, CanResetPasswo
} elseif ($format=='firstname') {
$username = str_slug($first_name);
}
}
$user['first_name'] = $first_name;
$user['last_name'] = $last_name;

View file

@ -71,5 +71,13 @@ class UserTest extends BaseTest
$this->assertEquals($expected_username, $user['username']);
}
public function testSingleName()
{
$fullname = "Natalia";
$expected_username = 'natalia';
$user = User::generateFormattedNameFromFullName('firstname_lastname', $fullname);
$this->assertEquals($expected_username, $user['username']);
}
}