‪TYPO3CMS  ‪main
PagesTsConfigGuardTest.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;
29 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
30 
31 final class ‪PagesTsConfigGuardTest extends FunctionalTestCase
32 {
34 
35  private const ‪LANGUAGE_PRESETS = [
36  'EN' => ['id' => 0, 'title' => 'English', 'locale' => 'en_US.UTF8'],
37  ];
38 
39  protected function ‪setUp(): void
40  {
41  parent::setUp();
42  $this->importCSVDataSet(__DIR__ . '/../DataSet/ImportDefault.csv');
43  $this->importCSVDataSet(__DIR__ . '/../../../Fixtures/be_groups.csv');
44  $this->importCSVDataSet(__DIR__ . '/../../../Fixtures/be_users.csv');
45 
47  'test',
48  $this->‪buildSiteConfiguration(1, '/'),
49  [
50  $this->‪buildDefaultLanguageConfiguration('EN', '/'),
51  ]
52  );
53  // define page create permissions for backend user group 9 on page 1
54  GeneralUtility::makeInstance(ConnectionPool::class)
55  ->getConnectionForTable('pages')
56  ->update(
57  'pages',
58  ['perms_groupid' => 9, 'perms_group' => ‪Permission::ALL],
59  ['uid' => 1]
60  );
61  }
62 
63  #[Test]
64  public function ‪pagesTsConfigIsConsideredForAdminUser(): void
65  {
67  $backendUser = $this->setUpBackendUser(1);
68  ‪$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->createFromUserPreferences($backendUser);
69 
70  $dataMap = [
71  'pages' => [
72  ‪$identifier => [
73  'pid' => 1,
74  'title' => 'New page',
75  'TSconfig' => 'custom.setting = 1',
76  'tsconfig_includes' => 'EXT:package/file.tsconfig',
77  ],
78  ],
79  ];
80 
81  $this->‪assertProcessedDataMap($dataMap, $backendUser);
82  $this->assertCSVDataSet(__DIR__ . '/DataSet/pagesTsConfigIsConsideredForAdminUser.csv');
83  }
84 
85  #[Test]
86  public function ‪pagesTsConfigIsIgnoredForNonAdminUser(): void
87  {
89  $backendUser = $this->setUpBackendUser(9);
90  ‪$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->createFromUserPreferences($backendUser);
91 
92  $dataMap = [
93  'pages' => [
94  ‪$identifier => [
95  'pid' => 1,
96  'title' => 'New page',
97  'TSconfig' => 'custom.setting = 1',
98  'tsconfig_includes' => 'EXT:package/file.tsconfig',
99  ],
100  ],
101  ];
102 
103  $this->‪assertProcessedDataMap($dataMap, $backendUser);
104  $this->assertCSVDataSet(__DIR__ . '/DataSet/pagesTsConfigIsIgnoredForNonAdminUser.csv');
105  }
106 
107  private function ‪assertProcessedDataMap(array $dataMap, ‪BackendUserAuthentication $backendUser): void
108  {
109  $dataHandler = GeneralUtility::makeInstance(DataHandler::class);
110  $dataHandler->start($dataMap, [], $backendUser);
111  $dataHandler->process_datamap();
112  self::assertEmpty($dataHandler->errorLog);
113  }
114 }
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory
Definition: LanguageServiceFactory.php:25
‪TYPO3\CMS\Core\DataHandling\DataHandler
Definition: DataHandler.php:94
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Regular\Hooks\PagesTsConfigGuardTest\setUp
‪setUp()
Definition: PagesTsConfigGuardTest.php:38
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Regular\Hooks\PagesTsConfigGuardTest\LANGUAGE_PRESETS
‪const LANGUAGE_PRESETS
Definition: PagesTsConfigGuardTest.php:34
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Regular\Hooks\PagesTsConfigGuardTest\pagesTsConfigIsConsideredForAdminUser
‪pagesTsConfigIsConsideredForAdminUser()
Definition: PagesTsConfigGuardTest.php:63
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Regular\Hooks\PagesTsConfigGuardTest\assertProcessedDataMap
‪assertProcessedDataMap(array $dataMap, BackendUserAuthentication $backendUser)
Definition: PagesTsConfigGuardTest.php:106
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Regular\Hooks\PagesTsConfigGuardTest
Definition: PagesTsConfigGuardTest.php:32
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait
Definition: SiteBasedTestTrait.php:37
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\writeSiteConfiguration
‪writeSiteConfiguration(string $identifier, array $site=[], array $languages=[], array $errorHandling=[])
Definition: SiteBasedTestTrait.php:50
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildSiteConfiguration
‪buildSiteConfiguration(int $rootPageId, string $base='')
Definition: SiteBasedTestTrait.php:88
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:26
‪TYPO3\CMS\Core\Type\Bitmask\Permission\ALL
‪const ALL
Definition: Permission.php:60
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Regular\Hooks
Definition: PagesTsConfigGuardTest.php:18
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildDefaultLanguageConfiguration
‪buildDefaultLanguageConfiguration(string $identifier, string $base)
Definition: SiteBasedTestTrait.php:98
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Regular\Hooks\PagesTsConfigGuardTest\pagesTsConfigIsIgnoredForNonAdminUser
‪pagesTsConfigIsIgnoredForNonAdminUser()
Definition: PagesTsConfigGuardTest.php:85
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:24
‪TYPO3\CMS\Webhooks\Message\$identifier
‪identifier readonly string $identifier
Definition: FileAddedMessage.php:37
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static getUniqueId(string $prefix='')
Definition: StringUtility.php:57