Let the account holder edit their own profile details
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
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
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]>
This commit is contained in:
@@ -321,6 +321,87 @@ class GuardianServiceTest extends TestCase
|
||||
self::assertSame('2015', $this->meta[42][GuardianService::META_BIRTH_YEAR]);
|
||||
}
|
||||
|
||||
public function testUpdateSelfRenamesAndStoresTheBirthYear(): void
|
||||
{
|
||||
$this->meta[5][GuardianService::META_GUARDIAN_ONLY] = '1';
|
||||
|
||||
Functions\expect('wp_update_user')
|
||||
->once()
|
||||
->with(['ID' => 5, 'display_name' => 'Grace H', 'nickname' => 'Grace H'])
|
||||
->andReturn(5);
|
||||
|
||||
self::assertNull($this->service->updateSelf(5, 'Grace H', '1984', true));
|
||||
|
||||
self::assertSame('1984', $this->meta[5][GuardianService::META_BIRTH_YEAR]);
|
||||
// Saying they take lessons makes them a bookable student again.
|
||||
self::assertFalse(GuardianService::isGuardianOnly(5));
|
||||
}
|
||||
|
||||
public function testUpdateSelfMarksTheAccountGuardianOnly(): void
|
||||
{
|
||||
Functions\when('wp_update_user')->justReturn(5);
|
||||
|
||||
self::assertNull($this->service->updateSelf(5, 'Grace H', '', false));
|
||||
|
||||
self::assertSame('1', $this->meta[5][GuardianService::META_GUARDIAN_ONLY]);
|
||||
}
|
||||
|
||||
/**
|
||||
* "I only book for other people" says who books, not "forget my birth year" —
|
||||
* ticking the box back on should not have cost them what was on file.
|
||||
*/
|
||||
public function testUpdateSelfKeepsAStoredBirthYearWhenTheyAreNoLongerAStudent(): void
|
||||
{
|
||||
$this->meta[5][GuardianService::META_BIRTH_YEAR] = '1984';
|
||||
|
||||
Functions\when('wp_update_user')->justReturn(5);
|
||||
|
||||
self::assertNull($this->service->updateSelf(5, 'Grace H', '', false));
|
||||
|
||||
self::assertSame('1984', $this->meta[5][GuardianService::META_BIRTH_YEAR]);
|
||||
}
|
||||
|
||||
public function testUpdateSelfRejectsABlankName(): void
|
||||
{
|
||||
Functions\expect('wp_update_user')->never();
|
||||
|
||||
self::assertInstanceOf(\WP_Error::class, $this->service->updateSelf(5, ' ', '1984', true));
|
||||
}
|
||||
|
||||
/**
|
||||
* The browser cannot enforce the year conditionally, so the server is the
|
||||
* only thing standing between a student and a nonsense age on their record.
|
||||
*
|
||||
* @dataProvider unusableBirthYears
|
||||
*/
|
||||
public function testUpdateSelfRefusesAnUnusableBirthYearFromAStudent(string $submitted): void
|
||||
{
|
||||
Functions\expect('wp_update_user')->never();
|
||||
|
||||
self::assertInstanceOf(\WP_Error::class, $this->service->updateSelf(5, 'Grace H', $submitted, true));
|
||||
}
|
||||
|
||||
public function testAccountHolderReportsTheirOwnDetails(): void
|
||||
{
|
||||
$this->meta[5][GuardianService::META_BIRTH_YEAR] = '1984';
|
||||
|
||||
Functions\when('get_userdata')->justReturn($this->user(5, 'Grace', 'Hopper', email: '[email protected]'));
|
||||
|
||||
self::assertSame(
|
||||
['name' => 'Grace Hopper', 'email' => '[email protected]', 'birth_year' => '1984', 'is_student' => true],
|
||||
$this->service->accountHolder(5)
|
||||
);
|
||||
}
|
||||
|
||||
public function testAccountHolderReportsAGuardianOnlyAccountAsNotAStudent(): void
|
||||
{
|
||||
$this->meta[5][GuardianService::META_GUARDIAN_ONLY] = '1';
|
||||
|
||||
Functions\when('get_userdata')->justReturn($this->user(5, 'Grace', 'Hopper', email: '[email protected]'));
|
||||
|
||||
self::assertFalse($this->service->accountHolder(5)['is_student']);
|
||||
}
|
||||
|
||||
public function testRemoveChildUnlinksAndDeletesAChildWithNoHistory(): void
|
||||
{
|
||||
$this->guardians->shouldReceive('isGuardianOf')->with(5, 42)->andReturn(true);
|
||||
|
||||
Reference in New Issue
Block a user