Let the studio book lessons and record intake collected elsewhere
CI / Tests (PHP 8.1) (pull_request) Successful in 6m39s
CI / Tests (PHP 8.2) (pull_request) Successful in 57s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m59s
CI / Tests (PHP 8.5) (pull_request) Successful in 3m31s
CI / No Debug Code (pull_request) Successful in 3s
CI / Coding Standards & Static Analysis (pull_request) Successful in 3m28s
CI / Build Plugin Zip (pull_request) Skipped

Two related gaps, closed together because the second is created by the first.

A private lesson could only be booked by the student or their guardian, so a
booking taken over the phone had no way in — where group classes have had "Add
students directly" all along. "Book a lesson for a student" is now a panel on
Scheduler and My Lessons: student, open time, lesson type, with weekly term
reservations and a no-charge option for make-up lessons. The booking core is
extracted to Booking\LessonBooker and shared with POST /bookings, so the two
paths cannot drift on offering rules, slot claiming, or billing.

That leaves a registration with no intake answers and no policy acceptances,
because nobody was at a keyboard to give them — already true of every directly
added group-class student. Ticking the boxes on a student's behalf would be an
audit trail that says something untrue, so instead the answers are collected
another way and recorded afterwards, from a lesson's or an enrolment's detail
page. Every recording must say how it was collected, which is stamped on each
row along with who typed it and shown in a new "How it was given" column: a
policy ticked online and one transcribed from paper must never look alike.

Only staff-made registrations qualify (us_lessons.booked_by,
us_group_enrollments.enrolled_by) — one the student made already holds their
own answers. Only what is still missing can be recorded, re-checked at write
time, so a stale or double-posted form cannot duplicate or overwrite. No IP is
stored for a transcription, and accepted_by stays the student while recorded_by
names the staff member.

Intake is now generic over Registration\IntakeSubject, which Lesson and
Enrollment both implement; LessonDetail became Registration\IntakeAudit and is
shared by both detail views rather than duplicated.

Closes #182

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QfHt6CyJHz6KkA4RuaS7WK
This commit is contained in:
2026-08-24 14:06:16 -03:00
co-authored by Claude Opus 5
parent 8a34ec41e9
commit 8c21a3fa9d
46 changed files with 3020 additions and 306 deletions
@@ -35,9 +35,11 @@ class EnrollmentRepositoryTest extends TestCase
return $d['offering_id'] === 7
&& $d['student_id'] === 5
&& $d['instructor_id'] === 3
&& $d['status'] === Enrollment::STATUS_ACTIVE;
&& $d['status'] === Enrollment::STATUS_ACTIVE
// Enrolled through the student-facing flow: no staff enroller.
&& $d['enrolled_by'] === 0;
}),
['%d', '%d', '%d', '%s', '%d', '%s']
['%d', '%d', '%d', '%s', '%d', '%d', '%s']
);
$this->db->insert_id = 12;
+19 -1
View File
@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Unsupervised\Schedular\Tests\Unit\GroupClass;
use Unsupervised\Schedular\GroupClass\Enrollment;
use Unsupervised\Schedular\Registration\Answer;
use Unsupervised\Schedular\Tests\Unit\TestCase;
class EnrollmentTest extends TestCase
@@ -45,8 +46,25 @@ class EnrollmentTest extends TestCase
{
$arr = (new Enrollment(7, 5, 3, id: 12))->toArray();
foreach (['id', 'offering_id', 'student_id', 'instructor_id', 'status', 'payment_id'] as $key) {
foreach (['id', 'offering_id', 'student_id', 'instructor_id', 'status', 'payment_id', 'enrolled_by'] as $key) {
self::assertArrayHasKey($key, $arr);
}
}
public function testAnEnrolmentIsItsOwnIntakeRegistration(): void
{
$enrollment = new Enrollment(7, 5, 3, id: 12);
self::assertSame(Answer::REG_ENROLLMENT, $enrollment->intakeRegistrationType());
// No series anchor to follow: a term of classes is one enrolment.
self::assertSame(12, $enrollment->intakeRegistrationId());
self::assertSame(7, $enrollment->intakeOfferingId());
self::assertSame(5, $enrollment->intakeStudentId());
}
public function testOnlyAStudioMadeEnrolmentIsStaffRegistered(): void
{
self::assertFalse((new Enrollment(7, 5, 3, id: 12))->isStaffRegistered());
self::assertTrue((new Enrollment(7, 5, 3, enrolledBy: 9, id: 12))->isStaffRegistered());
}
}
@@ -16,6 +16,8 @@ use Unsupervised\Schedular\Offering\OfferingRepository;
use Unsupervised\Schedular\Payment\Payment;
use Unsupervised\Schedular\Payment\PaymentRepository;
use Unsupervised\Schedular\Payment\PaymentService;
use Unsupervised\Schedular\Registration\IntakeAudit;
use Unsupervised\Schedular\Registration\IntakeRecording;
use Unsupervised\Schedular\Tests\Unit\TestCase;
class GroupClassControllerTest extends TestCase
@@ -27,6 +29,8 @@ class GroupClassControllerTest extends TestCase
private PaymentService&Mockery\MockInterface $paymentService;
private InviteRepository&Mockery\MockInterface $invites;
private RegistrationMailer&Mockery\MockInterface $mailer;
private IntakeAudit&Mockery\MockInterface $audit;
private IntakeRecording&Mockery\MockInterface $intake;
private GroupClassController $controller;
protected function setUp(): void
@@ -40,6 +44,8 @@ class GroupClassControllerTest extends TestCase
$this->paymentService = Mockery::mock(PaymentService::class);
$this->invites = Mockery::mock(InviteRepository::class);
$this->mailer = Mockery::mock(RegistrationMailer::class);
$this->audit = Mockery::mock(IntakeAudit::class);
$this->intake = Mockery::mock(IntakeRecording::class);
$this->controller = new GroupClassController(
$this->enrollments,
$this->offerings,
@@ -48,6 +54,8 @@ class GroupClassControllerTest extends TestCase
$this->paymentService,
$this->invites,
$this->mailer,
$this->audit,
$this->intake,
);
Functions\when('current_user_can')->justReturn(true);
@@ -411,7 +419,11 @@ class GroupClassControllerTest extends TestCase
$this->offerings->shouldReceive('findById')->with(8)->andReturn($this->inviteOnlyOffering(100.0));
$this->enrollments->shouldReceive('hasActiveEnrollment')->with(8, 5)->andReturn(false);
$this->enrollments->shouldReceive('insert')->once()->andReturn(44);
// Stamped with the staff member who added them (user 3), which is what
// later lets the studio record the intake it never had a chance to ask for.
$this->enrollments->shouldReceive('insert')->once()->with(Mockery::on(
static fn (Enrollment $e): bool => 3 === $e->enrolledBy && $e->isStaffRegistered()
))->andReturn(44);
$payment = new Payment(
studentId: 5,
@@ -435,6 +447,103 @@ class GroupClassControllerTest extends TestCase
self::assertStringContainsString('1 student(s) added to the class.', $html);
}
public function testEnrollmentIdOpensTheIntakeDetailView(): void
{
$_GET = ['enrollment_id' => '44'];
Functions\when('get_userdata')->justReturn($this->userNamed('Ada Lovelace'));
// enrolled_by 3: the studio added this student, so intake can be recorded.
$enrollment = new Enrollment(offeringId: 8, studentId: 5, instructorId: 3, enrolledBy: 3, id: 44);
$this->expectEnrollmentDetail($enrollment);
$this->intake->shouldReceive('pending')->once()->with($enrollment)->andReturn([
'questions' => [['id' => 9, 'label' => 'Anything we should know?', 'required' => false]],
'policies' => [['version_id' => 6, 'policy' => 'Cancellation', 'version' => 'v2']],
]);
$html = $this->renderInstructor();
self::assertStringContainsString('Enrolment details', $html);
self::assertStringContainsString('Ada Lovelace', $html);
self::assertStringContainsString('Record intake collected elsewhere', $html);
self::assertStringContainsString('Anything we should know?', $html);
self::assertStringContainsString('How were these collected?', $html);
}
public function testAnEnrolmentTheStudentMadeOffersNoRecordingForm(): void
{
$_GET = ['enrollment_id' => '44'];
Functions\when('get_userdata')->justReturn($this->userNamed('Ada Lovelace'));
// enrolled_by 0: the student enrolled themselves and gave their own answers.
$enrollment = new Enrollment(offeringId: 8, studentId: 5, instructorId: 3, id: 44);
$this->expectEnrollmentDetail($enrollment);
$this->intake->shouldNotReceive('pending');
self::assertStringNotContainsString('Record intake collected elsewhere', $this->renderInstructor());
}
public function testAnInstructorCannotOpenAnotherInstructorsEnrolment(): void
{
$_GET = ['enrollment_id' => '44'];
// Enrolment belongs to instructor 9; the current user is 3.
$this->enrollments->shouldReceive('findById')->once()->with(44)
->andReturn(new Enrollment(offeringId: 8, studentId: 5, instructorId: 9, enrolledBy: 9, id: 44));
$this->audit->shouldNotReceive('answers');
$this->intake->shouldNotReceive('pending');
$html = $this->renderInstructor();
self::assertStringContainsString('This enrolment could not be found.', $html);
self::assertStringNotContainsString('Record intake collected elsewhere', $html);
}
public function testSubmittedEnrolmentIntakeIsRecordedAndReported(): void
{
$_GET = ['enrollment_id' => '44'];
$_POST = [
'usc_action' => 'record_intake',
'answers' => ['9' => 'Nut allergy'],
'accepted_policy_version_ids' => ['6'],
'collected_via' => 'phone',
'collected_note' => 'Called the parent',
];
Functions\when('get_userdata')->justReturn($this->userNamed('Ada Lovelace'));
Functions\when('check_admin_referer')->justReturn(true);
Functions\when('sanitize_key')->alias(static fn ($v) => strtolower((string) $v));
Functions\when('sanitize_text_field')->returnArg();
Functions\when('sanitize_textarea_field')->returnArg();
Functions\when('wp_unslash')->returnArg();
$enrollment = new Enrollment(offeringId: 8, studentId: 5, instructorId: 3, enrolledBy: 3, id: 44);
$this->expectEnrollmentDetail($enrollment);
$this->intake->shouldReceive('pending')->andReturn(['questions' => [], 'policies' => []]);
$this->intake->shouldReceive('record')
->once()
->with($enrollment, [9 => 'Nut allergy'], [6], 'phone', 'Called the parent', 3)
->andReturn('Recorded 1 answer and 1 policy acceptance, collected: Over the phone');
$html = $this->renderInstructor();
self::assertStringContainsString('Recorded 1 answer and 1 policy acceptance', $html);
self::assertStringContainsString('notice-success', $html);
// The generic class-form handler must not also run and report a missing class.
self::assertStringNotContainsString('That group class was not found.', $html);
}
/** The lookups the enrolment detail view makes, with an empty audit trail. */
private function expectEnrollmentDetail(Enrollment $enrollment): void
{
$this->enrollments->shouldReceive('findById')->once()->with(44)->andReturn($enrollment);
$this->offerings->shouldReceive('findById')->with(8)->andReturn($this->offering(8, 'Choir', 10));
$this->audit->shouldReceive('answers')->with($enrollment)->andReturn([]);
$this->audit->shouldReceive('acceptances')->with($enrollment)->andReturn([]);
}
public function testGrantAccessCreatesGrantAndEmailsStudent(): void
{
$_POST = ['usc_action' => 'grant_access', 'offering_id' => 8, 'student_ids' => [5]];