1bb88f16bSGreg Roach<?php 2bb88f16bSGreg Roach 3bb88f16bSGreg Roach/** 4bb88f16bSGreg Roach * webtrees: online genealogy 5a091ac74SGreg Roach * Copyright (C) 2020 webtrees development team 6bb88f16bSGreg Roach * This program is free software: you can redistribute it and/or modify 7bb88f16bSGreg Roach * it under the terms of the GNU General Public License as published by 8bb88f16bSGreg Roach * the Free Software Foundation, either version 3 of the License, or 9bb88f16bSGreg Roach * (at your option) any later version. 10bb88f16bSGreg Roach * This program is distributed in the hope that it will be useful, 11bb88f16bSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12bb88f16bSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13bb88f16bSGreg Roach * GNU General Public License for more details. 14bb88f16bSGreg Roach * You should have received a copy of the GNU General Public License 15bb88f16bSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 16bb88f16bSGreg Roach */ 17bb88f16bSGreg Roach 18bb88f16bSGreg Roachdeclare(strict_types=1); 19bb88f16bSGreg Roach 20bb88f16bSGreg Roachnamespace Fisharebest\Webtrees; 21bb88f16bSGreg Roach 22bb88f16bSGreg Roachuse Fisharebest\Webtrees\Services\UserService; 23bb88f16bSGreg Roach 24bb88f16bSGreg Roachuse function strip_tags; 25bb88f16bSGreg Roach 26bb88f16bSGreg Roach/** 27bb88f16bSGreg Roach * Test the privacy logic 28bb88f16bSGreg Roach */ 29bb88f16bSGreg Roachclass Privacy extends TestCase 30bb88f16bSGreg Roach{ 31bb88f16bSGreg Roach protected static $uses_database = true; 32bb88f16bSGreg Roach 33bb88f16bSGreg Roach /** 34bb88f16bSGreg Roach * @return void 35bb88f16bSGreg Roach */ 36bb88f16bSGreg Roach public function testRecordAccess(): void 37bb88f16bSGreg Roach { 38bb88f16bSGreg Roach $tree = $this->importTree('demo.ged'); 39bb88f16bSGreg Roach 40bb88f16bSGreg Roach // Identify some individuals in the tree 41*6b9cb339SGreg Roach $queen_elizabeth = Registry::individualFactory()->make('X1030', $tree); 42bb88f16bSGreg Roach $this->assertInstanceOf(Individual::class, $queen_elizabeth); 43bb88f16bSGreg Roach $this->assertSame('Queen Elizabeth II', strip_tags($queen_elizabeth->fullName())); 44bb88f16bSGreg Roach 45*6b9cb339SGreg Roach $prince_charles = Registry::individualFactory()->make('X1052', $tree); 46bb88f16bSGreg Roach $this->assertInstanceOf(Individual::class, $prince_charles); 47bb88f16bSGreg Roach $this->assertSame('Charles, Prince of Wales', strip_tags($prince_charles->fullName())); 48bb88f16bSGreg Roach 49*6b9cb339SGreg Roach $savannah = Registry::individualFactory()->make('X1044', $tree); 50bb88f16bSGreg Roach $this->assertInstanceOf(Individual::class, $savannah); 51bb88f16bSGreg Roach $this->assertSame('Savannah Anne Kathleen Phillips', strip_tags($savannah->fullName())); 52bb88f16bSGreg Roach 53*6b9cb339SGreg Roach $beatrice = Registry::individualFactory()->make('X1047', $tree); 54bb88f16bSGreg Roach $this->assertInstanceOf(Individual::class, $beatrice); 55bb88f16bSGreg Roach $this->assertSame('Princess Beatrice of York', strip_tags($beatrice->fullName())); 56bb88f16bSGreg Roach 57bb88f16bSGreg Roach $user_service = new UserService(); 58bb88f16bSGreg Roach 59bb88f16bSGreg Roach $admin = $user_service->create('admin', 'admin', 'admin', '*'); 60bb88f16bSGreg Roach $admin->setPreference(User::PREF_IS_ADMINISTRATOR, '1'); 61bb88f16bSGreg Roach 62bb88f16bSGreg Roach $manager = $user_service->create('manager', 'manager', 'manager', '*'); 63bb88f16bSGreg Roach $tree->setUserPreference($manager, User::PREF_TREE_ROLE, User::ROLE_MANAGER); 64bb88f16bSGreg Roach 65bb88f16bSGreg Roach $moderator = $user_service->create('moderator', 'moderator', 'moderator', '*'); 66bb88f16bSGreg Roach $tree->setUserPreference($moderator, User::PREF_TREE_ROLE, User::ROLE_MODERATOR); 67bb88f16bSGreg Roach 68bb88f16bSGreg Roach $editor = $user_service->create('editor', 'editor', 'editor', '*'); 69bb88f16bSGreg Roach $tree->setUserPreference($editor, User::PREF_TREE_ROLE, User::ROLE_EDITOR); 70bb88f16bSGreg Roach 71bb88f16bSGreg Roach $member = $user_service->create('member', 'member', 'member', '*'); 72bb88f16bSGreg Roach $tree->setUserPreference($member, User::PREF_TREE_ROLE, User::ROLE_MEMBER); 73bb88f16bSGreg Roach 74bb88f16bSGreg Roach $visitor = $user_service->create('visitor', 'visitor', 'visitor', '*'); 75bb88f16bSGreg Roach $tree->setUserPreference($visitor, User::PREF_TREE_ROLE, User::ROLE_VISITOR); 76bb88f16bSGreg Roach 77bb88f16bSGreg Roach // Enable privacy functions 78bb88f16bSGreg Roach $tree->setPreference('HIDE_LIVE_PEOPLE', '1'); 79bb88f16bSGreg Roach 80bb88f16bSGreg Roach Auth::login($admin); 81bb88f16bSGreg Roach $this->assertTrue(Auth::isAdmin(), 'admin isAdmin()'); 82bb88f16bSGreg Roach $this->assertTrue(Auth::isManager($tree), 'admin isManager()'); 83bb88f16bSGreg Roach $this->assertTrue(Auth::isModerator($tree), 'admin isModerator()'); 84bb88f16bSGreg Roach $this->assertTrue(Auth::isEditor($tree), 'admin isEditor()'); 85bb88f16bSGreg Roach $this->assertTrue(Auth::isMember($tree), 'admin isMember()'); 86bb88f16bSGreg Roach 87bb88f16bSGreg Roach Auth::login($manager); 88bb88f16bSGreg Roach $this->assertFalse(Auth::isAdmin(), 'manager NOT isAdmin()'); 89bb88f16bSGreg Roach $this->assertTrue(Auth::isManager($tree, $manager), 'manager isManager()'); 90bb88f16bSGreg Roach $this->assertTrue(Auth::isModerator($tree, $manager), 'manager isModerator()'); 91bb88f16bSGreg Roach $this->assertTrue(Auth::isEditor($tree, $manager), 'manager isEditor()'); 92bb88f16bSGreg Roach $this->assertTrue(Auth::isMember($tree, $manager), 'manager isMember()'); 93bb88f16bSGreg Roach 94bb88f16bSGreg Roach Auth::login($moderator); 95bb88f16bSGreg Roach $this->assertFalse(Auth::isAdmin(), 'moderator NOT isAdmin()'); 96bb88f16bSGreg Roach $this->assertFalse(Auth::isManager($tree, $moderator), 'moderator NOT isManager()'); 97bb88f16bSGreg Roach $this->assertTrue(Auth::isModerator($tree, $moderator), 'moderator isModerator()'); 98bb88f16bSGreg Roach $this->assertTrue(Auth::isEditor($tree, $moderator), 'moderator isEditor()'); 99bb88f16bSGreg Roach $this->assertTrue(Auth::isMember($tree, $moderator), 'moderator isMember()'); 100bb88f16bSGreg Roach 101bb88f16bSGreg Roach Auth::login($editor); 102bb88f16bSGreg Roach $this->assertFalse(Auth::isAdmin(), 'editor NOT isAdmin()'); 103bb88f16bSGreg Roach $this->assertFalse(Auth::isManager($tree, $editor), 'editor NOT isManager()'); 104bb88f16bSGreg Roach $this->assertFalse(Auth::isModerator($tree, $editor), 'editor isModerator()'); 105bb88f16bSGreg Roach $this->assertTrue(Auth::isEditor($tree, $editor), 'editor isEditor()'); 106bb88f16bSGreg Roach $this->assertTrue(Auth::isMember($tree, $editor), 'editor isMember()'); 107bb88f16bSGreg Roach 108bb88f16bSGreg Roach Auth::login($member); 109bb88f16bSGreg Roach $this->assertFalse(Auth::isAdmin(), 'member NOT isAdmin()'); 110bb88f16bSGreg Roach $this->assertFalse(Auth::isManager($tree, $member), 'member NOT isManager()'); 111bb88f16bSGreg Roach $this->assertFalse(Auth::isModerator($tree, $member), 'member isModerator()'); 112bb88f16bSGreg Roach $this->assertFalse(Auth::isEditor($tree, $member), 'member isEditor()'); 113bb88f16bSGreg Roach $this->assertTrue(Auth::isMember($tree, $member), 'member isMember()'); 114bb88f16bSGreg Roach 115bb88f16bSGreg Roach Auth::login($visitor); 116bb88f16bSGreg Roach $this->assertFalse(Auth::isAdmin(), 'visitor NOT isAdmin()'); 117bb88f16bSGreg Roach $this->assertFalse(Auth::isManager($tree, $visitor), 'visitor NOT isManager()'); 118bb88f16bSGreg Roach $this->assertFalse(Auth::isModerator($tree, $visitor), 'visitor isModerator()'); 119bb88f16bSGreg Roach $this->assertFalse(Auth::isEditor($tree, $visitor), 'visitor isEditor()'); 120bb88f16bSGreg Roach $this->assertFalse(Auth::isMember($tree, $visitor), 'visitor isMember()'); 121bb88f16bSGreg Roach 122bb88f16bSGreg Roach Auth::logout(); 123bb88f16bSGreg Roach 124bb88f16bSGreg Roach 125bb88f16bSGreg Roach 126bb88f16bSGreg Roach Auth::login($admin); 127bb88f16bSGreg Roach $this->assertTrue($queen_elizabeth->canShow(), 'admin can see living individual with RESN=none'); 128bb88f16bSGreg Roach $this->assertTrue($prince_charles->canShow(), 'admin can see living individual'); 129bb88f16bSGreg Roach 130bb88f16bSGreg Roach Auth::login($manager); 131bb88f16bSGreg Roach $this->assertTrue($queen_elizabeth->canShow(), 'manager can see living individual with RESN=none'); 132bb88f16bSGreg Roach $this->assertTrue($prince_charles->canShow(), 'manager can see living individual'); 133bb88f16bSGreg Roach 134bb88f16bSGreg Roach Auth::login($moderator); 135bb88f16bSGreg Roach $this->assertTrue($queen_elizabeth->canShow(), 'moderator can see living individual with RESN=none'); 136bb88f16bSGreg Roach $this->assertTrue($prince_charles->canShow(), 'moderator can see living individual'); 137bb88f16bSGreg Roach 138bb88f16bSGreg Roach Auth::login($editor); 139bb88f16bSGreg Roach $this->assertTrue($queen_elizabeth->canShow(), 'editor can see living individual with RESN=none'); 140bb88f16bSGreg Roach $this->assertTrue($prince_charles->canShow(), 'editor can see living individual'); 141bb88f16bSGreg Roach 142bb88f16bSGreg Roach Auth::login($member); 143bb88f16bSGreg Roach $this->assertTrue($queen_elizabeth->canShow(), 'member can see living individual with RESN=none'); 144bb88f16bSGreg Roach $this->assertTrue($prince_charles->canShow(), 'member can see living individual'); 145bb88f16bSGreg Roach 146bb88f16bSGreg Roach Auth::login($visitor); 147bb88f16bSGreg Roach $this->assertTrue($queen_elizabeth->canShow(), 'visitor can see living individual with RESN=none'); 148bb88f16bSGreg Roach $this->assertFalse($prince_charles->canShow(), 'visitor can not see living individual'); 149bb88f16bSGreg Roach 150bb88f16bSGreg Roach Auth::logout(); 151bb88f16bSGreg Roach $this->assertTrue($queen_elizabeth->canShow(), 'guest can see living individual with RESN=none'); 152bb88f16bSGreg Roach $this->assertFalse($prince_charles->canShow(), 'guest can not see living individual'); 153bb88f16bSGreg Roach 154bb88f16bSGreg Roach // Relationship privacy 155bb88f16bSGreg Roach Auth::login($member); 156bb88f16bSGreg Roach $this->assertTrue($beatrice->canShow()); 157bb88f16bSGreg Roach $tree->setUserPreference($member, User::PREF_TREE_ACCOUNT_XREF, $savannah->xref()); 158bb88f16bSGreg Roach $tree->setUserPreference($member, User::PREF_TREE_PATH_LENGTH, '3'); 159bb88f16bSGreg Roach $this->assertFalse($beatrice->canShow()); 160bb88f16bSGreg Roach $tree->setUserPreference($member, User::PREF_TREE_PATH_LENGTH, '4'); 161bb88f16bSGreg Roach $this->assertTrue($beatrice->canShow()); 162bb88f16bSGreg Roach } 163bb88f16bSGreg Roach} 164