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 416b9cb339SGreg Roach $queen_elizabeth = Registry::individualFactory()->make('X1030', $tree); 42*5e933c21SGreg Roach self::assertInstanceOf(Individual::class, $queen_elizabeth); 43*5e933c21SGreg Roach self::assertSame('Queen Elizabeth II', strip_tags($queen_elizabeth->fullName())); 44bb88f16bSGreg Roach 456b9cb339SGreg Roach $prince_charles = Registry::individualFactory()->make('X1052', $tree); 46*5e933c21SGreg Roach self::assertInstanceOf(Individual::class, $prince_charles); 47*5e933c21SGreg Roach self::assertSame('Charles, Prince of Wales', strip_tags($prince_charles->fullName())); 48bb88f16bSGreg Roach 496b9cb339SGreg Roach $savannah = Registry::individualFactory()->make('X1044', $tree); 50*5e933c21SGreg Roach self::assertInstanceOf(Individual::class, $savannah); 51*5e933c21SGreg Roach self::assertSame('Savannah Anne Kathleen Phillips', strip_tags($savannah->fullName())); 52bb88f16bSGreg Roach 536b9cb339SGreg Roach $beatrice = Registry::individualFactory()->make('X1047', $tree); 54*5e933c21SGreg Roach self::assertInstanceOf(Individual::class, $beatrice); 55*5e933c21SGreg Roach self::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); 81*5e933c21SGreg Roach self::assertTrue(Auth::isAdmin(), 'admin isAdmin()'); 82*5e933c21SGreg Roach self::assertTrue(Auth::isManager($tree), 'admin isManager()'); 83*5e933c21SGreg Roach self::assertTrue(Auth::isModerator($tree), 'admin isModerator()'); 84*5e933c21SGreg Roach self::assertTrue(Auth::isEditor($tree), 'admin isEditor()'); 85*5e933c21SGreg Roach self::assertTrue(Auth::isMember($tree), 'admin isMember()'); 86bb88f16bSGreg Roach 87bb88f16bSGreg Roach Auth::login($manager); 88*5e933c21SGreg Roach self::assertFalse(Auth::isAdmin(), 'manager NOT isAdmin()'); 89*5e933c21SGreg Roach self::assertTrue(Auth::isManager($tree, $manager), 'manager isManager()'); 90*5e933c21SGreg Roach self::assertTrue(Auth::isModerator($tree, $manager), 'manager isModerator()'); 91*5e933c21SGreg Roach self::assertTrue(Auth::isEditor($tree, $manager), 'manager isEditor()'); 92*5e933c21SGreg Roach self::assertTrue(Auth::isMember($tree, $manager), 'manager isMember()'); 93bb88f16bSGreg Roach 94bb88f16bSGreg Roach Auth::login($moderator); 95*5e933c21SGreg Roach self::assertFalse(Auth::isAdmin(), 'moderator NOT isAdmin()'); 96*5e933c21SGreg Roach self::assertFalse(Auth::isManager($tree, $moderator), 'moderator NOT isManager()'); 97*5e933c21SGreg Roach self::assertTrue(Auth::isModerator($tree, $moderator), 'moderator isModerator()'); 98*5e933c21SGreg Roach self::assertTrue(Auth::isEditor($tree, $moderator), 'moderator isEditor()'); 99*5e933c21SGreg Roach self::assertTrue(Auth::isMember($tree, $moderator), 'moderator isMember()'); 100bb88f16bSGreg Roach 101bb88f16bSGreg Roach Auth::login($editor); 102*5e933c21SGreg Roach self::assertFalse(Auth::isAdmin(), 'editor NOT isAdmin()'); 103*5e933c21SGreg Roach self::assertFalse(Auth::isManager($tree, $editor), 'editor NOT isManager()'); 104*5e933c21SGreg Roach self::assertFalse(Auth::isModerator($tree, $editor), 'editor isModerator()'); 105*5e933c21SGreg Roach self::assertTrue(Auth::isEditor($tree, $editor), 'editor isEditor()'); 106*5e933c21SGreg Roach self::assertTrue(Auth::isMember($tree, $editor), 'editor isMember()'); 107bb88f16bSGreg Roach 108bb88f16bSGreg Roach Auth::login($member); 109*5e933c21SGreg Roach self::assertFalse(Auth::isAdmin(), 'member NOT isAdmin()'); 110*5e933c21SGreg Roach self::assertFalse(Auth::isManager($tree, $member), 'member NOT isManager()'); 111*5e933c21SGreg Roach self::assertFalse(Auth::isModerator($tree, $member), 'member isModerator()'); 112*5e933c21SGreg Roach self::assertFalse(Auth::isEditor($tree, $member), 'member isEditor()'); 113*5e933c21SGreg Roach self::assertTrue(Auth::isMember($tree, $member), 'member isMember()'); 114bb88f16bSGreg Roach 115bb88f16bSGreg Roach Auth::login($visitor); 116*5e933c21SGreg Roach self::assertFalse(Auth::isAdmin(), 'visitor NOT isAdmin()'); 117*5e933c21SGreg Roach self::assertFalse(Auth::isManager($tree, $visitor), 'visitor NOT isManager()'); 118*5e933c21SGreg Roach self::assertFalse(Auth::isModerator($tree, $visitor), 'visitor isModerator()'); 119*5e933c21SGreg Roach self::assertFalse(Auth::isEditor($tree, $visitor), 'visitor isEditor()'); 120*5e933c21SGreg Roach self::assertFalse(Auth::isMember($tree, $visitor), 'visitor isMember()'); 121bb88f16bSGreg Roach 122bb88f16bSGreg Roach Auth::logout(); 123bb88f16bSGreg Roach 124bb88f16bSGreg Roach 125bb88f16bSGreg Roach 126bb88f16bSGreg Roach Auth::login($admin); 127*5e933c21SGreg Roach self::assertTrue($queen_elizabeth->canShow(), 'admin can see living individual with RESN=none'); 128*5e933c21SGreg Roach self::assertTrue($prince_charles->canShow(), 'admin can see living individual'); 129bb88f16bSGreg Roach 130bb88f16bSGreg Roach Auth::login($manager); 131*5e933c21SGreg Roach self::assertTrue($queen_elizabeth->canShow(), 'manager can see living individual with RESN=none'); 132*5e933c21SGreg Roach self::assertTrue($prince_charles->canShow(), 'manager can see living individual'); 133bb88f16bSGreg Roach 134bb88f16bSGreg Roach Auth::login($moderator); 135*5e933c21SGreg Roach self::assertTrue($queen_elizabeth->canShow(), 'moderator can see living individual with RESN=none'); 136*5e933c21SGreg Roach self::assertTrue($prince_charles->canShow(), 'moderator can see living individual'); 137bb88f16bSGreg Roach 138bb88f16bSGreg Roach Auth::login($editor); 139*5e933c21SGreg Roach self::assertTrue($queen_elizabeth->canShow(), 'editor can see living individual with RESN=none'); 140*5e933c21SGreg Roach self::assertTrue($prince_charles->canShow(), 'editor can see living individual'); 141bb88f16bSGreg Roach 142bb88f16bSGreg Roach Auth::login($member); 143*5e933c21SGreg Roach self::assertTrue($queen_elizabeth->canShow(), 'member can see living individual with RESN=none'); 144*5e933c21SGreg Roach self::assertTrue($prince_charles->canShow(), 'member can see living individual'); 145bb88f16bSGreg Roach 146bb88f16bSGreg Roach Auth::login($visitor); 147*5e933c21SGreg Roach self::assertTrue($queen_elizabeth->canShow(), 'visitor can see living individual with RESN=none'); 148*5e933c21SGreg Roach self::assertFalse($prince_charles->canShow(), 'visitor can not see living individual'); 149bb88f16bSGreg Roach 150bb88f16bSGreg Roach Auth::logout(); 151*5e933c21SGreg Roach self::assertTrue($queen_elizabeth->canShow(), 'guest can see living individual with RESN=none'); 152*5e933c21SGreg Roach self::assertFalse($prince_charles->canShow(), 'guest can not see living individual'); 153bb88f16bSGreg Roach 154bb88f16bSGreg Roach // Relationship privacy 155bb88f16bSGreg Roach Auth::login($member); 156*5e933c21SGreg Roach self::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'); 159*5e933c21SGreg Roach self::assertFalse($beatrice->canShow()); 160bb88f16bSGreg Roach $tree->setUserPreference($member, User::PREF_TREE_PATH_LENGTH, '4'); 161*5e933c21SGreg Roach self::assertTrue($beatrice->canShow()); 162bb88f16bSGreg Roach } 163bb88f16bSGreg Roach} 164