CI / Tests (PHP 8.2) (pull_request) Successful in 46s
CI / Tests (PHP 8.1) (pull_request) Successful in 46s
CI / No Debug Code (pull_request) Successful in 2s
CI / PHPStan (pull_request) Successful in 2m47s
CI / Coding Standards (pull_request) Successful in 2m51s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m41s
CI / Build Plugin Zip (pull_request) Skipped
Add Auth\UserName::format(), which prefers a user's first + last name, then their nickname, avoiding display_name (which can be the login/username). Route the instructor name through it in both the front-end offerings response (instructor_name) and the back-end group-class summary and details views. Tests: composer test (513), composer lint, composer cs all pass. Co-Authored-By: Claude Opus 4.8 <[email protected]>
48 lines
1.3 KiB
PHP
48 lines
1.3 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Unsupervised\Schedular\Tests\Unit\Auth;
|
|
|
|
use Mockery;
|
|
use Unsupervised\Schedular\Auth\UserName;
|
|
use Unsupervised\Schedular\Tests\Unit\TestCase;
|
|
|
|
class UserNameTest extends TestCase
|
|
{
|
|
private function user(string $first, string $last, string $nickname): \WP_User
|
|
{
|
|
$user = Mockery::mock(\WP_User::class);
|
|
$user->first_name = $first;
|
|
$user->last_name = $last;
|
|
$user->nickname = $nickname;
|
|
|
|
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')));
|
|
}
|
|
|
|
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));
|
|
}
|
|
}
|