xref: /webtrees/tests/app/DefaultUserTest.php (revision d11be7027e34e3121be11cc025421873364403f9)
1e5a6b4d4SGreg Roach<?php
23976b470SGreg Roach
3e5a6b4d4SGreg Roach/**
4e5a6b4d4SGreg Roach * webtrees: online genealogy
5*d11be702SGreg Roach * Copyright (C) 2023 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
1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
16e5a6b4d4SGreg Roach */
17fcfa147eSGreg Roach
18e5a6b4d4SGreg Roachdeclare(strict_types=1);
19e5a6b4d4SGreg Roach
20e5a6b4d4SGreg Roachnamespace Fisharebest\Webtrees;
21e5a6b4d4SGreg Roach
2269675509SGreg Roachuse Fisharebest\Webtrees\Contracts\CacheFactoryInterface;
23e5a6b4d4SGreg Roachuse Fisharebest\Webtrees\Contracts\UserInterface;
2469675509SGreg Roachuse Symfony\Component\Cache\Adapter\NullAdapter;
25e5a6b4d4SGreg Roach
26e5a6b4d4SGreg Roach/**
27e5a6b4d4SGreg Roach * Test the DefaultUser class
28e5a6b4d4SGreg Roach */
29e5a6b4d4SGreg Roachclass DefaultUserTest extends TestCase
30e5a6b4d4SGreg Roach{
31cd94ca66SGreg Roach    protected static bool $uses_database = true;
32e5a6b4d4SGreg Roach
3392a78a2fSGreg Roach    /**
3492a78a2fSGreg Roach     * Things to run before every test.
3592a78a2fSGreg Roach     */
3657b69958SGreg Roach    protected function setUp(): void
3769675509SGreg Roach    {
3869675509SGreg Roach        parent::setUp();
3969675509SGreg Roach
40cd94ca66SGreg Roach        $cache_factory = $this->createMock(CacheFactoryInterface::class);
4169675509SGreg Roach        $cache_factory->method('array')->willReturn(new Cache(new NullAdapter()));
426b9cb339SGreg Roach        Registry::cache($cache_factory);
4369675509SGreg Roach    }
4469675509SGreg Roach
45e5a6b4d4SGreg Roach    /**
46e5a6b4d4SGreg Roach     * @covers \Fisharebest\Webtrees\DefaultUser::__construct
47e5a6b4d4SGreg Roach     * @covers \Fisharebest\Webtrees\DefaultUser::id
48e5a6b4d4SGreg Roach     * @covers \Fisharebest\Webtrees\DefaultUser::email
49e5a6b4d4SGreg Roach     * @covers \Fisharebest\Webtrees\DefaultUser::realName
50e5a6b4d4SGreg Roach     * @covers \Fisharebest\Webtrees\DefaultUser::userName
51e5a6b4d4SGreg Roach     * @return void
52e5a6b4d4SGreg Roach     */
53e5a6b4d4SGreg Roach    public function testDefaultUser(): void
54e5a6b4d4SGreg Roach    {
55e5a6b4d4SGreg Roach        $user = new DefaultUser();
56e5a6b4d4SGreg Roach
575e933c21SGreg Roach        self::assertInstanceOf(UserInterface::class, $user);
585e933c21SGreg Roach        self::assertSame(-1, $user->id());
595e933c21SGreg Roach        self::assertSame('DEFAULT_USER', $user->email());
605e933c21SGreg Roach        self::assertSame('DEFAULT_USER', $user->realName());
615e933c21SGreg Roach        self::assertSame('', $user->userName());
62e5a6b4d4SGreg Roach    }
63e5a6b4d4SGreg Roach
64e5a6b4d4SGreg Roach    /**
65e5a6b4d4SGreg Roach     * @covers \Fisharebest\Webtrees\DefaultUser::getPreference
66e5a6b4d4SGreg Roach     * @covers \Fisharebest\Webtrees\DefaultUser::setPreference
67e5a6b4d4SGreg Roach     * @return void
68e5a6b4d4SGreg Roach     */
69e5a6b4d4SGreg Roach    public function testPreferences(): void
70e5a6b4d4SGreg Roach    {
71e5a6b4d4SGreg Roach        $user = new DefaultUser();
72e5a6b4d4SGreg Roach
735e933c21SGreg Roach        self::assertSame('', $user->getPreference('foo'));
745e933c21SGreg Roach        self::assertSame('', $user->getPreference('foo'));
755e933c21SGreg Roach        self::assertSame('bar', $user->getPreference('foo', 'bar'));
76e5a6b4d4SGreg Roach
77e5a6b4d4SGreg Roach        // Default users store preferences in the database
78e5a6b4d4SGreg Roach        $user->setPreference('foo', 'bar');
79e5a6b4d4SGreg Roach
805e933c21SGreg Roach        self::assertSame('bar', $user->getPreference('foo'));
81e5a6b4d4SGreg Roach    }
82e5a6b4d4SGreg Roach}
83