xref: /webtrees/tests/app/GuestUserTest.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 GuestUser class
24*e5a6b4d4SGreg Roach */
25*e5a6b4d4SGreg Roachclass GuestUserTest extends TestCase
26*e5a6b4d4SGreg Roach{
27*e5a6b4d4SGreg Roach    /**
28*e5a6b4d4SGreg Roach     * @covers \Fisharebest\Webtrees\GuestUser::__construct
29*e5a6b4d4SGreg Roach     * @covers \Fisharebest\Webtrees\GuestUser::id
30*e5a6b4d4SGreg Roach     * @covers \Fisharebest\Webtrees\GuestUser::email
31*e5a6b4d4SGreg Roach     * @covers \Fisharebest\Webtrees\GuestUser::realName
32*e5a6b4d4SGreg Roach     * @covers \Fisharebest\Webtrees\GuestUser::userName
33*e5a6b4d4SGreg Roach     * @return void
34*e5a6b4d4SGreg Roach     */
35*e5a6b4d4SGreg Roach    public function testAnonymous(): void
36*e5a6b4d4SGreg Roach    {
37*e5a6b4d4SGreg Roach        $user = new GuestUser();
38*e5a6b4d4SGreg Roach
39*e5a6b4d4SGreg Roach        $this->assertInstanceOf(UserInterface::class, $user);
40*e5a6b4d4SGreg Roach        $this->assertSame(0, $user->id());
41*e5a6b4d4SGreg Roach        $this->assertSame('GUEST_USER', $user->email());
42*e5a6b4d4SGreg Roach        $this->assertSame('GUEST_USER', $user->realName());
43*e5a6b4d4SGreg Roach        $this->assertSame('', $user->userName());
44*e5a6b4d4SGreg Roach    }
45*e5a6b4d4SGreg Roach
46*e5a6b4d4SGreg Roach    /**
47*e5a6b4d4SGreg Roach     * @covers \Fisharebest\Webtrees\GuestUser::__construct
48*e5a6b4d4SGreg Roach     * @covers \Fisharebest\Webtrees\GuestUser::id
49*e5a6b4d4SGreg Roach     * @covers \Fisharebest\Webtrees\GuestUser::email
50*e5a6b4d4SGreg Roach     * @covers \Fisharebest\Webtrees\GuestUser::realName
51*e5a6b4d4SGreg Roach     * @covers \Fisharebest\Webtrees\GuestUser::userName
52*e5a6b4d4SGreg Roach     * @return void
53*e5a6b4d4SGreg Roach     */
54*e5a6b4d4SGreg Roach    public function testVisitor(): void
55*e5a6b4d4SGreg Roach    {
56*e5a6b4d4SGreg Roach        $user = new GuestUser('guest@example.com', 'guest user');
57*e5a6b4d4SGreg Roach
58*e5a6b4d4SGreg Roach        $this->assertInstanceOf(UserInterface::class, $user);
59*e5a6b4d4SGreg Roach        $this->assertSame(0, $user->id());
60*e5a6b4d4SGreg Roach        $this->assertSame('guest@example.com', $user->email());
61*e5a6b4d4SGreg Roach        $this->assertSame('guest user', $user->realName());
62*e5a6b4d4SGreg Roach        $this->assertSame('', $user->userName());
63*e5a6b4d4SGreg Roach    }
64*e5a6b4d4SGreg Roach
65*e5a6b4d4SGreg Roach    /**
66*e5a6b4d4SGreg Roach     * @covers \Fisharebest\Webtrees\GuestUser::getPreference
67*e5a6b4d4SGreg Roach     * @covers \Fisharebest\Webtrees\GuestUser::setPreference
68*e5a6b4d4SGreg Roach     * @return void
69*e5a6b4d4SGreg Roach     */
70*e5a6b4d4SGreg Roach    public function testPreferences(): void
71*e5a6b4d4SGreg Roach    {
72*e5a6b4d4SGreg Roach        $user = new GuestUser();
73*e5a6b4d4SGreg Roach
74*e5a6b4d4SGreg Roach        $this->assertSame('', $user->getPreference('foo'));
75*e5a6b4d4SGreg Roach        $this->assertSame('', $user->getPreference('foo', ''));
76*e5a6b4d4SGreg Roach        $this->assertSame('bar', $user->getPreference('foo', 'bar'));
77*e5a6b4d4SGreg Roach
78*e5a6b4d4SGreg Roach        // Guests users store preferences in the session
79*e5a6b4d4SGreg Roach        $user->setPreference('foo', 'bar');
80*e5a6b4d4SGreg Roach
81*e5a6b4d4SGreg Roach        $this->assertSame('bar', $user->getPreference('foo'));
82*e5a6b4d4SGreg Roach    }
83*e5a6b4d4SGreg Roach}
84