Ask some registration questions of students only
CI / Tests (PHP 8.2) (pull_request) Successful in 58s
CI / Tests (PHP 8.1) (pull_request) Successful in 58s
CI / No Debug Code (pull_request) Successful in 3s
CI / Coding Standards (pull_request) Successful in 2m53s
CI / PHPStan (pull_request) Successful in 3m0s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m42s
CI / Build Plugin Zip (pull_request) Skipped
CI / Tests (PHP 8.2) (pull_request) Successful in 58s
CI / Tests (PHP 8.1) (pull_request) Successful in 58s
CI / No Debug Code (pull_request) Successful in 3s
CI / Coding Standards (pull_request) Successful in 2m53s
CI / PHPStan (pull_request) Successful in 3m0s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m42s
CI / Build Plugin Zip (pull_request) Skipped
Every account-signup question was asked of everybody who registered, on the same terms: "school and grade" had to be put to an adult signing themselves up, and a question a studio needed answered for each student could only be made required by demanding it of everyone. A question now carries an audience — everyone, or only the students someone registers on behalf of — and its own required flag for each side, so optional for you and required for every student you enrol is expressible. Both settings are account-scope only: an offering asks its questions once, about the student being booked, so there is no second audience to differ from, and an offering question mirrors its single "required" into both columns. Every caller reads askedOfSelf()/isRequiredForSelf()/isRequiredForChild() rather than the raw flags, so a students-only question can neither block the account holder nor have an answer filed against them by a crafted post. The family screen, which only ever adds a student, is held to the students' rule. is_required_child arrives from dbDelta defaulting to 0, which would quietly stop every existing required question being required of the students a guardian registers — the case it most likely existed for. A one-time backfill copies is_required across, guarded by its own option so a question later made optional for students stays that way. Closes #163 Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
@@ -76,9 +76,21 @@ class FamilyPageTest extends TestCase
|
||||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* A question required of everyone, or of nobody — the shape every question
|
||||
* had before the account holder and the students could differ, and the shape
|
||||
* the upgrade backfill leaves them in.
|
||||
*/
|
||||
private function question(int $id, bool $required): Question
|
||||
{
|
||||
return new Question(offeringId: null, label: 'Instrument', isRequired: $required, scope: Question::SCOPE_ACCOUNT, id: $id);
|
||||
return new Question(
|
||||
offeringId: null,
|
||||
label: 'Instrument',
|
||||
isRequired: $required,
|
||||
scope: Question::SCOPE_ACCOUNT,
|
||||
isRequiredChild: $required,
|
||||
id: $id
|
||||
);
|
||||
}
|
||||
|
||||
public function testLoggedOutVisitorIsOfferedALoginLink(): void
|
||||
@@ -158,6 +170,71 @@ class FamilyPageTest extends TestCase
|
||||
self::assertNull($captured);
|
||||
}
|
||||
|
||||
/**
|
||||
* This screen only ever adds a student, so the students' required-ness is the
|
||||
* one that applies: a question required of the account holder alone must not
|
||||
* stop a guardian adding a child.
|
||||
*/
|
||||
public function testAddIsNotBlockedByAQuestionRequiredOnlyOfTheAccountHolder(): void
|
||||
{
|
||||
$_POST = [
|
||||
'us_family_action' => 'add',
|
||||
'child_name' => 'Ada',
|
||||
'child_birth_year' => '2015',
|
||||
'us_answers' => [7 => ' '],
|
||||
];
|
||||
|
||||
$question = new Question(
|
||||
offeringId: null,
|
||||
label: 'Instrument',
|
||||
isRequired: true,
|
||||
scope: Question::SCOPE_ACCOUNT,
|
||||
isRequiredChild: false,
|
||||
id: 7
|
||||
);
|
||||
|
||||
$this->questions->shouldReceive('findByScope')->once()->andReturn([$question]);
|
||||
$this->guardians->shouldReceive('createChild')->once()->andReturn(42);
|
||||
|
||||
// Nothing was typed, so nothing is stored — but the add went through.
|
||||
$this->answers->shouldNotReceive('insert');
|
||||
|
||||
$captured = null;
|
||||
$this->capturingPage($captured)->maybeHandleSubmit();
|
||||
|
||||
self::assertSame('https://studio.test/family/?us_family=added', $captured);
|
||||
}
|
||||
|
||||
public function testAddIsBlockedByAQuestionRequiredOnlyOfTheStudents(): void
|
||||
{
|
||||
$_POST = [
|
||||
'us_family_action' => 'add',
|
||||
'child_name' => 'Ada',
|
||||
'child_birth_year' => '2015',
|
||||
'us_answers' => [7 => ''],
|
||||
];
|
||||
|
||||
$question = new Question(
|
||||
offeringId: null,
|
||||
label: 'Instrument',
|
||||
isRequired: false,
|
||||
scope: Question::SCOPE_ACCOUNT,
|
||||
isRequiredChild: true,
|
||||
id: 7
|
||||
);
|
||||
|
||||
$this->questions->shouldReceive('findByScope')->once()->andReturn([$question]);
|
||||
$this->guardians->shouldNotReceive('createChild');
|
||||
|
||||
$captured = null;
|
||||
$page = $this->capturingPage($captured);
|
||||
$page->shouldNotReceive('redirect');
|
||||
|
||||
$page->maybeHandleSubmit();
|
||||
|
||||
self::assertNull($captured);
|
||||
}
|
||||
|
||||
public function testAddSurfacesAServiceErrorInsteadOfRedirecting(): void
|
||||
{
|
||||
$_POST = ['us_family_action' => 'add', 'child_name' => ''];
|
||||
|
||||
Reference in New Issue
Block a user