]> BookStack Code Mirror - bookstack/blobdiff - tests/Auth/AuthTest.php
Apply fixes from StyleCI
[bookstack] / tests / Auth / AuthTest.php
index 6257f841f9351db6d1eb4ffc2e961de6f4388b4b..febf583998d460e10440aa0ec36a2852eaa01641 100644 (file)
@@ -1,19 +1,21 @@
-<?php namespace Tests\Auth;
+<?php
+
+namespace Tests\Auth;
 
 use BookStack\Auth\Role;
 use BookStack\Auth\User;
-use BookStack\Entities\Page;
+use BookStack\Entities\Models\Page;
 use BookStack\Notifications\ConfirmEmail;
 use BookStack\Notifications\ResetPassword;
 use BookStack\Settings\SettingService;
 use DB;
 use Hash;
 use Illuminate\Support\Facades\Notification;
+use Illuminate\Support\Str;
 use Tests\BrowserKitTest;
 
 class AuthTest extends BrowserKitTest
 {
-
     public function test_auth_working()
     {
         $this->visit('/')
@@ -134,10 +136,10 @@ class AuthTest extends BrowserKitTest
 
         // Get confirmation and confirm notification matches
         $emailConfirmation = DB::table('email_confirmations')->where('user_id', '=', $dbUser->id)->first();
-        Notification::assertSentTo($dbUser, ConfirmEmail::class, function($notification, $channels) use ($emailConfirmation) {
+        Notification::assertSentTo($dbUser, ConfirmEmail::class, function ($notification, $channels) use ($emailConfirmation) {
             return $notification->token === $emailConfirmation->token;
         });
-        
+
         // Check confirmation email confirmation activation.
         $this->visit('/register/confirm/' . $emailConfirmation->token)
             ->seePageIs('/')
@@ -170,6 +172,11 @@ class AuthTest extends BrowserKitTest
             ->seePageIs('/register/confirm')
             ->seeInDatabase('users', ['name' => $user->name, 'email' => $user->email, 'email_confirmed' => false]);
 
+        $this->visit('/')
+            ->seePageIs('/register/confirm/awaiting');
+
+        auth()->logout();
+
         $this->visit('/')->seePageIs('/login')
             ->type($user->email, '#email')
             ->type($user->password, '#password')
@@ -202,6 +209,10 @@ class AuthTest extends BrowserKitTest
             ->seePageIs('/register/confirm')
             ->seeInDatabase('users', ['name' => $user->name, 'email' => $user->email, 'email_confirmed' => false]);
 
+        $this->visit('/')
+            ->seePageIs('/register/confirm/awaiting');
+
+        auth()->logout();
         $this->visit('/')->seePageIs('/login')
             ->type($user->email, '#email')
             ->type($user->password, '#password')
@@ -212,20 +223,25 @@ class AuthTest extends BrowserKitTest
 
     public function test_user_creation()
     {
+        /** @var User $user */
         $user = factory(User::class)->make();
+        $adminRole = Role::getRole('admin');
 
         $this->asAdmin()
             ->visit('/settings/users')
             ->click('Add New User')
             ->type($user->name, '#name')
             ->type($user->email, '#email')
-            ->check('roles[admin]')
+            ->check("roles[{$adminRole->id}]")
             ->type($user->password, '#password')
             ->type($user->password, '#password-confirm')
             ->press('Save')
             ->seePageIs('/settings/users')
-            ->seeInDatabase('users', $user->toArray())
+            ->seeInDatabase('users', $user->only(['name', 'email']))
             ->see($user->name);
+
+        $user->refresh();
+        $this->assertStringStartsWith(Str::slug($user->name), $user->slug);
     }
 
     public function test_user_updating()
@@ -242,6 +258,9 @@ class AuthTest extends BrowserKitTest
             ->seePageIs('/settings/users')
             ->seeInDatabase('users', ['id' => $user->id, 'name' => 'Barry Scott', 'password' => $password])
             ->notSeeInDatabase('users', ['name' => $user->name]);
+
+        $user->refresh();
+        $this->assertStringStartsWith(Str::slug($user->name), $user->slug);
     }
 
     public function test_user_password_update()
@@ -260,8 +279,8 @@ class AuthTest extends BrowserKitTest
             ->press('Save')
             ->seePageIs('/settings/users');
 
-            $userPassword = User::find($user->id)->password;
-            $this->assertTrue(Hash::check('newpassword', $userPassword));
+        $userPassword = User::find($user->id)->password;
+        $this->assertTrue(Hash::check('newpassword', $userPassword));
     }
 
     public function test_user_deletion()
@@ -322,7 +341,7 @@ class AuthTest extends BrowserKitTest
             ->see('A password reset link will be sent to [email protected] if that email address is found in the system.');
 
         $this->seeInDatabase('password_resets', [
-            'email' => '[email protected]'
+            'email' => '[email protected]',
         ]);
 
         $user = User::where('email', '=', '[email protected]')->first();
@@ -333,9 +352,9 @@ class AuthTest extends BrowserKitTest
         $this->visit('/password/reset/' . $n->first()->token)
             ->see('Reset Password')
             ->submitForm('Reset Password', [
-                'email' => '[email protected]',
-                'password' => 'randompass',
-                'password_confirmation' => 'randompass'
+                'email'                 => '[email protected]',
+                'password'              => 'randompass',
+                'password_confirmation' => 'randompass',
             ])->seePageIs('/')
             ->see('Your password has been successfully reset');
     }
@@ -349,13 +368,12 @@ class AuthTest extends BrowserKitTest
             ->see('A password reset link will be sent to [email protected] if that email address is found in the system.')
             ->dontSee('We can\'t find a user');
 
-
         $this->visit('/password/reset/arandometokenvalue')
             ->see('Reset Password')
             ->submitForm('Reset Password', [
-                'email' => '[email protected]',
-                'password' => 'randompass',
-                'password_confirmation' => 'randompass'
+                'email'                 => '[email protected]',
+                'password'              => 'randompass',
+                'password_confirmation' => 'randompass',
             ])->followRedirects()
             ->seePageIs('/password/reset/arandometokenvalue')
             ->dontSee('We can\'t find a user')
@@ -425,7 +443,7 @@ class AuthTest extends BrowserKitTest
     }
 
     /**
-     * Perform a login
+     * Perform a login.
      */
     protected function login(string $email, string $password): AuthTest
     {