‪TYPO3CMS  ‪main
BackendUserAuthenticationTest.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\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
23 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
24 
25 final class ‪BackendUserAuthenticationTest extends FunctionalTestCase
26 {
27  protected array ‪$testExtensionsToLoad = [
28  'typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_defaulttsconfig',
29  ];
30 
31  protected function ‪setUp(): void
32  {
33  parent::setUp();
34  $this->importCSVDataSet(__DIR__ . '/Fixtures/be_groups.csv');
35  $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv');
36  $this->importCSVDataSet(__DIR__ . '/Fixtures/be_users.csv');
37  $this->importCSVDataSet(__DIR__ . '/Fixtures/sys_filemounts.csv');
38  $this->importCSVDataSet(__DIR__ . '/../Fixtures/sys_file_storage.csv');
39  }
40 
41  #[Test]
43  {
44  $backendUser = $this->setUpBackendUser(3);
45  self::assertCount(3, $backendUser->getFileMountRecords());
46  }
47 
48  #[Test]
50  {
51  $subject = $this->setUpBackendUser(2);
52  self::assertNotNull($subject->isInWebMount(2));
53  }
54 
55  #[Test]
57  {
58  // Uses ext:test_defaulttsconfig/Configuration/user.tsconfig
59  $subject = $this->setUpBackendUser(2);
60  $subject->user['TSconfig'] = 'custom.property = from user';
61  $subject->userGroupsUID[] = 13;
62  $subject->userGroups[13]['TSconfig'] = "custom.property = from group\ncustom.groupProperty = 13";
63  $subject->fetchGroupData();
64  $result = $subject->getTSConfig();
65  self::assertEquals('from user', $result['custom.']['property']);
66  self::assertEquals('13', $result['custom.']['groupProperty']);
67  self::assertEquals('installation-wide-configuration', $result['custom.']['generic']);
68  }
69 
70  #[Test]
72  {
73  $subject = $this->setUpBackendUser(2);
74  $result = $subject->returnWebmounts();
75  self::assertNotContains('3', $result, 'Deleted page is not filtered out');
76  self::assertNotContains('4', $result, 'Page user has no permission to read is not filtered out');
77  self::assertNotContains('5', $result, 'Not existing page is not filtered out');
78  self::assertContains('40', $result, 'Accessible db mount page, child of a not accessible page is not shown');
79  self::assertEquals(['1', '40'], $result);
80  }
81 
82  #[Test]
84  {
85  $subject = $this->setUpBackendUser(3);
86  $subject->fetchGroupData();
87  self::assertEquals('web_info,web_layout,web_list,file_filelist', $subject->groupData['modules']);
88  self::assertEquals([1, 4, 5, 3, 2, 6], $subject->userGroupsUID);
89  self::assertEquals(['groupValue' => 'from_group_6', 'userValue' => 'from_user_3'], $subject->getTSConfig()['test.']['default.']);
90  }
91 
92  #[Test]
93  public function ‪mfaRequiredExceptionIsThrown(): void
94  {
95  $this->expectException(MfaRequiredException::class);
96  // This will set up a user and therefore implicit call the ->checkAuthentication() method
97  // which should fail since the user in the fixture has MFA activated but not yet passed.
98  $this->setUpBackendUser(4);
99  }
100 
101  public static function ‪isImportEnabledDataProvider(): array
102  {
103  return [
104  'admin user' => [
105  1,
106  true,
107  ],
108  'editor user' => [
109  2,
110  false,
111  ],
112  'editor user - enableImportForNonAdminUser = 1' => [
113  6,
114  true,
115  ],
116  ];
117  }
118 
119  #[DataProvider('isImportEnabledDataProvider')]
120  #[Test]
121  public function ‪isImportEnabledReturnsExpectedValues(int $userId, bool $expected): void
122  {
123  $subject = $this->setUpBackendUser($userId);
124  self::assertEquals($expected, $subject->isImportEnabled());
125  }
126 
127  public static function ‪isExportEnabledDataProvider(): array
128  {
129  return [
130  'admin user' => [
131  1,
132  true,
133  ],
134  'editor user' => [
135  2,
136  false,
137  ],
138  'editor user - enableExportForNonAdminUser = 1' => [
139  6,
140  true,
141  ],
142  ];
143  }
144 
145  #[DataProvider('isExportEnabledDataProvider')]
146  #[Test]
147  public function ‪isExportEnabledReturnsExpectedValues(int $userId, bool $expected): void
148  {
149  $subject = $this->setUpBackendUser($userId);
150  self::assertEquals($expected, $subject->isExportEnabled());
151  }
152 }
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\getFileMountRecordsReturnsFilemounts
‪getFileMountRecordsReturnsFilemounts()
Definition: BackendUserAuthenticationTest.php:42
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\userTsConfigIsResolvedProperlyWithPrioritization
‪userTsConfigIsResolvedProperlyWithPrioritization()
Definition: BackendUserAuthenticationTest.php:56
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\isImportEnabledDataProvider
‪static isImportEnabledDataProvider()
Definition: BackendUserAuthenticationTest.php:101
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\isImportEnabledReturnsExpectedValues
‪isImportEnabledReturnsExpectedValues(int $userId, bool $expected)
Definition: BackendUserAuthenticationTest.php:121
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest
Definition: BackendUserAuthenticationTest.php:26
‪TYPO3\CMS\Core\Authentication\Mfa\MfaRequiredException
Definition: MfaRequiredException.php:29
‪TYPO3\CMS\Core\Tests\Functional\Authentication
Definition: AbstractUserAuthenticationTest.php:18
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\setUp
‪setUp()
Definition: BackendUserAuthenticationTest.php:31
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\loadGroupsWithProperSettingsAndOrder
‪loadGroupsWithProperSettingsAndOrder()
Definition: BackendUserAuthenticationTest.php:83
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\getTranslatedPageOnWebMountIsInWebMountForNonAdminUser
‪getTranslatedPageOnWebMountIsInWebMountForNonAdminUser()
Definition: BackendUserAuthenticationTest.php:49
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\$testExtensionsToLoad
‪array $testExtensionsToLoad
Definition: BackendUserAuthenticationTest.php:27
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\isExportEnabledReturnsExpectedValues
‪isExportEnabledReturnsExpectedValues(int $userId, bool $expected)
Definition: BackendUserAuthenticationTest.php:147
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\isExportEnabledDataProvider
‪static isExportEnabledDataProvider()
Definition: BackendUserAuthenticationTest.php:127
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\mfaRequiredExceptionIsThrown
‪mfaRequiredExceptionIsThrown()
Definition: BackendUserAuthenticationTest.php:93
‪TYPO3\CMS\Core\Tests\Functional\Authentication\BackendUserAuthenticationTest\returnWebmountsFilterOutInaccessiblePages
‪returnWebmountsFilterOutInaccessiblePages()
Definition: BackendUserAuthenticationTest.php:71