forked from laravel/jetstream
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDeleteUserWithTeamsTest.php
77 lines (58 loc) · 2.08 KB
/
DeleteUserWithTeamsTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
namespace Laravel\Jetstream\Tests;
use App\Actions\Jetstream\CreateTeam;
use App\Actions\Jetstream\DeleteTeam;
use App\Actions\Jetstream\DeleteUser;
use App\Models\Team;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Str;
use Laravel\Jetstream\Jetstream;
use Laravel\Jetstream\Tests\Fixtures\TeamPolicy;
use Laravel\Jetstream\Tests\Fixtures\User;
class DeleteUserWithTeamsTest extends OrchestraTestCase
{
public function setUp(): void
{
parent::setUp();
Gate::policy(Team::class, TeamPolicy::class);
Jetstream::useUserModel(User::class);
}
public function test_user_can_be_deleted()
{
$this->migrate();
$team = $this->createTeam();
$otherTeam = $this->createTeam();
$otherTeam->users()->attach($team->owner, ['role' => null]);
$this->assertSame(2, DB::table('teams')->count());
$this->assertSame(1, DB::table('team_user')->count());
copy(__DIR__.'/../stubs/app/Actions/Jetstream/DeleteUserWithTeams.php', $fixture = __DIR__.'/Fixtures/DeleteUser.php');
require $fixture;
$action = new DeleteUser(new DeleteTeam);
$action->delete($team->owner);
$this->assertNull($team->owner->fresh());
$this->assertSame(1, DB::table('teams')->count());
$this->assertSame(0, DB::table('team_user')->count());
@unlink($fixture);
}
protected function createTeam()
{
$action = new CreateTeam;
$user = User::forceCreate([
'name' => Str::random(10),
'email' => Str::random(10).'@laravel.com',
'password' => 'secret',
]);
return $action->create($user, ['name' => 'Test Team']);
}
protected function migrate()
{
$this->artisan('migrate', ['--database' => 'testbench'])->run();
Schema::create('personal_access_tokens', function ($table) {
$table->id();
$table->foreignId('tokenable_id');
$table->string('tokenable_type');
});
}
}