mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
Fixed #5067 - account for only one name in generateFormattedNameFromFullName
This commit is contained in:
parent
a85b38850c
commit
cbd8409611
|
@ -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;
|
||||
|
|
|
@ -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']);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue