Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 57
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
phpbb_functional_switch_permissions_test
0.00% covered (danger)
0.00%
0 / 57
0.00% covered (danger)
0.00%
0 / 3
12
0.00% covered (danger)
0.00%
0 / 1
 setUp
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 test_switch_permissions_acp
0.00% covered (danger)
0.00%
0 / 24
0.00% covered (danger)
0.00%
0 / 1
2
 test_switch_permissions_ucp
0.00% covered (danger)
0.00%
0 / 29
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 *
4 * This file is part of the phpBB Forum Software package.
5 *
6 * @copyright (c) phpBB Limited <https://www.phpbb.com>
7 * @license GNU General Public License, version 2 (GPL-2.0)
8 *
9 * For full copyright and license information, please see
10 * the docs/CREDITS.txt file.
11 *
12 */
13
14/**
15 * @group functional
16 */
17class phpbb_functional_switch_permissions_test extends phpbb_functional_test_case
18{
19    private const TEST_USER = 'switch-permissions-test';
20
21    protected function setUp(): void
22    {
23        parent::setUp();
24
25        $this->login();
26        $this->admin_login();
27
28        $this->add_lang(['common', 'ucp']);
29    }
30
31    public function test_switch_permissions_acp()
32    {
33        $user_id = $this->create_user(self::TEST_USER);
34
35        // Open user administration page for new user
36        $crawler = self::request('GET', "adm/index.php?i=users&mode=overview&u={$user_id}&sid={$this->sid}");
37
38        // Use permissions
39        $link = $crawler->selectLink($this->lang('USE_PERMISSIONS'))->link();
40        $crawler = self::$client->click($link);
41
42        // Check that we switched permissions to test user
43        $this->assertStringContainsString(
44            str_replace('<br />', '<br>', $this->lang('PERMISSIONS_TRANSFERRED', self::TEST_USER)),
45            $crawler->html()
46        );
47
48        // Check that ACP pages get forced to acp main with restore permission info
49        $this->add_lang('acp/common');
50        $crawler = self::request('GET', "adm/index.php?i=users&mode=overview&u={$user_id}&sid={$this->sid}");
51        $this->assertStringContainsString(
52            $this->lang('PERMISSIONS_TRANSFERRED'),
53            $crawler->text()
54        );
55
56        // Check that restore permissions link exists
57        $crawler = self::$client->request('GET', '../index.php?sid=' . $this->sid);
58        $this->assertStringContainsString(
59            $this->lang('RESTORE_PERMISSIONS'),
60            $crawler->text()
61        );
62
63        // Check that restore permissions works
64        $crawler = self::$client->request('GET', 'ucp.php?mode=restore_perm&sid=' . $this->sid);
65        $this->assertStringContainsString(
66            $this->lang('PERMISSIONS_RESTORED'),
67            $crawler->text()
68        );
69    }
70
71    /**
72     * @depends test_switch_permissions_acp
73     */
74    public function test_switch_permissions_ucp()
75    {
76        $sql = 'SELECT user_id
77            FROM ' . USERS_TABLE . "
78            WHERE username = '" . self::TEST_USER . "'";
79        $result = $this->db->sql_query($sql);
80        $user_id = $this->db->sql_fetchfield('user_id');
81        $this->db->sql_freeresult($result);
82
83        // Open memberlist profile page for user
84        $crawler = self::request('GET', "memberlist.php?mode=viewprofile&u={$user_id}&sid={$this->sid}");
85
86        // Use permissions
87        $link = $crawler->selectLink($this->lang('USE_PERMISSIONS'))->link();
88        $crawler = self::$client->click($link);
89
90        // Check that we switched permissions to test user
91        $this->assertStringContainsString(
92            str_replace('<br />', '<br>', $this->lang('PERMISSIONS_TRANSFERRED', self::TEST_USER)),
93            $crawler->html()
94        );
95
96        // Check that UCP pages don't get forced to UCP main with restore permission info
97        $this->add_lang(['memberlist', 'ucp']);
98        $crawler = self::request('GET', "ucp.php?i=ucp_profile&mode=profile_info&sid={$this->sid}");
99        $this->assertStringContainsString(
100            $this->lang('EDIT_PROFILE'),
101            $crawler->text()
102        );
103
104        // Check that restore permissions link exists
105        $crawler = self::$client->request('GET', 'index.php?sid=' . $this->sid);
106        $this->assertStringContainsString(
107            $this->lang('RESTORE_PERMISSIONS'),
108            $crawler->text()
109        );
110
111        // Check that restore permissions works
112        $crawler = self::$client->request('GET', 'ucp.php?mode=restore_perm&sid=' . $this->sid);
113        $this->assertStringContainsString(
114            $this->lang('PERMISSIONS_RESTORED'),
115            $crawler->text()
116        );
117    }
118}