xref: /webtrees/tests/app/SiteUserTest.php (revision 3976b4703df669696105ed6b024b96d433c8fbdb)
12ab46aafSGreg Roach<?php
2*3976b470SGreg Roach
32ab46aafSGreg Roach/**
42ab46aafSGreg Roach * webtrees: online genealogy
52ab46aafSGreg Roach * Copyright (C) 2019 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
152ab46aafSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
162ab46aafSGreg Roach */
172ab46aafSGreg Roachdeclare(strict_types=1);
182ab46aafSGreg Roach
192ab46aafSGreg Roachnamespace Fisharebest\Webtrees;
202ab46aafSGreg Roach
212ab46aafSGreg Roachuse Fisharebest\Webtrees\Contracts\UserInterface;
222ab46aafSGreg Roach
232ab46aafSGreg Roach/**
242ab46aafSGreg Roach * Test the SiteUser class
252ab46aafSGreg Roach */
262ab46aafSGreg Roachclass SiteUserTest extends TestCase
272ab46aafSGreg Roach{
282ab46aafSGreg Roach    protected static $uses_database = true;
292ab46aafSGreg Roach
302ab46aafSGreg Roach    /**
312ab46aafSGreg Roach     * @covers \Fisharebest\Webtrees\SiteUser::id
322ab46aafSGreg Roach     * @covers \Fisharebest\Webtrees\SiteUser::email
332ab46aafSGreg Roach     * @covers \Fisharebest\Webtrees\SiteUser::realName
342ab46aafSGreg Roach     * @covers \Fisharebest\Webtrees\SiteUser::userName
352ab46aafSGreg Roach     * @return void
362ab46aafSGreg Roach     */
372ab46aafSGreg Roach    public function testConstructor(): void
382ab46aafSGreg Roach    {
392ab46aafSGreg Roach        $user = new SiteUser();
402ab46aafSGreg Roach
412ab46aafSGreg Roach        $this->assertInstanceOf(UserInterface::class, $user);
422ab46aafSGreg Roach        $this->assertSame(0, $user->id());
43502cab90SGreg Roach        $this->assertSame('', $user->email());
442ab46aafSGreg Roach        $this->assertSame('webtrees', $user->realName());
452ab46aafSGreg Roach        $this->assertSame('', $user->userName());
462ab46aafSGreg Roach    }
472ab46aafSGreg Roach
482ab46aafSGreg Roach    /**
492ab46aafSGreg Roach     * @covers \Fisharebest\Webtrees\SiteUser::getPreference
502ab46aafSGreg Roach     * @covers \Fisharebest\Webtrees\SiteUser::setPreference
512ab46aafSGreg Roach     * @return void
522ab46aafSGreg Roach     */
532ab46aafSGreg Roach    public function testPreferences(): void
542ab46aafSGreg Roach    {
552ab46aafSGreg Roach        $user = new SiteUser();
562ab46aafSGreg Roach
572ab46aafSGreg Roach        $this->assertSame('', $user->getPreference('foo'));
582ab46aafSGreg Roach        $this->assertSame('', $user->getPreference('foo', ''));
592ab46aafSGreg Roach        $this->assertSame('bar', $user->getPreference('foo', 'bar'));
602ab46aafSGreg Roach
612ab46aafSGreg Roach        // Site users do not have preferences
622ab46aafSGreg Roach        $user->setPreference('foo', 'bar');
632ab46aafSGreg Roach
642ab46aafSGreg Roach        $this->assertSame('', $user->getPreference('foo'));
652ab46aafSGreg Roach    }
662ab46aafSGreg Roach}
67