Files
unsupervised-scheduler/tests/Unit/Auth/RoleManagerTest.php
T
thatguygriff 36331388d1
CI / Coding Standards (pull_request) Successful in 55s
CI / PHPStan (pull_request) Successful in 1m0s
CI / Tests (PHP 8.1) (pull_request) Successful in 50s
CI / Tests (PHP 8.2) (pull_request) Successful in 46s
CI / Tests (PHP 8.3) (pull_request) Successful in 50s
CI / No Debug Code (pull_request) Successful in 2s
Add Offerings domain and studio-admin capabilities
Implements the offerings catalog (#1): private-lesson types and group
classes carrying pricing, billing mode (one_time/full_term), duration,
capacity, and term details. Adds the src/Offering/ domain (value object,
repository, REST endpoint, admin controller + template), the us_offerings
table, and an Offerings admin page.

Also lands the capability slice of #9: registers the us_studio_admin role
and the new capability strings (manage_instructors, manage_offerings,
manage_questions, manage_policies, manage_billing, view_all_payments,
view_own_payments, export_payments) so offering management gates correctly.

Tests: tests/Unit/Offering/ (value object + repository) and a studio-admin
case in RoleManagerTest. composer test, cs, and PHPStan level 6 all pass.

Refs #1 #9

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-05 10:33:02 -03:00

95 lines
3.3 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 testCreateRolesAddsStudioAdminRoleWithCorrectCaps(): void
{
Functions\when('get_role')->alias(static function (string $role): ?object {
return $role === RoleManager::STUDIO_ADMIN ? null : new \stdClass();
});
Functions\expect('add_role')
->once()
->with(
RoleManager::STUDIO_ADMIN,
\Mockery::any(),
\Mockery::on(static function (array $caps): bool {
return ($caps['read'] ?? false) === true
&& ($caps[RoleManager::CAP_MANAGE_INSTRUCTORS] ?? false) === true
&& ($caps[RoleManager::CAP_MANAGE_OFFERINGS] ?? false) === true
&& ($caps[RoleManager::CAP_MANAGE_POLICIES] ?? false) === true
&& ($caps[RoleManager::CAP_MANAGE_BILLING] ?? false) === true
&& ($caps[RoleManager::CAP_VIEW_ALL_PAYMENTS] ?? 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();
}
}