xref: /webtrees/tests/app/TreeUserTest.php (revision 502cab9067673ad571ede842ac467603d7f0fe88)
1e5a6b4d4SGreg Roach<?php
2e5a6b4d4SGreg Roach/**
3e5a6b4d4SGreg Roach * webtrees: online genealogy
4e5a6b4d4SGreg Roach * Copyright (C) 2019 webtrees development team
5e5a6b4d4SGreg Roach * This program is free software: you can redistribute it and/or modify
6e5a6b4d4SGreg Roach * it under the terms of the GNU General Public License as published by
7e5a6b4d4SGreg Roach * the Free Software Foundation, either version 3 of the License, or
8e5a6b4d4SGreg Roach * (at your option) any later version.
9e5a6b4d4SGreg Roach * This program is distributed in the hope that it will be useful,
10e5a6b4d4SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
11e5a6b4d4SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12e5a6b4d4SGreg Roach * GNU General Public License for more details.
13e5a6b4d4SGreg Roach * You should have received a copy of the GNU General Public License
14e5a6b4d4SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
15e5a6b4d4SGreg Roach */
16e5a6b4d4SGreg Roachdeclare(strict_types=1);
17e5a6b4d4SGreg Roach
18e5a6b4d4SGreg Roachnamespace Fisharebest\Webtrees;
19e5a6b4d4SGreg Roach
20e5a6b4d4SGreg Roachuse Fisharebest\Webtrees\Contracts\UserInterface;
21e5a6b4d4SGreg Roach
22e5a6b4d4SGreg Roach/**
23e5a6b4d4SGreg Roach * Test the TreeUser class
24e5a6b4d4SGreg Roach */
25e5a6b4d4SGreg Roachclass TreeUserTest extends TestCase
26e5a6b4d4SGreg Roach{
27e5a6b4d4SGreg Roach    protected static $uses_database = true;
28e5a6b4d4SGreg Roach
29e5a6b4d4SGreg Roach    /**
30e5a6b4d4SGreg Roach     * @covers \Fisharebest\Webtrees\TreeUser::__construct
31e5a6b4d4SGreg Roach     * @covers \Fisharebest\Webtrees\TreeUser::id
32e5a6b4d4SGreg Roach     * @covers \Fisharebest\Webtrees\TreeUser::email
33e5a6b4d4SGreg Roach     * @covers \Fisharebest\Webtrees\TreeUser::realName
34e5a6b4d4SGreg Roach     * @covers \Fisharebest\Webtrees\TreeUser::userName
35e5a6b4d4SGreg Roach     * @return void
36e5a6b4d4SGreg Roach     */
37e5a6b4d4SGreg Roach    public function testConstructor(): void
38e5a6b4d4SGreg Roach    {
39e5a6b4d4SGreg Roach        $tree = Tree::create('name', 'title');
40e5a6b4d4SGreg Roach        $user = new TreeUser($tree);
41e5a6b4d4SGreg Roach
42e5a6b4d4SGreg Roach        $this->assertInstanceOf(UserInterface::class, $user);
43e5a6b4d4SGreg Roach        $this->assertSame(0, $user->id());
44*502cab90SGreg Roach        $this->assertSame('', $user->email());
45e5a6b4d4SGreg Roach        $this->assertSame('title', $user->realName());
46e5a6b4d4SGreg Roach        $this->assertSame('', $user->userName());
47e5a6b4d4SGreg Roach    }
48e5a6b4d4SGreg Roach
49e5a6b4d4SGreg Roach    /**
50e5a6b4d4SGreg Roach     * @covers \Fisharebest\Webtrees\TreeUser::getPreference
51e5a6b4d4SGreg Roach     * @covers \Fisharebest\Webtrees\TreeUser::setPreference
52e5a6b4d4SGreg Roach     * @return void
53e5a6b4d4SGreg Roach     */
54e5a6b4d4SGreg Roach    public function testPreferences(): void
55e5a6b4d4SGreg Roach    {
56e5a6b4d4SGreg Roach        $tree = Tree::create('name', 'title');
57e5a6b4d4SGreg Roach        $user = new TreeUser($tree);
58e5a6b4d4SGreg Roach
59e5a6b4d4SGreg Roach        $this->assertSame('', $user->getPreference('foo'));
60e5a6b4d4SGreg Roach        $this->assertSame('', $user->getPreference('foo', ''));
61e5a6b4d4SGreg Roach        $this->assertSame('bar', $user->getPreference('foo', 'bar'));
62e5a6b4d4SGreg Roach
63e5a6b4d4SGreg Roach        // Tree users do not have preferences
64e5a6b4d4SGreg Roach        $user->setPreference('foo', 'bar');
65e5a6b4d4SGreg Roach
66e5a6b4d4SGreg Roach        $this->assertSame('', $user->getPreference('foo'));
67e5a6b4d4SGreg Roach    }
68e5a6b4d4SGreg Roach}
69