From 9ad16a94340772c2c1e1d18be5c1090383eb6655 Mon Sep 17 00:00:00 2001 From: Adam Wathan Date: Wed, 10 May 2017 11:08:24 -0400 Subject: [PATCH] (test for old input on failed login) --- app/Http/Controllers/Auth/LoginController.php | 2 +- tests/Browser/PromoterLoginTest.php | 1 + tests/Feature/PromoterLoginTest.php | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 9915a7f..e6533d2 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -16,7 +16,7 @@ class LoginController extends Controller public function login() { if (! Auth::attempt(request(['email', 'password']))) { - return redirect('/login')->withErrors([ + return redirect('/login')->withInput(request(['email']))->withErrors([ 'email' => ['These credentials do not match our records.'], ]); } diff --git a/tests/Browser/PromoterLoginTest.php b/tests/Browser/PromoterLoginTest.php index 2cfd485..2bfda86 100644 --- a/tests/Browser/PromoterLoginTest.php +++ b/tests/Browser/PromoterLoginTest.php @@ -42,6 +42,7 @@ class PromoterLoginTest extends DuskTestCase ->type('password', 'wrong-password') ->press('Log in') ->assertPathIs('/login') + ->assertInputValue('email', 'jane@example.com') ->assertSee('credentials do not match'); }); } diff --git a/tests/Feature/PromoterLoginTest.php b/tests/Feature/PromoterLoginTest.php index 330dff1..a265747 100644 --- a/tests/Feature/PromoterLoginTest.php +++ b/tests/Feature/PromoterLoginTest.php @@ -48,6 +48,8 @@ class PromoterLoginTest extends TestCase $response->assertRedirect('/login'); $response->assertSessionHasErrors('email'); + $this->assertTrue(session()->hasOldInput('email')); + $this->assertFalse(session()->hasOldInput('password')); $this->assertFalse(Auth::check()); } @@ -63,6 +65,8 @@ class PromoterLoginTest extends TestCase $response->assertRedirect('/login'); $response->assertSessionHasErrors('email'); + $this->assertTrue(session()->hasOldInput('email')); + $this->assertFalse(session()->hasOldInput('password')); $this->assertFalse(Auth::check()); } }