A parent registers once and manages lessons for one or more children, who need no login of their own. A child is a real wp_users row with the student role but no usable login — so student_id keeps meaning "a WordPress user" on every table, and booking, credits, policies and enrolments work unchanged. A us_guardians link table maps guardian to child. The signup form gains a parent/guardian tick that reveals a block per child, with the account-signup questions asked per child rather than per guardian — they describe the student, not the account holder. Signup policies are recorded once per child with the guardian as the acceptor, which is the record that actually means something. A family that half-creates is rolled back entirely rather than leaving a guardian who cannot re-register. The booking and enrolment forms gain a "Who is this for?" picker listing children first, so the default selection is never the parent — booking for the wrong child is correctable, quietly billing a parent for their kid's lesson is not. POST /bookings and POST /enrollments take an optional student_id honoured only for that child's guardian; anything else is a 403. That check is the authorisation boundary of the feature. Payments and credits gain a payer: the charge names the child it was for and the guardian who owes it, so per-child reporting is unchanged while notices, receipts and the payment step reach the parent. Credit is held by the payer, so one child's cancellation can settle a sibling's charge, and the daily billing scan sends a guardian one notice covering every child. Closes #132 Co-Authored-By: Claude Opus 5 <[email protected]>
77 lines
2.5 KiB
PHP
77 lines
2.5 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Unsupervised\Schedular\Tests\Unit\GroupClass;
|
|
|
|
use Brain\Monkey\Functions;
|
|
use Mockery;
|
|
use Unsupervised\Schedular\GroupClass\GroupClassPage;
|
|
use Unsupervised\Schedular\Guardian\GuardianService;
|
|
use Unsupervised\Schedular\Tests\Unit\TestCase;
|
|
|
|
class GroupClassPageTest extends TestCase
|
|
{
|
|
private GroupClassPage $page;
|
|
private GuardianService&Mockery\MockInterface $guardians;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->guardians = Mockery::mock(GuardianService::class);
|
|
$this->guardians->shouldReceive('bookableStudents')->andReturn(
|
|
[['id' => 3, 'name' => 'Ada', 'is_self' => true]]
|
|
)->byDefault();
|
|
|
|
$this->page = new GroupClassPage($this->guardians);
|
|
|
|
Functions\when('is_user_logged_in')->justReturn(true);
|
|
Functions\when('get_current_user_id')->justReturn(3);
|
|
Functions\when('current_user_can')->justReturn(true);
|
|
Functions\when('wp_enqueue_style')->justReturn(null);
|
|
Functions\when('wp_enqueue_script')->justReturn(null);
|
|
Functions\when('absint')->alias(static fn ($value) => abs((int) $value));
|
|
}
|
|
|
|
public function testDefaultRenderHasNoOfferingRestriction(): void
|
|
{
|
|
$html = $this->page->render([]);
|
|
|
|
self::assertStringContainsString('id="us-group-app"', $html);
|
|
self::assertStringNotContainsString('data-offering', $html);
|
|
}
|
|
|
|
public function testShortcodeOfferingAttributePinsASingleClass(): void
|
|
{
|
|
$html = $this->page->render(['offering' => '12']);
|
|
|
|
self::assertStringContainsString('data-offering="12"', $html);
|
|
}
|
|
|
|
public function testBlockOfferingIdAttributePinsASingleClass(): void
|
|
{
|
|
$html = $this->page->render(['offeringId' => 7]);
|
|
|
|
self::assertStringContainsString('data-offering="7"', $html);
|
|
}
|
|
|
|
public function testGarbageOfferingAttributeIsIgnored(): void
|
|
{
|
|
$html = $this->page->render(['offering' => 'banana']);
|
|
|
|
self::assertStringNotContainsString('data-offering', $html);
|
|
}
|
|
|
|
public function testLoggedOutVisitorGetsLoginPrompt(): void
|
|
{
|
|
Functions\when('is_user_logged_in')->justReturn(false);
|
|
Functions\when('get_permalink')->justReturn('http://example.com/classes/');
|
|
Functions\when('wp_login_url')->justReturn('http://example.com/wp-login.php');
|
|
|
|
$html = $this->page->render([]);
|
|
|
|
self::assertStringContainsString('log in to enrol in a class', $html);
|
|
self::assertStringNotContainsString('us-group-app', $html);
|
|
}
|
|
}
|