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