X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/f139cded789908efce3ac2ed1be26b947df647db..refs/pull/3365/head:/tests/Auth/AuthTest.php diff --git a/tests/Auth/AuthTest.php b/tests/Auth/AuthTest.php index 66ab09d3c..0ab6d0e8c 100644 --- a/tests/Auth/AuthTest.php +++ b/tests/Auth/AuthTest.php @@ -3,6 +3,7 @@ namespace Tests\Auth; use BookStack\Auth\Access\Mfa\MfaSession; +use BookStack\Auth\Role; use BookStack\Auth\User; use BookStack\Entities\Models\Page; use BookStack\Notifications\ConfirmEmail; @@ -43,7 +44,10 @@ class AuthTest extends TestCase public function test_normal_registration() { // Set settings and get user instance - $this->setSettings(['registration-enabled' => 'true']); + /** @var Role $registrationRole */ + $registrationRole = Role::query()->first(); + $this->setSettings(['registration-enabled' => 'true', 'registration-role' => $registrationRole->id]); + /** @var User $user */ $user = User::factory()->make(); // Test form and ensure user is created @@ -57,7 +61,12 @@ class AuthTest extends TestCase $resp = $this->get('/'); $resp->assertOk(); $resp->assertSee($user->name); + $this->assertDatabaseHas('users', ['name' => $user->name, 'email' => $user->email]); + + $user = User::query()->where('email', '=', $user->email)->first(); + $this->assertEquals(1, $user->roles()->count()); + $this->assertEquals($registrationRole->id, $user->roles()->first()->id); } public function test_empty_registration_redirects_back_with_errors() @@ -131,8 +140,8 @@ class AuthTest extends TestCase }); // Check confirmation email confirmation activation. - $this->get('/register/confirm/' . $emailConfirmation->token)->assertRedirect('/'); - $this->get('/')->assertSee($user->name); + $this->get('/register/confirm/' . $emailConfirmation->token)->assertRedirect('/login'); + $this->get('/login')->assertSee('Your email has been confirmed! You should now be able to login using this email address.'); $this->assertDatabaseMissing('email_confirmations', ['token' => $emailConfirmation->token]); $this->assertDatabaseHas('users', ['name' => $dbUser->name, 'email' => $dbUser->email, 'email_confirmed' => true]); } @@ -189,10 +198,18 @@ class AuthTest extends TestCase $this->assertNull(auth()->user()); } + public function test_registration_role_unset_by_default() + { + $this->assertFalse(setting('registration-role')); + + $resp = $this->asAdmin()->get('/settings/registration'); + $resp->assertElementContains('select[name="setting-registration-role"] option[value="0"][selected]', '-- None --'); + } + public function test_logout() { $this->asAdmin()->get('/')->assertOk(); - $this->get('/logout')->assertRedirect('/'); + $this->post('/logout')->assertRedirect('/'); $this->get('/')->assertRedirect('/login'); } @@ -204,7 +221,7 @@ class AuthTest extends TestCase $mfaSession->markVerifiedForUser($user); $this->assertTrue($mfaSession->isVerifiedForUser($user)); - $this->asAdmin()->get('/logout'); + $this->asAdmin()->post('/logout'); $this->assertFalse($mfaSession->isVerifiedForUser($user)); }