UsersCest.php 10.9 KB
Newer Older
Alexander Nitsche's avatar
Alexander Nitsche committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php

declare(strict_types=1);

/*
 * This file is part of the TYPO3 CMS project.
 *
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
 *
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
 *
 * The TYPO3 project - inspiring people to share!
 */

18
namespace TYPO3\CMS\Core\Tests\Acceptance\Application\Impexp;
Alexander Nitsche's avatar
Alexander Nitsche committed
19

20
use TYPO3\CMS\Core\Tests\Acceptance\Support\ApplicationTester;
Alexander Nitsche's avatar
Alexander Nitsche committed
21
22
23
24
25
26
27
use TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\PageTree;

/**
 * Various context menu related tests
 */
class UsersCest extends AbstractCest
{
28
29
30
31
32
33
34
    protected string $inPageTree = '#typo3-pagetree-treeContainer .nodes';
    protected string $inModuleHeader = '.module-docheader';
    protected string $inModuleTabs = '#ImportExportController .nav-tabs';
    protected string $inModuleTabsBody = '#ImportExportController .tab-content';

    protected string $buttonUser = '#typo3-cms-backend-backend-toolbaritems-usertoolbaritem';
    protected string $buttonLogout = '#typo3-cms-backend-backend-toolbaritems-usertoolbaritem button.btn.btn-danger';
35
36
37
    protected string $contextMenuMore = '#contentMenu0 li.context-menu-item-submenu';
    protected string $contextMenuExport = '#contentMenu1 li.context-menu-item[data-callback-action=exportT3d]';
    protected string $contextMenuImport = '#contentMenu1 li.context-menu-item[data-callback-action=importT3d]';
38
39
40
    protected string $buttonViewPage = 'span[data-identifier="actions-view-page"]';
    protected string $tabUpload = 'a[href="#import-upload"]';
    protected string $checkboxForceAllUids = 'input#checkForce_all_UIDS';
Alexander Nitsche's avatar
Alexander Nitsche committed
41
42
43
44

    /**
     * @throws \Exception
     */
45
    public function _before(ApplicationTester $I): void
Alexander Nitsche's avatar
Alexander Nitsche committed
46
47
48
49
50
51
52
53
54
    {
        $I->useExistingSession('admin');
        $I->click('List');
        $I->waitForElement('svg .nodes .node');
    }

    /**
     * @throws \Exception
     */
55
    public function doNotShowImportAndExportInContextMenuForNonAdminUser(ApplicationTester $I, PageTree $pageTree): void
Alexander Nitsche's avatar
Alexander Nitsche committed
56
57
58
59
60
61
62
63
64
65
    {
        $selectedPageTitle = 'Root';
        $selectedPageIcon = '//*[text()=\'' . $selectedPageTitle . '\']/../*[contains(@class, \'node-icon-container\')]';

        $this->setPageAccess($I, $pageTree, [$selectedPageTitle], 1);
        $this->setModAccess($I, 1, ['web_list' => true]);
        $this->setUserTsConfig($I, 2, '');
        $I->useExistingSession('editor');

        $I->click($selectedPageIcon);
66
67
        $this->selectInContextMenu($I, [$this->contextMenuMore]);
        $I->waitForElementVisible('#contentMenu1', 5);
68
        $I->dontSeeElement($this->contextMenuExport);
Alexander Nitsche's avatar
Alexander Nitsche committed
69
70
71
72
73
74
75
76
        $I->dontSeeElement($this->contextMenuImport);

        $I->useExistingSession('admin');
    }

    /**
     * @throws \Exception
     */
77
    public function showImportExportInContextMenuForNonAdminUserIfFlagSet(ApplicationTester $I): void
Alexander Nitsche's avatar
Alexander Nitsche committed
78
79
80
81
    {
        $selectedPageTitle = 'Root';
        $selectedPageIcon = '//*[text()=\'' . $selectedPageTitle . '\']/../*[contains(@class, \'node-icon-container\')]';

82
        $this->setUserTsConfig($I, 2, "options.impexp.enableImportForNonAdminUser = 1\noptions.impexp.enableExportForNonAdminUser = 1");
Alexander Nitsche's avatar
Alexander Nitsche committed
83
84
85
        $I->useExistingSession('editor');

        $I->click($selectedPageIcon);
86
87
        $this->selectInContextMenu($I, [$this->contextMenuMore]);
        $I->waitForElementVisible('#contentMenu1', 5);
Alexander Nitsche's avatar
Alexander Nitsche committed
88
        $I->seeElement($this->contextMenuImport);
89
        $I->seeElement($this->contextMenuExport);
Alexander Nitsche's avatar
Alexander Nitsche committed
90
91
92
93
94
95
96

        $I->useExistingSession('admin');
    }

    /**
     * @throws \Exception
     */
97
    public function hideImportCheckboxForceAllUidsForNonAdmin(ApplicationTester $I): void
Alexander Nitsche's avatar
Alexander Nitsche committed
98
99
100
    {
        $selectedPageTitle = 'Root';
        $selectedPageIcon = '//*[text()=\'' . $selectedPageTitle . '\']/../*[contains(@class, \'node-icon-container\')]';
101
        $importPageSectionTitle = 'Select file to import';
Alexander Nitsche's avatar
Alexander Nitsche committed
102
103

        $I->click($selectedPageIcon);
104
        $this->selectInContextMenu($I, [$this->contextMenuMore, $this->contextMenuImport]);
Alexander Nitsche's avatar
Alexander Nitsche committed
105
106
107
108
109
110
        $I->switchToContentFrame();
        $I->seeElement($this->checkboxForceAllUids);

        $I->useExistingSession('editor');

        $I->click($selectedPageIcon);
111
        $this->selectInContextMenu($I, [$this->contextMenuMore, $this->contextMenuImport]);
Alexander Nitsche's avatar
Alexander Nitsche committed
112
        $I->switchToContentFrame();
113
        $I->waitForText($importPageSectionTitle);
Alexander Nitsche's avatar
Alexander Nitsche committed
114
115
116
117
118
119
120
121
        $I->dontSeeElement($this->checkboxForceAllUids);

        $I->useExistingSession('admin');
    }

    /**
     * @throws \Exception
     */
122
    public function hideUploadTabAndImportPathIfNoImportFolderAvailable(ApplicationTester $I, PageTree $pageTree): void
Alexander Nitsche's avatar
Alexander Nitsche committed
123
124
125
    {
        $selectedPageTitle = 'Root';
        $selectedPageIcon = '//*[text()=\'' . $selectedPageTitle . '\']/../*[contains(@class, \'node-icon-container\')]';
126
        $importPageSectionTitle = 'Select file to import';
Alexander Nitsche's avatar
Alexander Nitsche committed
127
128

        $I->click($selectedPageIcon);
129
        $this->selectInContextMenu($I, [$this->contextMenuMore, $this->contextMenuImport]);
Alexander Nitsche's avatar
Alexander Nitsche committed
130
131
132
133
134
135
136
        $I->switchToContentFrame();
        $I->see('From path:', $this->inModuleTabsBody);
        $I->seeElement($this->inModuleTabs . ' ' . $this->tabUpload);

        $I->useExistingSession('editor');

        $I->click($selectedPageIcon);
137
        $this->selectInContextMenu($I, [$this->contextMenuMore, $this->contextMenuImport]);
Alexander Nitsche's avatar
Alexander Nitsche committed
138
        $I->switchToContentFrame();
139
        $I->waitForText($importPageSectionTitle);
Alexander Nitsche's avatar
Alexander Nitsche committed
140
141
142
143
144
145
146
147
148
149
150
151
152
        $I->dontSee('From path:', $this->inModuleTabsBody);
        $I->dontSeeElement($this->inModuleTabs . ' ' . $this->tabUpload);

        $I->useExistingSession('admin');

        $this->setPageAccess($I, $pageTree, ['Root'], 0);
        $this->setModAccess($I, 1, ['web_list' => false]);
        $this->setUserTsConfig($I, 2, '');
    }

    /**
     * @throws \Exception
     */
153
    public function checkVisualElements(ApplicationTester $I, PageTree $pageTree): void
Alexander Nitsche's avatar
Alexander Nitsche committed
154
155
156
    {
        $selectedPageTitle = 'Root';
        $selectedPageIcon = '//*[text()=\'' . $selectedPageTitle . '\']/../*[contains(@class, \'node-icon-container\')]';
157
        $importPageSectionTitle = 'Select file to import';
Alexander Nitsche's avatar
Alexander Nitsche committed
158

159
        $I->click($this->inPageTree . ' #identifier-0_0 .node-icon-container');
160
        $this->selectInContextMenu($I, [$this->contextMenuMore, $this->contextMenuImport]);
Alexander Nitsche's avatar
Alexander Nitsche committed
161
        $I->switchToContentFrame();
162
        $I->waitForText($importPageSectionTitle);
Alexander Nitsche's avatar
Alexander Nitsche committed
163
164
165
166
167
168
        $I->dontSeeElement($this->inModuleHeader . ' ' . $this->buttonViewPage);

        $I->switchToMainFrame();

        $I->click('List');
        $I->click($selectedPageIcon);
169
        $this->selectInContextMenu($I, [$this->contextMenuMore, $this->contextMenuImport]);
Alexander Nitsche's avatar
Alexander Nitsche committed
170
171
172
173
174
175
176
177
178
        $I->switchToContentFrame();
        $I->seeElement($this->inModuleHeader . ' ' . $this->buttonViewPage);

        $this->setPageAccess($I, $pageTree, ['Root'], 1);
        $this->setModAccess($I, 1, ['web_list' => true]);
        $this->setUserTsConfig($I, 2, 'options.impexp.enableImportForNonAdminUser = 1');
        $I->useExistingSession('editor');

        $I->click($selectedPageIcon);
179
        $this->selectInContextMenu($I, [$this->contextMenuMore, $this->contextMenuImport]);
Alexander Nitsche's avatar
Alexander Nitsche committed
180
181
182
183
184
185
186
187
188
        $I->switchToContentFrame();
        $I->seeElement($this->inModuleHeader . ' ' . $this->buttonViewPage);

        $I->useExistingSession('admin');

        $this->setPageAccess($I, $pageTree, ['Root'], 0);
        $this->setModAccess($I, 1, ['web_list' => false]);
        $this->setUserTsConfig($I, 2, '');
    }
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258

    protected function setPageAccess(ApplicationTester $I, PageTree $pageTree, array $pagePath, int $userGroupId, int $recursionLevel = 1): void
    {
        $I->switchToMainFrame();
        $I->click('Access');
        $I->waitForElement($this->inPageTree . ' .node', 5);
        $pageTree->openPath($pagePath);
        $I->switchToContentFrame();
        $I->waitForElementVisible('//table[@id="typo3-permissionList"]/tbody/tr[1]/td[2]/a[@title="Change permissions"]');
        $I->click('//table[@id="typo3-permissionList"]/tbody/tr[1]/td[2]/a[@title="Change permissions"]');
        $I->waitForElementVisible('#PermissionControllerEdit');
        $I->selectOption('//select[@id="selectGroup"]', ['value' => $userGroupId]);
        $recursionLevelOption = $I->grabTextFrom('//select[@id="recursionLevel"]/option[' . $recursionLevel . ']');
        $I->selectOption('//select[@id="recursionLevel"]', ['value' => $recursionLevelOption]);
        $I->click($this->inModuleHeader . ' .btn[title="Save and close"]');
    }

    protected function setModAccess(ApplicationTester $I, int $userGroupId, array $modAccessByName): void
    {
        try {
            $I->seeElement($this->inModuleHeader . ' [name=BackendUserModuleMenu]');
        } catch (\Exception $e) {
            $I->switchToMainFrame();
            $I->click('Backend Users');
            $I->switchToContentFrame();
        }

        $I->waitForElementVisible($this->inModuleHeader . ' [name=BackendUserModuleMenu]');
        $I->selectOption($this->inModuleHeader . ' [name=BackendUserModuleMenu]', ['text'=>'Backend user groups']);
        $I->waitForText('Backend User Group Listing');
        $I->click('//table/tbody/tr[descendant::a[@data-uid="' . $userGroupId . '"]]/td[2]/a');
        $I->waitForElementVisible('#EditDocumentController');
        $I->click('//form[@id="EditDocumentController"]//ul/li[2]/a');

        foreach ($modAccessByName as $modName => $modAccess) {
            if ((bool)$modAccess) {
                $I->checkOption('//input[@value="' . $modName . '"]');
            } else {
                $I->uncheckOption('//input[@value="' . $modName . '"]');
            }
        }

        $I->click($this->inModuleHeader . ' .btn[title="Save"]');
        $I->wait(0.5);
        $I->click($this->inModuleHeader . ' .btn[title="Close"]');
        $I->waitForText('Backend User Group Listing');
    }

    protected function setUserTsConfig(ApplicationTester $I, int $userId, string $userTsConfig): void
    {
        try {
            $I->seeElement($this->inModuleHeader . ' [name=BackendUserModuleMenu]');
        } catch (\Exception $e) {
            $I->switchToMainFrame();
            $I->click('Backend Users');
            $I->switchToContentFrame();
        }

        $I->waitForElementVisible($this->inModuleHeader . ' [name=BackendUserModuleMenu]');
        $I->selectOption($this->inModuleHeader . ' [name=BackendUserModuleMenu]', ['text'=>'Backend users']);
        $I->waitForElement('#typo3-backend-user-list');
        $I->click('//table[@id="typo3-backend-user-list"]/tbody/tr[descendant::a[@data-uid="' . $userId . '"]]//a[@title="Edit"]');
        $I->waitForElement('#EditDocumentController');
        $I->click('//form[@id="EditDocumentController"]//ul/li[4]/a');
        $I->fillField('//div[@class="tab-content"]/div[4]/fieldset[1]//textarea', $userTsConfig);
        $I->click($this->inModuleHeader . ' .btn[title="Save"]');
        $I->wait(0.5);
        $I->click($this->inModuleHeader . ' .btn[title="Close"]');
        $I->waitForElement('#typo3-backend-user-list');
    }
Alexander Nitsche's avatar
Alexander Nitsche committed
259
}