X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/3acea12f1c0013be4f1e3994cae2ea662e43bb4e..refs/pull/3593/head:/tests/Auth/UserInviteTest.php diff --git a/tests/Auth/UserInviteTest.php b/tests/Auth/UserInviteTest.php index 331262690..38124cc1a 100644 --- a/tests/Auth/UserInviteTest.php +++ b/tests/Auth/UserInviteTest.php @@ -1,33 +1,62 @@ -getAdmin(); - $this->actingAs($admin)->post('/settings/users/create', [ - 'name' => 'Barry', - 'email' => 'tester@example.com', + $email = Str::random(16) . '@example.com'; + $resp = $this->actingAs($admin)->post('/settings/users/create', [ + 'name' => 'Barry', + 'email' => $email, 'send_invite' => 'true', ]); + $resp->assertRedirect('/settings/users'); - $newUser = User::query()->where('email', '=', 'tester@example.com')->orderBy('id', 'desc')->first(); + $newUser = User::query()->where('email', '=', $email)->orderBy('id', 'desc')->first(); Notification::assertSentTo($newUser, UserInvite::class); $this->assertDatabaseHas('user_invites', [ - 'user_id' => $newUser->id + 'user_id' => $newUser->id, + ]); + } + + public function test_user_invite_sent_in_selected_language() + { + Notification::fake(); + $admin = $this->getAdmin(); + + $email = Str::random(16) . '@example.com'; + $resp = $this->actingAs($admin)->post('/settings/users/create', [ + 'name' => 'Barry', + 'email' => $email, + 'send_invite' => 'true', + 'language' => 'de', ]); + $resp->assertRedirect('/settings/users'); + + $newUser = User::query()->where('email', '=', $email)->orderBy('id', 'desc')->first(); + Notification::assertSentTo($newUser, UserInvite::class, function ($notification, $channels, $notifiable) { + /** @var MailMessage $mail */ + $mail = $notification->toMail($notifiable); + + return 'Du wurdest eingeladen BookStack beizutreten!' === $mail->subject && + 'Ein Konto wurde für Sie auf BookStack erstellt.' === $mail->greeting; + }); } public function test_invite_set_password() @@ -48,14 +77,14 @@ class UserInviteTest extends TestCase $setPasswordResp = $this->followingRedirects()->post('/register/invite/' . $token, [ 'password' => 'my test password', ]); - $setPasswordResp->assertSee('Password set, you now have access to BookStack!'); + $setPasswordResp->assertSee('Password set, you should now be able to login using your set password to access BookStack!'); $newPasswordValid = auth()->validate([ - 'email' => $user->email, - 'password' => 'my test password' + 'email' => $user->email, + 'password' => 'my test password', ]); $this->assertTrue($newPasswordValid); $this->assertDatabaseMissing('user_invites', [ - 'user_id' => $user->id + 'user_id' => $user->id, ]); } @@ -68,27 +97,29 @@ class UserInviteTest extends TestCase $inviteService->sendInvitation($user); $token = DB::table('user_invites')->where('user_id', '=', $user->id)->first()->token; + $this->get('/register/invite/' . $token); $shortPassword = $this->followingRedirects()->post('/register/invite/' . $token, [ - 'password' => 'mypas', + 'password' => 'mypassw', ]); - $shortPassword->assertSee('The password must be at least 6 characters.'); + $shortPassword->assertSee('The password must be at least 8 characters.'); + $this->get('/register/invite/' . $token); $noPassword = $this->followingRedirects()->post('/register/invite/' . $token, [ 'password' => '', ]); $noPassword->assertSee('The password field is required.'); $this->assertDatabaseHas('user_invites', [ - 'user_id' => $user->id + 'user_id' => $user->id, ]); } public function test_non_existent_invite_token_redirects_to_home() { - $setPasswordPageResp = $this->get('/register/invite/' . str_random(12)); + $setPasswordPageResp = $this->get('/register/invite/' . Str::random(12)); $setPasswordPageResp->assertRedirect('/'); - $setPasswordResp = $this->post('/register/invite/' . str_random(12), ['password' => 'Password Test']); + $setPasswordResp = $this->post('/register/invite/' . Str::random(12), ['password' => 'Password Test']); $setPasswordResp->assertRedirect('/'); } @@ -106,6 +137,4 @@ class UserInviteTest extends TestCase $setPasswordPageResp->assertRedirect('/password/email'); $setPasswordPageResp->assertSessionHas('error', 'This invitation link has expired. You can instead try to reset your account password.'); } - - -} \ No newline at end of file +}