Let the studio register the students who cannot register themselves
CI / No Debug Code (pull_request) Successful in 4s
CI / Tests (PHP 8.2) (pull_request) Successful in 50s
CI / Tests (PHP 8.1) (pull_request) Successful in 1m3s
CI / Tests (PHP 8.5) (pull_request) Successful in 2m48s
CI / Tests (PHP 8.3) (pull_request) Successful in 3m24s
CI / Coding Standards & Static Analysis (pull_request) Successful in 8m21s
CI / Build Plugin Zip (pull_request) Skipped
CI / No Debug Code (pull_request) Successful in 4s
CI / Tests (PHP 8.2) (pull_request) Successful in 50s
CI / Tests (PHP 8.1) (pull_request) Successful in 1m3s
CI / Tests (PHP 8.5) (pull_request) Successful in 2m48s
CI / Tests (PHP 8.3) (pull_request) Successful in 3m24s
CI / Coding Standards & Static Analysis (pull_request) Successful in 8m21s
CI / Build Plugin Zip (pull_request) Skipped
The Book a lesson for a student panel built its picker from the us_student role but vetted the submission with the book_lesson capability. ChildLoginGate and RegistrationLoginGate withhold that capability from accounts that keep the role, so the panel offered every guardian-managed child and every unapproved signup and then refused them — with a message claiming no student had been chosen, and a form cleared of all five fields. Withholding book_lesson stops those accounts registering in their own name. It was never meant to stop the studio acting for them, which is what the panel is for, and for a child is the only route to a lesson besides their guardian. Guard the student role instead, via a new RoleManager::isStudent() shared with every picker and guard on the staff side so the two cannot drift apart again. Group enrolment gets the same predicate: addDirect() and grantAccess() vetted their posted ids not at all, and would enrol an instructor, an administrator, or an account deleted since the page was drawn — raising a real payment against them for a priced class. Keep a refused booking's fields as submitted, reading the form through one LessonController::submittedBooking() so what gets booked and what is shown again cannot disagree about a field name. A booking that succeeds still leaves an empty form, so the next one does not inherit it. Closes #185 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01XunBYk2sFEc1oL14sUiuBU
This commit is contained in:
@@ -316,6 +316,54 @@ class LessonControllerTest extends TestCase
|
||||
self::assertStringContainsString('name="usc_action" value="book_for_student"', $html);
|
||||
}
|
||||
|
||||
/**
|
||||
* A refusal used to clear all five fields, so one mistake meant retyping the
|
||||
* whole form — and the panel is only ever reopened *because* something was
|
||||
* refused.
|
||||
*/
|
||||
public function testARefusedBookingComesBackWithEveryFieldStillFilledIn(): void
|
||||
{
|
||||
$this->postBooking();
|
||||
$this->offerPanel();
|
||||
|
||||
$this->adminBooking->shouldReceive('book')->once()->andReturn(
|
||||
new \WP_Error('slot_taken', 'That time has already been booked.')
|
||||
);
|
||||
$this->bookings->shouldReceive('findAllUpcoming')->once()->andReturn([]);
|
||||
|
||||
$html = $this->render();
|
||||
|
||||
self::assertStringContainsString('That time has already been booked.', $html);
|
||||
// Attribute spacing in the template is not what is under test here.
|
||||
$tags = (string) preg_replace('/\s+/', ' ', $html);
|
||||
|
||||
// The panel is reopened, showing the student, time and lesson type as posted.
|
||||
self::assertStringContainsString(' open>', $html);
|
||||
self::assertStringContainsString('value="42" selected=\'selected\'', $tags);
|
||||
self::assertStringContainsString('value="7" selected=\'selected\'', $tags);
|
||||
self::assertStringContainsString('value="3" selected=\'selected\'', $tags);
|
||||
// Both ticks and the note survive too.
|
||||
self::assertSame(2, substr_count($html, "checked='checked'"));
|
||||
self::assertStringContainsString('value="Make-up lesson"', $html);
|
||||
}
|
||||
|
||||
public function testASuccessfulBookingLeavesAnEmptyFormForTheNextOne(): void
|
||||
{
|
||||
$this->postBooking();
|
||||
$this->offerPanel();
|
||||
|
||||
$this->adminBooking->shouldReceive('book')->once()->andReturn('Booked.');
|
||||
$this->bookings->shouldReceive('findAllUpcoming')->once()->andReturn([]);
|
||||
|
||||
$html = $this->render();
|
||||
|
||||
self::assertStringContainsString('Booked.', $html);
|
||||
// Nothing carried over, or the next booking silently inherits this one's.
|
||||
self::assertStringNotContainsString("selected='selected'", $html);
|
||||
self::assertStringNotContainsString("checked='checked'", $html);
|
||||
self::assertStringContainsString('value=""', $html);
|
||||
}
|
||||
|
||||
public function testTheStudioSchedulerBooksAgainstAnyInstructorsTime(): void
|
||||
{
|
||||
$this->postBooking();
|
||||
@@ -390,6 +438,16 @@ class LessonControllerTest extends TestCase
|
||||
Functions\when('absint')->alias(static fn ($v): int => abs((int) $v));
|
||||
}
|
||||
|
||||
/** The panel with one of each choice, so a re-selected value has somewhere to land. */
|
||||
private function offerPanel(): void
|
||||
{
|
||||
$this->adminBooking->shouldReceive('formData')->once()->andReturn([
|
||||
'students' => [['id' => 42, 'name' => 'Ada Lovelace']],
|
||||
'offerings' => [['id' => 3, 'label' => '30 min piano (30 min)']],
|
||||
'slots' => [['id' => 7, 'label' => 'Wed Jul 1, 2026 10:00 AM (30 min)', 'weekly' => false]],
|
||||
]);
|
||||
}
|
||||
|
||||
public function testAStaffBookedLessonOffersTheRecordIntakeForm(): void
|
||||
{
|
||||
$_GET['lesson_id'] = '1';
|
||||
|
||||
Reference in New Issue
Block a user