‪TYPO3CMS  ‪main
PagePermissionTest.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;
21 use TYPO3\CMS\Backend\Utility\BackendUtility;
25 use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\ActionService;
26 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
27 
31 final class ‪PagePermissionTest extends FunctionalTestCase
32 {
33  protected array ‪$testExtensionsToLoad = [
34  'typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_defaulttsconfig',
35  ];
36 
38  'BE' => [
39  'defaultPermissions' => [
40  'user' => 'show,editcontent,edit,delete',
41  'group' => 'show,editcontent,new',
42  'everybody' => 'show',
43  ],
44  ],
45  ];
46 
48  private ActionService ‪$actionService;
49 
50  protected function ‪setUp(): void
51  {
52  parent::setUp();
53  $this->importCSVDataSet(__DIR__ . '/../../Fixtures/be_users_admin.csv');
54  $this->importCSVDataSet(__DIR__ . '/DataSet/LiveDefaultPages.csv');
55  $this->backendUser = $this->setUpBackendUser(1);
56  ‪$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->createFromUserPreferences($this->backendUser);
57  $this->actionService = new ActionService();
58  }
59 
60  #[Test]
62  {
63  $this->backendUser->user['uid'] = 13;
64  $this->backendUser->firstMainGroup = 14;
65  // Defaults from ext:test_defaulttsconfig/Configuration/page.tsconfig do not kick in, it's not below page 88
66  ‪$record = $this->‪insertPage(1);
67  self::assertEquals(13, ‪$record['perms_userid']);
68  self::assertEquals(14, ‪$record['perms_groupid']);
71  self::assertEquals(‪Permission::PAGE_SHOW, ‪$record['perms_everybody']);
72  }
73 
74  #[Test]
76  {
77  $this->backendUser->user['uid'] = 13;
78  $this->backendUser->firstMainGroup = 14;
79  // Defaults from ext:test_defaulttsconfig/Configuration/page.tsconfig kick in here for pages below 88
80  ‪$record = $this->‪insertPage();
81  self::assertEquals(12, ‪$record['perms_userid']);
82  self::assertEquals(42, ‪$record['perms_groupid']);
83  self::assertEquals(‪Permission::PAGE_SHOW + ‪Permission::PAGE_EDIT, ‪$record['perms_user']);
84  self::assertEquals(‪Permission::PAGE_SHOW + ‪Permission::PAGE_DELETE, ‪$record['perms_group']);
85  self::assertEquals(‪Permission::PAGE_SHOW + ‪Permission::PAGE_DELETE, ‪$record['perms_everybody']);
86  }
87 
88  #[Test]
90  {
91  $this->backendUser->user['uid'] = 13;
92  $this->backendUser->firstMainGroup = 14;
93  // Defaults from ext:test_defaulttsconfig/Configuration/page.tsconfig kick in here for pages below 88
94  $parent = $this->‪insertPage(88, [
95  'title' => 'Test page',
96  'TSconfig' => '
97 TCEMAIN.permissions.userid = copyFromParent
98 TCEMAIN.permissions.groupid = copyFromParent
99 TCEMAIN.permissions.user = copyFromParent
100 TCEMAIN.permissions.group = copyFromParent
101 TCEMAIN.permissions.everybody = copyFromParent
102  ',
103  ]);
104 
105  // We change perm settings of recently added page, so we can really check
106  // if perm settings are copied from parent page and not using default settings.
107  $this->actionService->modifyRecord(
108  'pages',
109  (int)$parent['uid'],
110  [
111  'perms_userid' => 1,
112  'perms_groupid' => 1,
113  'perms_user' => ‪Permission::PAGE_SHOW,
114  'perms_group' => ‪Permission::PAGE_SHOW,
115  'perms_everybody' => ‪Permission::PAGE_SHOW,
116  ]
117  );
118 
119  // Insert second page which should inherit settings from page 88
120  ‪$record = $this->‪insertPage((int)$parent['uid']);
121 
122  self::assertEquals(1, ‪$record['perms_userid']);
123  self::assertEquals(1, ‪$record['perms_groupid']);
124  self::assertEquals(‪Permission::PAGE_SHOW, ‪$record['perms_user']);
125  self::assertEquals(‪Permission::PAGE_SHOW, ‪$record['perms_group']);
126  self::assertEquals(‪Permission::PAGE_SHOW, ‪$record['perms_everybody']);
127  }
128 
129  private function ‪insertPage(int $pageId = 88, array ‪$fields = ['title' => 'Test page']): array
130  {
131  // pid 88 comes from ImportDefault
132  $result = $this->actionService->createNewRecord('pages', $pageId, ‪$fields);
133  $recordUid = $result['pages'][0];
134  return BackendUtility::getRecord('pages', $recordUid);
135  }
136 }
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory
Definition: LanguageServiceFactory.php:25
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\PagePermissionTest\$actionService
‪ActionService $actionService
Definition: PagePermissionTest.php:48
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\PagePermissionTest\$testExtensionsToLoad
‪array $testExtensionsToLoad
Definition: PagePermissionTest.php:33
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\PagePermissionTest\newPageReceivesOverriddenPageTsPermissionSetFromParent
‪newPageReceivesOverriddenPageTsPermissionSetFromParent()
Definition: PagePermissionTest.php:89
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler
Definition: CheckboxValidationTest.php:18
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_NEW
‪const PAGE_NEW
Definition: Permission.php:50
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\PagePermissionTest\setUp
‪setUp()
Definition: PagePermissionTest.php:50
‪$fields
‪$fields
Definition: pages.php:5
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:26
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\PagePermissionTest\$configurationToUseInTestInstance
‪array $configurationToUseInTestInstance
Definition: PagePermissionTest.php:37
‪TYPO3\CMS\Webhooks\Message\$record
‪identifier readonly int readonly array $record
Definition: PageModificationMessage.php:36
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\PagePermissionTest\insertPage
‪insertPage(int $pageId=88, array $fields=['title'=> 'Test page'])
Definition: PagePermissionTest.php:129
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:61
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_SHOW
‪const PAGE_SHOW
Definition: Permission.php:35
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\PagePermissionTest\newPageReceivesOverriddenPageTsPermissionSet
‪newPageReceivesOverriddenPageTsPermissionSet()
Definition: PagePermissionTest.php:75
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\PagePermissionTest\newPageReceivesDefaultPermissionSet
‪newPageReceivesDefaultPermissionSet()
Definition: PagePermissionTest.php:61
‪TYPO3\CMS\Core\Type\Bitmask\Permission\CONTENT_EDIT
‪const CONTENT_EDIT
Definition: Permission.php:55
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_EDIT
‪const PAGE_EDIT
Definition: Permission.php:40
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_DELETE
‪const PAGE_DELETE
Definition: Permission.php:45
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\PagePermissionTest\$backendUser
‪BackendUserAuthentication $backendUser
Definition: PagePermissionTest.php:47
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\PagePermissionTest
Definition: PagePermissionTest.php:32