->seeInDatabase('users', ['name' => $user->name, 'email' => $user->email, 'email_confirmed' => true]);
}
+ public function testUserCreation()
+ {
+ $user = factory(\BookStack\User::class)->make();
+
+ $this->asAdmin()
+ ->visit('/users')
+ ->click('Add new user')
+ ->type($user->name, '#name')
+ ->type($user->email, '#email')
+ ->select(2, '#role')
+ ->type($user->password, '#password')
+ ->type($user->password, '#password-confirm')
+ ->press('Save')
+ ->seeInDatabase('users', $user->toArray())
+ ->seePageIs('/users')
+ ->see($user->name);
+ }
+
+ public function testUserUpdating()
+ {
+ $user = \BookStack\User::all()->last();
+ $password = $user->password;
+ $this->asAdmin()
+ ->visit('/users')
+ ->click($user->name)
+ ->seePageIs('/users/' . $user->id)
+ ->see($user->email)
+ ->type('Barry Scott', '#name')
+ ->press('Save')
+ ->seePageIs('/users')
+ ->seeInDatabase('users', ['id' => $user->id, 'name' => 'Barry Scott', 'password' => $password])
+ ->notSeeInDatabase('users', ['name' => $user->name]);
+ }
+
+ public function testUserPasswordUpdate()
+ {
+ $user = \BookStack\User::all()->last();
+ $userProfilePage = '/users/' . $user->id;
+ $this->asAdmin()
+ ->visit($userProfilePage)
+ ->type('newpassword', '#password')
+ ->press('Save')
+ ->seePageIs($userProfilePage)
+ ->see('Password confirmation required')
+
+ ->type('newpassword', '#password')
+ ->type('newpassword', '#password-confirm')
+ ->press('Save')
+ ->seePageIs('/users');
+
+ $userPassword = \BookStack\User::find($user->id)->password;
+ $this->assertTrue(Hash::check('newpassword', $userPassword));
+ }
+
+ public function testUserDeletion()
+ {
+ $userDetails = factory(\BookStack\User::class)->make();
+ $user = $this->getNewUser($userDetails->toArray());
+
+ $this->asAdmin()
+ ->visit('/users/' . $user->id)
+ ->click('Delete User')
+ ->see($user->name)
+ ->press('Confirm')
+ ->seePageIs('/users')
+ ->notSeeInDatabase('users', ['name' => $user->name]);
+ }
+
+ public function testUserCannotBeDeletedIfLastAdmin()
+ {
+ $adminRole = \BookStack\Role::getRole('admin');
+ // Ensure we currently only have 1 admin user
+ $this->assertEquals(1, $adminRole->users()->count());
+ $user = $adminRole->users->first();
+
+ $this->asAdmin()->visit('/users/' . $user->id)
+ ->click('Delete User')
+ ->press('Confirm')
+ ->seePageIs('/users/' . $user->id)
+ ->see('You cannot delete the only admin');
+ }
+
public function testLogout()
{
$this->asAdmin()