]> BookStack Code Mirror - bookstack/blobdiff - tests/Auth/UserInviteTest.php
Add base64 image support
[bookstack] / tests / Auth / UserInviteTest.php
index 3312626909541455a06ac65d8475a92ed6191484..b6f521eaa23196466114b27a04d5cca41b885115 100644 (file)
@@ -1,4 +1,4 @@
-<?php namespace Tests;
+<?php namespace Tests\Auth;
 
 
 use BookStack\Auth\Access\UserInviteService;
@@ -6,7 +6,9 @@ use BookStack\Auth\User;
 use BookStack\Notifications\UserInvite;
 use Carbon\Carbon;
 use DB;
+use Illuminate\Support\Str;
 use Notification;
+use Tests\TestCase;
 
 class UserInviteTest extends TestCase
 {
@@ -16,13 +18,15 @@ class UserInviteTest extends TestCase
         Notification::fake();
         $admin = $this->getAdmin();
 
-        $this->actingAs($admin)->post('/settings/users/create', [
+        $email = Str::random(16) . '@example.com';
+        $resp = $this->actingAs($admin)->post('/settings/users/create', [
             'name' => 'Barry',
-            'email' => '[email protected]',
+            'email' => $email,
             'send_invite' => 'true',
         ]);
+        $resp->assertRedirect('/settings/users');
 
-        $newUser = User::query()->where('email', '=', '[email protected]')->orderBy('id', 'desc')->first();
+        $newUser = User::query()->where('email', '=', $email)->orderBy('id', 'desc')->first();
 
         Notification::assertSentTo($newUser, UserInvite::class);
         $this->assertDatabaseHas('user_invites', [
@@ -68,11 +72,13 @@ 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' => '',
         ]);
@@ -85,10 +91,10 @@ class UserInviteTest extends TestCase
 
     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('/');
     }