1e5a6b4d4SGreg Roach<?php 23976b470SGreg Roach 3e5a6b4d4SGreg Roach/** 4e5a6b4d4SGreg Roach * webtrees: online genealogy 5*d11be702SGreg Roach * Copyright (C) 2023 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 1589f7189bSGreg Roach * along with this program. If not, see <https://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; 232c685d76SGreg Roachuse Fisharebest\Webtrees\Services\GedcomImportService; 241e653452SGreg Roachuse Fisharebest\Webtrees\Services\TreeService; 25e5a6b4d4SGreg Roach 26e5a6b4d4SGreg Roach/** 27e5a6b4d4SGreg Roach * Test the TreeUser class 28e5a6b4d4SGreg Roach */ 29e5a6b4d4SGreg Roachclass TreeUserTest extends TestCase 30e5a6b4d4SGreg Roach{ 31cd94ca66SGreg Roach protected static bool $uses_database = true; 32e5a6b4d4SGreg Roach 33e5a6b4d4SGreg Roach /** 34e5a6b4d4SGreg Roach * @covers \Fisharebest\Webtrees\TreeUser::__construct 35e5a6b4d4SGreg Roach * @covers \Fisharebest\Webtrees\TreeUser::id 36e5a6b4d4SGreg Roach * @covers \Fisharebest\Webtrees\TreeUser::email 37e5a6b4d4SGreg Roach * @covers \Fisharebest\Webtrees\TreeUser::realName 38e5a6b4d4SGreg Roach * @covers \Fisharebest\Webtrees\TreeUser::userName 39e5a6b4d4SGreg Roach * @return void 40e5a6b4d4SGreg Roach */ 41e5a6b4d4SGreg Roach public function testConstructor(): void 42e5a6b4d4SGreg Roach { 432c685d76SGreg Roach $gedcom_import_service = new GedcomImportService(); 442c685d76SGreg Roach $tree_service = new TreeService($gedcom_import_service); 451e653452SGreg Roach $tree = $tree_service->create('name', 'title'); 46e5a6b4d4SGreg Roach $user = new TreeUser($tree); 47e5a6b4d4SGreg Roach 485e933c21SGreg Roach self::assertInstanceOf(UserInterface::class, $user); 495e933c21SGreg Roach self::assertSame(0, $user->id()); 505e933c21SGreg Roach self::assertSame('', $user->email()); 515e933c21SGreg Roach self::assertSame('title', $user->realName()); 525e933c21SGreg Roach self::assertSame('', $user->userName()); 53e5a6b4d4SGreg Roach } 54e5a6b4d4SGreg Roach 55e5a6b4d4SGreg Roach /** 56e5a6b4d4SGreg Roach * @covers \Fisharebest\Webtrees\TreeUser::getPreference 57e5a6b4d4SGreg Roach * @covers \Fisharebest\Webtrees\TreeUser::setPreference 58e5a6b4d4SGreg Roach * @return void 59e5a6b4d4SGreg Roach */ 60e5a6b4d4SGreg Roach public function testPreferences(): void 61e5a6b4d4SGreg Roach { 622c685d76SGreg Roach $gedcom_import_service = new GedcomImportService(); 632c685d76SGreg Roach $tree_service = new TreeService($gedcom_import_service); 641e653452SGreg Roach $tree = $tree_service->create('name', 'title'); 65e5a6b4d4SGreg Roach $user = new TreeUser($tree); 66e5a6b4d4SGreg Roach 675e933c21SGreg Roach self::assertSame('', $user->getPreference('foo')); 685e933c21SGreg Roach self::assertSame('', $user->getPreference('foo')); 695e933c21SGreg Roach self::assertSame('bar', $user->getPreference('foo', 'bar')); 70e5a6b4d4SGreg Roach 71e5a6b4d4SGreg Roach // Tree users do not have preferences 72e5a6b4d4SGreg Roach $user->setPreference('foo', 'bar'); 73e5a6b4d4SGreg Roach 745e933c21SGreg Roach self::assertSame('', $user->getPreference('foo')); 75e5a6b4d4SGreg Roach } 76e5a6b4d4SGreg Roach} 77