snipe-it/tests/unit/UserTest.php
Laravel Shift 934afa036f Adopt Laravel coding style
Shift automatically applies the Laravel coding style - which uses the PSR-2 coding style as a base with some minor additions.

You may customize the adopted coding style by adding your own [PHP CS Fixer][1] `.php_cs` config file to your project root. Feel free to use [Shift's Laravel ruleset][2] to help you get started.

[1]: https://github.com/FriendsOfPHP/PHP-CS-Fixer
[2]: https://gist.github.com/laravel-shift/cab527923ed2a109dda047b97d53c200
2021-06-10 20:15:52 +00:00

121 lines
4.4 KiB
PHP

<?php
use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Support\Facades\Hash;
class UserTest extends BaseTest
{
/**
* @var \UnitTester
*/
protected $tester;
// public function testUserAdd()
// {
// $user = factory(User::class)->make();
// $values = [
// 'first_name' => $user->first_name,
// 'last_name' => $user->last_name,
// 'email' => $user->email,
// 'username' => $user->username,
// 'password' => $user->password,
// ];
// User::create($values);
// $this->tester->seeRecord('users', $values);
// }
public function testFirstNameSplit()
{
$fullname = "Natalia Allanovna Romanova-O'Shostakova";
$expected_firstname = 'Natalia';
$expected_lastname = "Allanovna Romanova-O'Shostakova";
$user = User::generateFormattedNameFromFullName('firstname', $fullname);
$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 = 'n_allanovna-romanova-oshostakova';
$user = User::generateFormattedNameFromFullName($fullname, 'firstname_lastname');
$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']);
}
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']);
}
}