progetto di test della creazione di un progetto basato sul framework laravel e aggiunta form login e register utilizzando breeze
filippo.bertilotti
2024-04-12 f7d0ce435d960868043e25ce3a7c647c890bb132
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
 
namespace Tests\Feature\Auth;
 
use App\Models\User;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Volt\Volt;
use Tests\TestCase;
 
class AuthenticationTest extends TestCase
{
    use RefreshDatabase;
 
    public function test_login_screen_can_be_rendered(): void
    {
        $response = $this->get('/login');
 
        $response
            ->assertOk()
            ->assertSeeVolt('pages.auth.login');
    }
 
    public function test_users_can_authenticate_using_the_login_screen(): void
    {
        $user = User::factory()->create();
 
        $component = Volt::test('pages.auth.login')
            ->set('form.email', $user->email)
            ->set('form.password', 'password');
 
        $component->call('login');
 
        $component
            ->assertHasNoErrors()
            ->assertRedirect(RouteServiceProvider::HOME);
 
        $this->assertAuthenticated();
    }
 
    public function test_users_can_not_authenticate_with_invalid_password(): void
    {
        $user = User::factory()->create();
 
        $component = Volt::test('pages.auth.login')
            ->set('form.email', $user->email)
            ->set('form.password', 'wrong-password');
 
        $component->call('login');
 
        $component
            ->assertHasErrors()
            ->assertNoRedirect();
 
        $this->assertGuest();
    }
 
    public function test_navigation_menu_can_be_rendered(): void
    {
        $user = User::factory()->create();
 
        $this->actingAs($user);
 
        $response = $this->get('/dashboard');
 
        $response
            ->assertOk()
            ->assertSeeVolt('layout.navigation');
    }
 
    public function test_users_can_logout(): void
    {
        $user = User::factory()->create();
 
        $this->actingAs($user);
 
        $component = Volt::test('layout.navigation');
 
        $component->call('logout');
 
        $component
            ->assertHasNoErrors()
            ->assertRedirect('/');
 
        $this->assertGuest();
    }
}