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;
|
2023-08-01 11:28:27 +02:00
|
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
2021-11-30 17:39:33 +01:00
|
|
|
use Tests\ModelTestCase;
|
|
|
|
|
|
|
|
/**
|
2023-08-01 11:28:27 +02:00
|
|
|
* UserModelTest test class
|
2021-11-30 17:39:33 +01:00
|
|
|
*/
|
2023-08-01 11:28:27 +02:00
|
|
|
#[CoversClass(User::class)]
|
2021-11-30 17:39:33 +01:00
|
|
|
class UserModelTest extends ModelTestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function test_model_configuration()
|
|
|
|
{
|
|
|
|
$this->runConfigurationAssertions(new User(),
|
2023-12-14 12:36:38 +01:00
|
|
|
['name', 'email', 'password', 'oauth_id', 'oauth_provider'],
|
2021-11-30 17:39:33 +01:00
|
|
|
['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',
|
2023-08-01 16:33:55 +02:00
|
|
|
'password' => 'hashed',
|
2023-03-08 17:43:26 +01:00
|
|
|
'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
|
|
|
}
|