1a25f0a04SGreg Roach<?php 2a25f0a04SGreg Roach/** 3a25f0a04SGreg Roach * webtrees: online genealogy 48fcd0d32SGreg Roach * Copyright (C) 2019 webtrees development team 5a25f0a04SGreg Roach * This program is free software: you can redistribute it and/or modify 6a25f0a04SGreg Roach * it under the terms of the GNU General Public License as published by 7a25f0a04SGreg Roach * the Free Software Foundation, either version 3 of the License, or 8a25f0a04SGreg Roach * (at your option) any later version. 9a25f0a04SGreg Roach * This program is distributed in the hope that it will be useful, 10a25f0a04SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 11a25f0a04SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12a25f0a04SGreg Roach * GNU General Public License for more details. 13a25f0a04SGreg Roach * You should have received a copy of the GNU General Public License 14a25f0a04SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 15a25f0a04SGreg Roach */ 16e7f56f2aSGreg Roachdeclare(strict_types=1); 17e7f56f2aSGreg Roach 1884e2cf4eSGreg Roachnamespace Fisharebest\Webtrees; 19a25f0a04SGreg Roach 20a25f0a04SGreg Roach/** 21a25f0a04SGreg Roach * Test harness for the class Tree 22a25f0a04SGreg Roach */ 2384e2cf4eSGreg Roachclass TreeTest extends \Fisharebest\Webtrees\TestCase 24c1010edaSGreg Roach{ 25126654d7SGreg Roach protected static $uses_database = true; 26126654d7SGreg Roach 27a25f0a04SGreg Roach /** 28126654d7SGreg Roach * @covers \Fisharebest\Webtrees\Tree::__construct 29126654d7SGreg Roach * @covers \Fisharebest\Webtrees\Tree::create 30126654d7SGreg Roach * @covers \Fisharebest\Webtrees\Tree::id 31126654d7SGreg Roach * @covers \Fisharebest\Webtrees\Tree::name 32126654d7SGreg Roach * @covers \Fisharebest\Webtrees\Tree::title 3352348eb8SGreg Roach * 3452348eb8SGreg Roach * @return void 35a25f0a04SGreg Roach */ 36126654d7SGreg Roach public function testConstructor(): void 37c1010edaSGreg Roach { 38126654d7SGreg Roach $tree = Tree::create('tree-name', 'Tree title'); 39126654d7SGreg Roach 40126654d7SGreg Roach $this->assertSame(1, $tree->id()); 41126654d7SGreg Roach $this->assertSame('tree-name', $tree->name()); 42126654d7SGreg Roach $this->assertSame('Tree title', $tree->title()); 43126654d7SGreg Roach } 44126654d7SGreg Roach 45126654d7SGreg Roach /** 46126654d7SGreg Roach * @covers \Fisharebest\Webtrees\Tree::getPreference 47126654d7SGreg Roach * @covers \Fisharebest\Webtrees\Tree::setPreference 48126654d7SGreg Roach * 49126654d7SGreg Roach * @return void 50126654d7SGreg Roach */ 51af343084SGreg Roach public function testTreePreferences(): void 52126654d7SGreg Roach { 53126654d7SGreg Roach $tree = Tree::create('tree-name', 'Tree title'); 54126654d7SGreg Roach 55126654d7SGreg Roach $pref = $tree->getPreference('foo', 'default'); 56126654d7SGreg Roach $this->assertSame('default', $pref); 57126654d7SGreg Roach 58126654d7SGreg Roach $tree->setPreference('foo', 'bar'); 59126654d7SGreg Roach $pref = $tree->getPreference('foo', 'default'); 60126654d7SGreg Roach $this->assertSame('bar', $pref); 61a25f0a04SGreg Roach } 62af343084SGreg Roach 63af343084SGreg Roach /** 64af343084SGreg Roach * @covers \Fisharebest\Webtrees\Tree::getUserPreference 65*000dd58cSGreg Roach * @covers \Fisharebest\Webtrees\Tree::setUserPreference 66af343084SGreg Roach * 67af343084SGreg Roach * @return void 68af343084SGreg Roach */ 69af343084SGreg Roach public function testUserTreePreferences(): void 70af343084SGreg Roach { 71af343084SGreg Roach $tree = Tree::create('tree-name', 'Tree title'); 72af343084SGreg Roach $user = User::create('user', 'User', 'user@example.com', 'secret'); 73af343084SGreg Roach 74af343084SGreg Roach $pref = $tree->getUserPreference($user, 'foo', 'default'); 75af343084SGreg Roach $this->assertSame('default', $pref); 76af343084SGreg Roach 77af343084SGreg Roach $tree->setUserPreference($user, 'foo', 'bar'); 78af343084SGreg Roach $pref = $tree->getUserPreference($user, 'foo', 'default'); 79af343084SGreg Roach $this->assertSame('bar', $pref); 80af343084SGreg Roach } 81a25f0a04SGreg Roach} 82