@@ -102,10 +102,10 @@ public function testConfirmedRegistration()
102102 ->seeInDatabase ('users ' , ['name ' => $ user ->name , 'email ' => $ user ->email , 'email_confirmed ' => true ]);
103103 }
104104
105- public function testUserControl ()
105+ public function testUserCreation ()
106106 {
107107 $ user = factory (\BookStack \User::class)->make ();
108- // Test creation
108+
109109 $ this ->asAdmin ()
110110 ->visit ('/users ' )
111111 ->click ('Add new user ' )
@@ -118,9 +118,12 @@ public function testUserControl()
118118 ->seeInDatabase ('users ' , $ user ->toArray ())
119119 ->seePageIs ('/users ' )
120120 ->see ($ user ->name );
121- $ user = $ user -> where ( ' email ' , ' = ' , $ user -> email )-> first ();
121+ }
122122
123- // Test editing
123+ public function testUserUpdating ()
124+ {
125+ $ user = \BookStack \User::all ()->last ();
126+ $ password = $ user ->password ;
124127 $ this ->asAdmin ()
125128 ->visit ('/users ' )
126129 ->click ($ user ->name )
@@ -129,20 +132,58 @@ public function testUserControl()
129132 ->type ('Barry Scott ' , '#name ' )
130133 ->press ('Save ' )
131134 ->seePageIs ('/users ' )
132- ->seeInDatabase ('users ' , ['id ' => $ user ->id , 'name ' => 'Barry Scott ' ])
135+ ->seeInDatabase ('users ' , ['id ' => $ user ->id , 'name ' => 'Barry Scott ' , ' password ' => $ password ])
133136 ->notSeeInDatabase ('users ' , ['name ' => $ user ->name ]);
134- $ user = $ user ->find ($ user ->id );
137+ }
138+
139+ public function testUserPasswordUpdate ()
140+ {
141+ $ user = \BookStack \User::all ()->last ();
142+ $ userProfilePage = '/users/ ' . $ user ->id ;
143+ $ this ->asAdmin ()
144+ ->visit ($ userProfilePage )
145+ ->type ('newpassword ' , '#password ' )
146+ ->press ('Save ' )
147+ ->seePageIs ($ userProfilePage )
148+ ->see ('Password confirmation required ' )
149+
150+ ->type ('newpassword ' , '#password ' )
151+ ->type ('newpassword ' , '#password-confirm ' )
152+ ->press ('Save ' )
153+ ->seePageIs ('/users ' );
154+
155+ $ userPassword = \BookStack \User::find ($ user ->id )->password ;
156+ $ this ->assertTrue (Hash::check ('newpassword ' , $ userPassword ));
157+ }
158+
159+ public function testUserDeletion ()
160+ {
161+ $ userDetails = factory (\BookStack \User::class)->make ();
162+ $ user = $ this ->getNewUser ($ userDetails ->toArray ());
135163
136- // Test Deletion
137164 $ this ->asAdmin ()
138165 ->visit ('/users/ ' . $ user ->id )
139- ->click ('Delete user ' )
166+ ->click ('Delete User ' )
140167 ->see ($ user ->name )
141168 ->press ('Confirm ' )
142169 ->seePageIs ('/users ' )
143170 ->notSeeInDatabase ('users ' , ['name ' => $ user ->name ]);
144171 }
145172
173+ public function testUserCannotBeDeletedIfLastAdmin ()
174+ {
175+ $ adminRole = \BookStack \Role::getRole ('admin ' );
176+ // Ensure we currently only have 1 admin user
177+ $ this ->assertEquals (1 , $ adminRole ->users ()->count ());
178+ $ user = $ adminRole ->users ->first ();
179+
180+ $ this ->asAdmin ()->visit ('/users/ ' . $ user ->id )
181+ ->click ('Delete User ' )
182+ ->press ('Confirm ' )
183+ ->seePageIs ('/users/ ' . $ user ->id )
184+ ->see ('You cannot delete the only admin ' );
185+ }
186+
146187 public function testLogout ()
147188 {
148189 $ this ->asAdmin ()
0 commit comments