From b1282fcbc7a06c8f108d631341aa3e15284cb057 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 10 Oct 2024 21:38:19 +0200 Subject: [PATCH] [ticket/17410] Only fall back acp main page when in ACP with test permission PHPBB-17410 --- phpBB/includes/functions_module.php | 4 +- tests/functional/switch_permissions_test.php | 51 +++++++++++++++++++- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 53ea967fac..573c4146d1 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -502,8 +502,8 @@ class p_master $id = $this->p_class . '_' . $id; } - // Fallback to acp main page for special restore permission mode - if ($user->data['user_perm_from'] && $auth->acl_get('a_switchperm')) + // Fallback to acp main page for special test permission mode + if ($this->p_class === 'acp' && $user->data['user_perm_from'] && $auth->acl_get('a_switchperm')) { $id = ''; $mode = ''; diff --git a/tests/functional/switch_permissions_test.php b/tests/functional/switch_permissions_test.php index a8c64422f3..b7e8819a6e 100644 --- a/tests/functional/switch_permissions_test.php +++ b/tests/functional/switch_permissions_test.php @@ -28,7 +28,7 @@ class phpbb_functional_switch_permissions_test extends phpbb_functional_test_cas $this->add_lang(['common', 'ucp']); } - public function test_switch_permissions() + public function test_switch_permissions_acp() { $user_id = $this->create_user(self::TEST_USER); @@ -67,4 +67,53 @@ class phpbb_functional_switch_permissions_test extends phpbb_functional_test_cas $crawler->text() ); } + + /** + * @depends test_switch_permissions_acp + */ + public function test_switch_permissions_ucp() + { + $db = $this->get_db(); + $sql = 'SELECT user_id + FROM ' . USERS_TABLE . " + WHERE username = '" . self::TEST_USER . "'"; + $result = $db->sql_query($sql); + $user_id = $db->sql_fetchfield('user_id'); + $db->sql_freeresult($result); + + // Open memberlist profile page for user + $crawler = self::request('GET', "memberlist.php?mode=viewprofile&u={$user_id}&sid={$this->sid}"); + + // Use permissions + $link = $crawler->selectLink($this->lang('USE_PERMISSIONS'))->link(); + $crawler = self::$client->click($link); + + // Check that we switched permissions to test user + $this->assertStringContainsString( + str_replace('
', '
', $this->lang('PERMISSIONS_TRANSFERRED', self::TEST_USER)), + $crawler->html() + ); + + // Check that UCP pages don't get forced to UCP main with restore permission info + $this->add_lang(['memberlist', 'ucp']); + $crawler = self::request('GET', "ucp.php?i=ucp_profile&mode=profile_info&sid={$this->sid}"); + $this->assertStringContainsString( + $this->lang('EDIT_PROFILE'), + $crawler->text() + ); + + // Check that restore permissions link exists + $crawler = self::$client->request('GET', 'index.php?sid=' . $this->sid); + $this->assertStringContainsString( + $this->lang('RESTORE_PERMISSIONS'), + $crawler->text() + ); + + // Check that restore permissions works + $crawler = self::$client->request('GET', 'ucp.php?mode=restore_perm&sid=' . $this->sid); + $this->assertStringContainsString( + $this->lang('PERMISSIONS_RESTORED'), + $crawler->text() + ); + } }