xref: /webtrees/tests/app/GuestUserTest.php (revision 202c018b592d5a516e4a465dc6dc515f3be37399)
1e5a6b4d4SGreg Roach<?php
23976b470SGreg Roach
3e5a6b4d4SGreg Roach/**
4e5a6b4d4SGreg Roach * webtrees: online genealogy
5d11be702SGreg 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
22e5a6b4d4SGreg Roachuse Fisharebest\Webtrees\Contracts\UserInterface;
23*202c018bSGreg Roachuse PHPUnit\Framework\Attributes\CoversClass;
24e5a6b4d4SGreg Roach
25*202c018bSGreg Roach
26*202c018bSGreg Roach#[CoversClass(GuestUser::class)]
27e5a6b4d4SGreg Roachclass GuestUserTest extends TestCase
28e5a6b4d4SGreg Roach{
29e5a6b4d4SGreg Roach    public function testAnonymous(): void
30e5a6b4d4SGreg Roach    {
31e5a6b4d4SGreg Roach        $user = new GuestUser();
32e5a6b4d4SGreg Roach
335e933c21SGreg Roach        self::assertInstanceOf(UserInterface::class, $user);
345e933c21SGreg Roach        self::assertSame(0, $user->id());
355e933c21SGreg Roach        self::assertSame('GUEST_USER', $user->email());
365e933c21SGreg Roach        self::assertSame('GUEST_USER', $user->realName());
375e933c21SGreg Roach        self::assertSame('', $user->userName());
38e5a6b4d4SGreg Roach    }
39e5a6b4d4SGreg Roach
40e5a6b4d4SGreg Roach    public function testVisitor(): void
41e5a6b4d4SGreg Roach    {
42e5a6b4d4SGreg Roach        $user = new GuestUser('guest@example.com', 'guest user');
43e5a6b4d4SGreg Roach
445e933c21SGreg Roach        self::assertInstanceOf(UserInterface::class, $user);
455e933c21SGreg Roach        self::assertSame(0, $user->id());
465e933c21SGreg Roach        self::assertSame('guest@example.com', $user->email());
475e933c21SGreg Roach        self::assertSame('guest user', $user->realName());
485e933c21SGreg Roach        self::assertSame('', $user->userName());
49e5a6b4d4SGreg Roach    }
50e5a6b4d4SGreg Roach
51e5a6b4d4SGreg Roach    public function testPreferences(): void
52e5a6b4d4SGreg Roach    {
53e5a6b4d4SGreg Roach        $user = new GuestUser();
54e5a6b4d4SGreg Roach
555e933c21SGreg Roach        self::assertSame('', $user->getPreference('foo'));
565e933c21SGreg Roach        self::assertSame('', $user->getPreference('foo'));
575e933c21SGreg Roach        self::assertSame('bar', $user->getPreference('foo', 'bar'));
58e5a6b4d4SGreg Roach
59e5a6b4d4SGreg Roach        // Guests users store preferences in the session
60e5a6b4d4SGreg Roach        $user->setPreference('foo', 'bar');
61e5a6b4d4SGreg Roach
625e933c21SGreg Roach        self::assertSame('bar', $user->getPreference('foo'));
63e5a6b4d4SGreg Roach    }
64e5a6b4d4SGreg Roach}
65