Restore native ResetPassword notification and test it

This commit is contained in:
Bubka 2020-03-06 15:07:09 +01:00
parent 23a49fbb83
commit 8927a4c7c0
4 changed files with 5 additions and 32 deletions

View File

@ -1,25 +0,0 @@
<?php
namespace App\Notifications;
use Illuminate\Auth\Notifications\ResetPassword as Notification;
use Illuminate\Notifications\Messages\MailMessage;
class ResetPassword extends Notification
{
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->line('You are receiving this email because we received a password reset request for your account.')
->action('Reset Password', url(config('app.url').'/password/reset/'.$this->token).'?email='.urlencode($notifiable->email))
->line('If you did not request a password reset, no further action is required.');
}
}

View File

@ -2,7 +2,7 @@
namespace App;
use App\Notifications\ResetPassword;
use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;

View File

@ -20,7 +20,7 @@
Route::post('register', 'Auth\RegisterController@register');
Route::post('password/email', 'Auth\ForgotPasswordController@sendResetLinkEmail');
Route::post('password/reset', 'Auth\ResetPasswordController@reset');
Route::post('password/reset', 'Auth\ResetPasswordController@reset')->name('password.reset');
});

View File

@ -71,8 +71,6 @@ public function testSubmitEmailPasswordRequest()
'remember_token' => \Illuminate\Support\Str::random(10),
]);
//$this->expectsNotification($this->user, ResetPassword::class);
$response = $this->json('POST', '/api/password/email', [
'email' => $this->user->email
]);
@ -82,9 +80,9 @@ public function testSubmitEmailPasswordRequest()
$token = \Illuminate\Support\Facades\DB::table('password_resets')->first();
$this->assertNotNull($token);
// Notification::assertSentTo($this->user, ResetPassword::class, function ($notification, $channels) use ($token) {
// return Hash::check($notification->token, $token->token) === true;
// });
Notification::assertSentTo($this->user, ResetPassword::class, function ($notification, $channels) use ($token) {
return Hash::check($notification->token, $token->token) === true;
});
}
}