|
0
|
1 <?php
|
|
|
2
|
|
|
3 namespace Tests\Feature\Auth;
|
|
|
4
|
|
|
5 use App\Models\User;
|
|
|
6 use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
7 use Tests\TestCase;
|
|
|
8
|
|
|
9 class AuthenticationTest extends TestCase
|
|
|
10 {
|
|
|
11 use RefreshDatabase;
|
|
|
12
|
|
|
13 public function test_login_screen_can_be_rendered(): void
|
|
|
14 {
|
|
|
15 $response = $this->get('/login');
|
|
|
16
|
|
|
17 $response->assertStatus(200);
|
|
|
18 }
|
|
|
19
|
|
|
20 public function test_users_can_authenticate_using_the_login_screen(): void
|
|
|
21 {
|
|
|
22 $user = User::factory()->create();
|
|
|
23
|
|
|
24 $response = $this->post('/login', [
|
|
|
25 'email' => $user->email,
|
|
|
26 'password' => 'password',
|
|
|
27 ]);
|
|
|
28
|
|
|
29 $this->assertAuthenticated();
|
|
|
30 $response->assertRedirect(route('dashboard', absolute: false));
|
|
|
31 }
|
|
|
32
|
|
|
33 public function test_users_can_not_authenticate_with_invalid_password(): void
|
|
|
34 {
|
|
|
35 $user = User::factory()->create();
|
|
|
36
|
|
|
37 $this->post('/login', [
|
|
|
38 'email' => $user->email,
|
|
|
39 'password' => 'wrong-password',
|
|
|
40 ]);
|
|
|
41
|
|
|
42 $this->assertGuest();
|
|
|
43 }
|
|
|
44
|
|
|
45 public function test_users_can_logout(): void
|
|
|
46 {
|
|
|
47 $user = User::factory()->create();
|
|
|
48
|
|
|
49 $response = $this->actingAs($user)->post('/logout');
|
|
|
50
|
|
|
51 $this->assertGuest();
|
|
|
52 $response->assertRedirect('/');
|
|
|
53 }
|
|
|
54 }
|