‪TYPO3CMS  ‪main
BackendUsersVisibleFieldsTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\Attributes\Test;
24 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
25 
26 final class ‪BackendUsersVisibleFieldsTest extends FunctionalTestCase
27 {
28  protected static ‪$backendUserFields = [
29  'disable',
30  'username',
31  'password',
32  'description',
33  'avatar',
34  'usergroup',
35  'admin',
36  'realName',
37  'email',
38  'lang',
39  'userMods',
40  'allowed_languages',
41  'db_mountpoints',
42  'options',
43  'file_mountpoints',
44  'file_permissions',
45  'category_perms',
46  'TSconfig',
47  'starttime',
48  'endtime',
49  ];
50 
51  protected static ‪$adminHiddenFields = [
52  'userMods',
53  'allowed_languages',
54  'workspace_perms',
55  'file_permissions',
56  'category_perms',
57  ];
58 
59  protected static ‪$specialFields = [
60  'mfa' => 'Multi-factor authentication',
61  'lastlogin' => 'Last login',
62  ];
63 
64  #[Test]
66  {
67  $this->importCSVDataSet(__DIR__ . '/../Fixtures/be_users.csv');
68  $this->setUpBackendUser(1);
69  ‪$GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageServiceFactory::class)->create('default');
70 
71  $formEngineTestService = GeneralUtility::makeInstance(FormTestService::class);
72  $formResult = $formEngineTestService->createNewRecordForm('be_users');
73 
74  foreach (static::$backendUserFields as $expectedField) {
75  self::assertNotFalse(
76  $formEngineTestService->formHtmlContainsField($expectedField, $formResult['html']),
77  'The field ' . $expectedField . ' is not in the HTML'
78  );
79  }
80 
81  foreach (static::$specialFields as $fieldName => $searchString) {
82  self::assertNotFalse(
83  strpos($formResult['html'], $searchString),
84  'The field ' . $fieldName . ' is not in the HTML'
85  );
86  }
87  }
88 
89  #[Test]
91  {
92  $this->importCSVDataSet(__DIR__ . '/../Fixtures/be_users.csv');
93  $this->setUpBackendUser(1);
94  ‪$GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageServiceFactory::class)->create('default');
95 
96  $formEngineTestService = GeneralUtility::makeInstance(FormTestService::class);
97  $formResult = $formEngineTestService->createNewRecordForm('be_users', ['admin' => true]);
98 
99  $expectedFields = array_diff(static::$backendUserFields, static::$adminHiddenFields);
100 
101  foreach ($expectedFields as $expectedField) {
102  self::assertNotFalse(
103  $formEngineTestService->formHtmlContainsField($expectedField, $formResult['html']),
104  'The field ' . $expectedField . ' is not in the HTML'
105  );
106  }
107 
108  foreach (static::$adminHiddenFields as $hiddenField) {
109  self::assertFalse(
110  $formEngineTestService->formHtmlContainsField($hiddenField, $formResult['html']),
111  'The field ' . $hiddenField . ' is in the HTML'
112  );
113  }
114 
115  foreach (static::$specialFields as $fieldName => $searchString) {
116  self::assertNotFalse(
117  strpos($formResult['html'], $searchString),
118  'The field ' . $fieldName . ' is not in the HTML'
119  );
120  }
121  }
122 }
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory
Definition: LanguageServiceFactory.php:25
‪TYPO3\CMS\Core\Tests\Functional\Tca\BackendUsersVisibleFieldsTest
Definition: BackendUsersVisibleFieldsTest.php:27
‪TYPO3\CMS\Core\Tests\Functional\Tca\BackendUsersVisibleFieldsTest\$backendUserFields
‪static $backendUserFields
Definition: BackendUsersVisibleFieldsTest.php:28
‪TYPO3\CMS\Core\Tests\Functional\Tca
Definition: AfterTcaCompilationEventTest.php:18
‪TYPO3\CMS\Core\Tests\Functional\Tca\BackendUsersVisibleFieldsTest\backendUsersFormContainsExpectedFields
‪backendUsersFormContainsExpectedFields()
Definition: BackendUsersVisibleFieldsTest.php:65
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\Tests\Functional\Form\FormTestService
Definition: FormTestService.php:32
‪TYPO3\CMS\Core\Tests\Functional\Tca\BackendUsersVisibleFieldsTest\$specialFields
‪static $specialFields
Definition: BackendUsersVisibleFieldsTest.php:59
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Tests\Functional\Tca\BackendUsersVisibleFieldsTest\$adminHiddenFields
‪static $adminHiddenFields
Definition: BackendUsersVisibleFieldsTest.php:51
‪TYPO3\CMS\Core\Tests\Functional\Tca\BackendUsersVisibleFieldsTest\backendUsersFormContainsExpectedFieldsForAdmins
‪backendUsersFormContainsExpectedFieldsForAdmins()
Definition: BackendUsersVisibleFieldsTest.php:90