CI / Tests (PHP 8.1) (pull_request) Successful in 1m18s
CI / Tests (PHP 8.2) (pull_request) Successful in 1m18s
CI / No Debug Code (pull_request) Successful in 2s
CI / PHPStan (pull_request) Successful in 3m20s
CI / Coding Standards (pull_request) Successful in 3m25s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m33s
CI / Build Plugin Zip (pull_request) Skipped
Students could previously join by invite only. Add an optional self-approval mode, toggled from Studio Settings → Registration: anyone may sign up on the existing [us_student_register] page, confirm their email via a tokenised link, and then be approved by a studio admin before the account is usable. - Enabling the toggle mirrors WordPress's own membership settings (users_can_register + default_role = us_student) and snapshots their previous values so disabling restores them. - WordPress's native registration form is blocked while open registration is on (login_init redirect + registration_errors fail-safe + register_url) so it cannot bypass signup policy acceptance. - Pending accounts: unconfirmed email cannot log in; confirmed but unapproved can log in but the booking capability is withheld and the booking page shows an "awaiting approval" screen. - Approve/reject from Students → Pending Students; reject hard-deletes the account so the email is freed to re-apply. - Invite registration is unchanged; both modes coexist. Account lifecycle lives in user meta (RegistrationStatus); no new tables. Closes #63 Co-Authored-By: Claude Opus 4.8 <[email protected]>
89 lines
3.9 KiB
PHP
89 lines
3.9 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Unsupervised\Schedular\Tests\Unit\Payment;
|
|
|
|
use Brain\Monkey\Functions;
|
|
use Unsupervised\Schedular\Auth\RoleManager;
|
|
use Unsupervised\Schedular\Payment\StudioSettings;
|
|
use Unsupervised\Schedular\Tests\Unit\TestCase;
|
|
|
|
class StudioSettingsTest extends TestCase
|
|
{
|
|
public function testRegistrationModeDefaultsToInvite(): void
|
|
{
|
|
Functions\when('get_option')->alias(static fn (string $name, $default) => $default);
|
|
|
|
$settings = new StudioSettings();
|
|
|
|
self::assertSame(StudioSettings::MODE_INVITE, $settings->registrationMode());
|
|
self::assertFalse($settings->openRegistrationEnabled());
|
|
}
|
|
|
|
public function testOpenRegistrationEnabledWhenStored(): void
|
|
{
|
|
Functions\when('get_option')->alias(static fn (string $name) =>
|
|
$name === StudioSettings::OPT_REGISTRATION_MODE ? StudioSettings::MODE_SELF_APPROVAL : '');
|
|
|
|
self::assertTrue((new StudioSettings())->openRegistrationEnabled());
|
|
}
|
|
|
|
public function testEnablingMirrorsCoreOptionsAndSnapshots(): void
|
|
{
|
|
Functions\when('get_option')->alias(static function (string $name, $default = false) {
|
|
return match ($name) {
|
|
StudioSettings::OPT_REGISTRATION_MODE => StudioSettings::MODE_INVITE, // currently closed
|
|
'users_can_register' => false, // snapshot as '0'
|
|
'default_role' => 'contributor',
|
|
default => $default,
|
|
};
|
|
});
|
|
|
|
Functions\expect('update_option')->once()->with(StudioSettings::OPT_PREV_USERS_CAN_REGISTER, '0');
|
|
Functions\expect('update_option')->once()->with(StudioSettings::OPT_PREV_DEFAULT_ROLE, 'contributor');
|
|
Functions\expect('update_option')->once()->with('users_can_register', '1');
|
|
Functions\expect('update_option')->once()->with('default_role', RoleManager::STUDENT);
|
|
Functions\expect('update_option')->once()->with(StudioSettings::OPT_REGISTRATION_MODE, StudioSettings::MODE_SELF_APPROVAL);
|
|
|
|
$this->applyMode(true);
|
|
}
|
|
|
|
public function testDisablingRestoresSnapshot(): void
|
|
{
|
|
Functions\when('get_option')->alias(static function (string $name, $default = false) {
|
|
return match ($name) {
|
|
StudioSettings::OPT_REGISTRATION_MODE => StudioSettings::MODE_SELF_APPROVAL, // currently open
|
|
StudioSettings::OPT_PREV_USERS_CAN_REGISTER => '1',
|
|
StudioSettings::OPT_PREV_DEFAULT_ROLE => 'contributor',
|
|
default => $default,
|
|
};
|
|
});
|
|
|
|
Functions\expect('update_option')->once()->with('users_can_register', '1');
|
|
Functions\expect('update_option')->once()->with('default_role', 'contributor');
|
|
Functions\expect('delete_option')->once()->with(StudioSettings::OPT_PREV_USERS_CAN_REGISTER);
|
|
Functions\expect('delete_option')->once()->with(StudioSettings::OPT_PREV_DEFAULT_ROLE);
|
|
Functions\expect('update_option')->once()->with(StudioSettings::OPT_REGISTRATION_MODE, StudioSettings::MODE_INVITE);
|
|
|
|
$this->applyMode(false);
|
|
}
|
|
|
|
public function testNoTransitionLeavesCoreOptionsUntouched(): void
|
|
{
|
|
// Already open, asked to enable again: nothing should be written.
|
|
Functions\when('get_option')->alias(static fn (string $name, $default = false) =>
|
|
$name === StudioSettings::OPT_REGISTRATION_MODE ? StudioSettings::MODE_SELF_APPROVAL : $default);
|
|
|
|
Functions\expect('update_option')->never();
|
|
Functions\expect('delete_option')->never();
|
|
|
|
$this->applyMode(true);
|
|
}
|
|
|
|
private function applyMode(bool $enable): void
|
|
{
|
|
$method = new \ReflectionMethod(StudioSettings::class, 'applyRegistrationMode');
|
|
$method->invoke(new StudioSettings(), $enable);
|
|
}
|
|
}
|