first_name = $first; $user->last_name = $last; $user->nickname = $nickname; $user->display_name = $displayName; $user->user_login = $login; $user->user_email = $email; return $user; } public function testPrefersFirstAndLastName(): void { self::assertSame('Ada Lovelace', UserName::format($this->user('Ada', 'Lovelace', 'ada_login'))); } public function testUsesFirstNameAloneWhenLastNameMissing(): void { self::assertSame('Ada', UserName::format($this->user('Ada', '', 'ada_login'))); } public function testFallsBackToNicknameWhenNoRealName(): void { 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( '', '', 'grace@example.test', 'Grace Hopper', login: 'grace@example.test', email: 'grace@example.test', ); self::assertSame('Grace Hopper', UserName::format($user, 42)); } public function testSkipsANicknameThatIsReallyTheEmailAddress(): void { $user = $this->user( '', '', 'Grace@Example.test', 'Grace Hopper', login: 'gracehopper', email: 'grace@example.test', ); // 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( '', '', 'grace@example.test', 'grace@example.test', login: 'grace@example.test', email: 'grace@example.test', ); self::assertSame('42', UserName::format($user, 42)); } public function testFallsBackToIdWhenNothingSet(): void { self::assertSame('42', UserName::format($this->user('', '', ''), 42)); } public function testReturnsFallbackIdWhenUserMissing(): void { self::assertSame('42', UserName::format(null, 42)); self::assertSame('', UserName::format(null)); } }