xref: /webtrees/tests/app/TreeTest.php (revision 000dd58ceb4b73efd5343597ffb20d49cbfbb092)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2019 webtrees development team
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16declare(strict_types=1);
17
18namespace Fisharebest\Webtrees;
19
20/**
21 * Test harness for the class Tree
22 */
23class TreeTest extends \Fisharebest\Webtrees\TestCase
24{
25    protected static $uses_database = true;
26
27    /**
28     * @covers \Fisharebest\Webtrees\Tree::__construct
29     * @covers \Fisharebest\Webtrees\Tree::create
30     * @covers \Fisharebest\Webtrees\Tree::id
31     * @covers \Fisharebest\Webtrees\Tree::name
32     * @covers \Fisharebest\Webtrees\Tree::title
33     *
34     * @return void
35     */
36    public function testConstructor(): void
37    {
38        $tree = Tree::create('tree-name', 'Tree title');
39
40        $this->assertSame(1, $tree->id());
41        $this->assertSame('tree-name', $tree->name());
42        $this->assertSame('Tree title', $tree->title());
43    }
44
45    /**
46     * @covers \Fisharebest\Webtrees\Tree::getPreference
47     * @covers \Fisharebest\Webtrees\Tree::setPreference
48     *
49     * @return void
50     */
51    public function testTreePreferences(): void
52    {
53        $tree = Tree::create('tree-name', 'Tree title');
54
55        $pref = $tree->getPreference('foo', 'default');
56        $this->assertSame('default', $pref);
57
58        $tree->setPreference('foo', 'bar');
59        $pref = $tree->getPreference('foo', 'default');
60        $this->assertSame('bar', $pref);
61    }
62
63    /**
64     * @covers \Fisharebest\Webtrees\Tree::getUserPreference
65     * @covers \Fisharebest\Webtrees\Tree::setUserPreference
66     *
67     * @return void
68     */
69    public function testUserTreePreferences(): void
70    {
71        $tree = Tree::create('tree-name', 'Tree title');
72        $user = User::create('user', 'User', 'user@example.com', 'secret');
73
74        $pref = $tree->getUserPreference($user, 'foo', 'default');
75        $this->assertSame('default', $pref);
76
77        $tree->setUserPreference($user, 'foo', 'bar');
78        $pref = $tree->getUserPreference($user, 'foo', 'default');
79        $this->assertSame('bar', $pref);
80    }
81}
82