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