3 namespace Tests\Commands;
5 use BookStack\Auth\User;
6 use Illuminate\Support\Facades\Auth;
9 class CreateAdminCommandTest extends TestCase
11 public function test_standard_command_usage()
13 $this->artisan('bookstack:create-admin', [
14 '--email' => 'admintest@example.com',
15 '--name' => 'Admin Test',
16 '--password' => 'testing-4',
17 ])->assertExitCode(0);
19 $this->assertDatabaseHas('users', [
20 'email' => 'admintest@example.com',
21 'name' => 'Admin Test',
24 /** @var User $user */
25 $user = User::query()->where('email', '=', 'admintest@example.com')->first();
26 $this->assertTrue($user->hasSystemRole('admin'));
27 $this->assertTrue(Auth::attempt(['email' => 'admintest@example.com', 'password' => 'testing-4']));
30 public function test_providing_external_auth_id()
32 $this->artisan('bookstack:create-admin', [
33 '--email' => 'admintest@example.com',
34 '--name' => 'Admin Test',
35 '--external-auth-id' => 'xX_admin_Xx',
36 ])->assertExitCode(0);
38 $this->assertDatabaseHas('users', [
39 'email' => 'admintest@example.com',
40 'name' => 'Admin Test',
41 'external_auth_id' => 'xX_admin_Xx',
44 /** @var User $user */
45 $user = User::query()->where('email', '=', 'admintest@example.com')->first();
46 $this->assertNotEmpty($user->password);
49 public function test_password_required_if_external_auth_id_not_given()
51 $this->artisan('bookstack:create-admin', [
52 '--email' => 'admintest@example.com',
53 '--name' => 'Admin Test',
54 ])->expectsQuestion('Please specify a password for the new admin user (8 characters min)', 'hunter2000')
57 $this->assertDatabaseHas('users', [
58 'email' => 'admintest@example.com',
59 'name' => 'Admin Test',
61 $this->assertTrue(Auth::attempt(['email' => 'admintest@example.com', 'password' => 'hunter2000']));