Files
unsupervised-scheduler/tests/Unit/Auth/RoleManagerTest.php
James Griffin 2fb2ca392d
All checks were successful
CI / Coding Standards (push) Successful in 43s
CI / PHPStan (push) Successful in 52s
CI / Tests (PHP 8.1) (push) Successful in 47s
CI / Tests (PHP 8.2) (push) Successful in 49s
CI / Tests (PHP 8.3) (push) Successful in 37s
CI / No Debug Code (push) Successful in 2s
Restructure src/ and tests/ from package-by-type to package-by-domain
All classes are now organised by domain (Availability, Booking, Auth).
Each domain package contains its value object, repository, admin controller,
REST endpoint, and any shortcode pages under a matching sub-namespace.
Cross-cutting wiring (Plugin, AdminMenu, RestRegistrar, ShortcodeRegistrar,
Schema) lives at src/ root. Tests mirror the domain structure.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-30 16:37:30 -03:00

71 lines
2.2 KiB
PHP

<?php
declare(strict_types=1);
namespace Unsupervised\Schedular\Tests\Unit\Auth;
use Brain\Monkey\Functions;
use Unsupervised\Schedular\Auth\RoleManager;
use Unsupervised\Schedular\Tests\Unit\TestCase;
class RoleManagerTest extends TestCase
{
public function testRegisterAddsInitHook(): void
{
Functions\expect('add_action')
->once()
->with('init', \Mockery::any());
(new RoleManager())->register();
}
public function testCreateRolesSkipsExistingRoles(): void
{
Functions\when('get_role')->alias(static fn() => new \stdClass());
Functions\expect('add_role')->never();
(new RoleManager())->createRoles();
}
public function testCreateRolesAddsInstructorRoleWithCorrectCaps(): void
{
Functions\when('get_role')->alias(static function (string $role): ?object {
return $role === RoleManager::INSTRUCTOR ? null : new \stdClass();
});
Functions\expect('add_role')
->once()
->with(
RoleManager::INSTRUCTOR,
\Mockery::any(),
\Mockery::on(static function (array $caps): bool {
return ($caps['read'] ?? false) === true
&& ($caps[RoleManager::CAP_MANAGE_AVAILABILITY] ?? false) === true
&& ($caps[RoleManager::CAP_VIEW_LESSONS] ?? false) === true;
})
);
(new RoleManager())->createRoles();
}
public function testCreateRolesAddsStudentRoleWithCorrectCaps(): void
{
Functions\when('get_role')->alias(static function (string $role): ?object {
return $role === RoleManager::STUDENT ? null : new \stdClass();
});
Functions\expect('add_role')
->once()
->with(
RoleManager::STUDENT,
\Mockery::any(),
\Mockery::on(static function (array $caps): bool {
return ($caps['read'] ?? false) === true
&& ($caps[RoleManager::CAP_BOOK_LESSON] ?? false) === true
&& ($caps[RoleManager::CAP_VIEW_LESSONS] ?? false) === true;
})
);
(new RoleManager())->createRoles();
}
}