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