Skip to content

Commit

Permalink
Added tests for the password reset flow
Browse files Browse the repository at this point in the history
[touch:26]
  • Loading branch information
brokenhd committed Mar 31, 2017
1 parent 8fb5d65 commit db5e7ea
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 2 deletions.
2 changes: 1 addition & 1 deletion example/config/mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
|
*/

'driver' => env('MAIL_DRIVER', 'smtp'),
'driver' => env('MAIL_DRIVER', 'mail'),

/*
|--------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="DB_CONNECTION" value="testing"/>
<env name="MAIL_DRIVER" value="log"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>

Expand Down
79 changes: 78 additions & 1 deletion tests/Integration/AdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
namespace Tests\Integration;

use App\Article;
use Tests\TestCase;
use Bkwld\Decoy\Models\Admin;
use Carbon\Carbon;
use Illuminate\Support\Str;
use Tests\TestCase;

class AdminTest extends TestCase
{
Expand Down Expand Up @@ -67,4 +69,79 @@ public function testAdminDisableAdmins()
$this->assertResponseStatus(403);
}

/**
* Test the reset password flow
*
* @return void
*/
public function testResetPasswordIndex()
{
$response = $this->get('admin/forgot');

$this->assertResponseOk();
}

/**
* Test the reset password submit button works
*
* @return void
*/
public function testResetPasswordSubmit()
{
$response = $this->call('POST', 'admin/forgot', [
'email' => '[email protected]',
]);

$this->assertResponseStatus(302);
}

/**
* Test reset password form
*
* @return void
*/
public function testResetPasswordFormIndex()
{
$token = Str::random(60);
\DB::table('password_resets')->insert([
'email' => '[email protected]',
'token' => $token,
'created_at' => Carbon::now(),
]);

$response = $this->get('admin/reset/'.$token);
$this->assertResponseOk();
}

/**
* Test that the reset password form works
*
* @return void
*/
public function testResetPasswordFormSave()
{
$current_password = Admin::findOrFail(1)->password;

$token = Str::random(60);
\DB::table('password_resets')->insert([
'email' => '[email protected]',
'token' => $token,
'created_at' => Carbon::now(),
]);

$response = $this->post('admin/reset/'.$token, [
'email' => '[email protected]',
'password' => 'farting',
'password_confirmation' => 'farting',
'token' => $token,
]);

$new_password = Admin::findOrFail(1)->password;

$this->assertResponseStatus(302);
$this->assertNotEquals($current_password, $new_password);
$this->assertEmpty(\DB::table('password_resets')
->where('email', '[email protected]')->get());
}

}

0 comments on commit db5e7ea

Please sign in to comment.