. */ declare(strict_types=1); namespace Fisharebest\Webtrees; /** * Test harness for the class Tree */ class TreeTest extends \Fisharebest\Webtrees\TestCase { protected static $uses_database = true; /** * @covers \Fisharebest\Webtrees\Tree::__construct * @covers \Fisharebest\Webtrees\Tree::create * @covers \Fisharebest\Webtrees\Tree::id * @covers \Fisharebest\Webtrees\Tree::name * @covers \Fisharebest\Webtrees\Tree::title * * @return void */ public function testConstructor(): void { $tree = Tree::create('tree-name', 'Tree title'); $this->assertSame(1, $tree->id()); $this->assertSame('tree-name', $tree->name()); $this->assertSame('Tree title', $tree->title()); } /** * @covers \Fisharebest\Webtrees\Tree::getPreference * @covers \Fisharebest\Webtrees\Tree::setPreference * * @return void */ public function testTreePreferences(): void { $tree = Tree::create('tree-name', 'Tree title'); $pref = $tree->getPreference('foo', 'default'); $this->assertSame('default', $pref); $tree->setPreference('foo', 'bar'); $pref = $tree->getPreference('foo', 'default'); $this->assertSame('bar', $pref); } /** * @covers \Fisharebest\Webtrees\Tree::getUserPreference * @covers \Fisharebest\Webtrees\Tree::setUserPreference * * @return void */ public function testUserTreePreferences(): void { $tree = Tree::create('tree-name', 'Tree title'); $user = User::create('user', 'User', 'user@example.com', 'secret'); $pref = $tree->getUserPreference($user, 'foo', 'default'); $this->assertSame('default', $pref); $tree->setUserPreference($user, 'foo', 'bar'); $pref = $tree->getUserPreference($user, 'foo', 'default'); $this->assertSame('bar', $pref); } }