. */ declare(strict_types=1); namespace Fisharebest\Webtrees; use Fisharebest\Webtrees\Contracts\UserInterface; /** * Test the GuestUser class */ class GuestUserTest extends TestCase { /** * @covers \Fisharebest\Webtrees\GuestUser::__construct * @covers \Fisharebest\Webtrees\GuestUser::id * @covers \Fisharebest\Webtrees\GuestUser::email * @covers \Fisharebest\Webtrees\GuestUser::realName * @covers \Fisharebest\Webtrees\GuestUser::userName */ 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()); } /** * @covers \Fisharebest\Webtrees\GuestUser::__construct * @covers \Fisharebest\Webtrees\GuestUser::id * @covers \Fisharebest\Webtrees\GuestUser::email * @covers \Fisharebest\Webtrees\GuestUser::realName * @covers \Fisharebest\Webtrees\GuestUser::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()); } /** * @covers \Fisharebest\Webtrees\GuestUser::getPreference * @covers \Fisharebest\Webtrees\GuestUser::setPreference */ 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')); } }