Files
thatguygriffandClaude Opus 5 f97b8a4576
CI / Tests (PHP 8.1) (pull_request) Successful in 45s
CI / No Debug Code (pull_request) Successful in 2s
CI / Tests (PHP 8.2) (pull_request) Successful in 55s
CI / PHPStan (pull_request) Successful in 2m57s
CI / Coding Standards (pull_request) Successful in 3m3s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m42s
CI / Build Plugin Zip (pull_request) Skipped
Let the account holder edit their own profile details
The Profile block is headed "Your profile", but the one person on it you
could not change was yourself: your name, your birth year, and whether you
take lessons yourself were fixed at whatever signup recorded, and correcting
any of them meant asking a studio admin.

A "Your details" section now opens the page, saved through the same
nonce-checked template_redirect post/redirect/get path the child rows use:

- Your name, written to display_name and nickname together, for the reason
  updateChild() does — UserName reads the nickname first, and leaving it
  behind would put the account's email address back on every screen that
  names a person.
- "I take lessons myself", the positive of us_guardian_only. This makes good
  on the claim already in bookableStudents() and the feature doc that a
  guardian-only account can put itself right from the profile page.
- Your birth year, held to the same normaliseBirthYear() rule as every other
  student.

The email is shown but not editable: it is the account's user_login as well
as its address, so changing it stays a studio-side job.

The birth-year field deliberately carries no `required` attribute. It is
asked of a student only, and this page loads no JavaScript, so a
browser-enforced `required` would leave a guardian who books solely for
other people unable to submit the form at all; handleSelf() enforces it
against the checkbox instead. Unticking the box does not clear a stored
birth year — it says who books, not "forget what is on file".

Closes #165

Co-Authored-By: Claude Opus 5 <[email protected]>
2026-07-30 15:08:05 -03:00

106 lines
4.4 KiB
PHP

<?php
declare(strict_types=1);
namespace Unsupervised\Schedular\Tests\Unit;
use Brain\Monkey\Functions;
use Unsupervised\Schedular\BlockPreview;
use Unsupervised\Schedular\Booking\BookingPage;
class BlockPreviewTest extends TestCase
{
public function testBookingPreviewMirrorsTheLiveMarkup(): void
{
$html = BlockPreview::booking();
self::assertStringContainsString('id="us-booking-app"', $html);
self::assertStringContainsString('id="us-slot-list"', $html);
self::assertStringContainsString('class="us-day"', $html);
self::assertStringContainsString('class="us-slot"', $html);
self::assertStringContainsString('class="us-book-btn" disabled', $html);
self::assertStringContainsString('us-editor-note', $html);
self::assertStringContainsString('id="us-my-lessons"', $html);
}
public function testBookingOnlyPreviewLeavesOutTheUpcomingLessons(): void
{
$html = BlockPreview::booking(BookingPage::MODE_BOOKING);
self::assertStringContainsString('id="us-slot-list"', $html);
self::assertStringNotContainsString('us-my-lessons', $html);
}
public function testUpcomingOnlyPreviewLeavesOutTheCalendar(): void
{
$html = BlockPreview::booking(BookingPage::MODE_UPCOMING);
self::assertStringContainsString('id="us-my-lessons"', $html);
self::assertStringContainsString('Your upcoming lessons', $html);
self::assertStringNotContainsString('us-slot-list', $html);
self::assertStringNotContainsString('us-book-btn', $html);
}
public function testGroupClassesPreviewMirrorsTheLiveMarkup(): void
{
$html = BlockPreview::groupClasses();
self::assertStringContainsString('id="us-group-app"', $html);
self::assertStringContainsString('id="us-group-list"', $html);
self::assertStringContainsString('class="us-class"', $html);
self::assertStringContainsString('class="us-enrol-btn" disabled', $html);
self::assertStringContainsString('us-editor-note', $html);
self::assertStringContainsString('A sample class shown so the page can be styled.', $html);
}
public function testSingleClassGroupPreviewDropsTheDescriptionButKeepsScheduleAndEnrolment(): void
{
$html = BlockPreview::groupClasses(true);
self::assertStringNotContainsString('A sample class shown so the page can be styled.', $html);
self::assertStringContainsString('class="us-class-when"', $html);
self::assertStringContainsString('class="us-enrol-deadline"', $html);
self::assertStringContainsString('class="us-enrol-btn" disabled', $html);
}
public function testLoginPreviewIncludesTheRealLoginTemplate(): void
{
Functions\when('wp_nonce_field')->justReturn('');
$html = BlockPreview::login();
self::assertStringContainsString('class="us-login-form"', $html);
self::assertStringContainsString('name="log"', $html);
self::assertStringContainsString('name="pwd"', $html);
self::assertStringContainsString('us-editor-note', $html);
}
/**
* The preview is what someone placing the block styles against, so it has to
* show both halves of the page — your own details as well as your students'.
*/
public function testFamilyPreviewShowsTheAccountHoldersDetailsAndTheirStudents(): void
{
$html = BlockPreview::family();
self::assertStringContainsString('class="us-family-self"', $html);
self::assertStringContainsString('id="us-own-name"', $html);
self::assertStringContainsString('id="us-own-birth-year"', $html);
self::assertStringContainsString('I take lessons myself', $html);
self::assertStringContainsString('class="us-family-list"', $html);
self::assertStringContainsString('class="us-family-add"', $html);
self::assertStringContainsString('us-editor-note', $html);
}
public function testRegistrationPreviewShowsADisabledSampleForm(): void
{
$html = BlockPreview::registration();
self::assertStringContainsString('class="us-register-form"', $html);
self::assertStringContainsString('id="us-reg-email"', $html);
self::assertStringContainsString('id="us-reg-name"', $html);
self::assertStringContainsString('id="us-reg-pass"', $html);
self::assertStringContainsString('disabled', $html);
self::assertStringContainsString('us-editor-note', $html);
}
}