mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-27 06:29:47 -08:00
99 lines
3.8 KiB
PHP
99 lines
3.8 KiB
PHP
<?php
|
|
namespace Tests\Unit;
|
|
|
|
use App\Models\User;
|
|
use Tests\TestCase;
|
|
|
|
class UserTest extends TestCase
|
|
{
|
|
public function testFirstNameSplit()
|
|
{
|
|
$fullname = "Natalia Allanovna Romanova-O'Shostakova";
|
|
$expected_firstname = 'Natalia';
|
|
$expected_lastname = "Allanovna Romanova-O'Shostakova";
|
|
$user = User::generateFormattedNameFromFullName($fullname, 'firstname');
|
|
$this->assertEquals($expected_firstname, $user['first_name']);
|
|
$this->assertEquals($expected_lastname, $user['last_name']);
|
|
}
|
|
|
|
public function testFirstName()
|
|
{
|
|
$fullname = "Natalia Allanovna Romanova-O'Shostakova";
|
|
$expected_username = 'natalia';
|
|
$user = User::generateFormattedNameFromFullName($fullname, 'firstname');
|
|
$this->assertEquals($expected_username, $user['username']);
|
|
}
|
|
|
|
public function testFirstNameDotLastName()
|
|
{
|
|
$fullname = "Natalia Allanovna Romanova-O'Shostakova";
|
|
$expected_username = 'natalia.allanovna-romanova-oshostakova';
|
|
$user = User::generateFormattedNameFromFullName($fullname, 'firstname.lastname');
|
|
$this->assertEquals($expected_username, $user['username']);
|
|
}
|
|
|
|
public function testLastNameFirstInitial()
|
|
{
|
|
$fullname = "Natalia Allanovna Romanova-O'Shostakova";
|
|
$expected_username = 'allanovna-romanova-oshostakovan';
|
|
$user = User::generateFormattedNameFromFullName($fullname, 'lastnamefirstinitial');
|
|
$this->assertEquals($expected_username, $user['username']);
|
|
}
|
|
|
|
public function testFirstInitialLastName()
|
|
{
|
|
$fullname = "Natalia Allanovna Romanova-O'Shostakova";
|
|
$expected_username = 'nallanovna-romanova-oshostakova';
|
|
$user = User::generateFormattedNameFromFullName($fullname, 'filastname');
|
|
$this->assertEquals($expected_username, $user['username']);
|
|
}
|
|
|
|
public function testFirstInitialUnderscoreLastName()
|
|
{
|
|
$fullname = "Natalia Allanovna Romanova-O'Shostakova";
|
|
$expected_username = 'nallanovna-romanova-oshostakova';
|
|
$user = User::generateFormattedNameFromFullName($fullname, 'firstinitial_lastname');
|
|
$this->assertEquals($expected_username, $user['username']);
|
|
}
|
|
|
|
public function testSingleName()
|
|
{
|
|
$fullname = 'Natalia';
|
|
$expected_username = 'natalia';
|
|
$user = User::generateFormattedNameFromFullName($fullname, 'firstname_lastname',);
|
|
$this->assertEquals($expected_username, $user['username']);
|
|
}
|
|
|
|
public function firstInitialDotLastname()
|
|
{
|
|
$fullname = "Natalia Allanovna Romanova-O'Shostakova";
|
|
$expected_username = 'n.allanovnaromanovaoshostakova';
|
|
$user = User::generateFormattedNameFromFullName($fullname, 'firstinitial.lastname');
|
|
$this->assertEquals($expected_username, $user['username']);
|
|
}
|
|
|
|
public function lastNameUnderscoreFirstInitial()
|
|
{
|
|
$fullname = "Natalia Allanovna Romanova-O'Shostakova";
|
|
$expected_username = 'allanovnaromanovaoshostakova_n';
|
|
$user = User::generateFormattedNameFromFullName($fullname, 'lastname_firstinitial');
|
|
$this->assertEquals($expected_username, $user['username']);
|
|
}
|
|
|
|
public function firstNameLastName()
|
|
{
|
|
$fullname = "Natalia Allanovna Romanova-O'Shostakova";
|
|
$expected_username = 'nataliaallanovnaromanovaoshostakova';
|
|
$user = User::generateFormattedNameFromFullName($fullname, 'firstnamelastname');
|
|
$this->assertEquals($expected_username, $user['username']);
|
|
}
|
|
|
|
public function firstNameLastInitial()
|
|
{
|
|
$fullname = "Natalia Allanovna Romanova-O'Shostakova";
|
|
$expected_username = 'nataliaa';
|
|
$user = User::generateFormattedNameFromFullName($fullname, 'firstnamelastinitial');
|
|
$this->assertEquals($expected_username, $user['username']);
|
|
}
|
|
}
|