6e588f0ba7aebf6e4cd2c122a12c1e6b8eac14f1
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Functional / Tca / BackendUsersVisibleFieldsTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Tca;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Tests\Functional\Form\FormTestService;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19 use TYPO3\CMS\Lang\LanguageService;
20
21 class BackendUsersVisibleFieldsTest extends \TYPO3\Components\TestingFramework\Core\FunctionalTestCase
22 {
23 protected static $backendUserFields = [
24 'disable',
25 'username',
26 'password',
27 'description',
28 'avatar',
29 'usergroup',
30 'admin',
31 'realName',
32 'email',
33 'lang',
34 'userMods',
35 'allowed_languages',
36 'workspace_perms',
37 'db_mountpoints',
38 'options',
39 'file_mountpoints',
40 'file_permissions',
41 'category_perms',
42 'lockToDomain',
43 'disableIPlock',
44 'TSconfig',
45 'starttime',
46 'endtime',
47 ];
48
49 protected static $adminHiddenFields = [
50 'userMods',
51 'allowed_languages',
52 'workspace_perms',
53 'file_permissions',
54 'category_perms',
55 'lockToDomain',
56 ];
57
58 /**
59 * @test
60 */
61 public function backendUsersFormContainsExpectedFields()
62 {
63 $this->setUpBackendUserFromFixture(1);
64 $GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageService::class);
65
66 $formEngineTestService = GeneralUtility::makeInstance(FormTestService::class);
67 $formResult = $formEngineTestService->createNewRecordForm('be_users');
68
69 foreach (static::$backendUserFields as $expectedField) {
70 $this->assertNotFalse(
71 strpos($formResult['html'], '[' . $expectedField . ']'),
72 'The field ' . $expectedField . ' is not in the HTML'
73 );
74 }
75
76 $this->assertNotFalse(
77 strpos($formResult['html'], 'Last login'),
78 'The field lastlogin is not in the HTML'
79 );
80 }
81
82 /**
83 * @test
84 */
85 public function backendUsersFormContainsExpectedFieldsForAdmins()
86 {
87 $this->setUpBackendUserFromFixture(1);
88 $GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageService::class);
89
90 $formEngineTestService = GeneralUtility::makeInstance(FormTestService::class);
91 $formResult = $formEngineTestService->createNewRecordForm('be_users', ['admin' => true]);
92
93 $expectedFields = array_diff(static::$backendUserFields, static::$adminHiddenFields);
94
95 foreach ($expectedFields as $expectedField) {
96 $this->assertNotFalse(
97 $formEngineTestService->formHtmlContainsField($expectedField, $formResult['html']),
98 'The field ' . $expectedField . ' is not in the HTML'
99 );
100 }
101
102 foreach (static::$adminHiddenFields as $hiddenField) {
103 $this->assertFalse(
104 $formEngineTestService->formHtmlContainsField($hiddenField, $formResult['html']),
105 'The field ' . $hiddenField . ' is in the HTML'
106 );
107 }
108
109 $this->assertNotFalse(
110 strpos($formResult['html'], 'Last login'),
111 'The field lastlogin is not in the HTML'
112 );
113 }
114 }