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