. */ declare(strict_types=1); namespace Fisharebest\Webtrees; use Fisharebest\Webtrees\Contracts\UserInterface; use Fisharebest\Webtrees\Services\GedcomImportService; use Fisharebest\Webtrees\Services\TreeService; /** * Test the TreeUser class */ class TreeUserTest extends TestCase { protected static bool $uses_database = true; /** * @covers \Fisharebest\Webtrees\TreeUser::__construct * @covers \Fisharebest\Webtrees\TreeUser::id * @covers \Fisharebest\Webtrees\TreeUser::email * @covers \Fisharebest\Webtrees\TreeUser::realName * @covers \Fisharebest\Webtrees\TreeUser::userName */ public function testConstructor(): void { $gedcom_import_service = new GedcomImportService(); $tree_service = new TreeService($gedcom_import_service); $tree = $tree_service->create('name', 'title'); $user = new TreeUser($tree); self::assertInstanceOf(UserInterface::class, $user); self::assertSame(0, $user->id()); self::assertSame('', $user->email()); self::assertSame('title', $user->realName()); self::assertSame('', $user->userName()); } /** * @covers \Fisharebest\Webtrees\TreeUser::getPreference * @covers \Fisharebest\Webtrees\TreeUser::setPreference */ public function testPreferences(): void { $gedcom_import_service = new GedcomImportService(); $tree_service = new TreeService($gedcom_import_service); $tree = $tree_service->create('name', 'title'); $user = new TreeUser($tree); self::assertSame('', $user->getPreference('foo')); self::assertSame('', $user->getPreference('foo')); self::assertSame('bar', $user->getPreference('foo', 'bar')); // Tree users do not have preferences $user->setPreference('foo', 'bar'); self::assertSame('', $user->getPreference('foo')); } }