- AuthTest, ProgramTest, CheckinTest, QuestionnaireTest, CertificateTest — 19 feature tests, 35 total pass - ProgramFactory with published() state - UserFactory: is_admin=true default, nonAdmin() state - Fix attendance_source column name in StatisticsController (was: source) - Fix route(dashboard) → route(admin.dashboard) in all Breeze auth controllers - Remove irrelevant Breeze boilerplate tests (Profile, Example, Registration) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
50 lines
1.2 KiB
PHP
50 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class AuthTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_admin_can_login_and_is_redirected_to_dashboard(): void
|
|
{
|
|
$admin = User::factory()->create(['email' => 'admin@test.com', 'password' => bcrypt('password')]);
|
|
|
|
$this->post('/login', [
|
|
'email' => 'admin@test.com',
|
|
'password' => 'password',
|
|
])->assertRedirect('/admin/dashboard');
|
|
|
|
$this->assertAuthenticatedAs($admin);
|
|
}
|
|
|
|
public function test_unauthenticated_user_is_redirected_from_admin(): void
|
|
{
|
|
$this->get('/admin/dashboard')->assertRedirect('/login');
|
|
}
|
|
|
|
public function test_non_admin_cannot_access_admin_routes(): void
|
|
{
|
|
$user = User::factory()->nonAdmin()->create();
|
|
|
|
$this->actingAs($user)
|
|
->get('/admin/dashboard')
|
|
->assertForbidden();
|
|
}
|
|
|
|
public function test_admin_can_logout(): void
|
|
{
|
|
$admin = User::factory()->create();
|
|
|
|
$this->actingAs($admin)
|
|
->post('/logout')
|
|
->assertRedirect('/');
|
|
|
|
$this->assertGuest();
|
|
}
|
|
}
|