|
2 | 2 | namespace Tests\Integration; |
3 | 3 |
|
4 | 4 | use App\Article; |
5 | | -use Tests\TestCase; |
6 | 5 | use Bkwld\Decoy\Models\Admin; |
| 6 | +use Carbon\Carbon; |
| 7 | +use Illuminate\Support\Str; |
| 8 | +use Tests\TestCase; |
7 | 9 |
|
8 | 10 | class AdminTest extends TestCase |
9 | 11 | { |
@@ -67,4 +69,79 @@ public function testAdminDisableAdmins() |
67 | 69 | $this->assertResponseStatus(403); |
68 | 70 | } |
69 | 71 |
|
| 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 | + |
70 | 147 | } |
0 commit comments