mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-24 15:54:28 +02:00
57 lines
1.4 KiB
PHP
57 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Models\Auth\Role;
|
|
use App\Models\Auth\User;
|
|
use Illuminate\Auth\Events\Verified;
|
|
use Illuminate\Foundation\Testing\WithFaker;
|
|
use Illuminate\Support\Collection;
|
|
use Illuminate\Support\Facades\App;
|
|
use Illuminate\Support\Facades\Event;
|
|
use Illuminate\Support\Facades\URL;
|
|
use Illuminate\Support\Str;
|
|
|
|
use function Pest\Laravel\actingAs;
|
|
|
|
use Spatie\Permission\PermissionRegistrar;
|
|
|
|
uses(WithFaker::class);
|
|
|
|
test('assigns default roles', function (): void {
|
|
Event::fakeExcept(Verified::class);
|
|
|
|
Collection::times(fake()->randomDigitNotNull(), function (): void {
|
|
Role::findOrCreate(Str::random());
|
|
});
|
|
|
|
$defaultRoleCount = fake()->randomDigitNotNull();
|
|
|
|
Collection::times($defaultRoleCount, function (): void {
|
|
/** @var Role $role */
|
|
$role = Role::findOrCreate(Str::random());
|
|
|
|
$role->default = true;
|
|
$role->save();
|
|
});
|
|
|
|
App::make(PermissionRegistrar::class)->forgetCachedPermissions();
|
|
|
|
$user = User::factory()->createOne([
|
|
User::ATTRIBUTE_EMAIL_VERIFIED_AT => null,
|
|
]);
|
|
|
|
$url = URL::temporarySignedRoute(
|
|
'verification.verify',
|
|
now()->addMinutes(60),
|
|
[
|
|
'id' => $user->getKey(),
|
|
'hash' => sha1($user->email),
|
|
]
|
|
);
|
|
|
|
actingAs($user)->get($url);
|
|
|
|
$this->assertCount($defaultRoleCount, $user->roles()->get());
|
|
});
|