From dfb1cbdef201b4ab30d3c9c98940447e361703b4 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Thu, 18 Oct 2018 20:45:22 +0800 Subject: [PATCH] Add change password test --- tests/Feature/ChangePasswordTest.php | 55 ++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/Feature/ChangePasswordTest.php diff --git a/tests/Feature/ChangePasswordTest.php b/tests/Feature/ChangePasswordTest.php new file mode 100644 index 0000000..546003a --- /dev/null +++ b/tests/Feature/ChangePasswordTest.php @@ -0,0 +1,55 @@ +loginAsUser(['password' => bcrypt('secret')]); + + $this->visit(route('home')); + $this->click(trans('auth.change_password')); + + $this->submitForm(trans('auth.change_password'), [ + 'old_password' => 'secret', + 'new_password' => 'rahasia', + 'new_password_confirmation' => 'rahasia', + ]); + + $this->seeText(trans('auth.change_password_success')); + + $this->assertTrue( + app('hash')->check('rahasia', $user->password), + 'The password should changed!' + ); + } + + /** @test */ + public function user_cannot_change_password_if_old_password_wrong() + { + $user = $this->loginAsUser(['password' => bcrypt('secret')]); + + $this->visit(route('home')); + $this->click(trans('auth.change_password')); + + $this->submitForm(trans('auth.change_password'), [ + 'old_password' => 'member1', + 'new_password' => 'rahasia', + 'new_password_confirmation' => 'rahasia', + ]); + + $this->seeText(trans('passwords.old_password')); + + $this->assertTrue( + app('hash')->check('secret', $user->password), + 'The password shouldn\'t changed!' + ); + } +}