Email verification test

This commit is contained in:
PovilasKorop
2021-11-01 08:21:55 +02:00
parent 177b740701
commit 355d40f627
4 changed files with 71 additions and 0 deletions
+38
View File
@@ -3,9 +3,13 @@
namespace Tests\Feature;
use App\Models\User;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Auth;
use Tests\TestCase;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\URL;
use Illuminate\Auth\Events\Verified;
class AuthenticationTest extends TestCase
{
@@ -78,4 +82,38 @@ class AuthenticationTest extends TestCase
'password' => 'newpassword'
]));
}
public function test_email_can_be_verified()
{
$newData = [
'name' => 'New name',
'email' => 'new@email.com',
'password' => 'newpassword',
'password_confirmation' => 'newpassword'
];
$response = $this->post('/register', $newData);
$response->assertRedirect('/');
$response = $this->get('/secretpage');
$response->assertRedirect('/verify-email');
$user = User::factory()->create([
'email_verified_at' => null,
]);
Event::fake();
$verificationUrl = URL::temporarySignedRoute(
'verification.verify',
now()->addMinutes(60),
['id' => $user->id, 'hash' => sha1($user->email)]
);
$this->actingAs($user)->get($verificationUrl);
Event::assertDispatched(Verified::class);
$this->assertTrue($user->fresh()->hasVerifiedEmail());
$response = $this->get('/secretpage');
$response->assertOk();
}
}