3 namespace Tests\Commands;
5 use BookStack\Users\Models\User;
6 use Illuminate\Database\Eloquent\Collection;
9 class DeleteUsersCommandTest extends TestCase
11 public function test_command_deletes_users()
13 $userCount = User::query()->count();
14 $normalUsers = $this->getNormalUsers();
16 $normalUserCount = $userCount - count($normalUsers);
17 $this->artisan('bookstack:delete-users')
18 ->expectsConfirmation('Are you sure you want to continue?', 'yes')
19 ->expectsOutputToContain("Deleted $normalUserCount of $userCount total users.")
22 $this->assertDatabaseMissing('users', ['id' => $normalUsers->first()->id]);
25 public function test_command_requires_confirmation()
27 $normalUsers = $this->getNormalUsers();
29 $this->artisan('bookstack:delete-users')
30 ->expectsConfirmation('Are you sure you want to continue?', 'no')
33 $this->assertDatabaseHas('users', ['id' => $normalUsers->first()->id]);
36 protected function getNormalUsers(): Collection
38 return User::query()->whereNull('system_name')
40 ->filter(function (User $user) {
41 return !$user->hasSystemRole('admin');