Add cancellation cutoff limiting how close to a lesson a student can cancel
CI / Tests (PHP 8.1) (pull_request) Successful in 41s
CI / Tests (PHP 8.2) (pull_request) Successful in 53s
CI / No Debug Code (pull_request) Successful in 2s
CI / PHPStan (pull_request) Successful in 2m51s
CI / Coding Standards (pull_request) Successful in 2m54s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m38s
CI / Build Plugin Zip (pull_request) Skipped

Students can no longer cancel their own lesson online once it starts within a
configured window; instructors and studio admins can always cancel.

- Studio default `us_cancellation_cutoff_hours` (stored/computed in hours,
  entered and displayed in days under Studio Settings → Cancellations).
- Optional per-offering override `cancellation_cutoff_hours` (entered in hours);
  blank inherits the studio default, 0 allows anytime cancellation.
- `Booking\CancellationPolicy` resolves the effective window and decides;
  `BookingEndpoint::cancel()` returns a 403 `cancellation_closed` when too late.
  The instructor status endpoint and studio-admin student actions bypass it.

Closes #93

Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
2026-07-23 11:57:18 -03:00
co-authored by Claude Opus 4.8
parent a777f5d05a
commit 8b90b8d78d
18 changed files with 462 additions and 33 deletions
+23
View File
@@ -20,6 +20,29 @@ class StudioSettingsTest extends TestCase
self::assertFalse($settings->openRegistrationEnabled());
}
public function testCancellationCutoffDefaultsToOneDay(): void
{
Functions\when('get_option')->alias(static fn (string $name, $default) => $default);
self::assertSame(24, (new StudioSettings())->cancellationCutoffHours());
}
public function testCancellationCutoffReadsStoredHours(): void
{
Functions\when('get_option')->alias(static fn (string $name) =>
$name === StudioSettings::OPT_CANCELLATION_CUTOFF_HOURS ? '72' : '');
self::assertSame(72, (new StudioSettings())->cancellationCutoffHours());
}
public function testCancellationCutoffClampsNegativeToZero(): void
{
Functions\when('get_option')->alias(static fn (string $name) =>
$name === StudioSettings::OPT_CANCELLATION_CUTOFF_HOURS ? '-5' : '');
self::assertSame(0, (new StudioSettings())->cancellationCutoffHours());
}
public function testOpenRegistrationEnabledWhenStored(): void
{
Functions\when('get_option')->alias(static fn (string $name) =>