. */ declare(strict_types=1); namespace Fisharebest\Webtrees; use Fisharebest\Webtrees\Contracts\UserInterface; use PHPUnit\Framework\Attributes\CoversClass; #[CoversClass(GuestUser::class)] class GuestUserTest extends TestCase { public function testAnonymous(): void { $user = new GuestUser(); self::assertInstanceOf(UserInterface::class, $user); self::assertSame(0, $user->id()); self::assertSame('GUEST_USER', $user->email()); self::assertSame('GUEST_USER', $user->realName()); self::assertSame('', $user->userName()); } public function testVisitor(): void { $user = new GuestUser('guest@example.com', 'guest user'); self::assertInstanceOf(UserInterface::class, $user); self::assertSame(0, $user->id()); self::assertSame('guest@example.com', $user->email()); self::assertSame('guest user', $user->realName()); self::assertSame('', $user->userName()); } public function testPreferences(): void { $user = new GuestUser(); self::assertSame('', $user->getPreference('foo')); self::assertSame('', $user->getPreference('foo')); self::assertSame('bar', $user->getPreference('foo', 'bar')); // Guests users store preferences in the session $user->setPreference('foo', 'bar'); self::assertSame('bar', $user->getPreference('foo')); } }