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