. */ 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); } /** * @covers \Fisharebest\Webtrees\Tree::createIndividual * * @return void */ public function testCreateIndividual(): void { $tree = Tree::create('tree-name', 'Tree title'); $user = User::create('user', 'User', 'user@example.com', 'secret'); $user->setPreference('canadmin', '1'); Auth::login($user); $gedcom = "0 @@ INDI\n1 SEX F\n1 NAME Foo /Bar/"; $individual1 = $tree->createIndividual($gedcom); $this->assertTrue($individual1->isPendingAddition()); $user->setPreference('auto_accept', '1'); $individual2 = $tree->createIndividual($gedcom); $this->assertFalse($individual2->isPendingAddition()); } }