‪TYPO3CMS  11.5
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 Symfony\Component\Yaml\Yaml;
29 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
30 
31 class ‪PagesTsConfigGuardTest extends FunctionalTestCase
32 {
38  protected ‪$backendUserFixture = 'typo3/sysext/core/Tests/Functional/Fixtures/be_users.xml';
39 
40  protected function ‪setUp(): void
41  {
42  parent::setUp();
43  $this->importCSVDataSet(__DIR__ . '/../DataSet/ImportDefault.csv');
44  $this->importCSVDataSet(__DIR__ . '/../../../Fixtures/be_groups.csv');
45  $this->‪addSiteConfiguration(1);
46  // define page create permissions for backend user group 9 on page 1
47  GeneralUtility::makeInstance(ConnectionPool::class)
48  ->getConnectionForTable('pages')
49  ->update(
50  'pages',
51  ['perms_groupid' => 9, 'perms_group' => ‪Permission::ALL],
52  ['uid' => 1]
53  );
54  }
55 
59  public function ‪pagesTsConfigIsConsideredForAdminUser(): void
60  {
61  $backendUser = $this->setUpBackendUserFromFixture(1);
63  $identifier = ‪StringUtility::getUniqueId('NEW');
64 
65  $dataMap = [
66  'pages' => [
67  $identifier => [
68  'pid' => 1,
69  'title' => 'New page',
70  'TSconfig' => 'custom.setting = 1',
71  'tsconfig_includes' => 'EXT:package/file.tsconfig',
72  ],
73  ],
74  ];
75 
76  $this->‪assertProcessedDataMap($dataMap, $backendUser);
77  $this->assertCSVDataSet(__DIR__ . '/DataSet/pagesTsConfigIsConsideredForAdminUser.csv');
78  }
79 
83  public function ‪pagesTsConfigIsIgnoredForNonAdminUser(): void
84  {
85  $backendUser = $this->setUpBackendUserFromFixture(9);
87  $identifier = ‪StringUtility::getUniqueId('NEW');
88 
89  $dataMap = [
90  'pages' => [
91  $identifier => [
92  'pid' => 1,
93  'title' => 'New page',
94  'TSconfig' => 'custom.setting = 1',
95  'tsconfig_includes' => 'EXT:package/file.tsconfig',
96  ],
97  ],
98  ];
99 
100  $this->‪assertProcessedDataMap($dataMap, $backendUser);
101  $this->assertCSVDataSet(__DIR__ . '/DataSet/pagesTsConfigIsIgnoredForNonAdminUser.csv');
102  }
103 
104  private function ‪assertProcessedDataMap(array $dataMap, ‪BackendUserAuthentication $backendUser): void
105  {
106  $dataHandler = GeneralUtility::makeInstance(DataHandler::class);
107  $dataHandler->start($dataMap, [], $backendUser);
108  $dataHandler->process_datamap();
109  self::assertEmpty($dataHandler->errorLog);
110  }
111 
117  protected function ‪addSiteConfiguration(int $pageId): void
118  {
119  $configuration = [
120  'rootPageId' => $pageId,
121  'base' => '/',
122  'languages' => [
123  0 => [
124  'title' => 'English',
125  'enabled' => true,
126  'languageId' => 0,
127  'base' => '/',
128  'typo3Language' => 'default',
129  'locale' => 'en_US.UTF-8',
130  'iso-639-1' => 'en',
131  'navigationTitle' => '',
132  'hreflang' => '',
133  'direction' => '',
134  'flag' => 'us',
135  ],
136  ],
137  'errorHandling' => [],
138  'routes' => [],
139  ];
140  ‪GeneralUtility::mkdir_deep($this->instancePath . '/typo3conf/sites/testing/');
141  $yamlFileContents = Yaml::dump($configuration, 99, 2);
142  $fileName = $this->instancePath . '/typo3conf/sites/testing/config.yaml';
143  ‪GeneralUtility::writeFile($fileName, $yamlFileContents);
144  // Ensure that no other site configuration was cached before
145  $cache = GeneralUtility::makeInstance(CacheManager::class)->getCache('core');
146  if ($cache->has('sites-configuration')) {
147  $cache->remove('sites-configuration');
148  }
149  }
150 }
‪TYPO3\CMS\Core\DataHandling\DataHandler
Definition: DataHandler.php:86
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Regular\Hooks\PagesTsConfigGuardTest\setUp
‪setUp()
Definition: PagesTsConfigGuardTest.php:39
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Regular\Hooks\PagesTsConfigGuardTest\$backendUserFixture
‪string $backendUserFixture
Definition: PagesTsConfigGuardTest.php:37
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Regular\Hooks\PagesTsConfigGuardTest\pagesTsConfigIsConsideredForAdminUser
‪pagesTsConfigIsConsideredForAdminUser()
Definition: PagesTsConfigGuardTest.php:58
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Regular\Hooks\PagesTsConfigGuardTest\assertProcessedDataMap
‪assertProcessedDataMap(array $dataMap, BackendUserAuthentication $backendUser)
Definition: PagesTsConfigGuardTest.php:103
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Regular\Hooks\PagesTsConfigGuardTest
Definition: PagesTsConfigGuardTest.php:32
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:26
‪TYPO3\CMS\Core\Core\Bootstrap\initializeLanguageObject
‪static initializeLanguageObject()
Definition: Bootstrap.php:598
‪TYPO3\CMS\Core\Utility\GeneralUtility\mkdir_deep
‪static mkdir_deep($directory)
Definition: GeneralUtility.php:1908
‪TYPO3\CMS\Core\Type\Bitmask\Permission\ALL
‪const ALL
Definition: Permission.php:60
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:36
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Regular\Hooks
Definition: PagesTsConfigGuardTest.php:18
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static string getUniqueId($prefix='')
Definition: StringUtility.php:128
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Regular\Hooks\PagesTsConfigGuardTest\addSiteConfiguration
‪addSiteConfiguration(int $pageId)
Definition: PagesTsConfigGuardTest.php:116
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Regular\Hooks\PagesTsConfigGuardTest\pagesTsConfigIsIgnoredForNonAdminUser
‪pagesTsConfigIsIgnoredForNonAdminUser()
Definition: PagesTsConfigGuardTest.php:82
‪TYPO3\CMS\Core\Core\Bootstrap
Definition: Bootstrap.php:70
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:22
‪TYPO3\CMS\Core\Utility\GeneralUtility\writeFile
‪static bool writeFile($file, $content, $changePermissions=false)
Definition: GeneralUtility.php:1722