2016-03-25 01:18:05 -07:00
|
|
|
<?php
|
|
|
|
use App\Models\User;
|
|
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
|
2017-07-11 20:37:02 -07:00
|
|
|
class UserTest extends BaseTest
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \UnitTester
|
|
|
|
*/
|
|
|
|
protected $tester;
|
2017-06-12 17:39:03 -07:00
|
|
|
|
2018-02-22 21:46:58 -08:00
|
|
|
// 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,
|
|
|
|
// ];
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2018-02-22 21:46:58 -08:00
|
|
|
// User::create($values);
|
|
|
|
// $this->tester->seeRecord('users', $values);
|
|
|
|
// }
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2018-02-13 20:31:11 -08:00
|
|
|
|
|
|
|
public function testFirstNameSplit()
|
|
|
|
{
|
|
|
|
$fullname = "Natalia Allanovna Romanova-O'Shostakova";
|
|
|
|
$expected_firstname = 'Natalia';
|
|
|
|
$expected_lastname = "Allanovna Romanova-O'Shostakova";
|
2018-07-25 07:14:16 -07:00
|
|
|
$user = User::generateFormattedNameFromFullName($fullname, 'firstname');
|
2018-02-13 20:31:11 -08:00
|
|
|
$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';
|
2018-07-25 07:14:16 -07:00
|
|
|
$user = User::generateFormattedNameFromFullName($fullname, 'firstname');
|
2018-02-13 20:31:11 -08:00
|
|
|
$this->assertEquals($expected_username, $user['username']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFirstNameDotLastName()
|
|
|
|
{
|
|
|
|
$fullname = "Natalia Allanovna Romanova-O'Shostakova";
|
|
|
|
$expected_username = 'natalia.allanovna-romanova-oshostakova';
|
2018-07-25 07:14:16 -07:00
|
|
|
$user = User::generateFormattedNameFromFullName($fullname, 'firstname.lastname');
|
2018-02-13 20:31:11 -08:00
|
|
|
$this->assertEquals($expected_username, $user['username']);
|
2018-03-05 21:39:05 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testLastNameFirstInitial()
|
|
|
|
{
|
|
|
|
$fullname = "Natalia Allanovna Romanova-O'Shostakova";
|
|
|
|
$expected_username = 'allanovna-romanova-oshostakovan';
|
2018-07-25 07:14:16 -07:00
|
|
|
$user = User::generateFormattedNameFromFullName($fullname, 'lastnamefirstinitial');
|
2018-03-05 21:39:05 -08:00
|
|
|
$this->assertEquals($expected_username, $user['username']);
|
2018-02-13 20:31:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testFirstInitialLastName()
|
|
|
|
{
|
|
|
|
$fullname = "Natalia Allanovna Romanova-O'Shostakova";
|
|
|
|
$expected_username = 'nallanovna-romanova-oshostakova';
|
2018-07-25 07:14:16 -07:00
|
|
|
$user = User::generateFormattedNameFromFullName($fullname, 'filastname');
|
2018-02-13 20:31:11 -08:00
|
|
|
$this->assertEquals($expected_username, $user['username']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFirstInitialUnderscoreLastName()
|
|
|
|
{
|
|
|
|
$fullname = "Natalia Allanovna Romanova-O'Shostakova";
|
|
|
|
$expected_username = 'natalia_allanovna-romanova-oshostakova';
|
2018-07-25 07:14:16 -07:00
|
|
|
$user = User::generateFormattedNameFromFullName($fullname, 'firstname_lastname');
|
2018-02-13 20:31:11 -08:00
|
|
|
$this->assertEquals($expected_username, $user['username']);
|
|
|
|
}
|
|
|
|
|
2018-02-22 14:10:58 -08:00
|
|
|
public function testSingleName()
|
|
|
|
{
|
|
|
|
$fullname = "Natalia";
|
|
|
|
$expected_username = 'natalia';
|
2018-07-25 07:14:16 -07:00
|
|
|
$user = User::generateFormattedNameFromFullName($fullname, 'firstname_lastname');
|
2018-02-22 14:10:58 -08:00
|
|
|
$this->assertEquals($expected_username, $user['username']);
|
|
|
|
}
|
|
|
|
|
2018-02-13 20:31:11 -08:00
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|