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