first
This commit is contained in:
68
tests/Feature/Auth/LoginTest.php
Normal file
68
tests/Feature/Auth/LoginTest.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Auth;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class LoginTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_login_page_loads(): void
|
||||
{
|
||||
$this->get(route('login'))->assertOk()->assertViewIs('auth.login');
|
||||
}
|
||||
|
||||
public function test_admin_redirected_to_admin_dashboard(): void
|
||||
{
|
||||
$admin = User::factory()->admin()->create();
|
||||
|
||||
$this->post(route('login'), [
|
||||
'email' => $admin->email,
|
||||
'password' => 'password',
|
||||
])->assertRedirect(route('admin.dashboard'));
|
||||
}
|
||||
|
||||
public function test_user_redirected_to_user_dashboard(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->post(route('login'), [
|
||||
'email' => $user->email,
|
||||
'password' => 'password',
|
||||
])->assertRedirect(route('user.dashboard'));
|
||||
}
|
||||
|
||||
public function test_deactivated_user_cannot_login(): void
|
||||
{
|
||||
$user = User::factory()->inactive()->create();
|
||||
|
||||
$this->post(route('login'), [
|
||||
'email' => $user->email,
|
||||
'password' => 'password',
|
||||
])->assertSessionHasErrors('email');
|
||||
}
|
||||
|
||||
public function test_wrong_password_fails(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->post(route('login'), [
|
||||
'email' => $user->email,
|
||||
'password' => 'wrong-password',
|
||||
])->assertSessionHasErrors('email');
|
||||
}
|
||||
|
||||
public function test_logout_works(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->actingAs($user)
|
||||
->post(route('logout'))
|
||||
->assertRedirect(route('login'));
|
||||
|
||||
$this->assertGuest();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user