1e5a6b4d4SGreg Roach<?php 23976b470SGreg Roach 3e5a6b4d4SGreg Roach/** 4e5a6b4d4SGreg Roach * webtrees: online genealogy 5*5e933c21SGreg Roach * Copyright (C) 2020 webtrees development team 6e5a6b4d4SGreg Roach * This program is free software: you can redistribute it and/or modify 7e5a6b4d4SGreg Roach * it under the terms of the GNU General Public License as published by 8e5a6b4d4SGreg Roach * the Free Software Foundation, either version 3 of the License, or 9e5a6b4d4SGreg Roach * (at your option) any later version. 10e5a6b4d4SGreg Roach * This program is distributed in the hope that it will be useful, 11e5a6b4d4SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12e5a6b4d4SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13e5a6b4d4SGreg Roach * GNU General Public License for more details. 14e5a6b4d4SGreg Roach * You should have received a copy of the GNU General Public License 15e5a6b4d4SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 16e5a6b4d4SGreg Roach */ 17fcfa147eSGreg Roach 18e5a6b4d4SGreg Roachdeclare(strict_types=1); 19e5a6b4d4SGreg Roach 20e5a6b4d4SGreg Roachnamespace Fisharebest\Webtrees; 21e5a6b4d4SGreg Roach 22e5a6b4d4SGreg Roachuse Fisharebest\Webtrees\Contracts\UserInterface; 23e5a6b4d4SGreg Roach 24e5a6b4d4SGreg Roach/** 25e5a6b4d4SGreg Roach * Test the GuestUser class 26e5a6b4d4SGreg Roach */ 27e5a6b4d4SGreg Roachclass GuestUserTest extends TestCase 28e5a6b4d4SGreg Roach{ 29e5a6b4d4SGreg Roach /** 30e5a6b4d4SGreg Roach * @covers \Fisharebest\Webtrees\GuestUser::__construct 31e5a6b4d4SGreg Roach * @covers \Fisharebest\Webtrees\GuestUser::id 32e5a6b4d4SGreg Roach * @covers \Fisharebest\Webtrees\GuestUser::email 33e5a6b4d4SGreg Roach * @covers \Fisharebest\Webtrees\GuestUser::realName 34e5a6b4d4SGreg Roach * @covers \Fisharebest\Webtrees\GuestUser::userName 35e5a6b4d4SGreg Roach * @return void 36e5a6b4d4SGreg Roach */ 37e5a6b4d4SGreg Roach public function testAnonymous(): void 38e5a6b4d4SGreg Roach { 39e5a6b4d4SGreg Roach $user = new GuestUser(); 40e5a6b4d4SGreg Roach 41*5e933c21SGreg Roach self::assertInstanceOf(UserInterface::class, $user); 42*5e933c21SGreg Roach self::assertSame(0, $user->id()); 43*5e933c21SGreg Roach self::assertSame('GUEST_USER', $user->email()); 44*5e933c21SGreg Roach self::assertSame('GUEST_USER', $user->realName()); 45*5e933c21SGreg Roach self::assertSame('', $user->userName()); 46e5a6b4d4SGreg Roach } 47e5a6b4d4SGreg Roach 48e5a6b4d4SGreg Roach /** 49e5a6b4d4SGreg Roach * @covers \Fisharebest\Webtrees\GuestUser::__construct 50e5a6b4d4SGreg Roach * @covers \Fisharebest\Webtrees\GuestUser::id 51e5a6b4d4SGreg Roach * @covers \Fisharebest\Webtrees\GuestUser::email 52e5a6b4d4SGreg Roach * @covers \Fisharebest\Webtrees\GuestUser::realName 53e5a6b4d4SGreg Roach * @covers \Fisharebest\Webtrees\GuestUser::userName 54e5a6b4d4SGreg Roach * @return void 55e5a6b4d4SGreg Roach */ 56e5a6b4d4SGreg Roach public function testVisitor(): void 57e5a6b4d4SGreg Roach { 58e5a6b4d4SGreg Roach $user = new GuestUser('guest@example.com', 'guest user'); 59e5a6b4d4SGreg Roach 60*5e933c21SGreg Roach self::assertInstanceOf(UserInterface::class, $user); 61*5e933c21SGreg Roach self::assertSame(0, $user->id()); 62*5e933c21SGreg Roach self::assertSame('guest@example.com', $user->email()); 63*5e933c21SGreg Roach self::assertSame('guest user', $user->realName()); 64*5e933c21SGreg Roach self::assertSame('', $user->userName()); 65e5a6b4d4SGreg Roach } 66e5a6b4d4SGreg Roach 67e5a6b4d4SGreg Roach /** 68e5a6b4d4SGreg Roach * @covers \Fisharebest\Webtrees\GuestUser::getPreference 69e5a6b4d4SGreg Roach * @covers \Fisharebest\Webtrees\GuestUser::setPreference 70e5a6b4d4SGreg Roach * @return void 71e5a6b4d4SGreg Roach */ 72e5a6b4d4SGreg Roach public function testPreferences(): void 73e5a6b4d4SGreg Roach { 74e5a6b4d4SGreg Roach $user = new GuestUser(); 75e5a6b4d4SGreg Roach 76*5e933c21SGreg Roach self::assertSame('', $user->getPreference('foo')); 77*5e933c21SGreg Roach self::assertSame('', $user->getPreference('foo')); 78*5e933c21SGreg Roach self::assertSame('bar', $user->getPreference('foo', 'bar')); 79e5a6b4d4SGreg Roach 80e5a6b4d4SGreg Roach // Guests users store preferences in the session 81e5a6b4d4SGreg Roach $user->setPreference('foo', 'bar'); 82e5a6b4d4SGreg Roach 83*5e933c21SGreg Roach self::assertSame('bar', $user->getPreference('foo')); 84e5a6b4d4SGreg Roach } 85e5a6b4d4SGreg Roach} 86