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