Files
beatbook/tests/Feature/AuthenticationTest.php
T
2026-09-12 21:04:45 +01:00

49 lines
1.4 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\User;
use Illuminate\Foundation\Http\Middleware\PreventRequestForgery;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Spatie\Permission\Models\Role;
use Tests\TestCase;
class AuthenticationTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
$this->withoutMiddleware(PreventRequestForgery::class);
}
public function test_user_can_register(): void
{
Role::create(['name' => 'client', 'guard_name' => 'web']);
$response = $this->post('/register', [
'name' => 'Test Client',
'email' => 'client@example.test',
'password' => 'password12345',
'password_confirmation' => 'password12345',
]);
$response->assertRedirect('/dashboard');
$this->assertAuthenticated();
$this->assertDatabaseHas('users', ['email' => 'client@example.test']);
}
public function test_user_can_login_and_logout(): void
{
$user = User::factory()->create(['password' => 'password12345']);
$this->post('/login', ['email' => $user->email, 'password' => 'password12345'])
->assertRedirect('/dashboard');
$this->assertAuthenticatedAs($user);
$this->post('/logout')->assertRedirect('/');
$this->assertGuest();
}
}