2021-11-30 17:39:33 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Unit;
|
|
|
|
|
2023-03-08 17:43:26 +01:00
|
|
|
use App\Models\Group;
|
|
|
|
use App\Models\TwoFAccount;
|
2021-12-02 13:15:53 +01:00
|
|
|
use App\Models\User;
|
2021-11-30 17:39:33 +01:00
|
|
|
use Tests\ModelTestCase;
|
|
|
|
|
|
|
|
/**
|
2021-12-02 13:15:53 +01:00
|
|
|
* @covers \App\Models\User
|
2021-11-30 17:39:33 +01:00
|
|
|
*/
|
|
|
|
class UserModelTest extends ModelTestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function test_model_configuration()
|
|
|
|
{
|
|
|
|
$this->runConfigurationAssertions(new User(),
|
|
|
|
['name', 'email', 'password'],
|
|
|
|
['password', 'remember_token'],
|
|
|
|
['*'],
|
|
|
|
[],
|
2023-03-08 17:43:26 +01:00
|
|
|
[
|
2023-03-10 22:59:46 +01:00
|
|
|
'id' => 'int',
|
2023-03-08 17:43:26 +01:00
|
|
|
'email_verified_at' => 'datetime',
|
|
|
|
'is_admin' => 'boolean',
|
|
|
|
'twofaccounts_count' => 'integer',
|
|
|
|
'groups_count' => 'integer',
|
|
|
|
]
|
2021-11-30 17:39:33 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function test_email_is_set_lowercased()
|
|
|
|
{
|
2021-12-02 13:15:53 +01:00
|
|
|
$user = User::factory()->make([
|
2021-11-30 17:39:33 +01:00
|
|
|
'email' => 'UPPERCASE@example.COM',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(strtolower('UPPERCASE@example.COM'), $user->email);
|
|
|
|
}
|
2023-03-08 17:43:26 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function test_twofaccounts_relation()
|
|
|
|
{
|
2023-03-10 22:59:46 +01:00
|
|
|
$user = new User();
|
2023-03-08 17:43:26 +01:00
|
|
|
$accounts = $user->twofaccounts();
|
|
|
|
$this->assertHasManyRelation($accounts, $user, new TwoFAccount());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function test_groups_relation()
|
|
|
|
{
|
|
|
|
$user = new User();
|
|
|
|
$groups = $user->groups();
|
|
|
|
$this->assertHasManyRelation($groups, $user, new Group());
|
|
|
|
}
|
2022-11-22 15:15:52 +01:00
|
|
|
}
|