Files
pricebuddy/tests/Unit/Enums/RoleTest.php
Jeremy d2ca105091 test: cover UserResource role-based page access
feat: add Role enum (Admin/User)

feat: add role column to users, backfill existing to admin

feat: cast user role to enum and add isAdmin helper

feat: user factory defaults to User role with admin() state

feat: add UserPolicy (admin manages all, users manage self)

feat: restrict AppSettingsPage to admins

feat: admin-only role select on user form with role-based resource access

test: prove non-admins cannot escalate role; guard global search

Add canGloballySearch() to UserResource so the user list is never
surfaced in Filament global search for non-admins (defense-in-depth
alongside the broad canAccess() needed for self-edit). Commit the
adversarial escalation regression tests that prove both fillForm and
raw data.role injection cannot persist a role change for a non-admin.

feat: seed test@test.com as admin, another@test.com as user
2026-06-13 13:08:33 +10:00

24 lines
617 B
PHP

<?php
namespace Tests\Unit\Enums;
use App\Enums\Role;
use Filament\Support\Contracts\HasLabel;
use Tests\TestCase;
class RoleTest extends TestCase
{
public function test_it_has_admin_and_user_cases_with_string_values()
{
$this->assertSame('admin', Role::Admin->value);
$this->assertSame('user', Role::User->value);
}
public function test_it_implements_has_label_returning_case_name()
{
$this->assertInstanceOf(HasLabel::class, Role::Admin);
$this->assertSame('Admin', Role::Admin->getLabel());
$this->assertSame('User', Role::User->getLabel());
}
}