. */ 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 * @return void */ public function testAnonymous(): void { $user = new GuestUser(); $this->assertInstanceOf(UserInterface::class, $user); $this->assertSame(0, $user->id()); $this->assertSame('GUEST_USER', $user->email()); $this->assertSame('GUEST_USER', $user->realName()); $this->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 * @return void */ public function testVisitor(): void { $user = new GuestUser('guest@example.com', 'guest user'); $this->assertInstanceOf(UserInterface::class, $user); $this->assertSame(0, $user->id()); $this->assertSame('guest@example.com', $user->email()); $this->assertSame('guest user', $user->realName()); $this->assertSame('', $user->userName()); } /** * @covers \Fisharebest\Webtrees\GuestUser::getPreference * @covers \Fisharebest\Webtrees\GuestUser::setPreference * @return void */ public function testPreferences(): void { $user = new GuestUser(); $this->assertSame('', $user->getPreference('foo')); $this->assertSame('', $user->getPreference('foo', '')); $this->assertSame('bar', $user->getPreference('foo', 'bar')); // Guests users store preferences in the session $user->setPreference('foo', 'bar'); $this->assertSame('bar', $user->getPreference('foo')); } }