Name people by their name, not their email address
CI / Tests (PHP 8.2) (pull_request) Successful in 58s
CI / Tests (PHP 8.1) (pull_request) Successful in 59s
CI / Coding Standards (pull_request) Successful in 2m51s
CI / PHPStan (pull_request) Successful in 3m1s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m42s
CI / No Debug Code (pull_request) Successful in 3s
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 59s
CI / Coding Standards (pull_request) Successful in 2m51s
CI / PHPStan (pull_request) Successful in 3m1s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m42s
CI / No Debug Code (pull_request) Successful in 3s
CI / Build Plugin Zip (pull_request) Skipped
Anywhere the plugin named a person it could show their email instead — "Managed by [email protected]" in the students table, the same under Booked by, instructor names on the class pages. WordPress defaults a new account's `nickname` to its `user_login`, and signup uses the email address as the login. So every self-registered account carried its own address as its nickname, and UserName::format() fell straight through to it. The name they typed was in `display_name` all along. Accounts created by a guardian were never affected — GuardianService::createChild() sets `nickname` outright, which is exactly why children read correctly and their parents did not. UserName::format() now walks nickname then display name, skipping either when it is really the login or the email, so existing accounts read correctly with nothing to migrate. An identifier still never reaches the screen: an account with nothing but its address on file falls back to the id, as before. Signup also sets `nickname` at insert, so new accounts are right at the source rather than relying on the fallback. Tests: composer test (866), composer lint, composer cs all pass. Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
@@ -9,12 +9,21 @@ use Unsupervised\Schedular\Tests\Unit\TestCase;
|
||||
|
||||
class UserNameTest extends TestCase
|
||||
{
|
||||
private function user(string $first, string $last, string $nickname): \WP_User
|
||||
{
|
||||
private function user(
|
||||
string $first,
|
||||
string $last,
|
||||
string $nickname,
|
||||
string $displayName = '',
|
||||
string $login = 'ada_login',
|
||||
string $email = '[email protected]',
|
||||
): \WP_User {
|
||||
$user = Mockery::mock(\WP_User::class);
|
||||
$user->first_name = $first;
|
||||
$user->last_name = $last;
|
||||
$user->nickname = $nickname;
|
||||
$user->first_name = $first;
|
||||
$user->last_name = $last;
|
||||
$user->nickname = $nickname;
|
||||
$user->display_name = $displayName;
|
||||
$user->user_login = $login;
|
||||
$user->user_email = $email;
|
||||
|
||||
return $user;
|
||||
}
|
||||
@@ -34,6 +43,60 @@ class UserNameTest extends TestCase
|
||||
self::assertSame('Countess', UserName::format($this->user('', '', 'Countess')));
|
||||
}
|
||||
|
||||
/**
|
||||
* WordPress defaults a new account's nickname to its `user_login`, and signup
|
||||
* uses the email address as the login — so a self-registered account carried
|
||||
* its own address as its nickname and every screen naming that person showed
|
||||
* the address. The name they typed was in `display_name` all along.
|
||||
*/
|
||||
public function testSkipsANicknameThatIsReallyTheLoginAndUsesTheDisplayName(): void
|
||||
{
|
||||
$user = $this->user(
|
||||
'',
|
||||
'',
|
||||
'[email protected]',
|
||||
'Grace Hopper',
|
||||
login: '[email protected]',
|
||||
email: '[email protected]',
|
||||
);
|
||||
|
||||
self::assertSame('Grace Hopper', UserName::format($user, 42));
|
||||
}
|
||||
|
||||
public function testSkipsANicknameThatIsReallyTheEmailAddress(): void
|
||||
{
|
||||
$user = $this->user(
|
||||
'',
|
||||
'',
|
||||
'[email protected]',
|
||||
'Grace Hopper',
|
||||
login: 'gracehopper',
|
||||
email: '[email protected]',
|
||||
);
|
||||
|
||||
// Case-insensitively: the address is the address however it was typed.
|
||||
self::assertSame('Grace Hopper', UserName::format($user, 42));
|
||||
}
|
||||
|
||||
/**
|
||||
* The whole point of the class: an identifier never reaches the screen, even
|
||||
* when it is the only thing on file. Someone who registered without giving a
|
||||
* name is shown as their id rather than as their email address.
|
||||
*/
|
||||
public function testNeverFallsThroughToAnIdentifier(): void
|
||||
{
|
||||
$user = $this->user(
|
||||
'',
|
||||
'',
|
||||
'[email protected]',
|
||||
'[email protected]',
|
||||
login: '[email protected]',
|
||||
email: '[email protected]',
|
||||
);
|
||||
|
||||
self::assertSame('42', UserName::format($user, 42));
|
||||
}
|
||||
|
||||
public function testFallsBackToIdWhenNothingSet(): void
|
||||
{
|
||||
self::assertSame('42', UserName::format($this->user('', '', ''), 42));
|
||||
|
||||
Reference in New Issue
Block a user