Skip to content

Commit db5e7ea

Browse files
committed
Added tests for the password reset flow
[touch:26]
1 parent 8fb5d65 commit db5e7ea

File tree

3 files changed

+80
-2
lines changed

3 files changed

+80
-2
lines changed

example/config/mail.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
|
1717
*/
1818

19-
'driver' => env('MAIL_DRIVER', 'smtp'),
19+
'driver' => env('MAIL_DRIVER', 'mail'),
2020

2121
/*
2222
|--------------------------------------------------------------------------

phpunit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<env name="APP_ENV" value="testing"/>
3131
<env name="CACHE_DRIVER" value="array"/>
3232
<env name="DB_CONNECTION" value="testing"/>
33+
<env name="MAIL_DRIVER" value="log"/>
3334
<env name="SESSION_DRIVER" value="array"/>
3435
<env name="QUEUE_DRIVER" value="sync"/>
3536

tests/Integration/AdminTest.php

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
namespace Tests\Integration;
33

44
use App\Article;
5-
use Tests\TestCase;
65
use Bkwld\Decoy\Models\Admin;
6+
use Carbon\Carbon;
7+
use Illuminate\Support\Str;
8+
use Tests\TestCase;
79

810
class AdminTest extends TestCase
911
{
@@ -67,4 +69,79 @@ public function testAdminDisableAdmins()
6769
$this->assertResponseStatus(403);
6870
}
6971

72+
/**
73+
* Test the reset password flow
74+
*
75+
* @return void
76+
*/
77+
public function testResetPasswordIndex()
78+
{
79+
$response = $this->get('admin/forgot');
80+
81+
$this->assertResponseOk();
82+
}
83+
84+
/**
85+
* Test the reset password submit button works
86+
*
87+
* @return void
88+
*/
89+
public function testResetPasswordSubmit()
90+
{
91+
$response = $this->call('POST', 'admin/forgot', [
92+
'email' => 'test@domain.com',
93+
]);
94+
95+
$this->assertResponseStatus(302);
96+
}
97+
98+
/**
99+
* Test reset password form
100+
*
101+
* @return void
102+
*/
103+
public function testResetPasswordFormIndex()
104+
{
105+
$token = Str::random(60);
106+
\DB::table('password_resets')->insert([
107+
'email' => 'test@domain.com',
108+
'token' => $token,
109+
'created_at' => Carbon::now(),
110+
]);
111+
112+
$response = $this->get('admin/reset/'.$token);
113+
$this->assertResponseOk();
114+
}
115+
116+
/**
117+
* Test that the reset password form works
118+
*
119+
* @return void
120+
*/
121+
public function testResetPasswordFormSave()
122+
{
123+
$current_password = Admin::findOrFail(1)->password;
124+
125+
$token = Str::random(60);
126+
\DB::table('password_resets')->insert([
127+
'email' => 'test@domain.com',
128+
'token' => $token,
129+
'created_at' => Carbon::now(),
130+
]);
131+
132+
$response = $this->post('admin/reset/'.$token, [
133+
'email' => 'test@domain.com',
134+
'password' => 'farting',
135+
'password_confirmation' => 'farting',
136+
'token' => $token,
137+
]);
138+
139+
$new_password = Admin::findOrFail(1)->password;
140+
141+
$this->assertResponseStatus(302);
142+
$this->assertNotEquals($current_password, $new_password);
143+
$this->assertEmpty(\DB::table('password_resets')
144+
->where('email', 'test@domain.com')->get());
145+
}
146+
70147
}

0 commit comments

Comments
 (0)