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 TreeUser class 24*e5a6b4d4SGreg Roach */ 25*e5a6b4d4SGreg Roachclass TreeUserTest extends TestCase 26*e5a6b4d4SGreg Roach{ 27*e5a6b4d4SGreg Roach protected static $uses_database = true; 28*e5a6b4d4SGreg Roach 29*e5a6b4d4SGreg Roach /** 30*e5a6b4d4SGreg Roach * @covers \Fisharebest\Webtrees\TreeUser::__construct 31*e5a6b4d4SGreg Roach * @covers \Fisharebest\Webtrees\TreeUser::id 32*e5a6b4d4SGreg Roach * @covers \Fisharebest\Webtrees\TreeUser::email 33*e5a6b4d4SGreg Roach * @covers \Fisharebest\Webtrees\TreeUser::realName 34*e5a6b4d4SGreg Roach * @covers \Fisharebest\Webtrees\TreeUser::userName 35*e5a6b4d4SGreg Roach * @return void 36*e5a6b4d4SGreg Roach */ 37*e5a6b4d4SGreg Roach public function testConstructor(): void 38*e5a6b4d4SGreg Roach { 39*e5a6b4d4SGreg Roach $tree = Tree::create('name', 'title'); 40*e5a6b4d4SGreg Roach $user = new TreeUser($tree); 41*e5a6b4d4SGreg Roach 42*e5a6b4d4SGreg Roach $this->assertInstanceOf(UserInterface::class, $user); 43*e5a6b4d4SGreg Roach $this->assertSame(0, $user->id()); 44*e5a6b4d4SGreg Roach $this->assertSame('no-reply@example.com', $user->email()); 45*e5a6b4d4SGreg Roach $this->assertSame('title', $user->realName()); 46*e5a6b4d4SGreg Roach $this->assertSame('', $user->userName()); 47*e5a6b4d4SGreg Roach 48*e5a6b4d4SGreg Roach app()->make('cache.array')->flush(); 49*e5a6b4d4SGreg Roach $tree->setPreference('WEBTREES_EMAIL', 'foo@example.com'); 50*e5a6b4d4SGreg Roach $this->assertSame('foo@example.com', $user->email()); 51*e5a6b4d4SGreg Roach } 52*e5a6b4d4SGreg Roach 53*e5a6b4d4SGreg Roach /** 54*e5a6b4d4SGreg Roach * @covers \Fisharebest\Webtrees\TreeUser::getPreference 55*e5a6b4d4SGreg Roach * @covers \Fisharebest\Webtrees\TreeUser::setPreference 56*e5a6b4d4SGreg Roach * @return void 57*e5a6b4d4SGreg Roach */ 58*e5a6b4d4SGreg Roach public function testPreferences(): void 59*e5a6b4d4SGreg Roach { 60*e5a6b4d4SGreg Roach $tree = Tree::create('name', 'title'); 61*e5a6b4d4SGreg Roach $user = new TreeUser($tree); 62*e5a6b4d4SGreg Roach 63*e5a6b4d4SGreg Roach $this->assertSame('', $user->getPreference('foo')); 64*e5a6b4d4SGreg Roach $this->assertSame('', $user->getPreference('foo', '')); 65*e5a6b4d4SGreg Roach $this->assertSame('bar', $user->getPreference('foo', 'bar')); 66*e5a6b4d4SGreg Roach 67*e5a6b4d4SGreg Roach // Tree users do not have preferences 68*e5a6b4d4SGreg Roach $user->setPreference('foo', 'bar'); 69*e5a6b4d4SGreg Roach 70*e5a6b4d4SGreg Roach $this->assertSame('', $user->getPreference('foo')); 71*e5a6b4d4SGreg Roach } 72*e5a6b4d4SGreg Roach} 73