2FAuth/tests/Feature/Auth/ResetPasswordTest.php

100 lines
2.6 KiB
PHP
Raw Normal View History

2020-03-03 17:06:40 +01:00
<?php
2020-03-04 17:19:13 +01:00
namespace Tests\Feature\Auth;
2020-03-03 17:06:40 +01:00
use App\User;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Password;
use Illuminate\Support\Facades\Notification;
use Tests\TestCase;
2020-03-04 17:19:13 +01:00
class ResetPasswordTest extends TestCase
2020-03-03 17:06:40 +01:00
{
/** @var \App\User */
protected $user;
/**
* Testing submitting the reset password without
* email address.
*/
public function testSubmitResetPasswordWithoutInput()
{
$response = $this->json('POST', '/api/password/reset', [
'email' => '',
'password' => '',
'password_confirmation' => '',
'token' => ''
]);
$response->assertStatus(422)
->assertJsonValidationErrors(['email', 'password', 'token']);
}
/**
* Testing submitting the reset password with
* invalid input.
*/
public function testSubmitResetPasswordWithInvalidInput()
{
$response = $this->json('POST', '/api/password/reset', [
'email' => 'qsdqsdqsd',
'password' => 'foofoofoo',
'password_confirmation' => 'barbarbar',
'token' => 'token'
]);
$response->assertStatus(422)
->assertJsonValidationErrors(['email', 'password']);
}
/**
* Testing submitting the reset password with
* invalid input.
*/
public function testSubmitResetPasswordWithTooShortPasswords()
{
$response = $this->json('POST', '/api/password/reset', [
'email' => 'foo@bar.com',
'password' => 'foo',
'password_confirmation' => 'foo',
'token' => 'token'
]);
$response->assertStatus(422)
->assertJsonValidationErrors(['password']);
}
/**
* Testing submitting the rest password.
*/
public function testSubmitResetPassword()
{
Notification::fake();
$this->user = factory(User::class)->create([
'name' => 'user',
'email' => 'user@example.org',
'password' => bcrypt('password'),
'email_verified_at' => now(),
'remember_token' => \Illuminate\Support\Str::random(10)
]);
$token = Password::broker()->createToken($this->user);
$response = $this->json('POST', '/api/password/reset', [
'email' => $this->user->email,
'password' => 'newpassword',
'password_confirmation' => 'newpassword',
'token' => $token
]);
$this->user->refresh();
$response->assertStatus(200);
$this->assertTrue(Hash::check('newpassword', $this->user->password));
}
}