xref: /webtrees/tests/app/SiteUserTest.php (revision 5a8afed46297e8105e3e5a33ce37e6a8e88bc79d)
12ab46aafSGreg Roach<?php
23976b470SGreg Roach
32ab46aafSGreg Roach/**
42ab46aafSGreg Roach * webtrees: online genealogy
5d11be702SGreg Roach * Copyright (C) 2023 webtrees development team
62ab46aafSGreg Roach * This program is free software: you can redistribute it and/or modify
72ab46aafSGreg Roach * it under the terms of the GNU General Public License as published by
82ab46aafSGreg Roach * the Free Software Foundation, either version 3 of the License, or
92ab46aafSGreg Roach * (at your option) any later version.
102ab46aafSGreg Roach * This program is distributed in the hope that it will be useful,
112ab46aafSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
122ab46aafSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
132ab46aafSGreg Roach * GNU General Public License for more details.
142ab46aafSGreg 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/>.
162ab46aafSGreg Roach */
17fcfa147eSGreg Roach
182ab46aafSGreg Roachdeclare(strict_types=1);
192ab46aafSGreg Roach
202ab46aafSGreg Roachnamespace Fisharebest\Webtrees;
212ab46aafSGreg Roach
222ab46aafSGreg Roachuse Fisharebest\Webtrees\Contracts\UserInterface;
23*202c018bSGreg Roachuse PHPUnit\Framework\Attributes\CoversClass;
242ab46aafSGreg Roach
25*202c018bSGreg Roach#[CoversClass(SiteUser::class)]
262ab46aafSGreg Roachclass SiteUserTest extends TestCase
272ab46aafSGreg Roach{
28cd94ca66SGreg Roach    protected static bool $uses_database = true;
292ab46aafSGreg Roach
302ab46aafSGreg Roach    public function testConstructor(): void
312ab46aafSGreg Roach    {
322ab46aafSGreg Roach        $user = new SiteUser();
33cdf1da30SGreg Roach        Site::setPreference('SMTP_FROM_NAME', 'email@example.com');
34cdf1da30SGreg Roach        Site::setPreference('SMTP_DISP_NAME', 'My site');
352ab46aafSGreg Roach
365e933c21SGreg Roach        self::assertInstanceOf(UserInterface::class, $user);
375e933c21SGreg Roach        self::assertSame(0, $user->id());
38cdf1da30SGreg Roach        self::assertSame('email@example.com', $user->email());
39cdf1da30SGreg Roach        self::assertSame('My site', $user->realName());
405e933c21SGreg Roach        self::assertSame('', $user->userName());
412ab46aafSGreg Roach    }
422ab46aafSGreg Roach
432ab46aafSGreg Roach    public function testPreferences(): void
442ab46aafSGreg Roach    {
452ab46aafSGreg Roach        $user = new SiteUser();
462ab46aafSGreg Roach
475e933c21SGreg Roach        self::assertSame('', $user->getPreference('foo'));
485e933c21SGreg Roach        self::assertSame('', $user->getPreference('foo'));
495e933c21SGreg Roach        self::assertSame('bar', $user->getPreference('foo', 'bar'));
502ab46aafSGreg Roach
512ab46aafSGreg Roach        // Site users do not have preferences
522ab46aafSGreg Roach        $user->setPreference('foo', 'bar');
532ab46aafSGreg Roach
545e933c21SGreg Roach        self::assertSame('', $user->getPreference('foo'));
552ab46aafSGreg Roach    }
562ab46aafSGreg Roach}
57