TYPO3 CMS  TYPO3_8-7
PagesTsConfigGuardTest.php
Go to the documentation of this file.
1 <?php
2 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 
26 
27 class PagesTsConfigGuardTest extends FunctionalTestCase
28 {
32  private $scenarioDataSetDirectory = 'typo3/sysext/core/Tests/Functional/DataHandling/Regular/DataSet/';
33 
37  private $assertionDataSetDirectory = 'typo3/sysext/core/Tests/Functional/DataHandling/Regular/Hooks/DataSet/';
38 
44  protected $backendUserFixture = 'typo3/sysext/sv/Tests/Functional/Fixtures/be_users.xml';
45 
46  protected function setUp()
47  {
48  parent::setUp();
49  $GLOBALS['LANG'] = $this->getMockBuilder(LanguageService::class)
50  ->setMethods(['sL'])
51  ->getMock();
52 
53  $this->importScenarioDataSet('LiveDefaultPages');
54  $this->importDataSet(dirname($this->backendUserFixture) . '/be_groups.xml');
55  // define page create permissions for backend user group 9 on page 1
56  GeneralUtility::makeInstance(ConnectionPool::class)
57  ->getConnectionForTable('pages')
58  ->update(
59  'pages',
60  ['perms_groupid' => 9, 'perms_group' => Permission::ALL],
61  ['uid' => 1]
62  );
63  }
64 
69  {
70  $backendUser = $this->setUpBackendUserFromFixture(1);
71  $identifier = StringUtility::getUniqueId('NEW');
72 
73  $dataMap = [
74  'pages' => [
75  $identifier => [
76  'pid' => 1,
77  'title' => 'New page',
78  'TSconfig' => 'custom.setting = 1',
79  'tsconfig_includes' => 'EXT:package/file.tsconfig',
80  ],
81  ],
82  ];
83 
84  $this->assertProcessedDataMap($dataMap, $backendUser);
85  $this->assertAssertionDataSet('pagesTsConfigIsConsideredForAdminUser');
86  }
87 
92  {
93  $backendUser = $this->setUpBackendUserFromFixture(9);
94  $identifier = StringUtility::getUniqueId('NEW');
95 
96  $dataMap = [
97  'pages' => [
98  $identifier => [
99  'pid' => 1,
100  'title' => 'New page',
101  'TSconfig' => 'custom.setting = 1',
102  'tsconfig_includes' => 'EXT:package/file.tsconfig',
103  ],
104  ],
105  ];
106 
107  $this->assertProcessedDataMap($dataMap, $backendUser);
108  $this->assertAssertionDataSet('pagesTsConfigIsIgnoredForNonAdminUser');
109  }
110 
114  private function importScenarioDataSet($dataSetName)
115  {
116  $fileName = rtrim($this->scenarioDataSetDirectory, '/') . '/' . $dataSetName . '.csv';
117  $fileName = GeneralUtility::getFileAbsFileName($fileName);
118  $this->importCSVDataSet($fileName);
119  }
120 
121  private function assertAssertionDataSet($dataSetName)
122  {
123  $fileName = rtrim($this->assertionDataSetDirectory, '/') . '/' . $dataSetName . '.csv';
124  $fileName = GeneralUtility::getFileAbsFileName($fileName);
125  $this->assertCSVDataSet($fileName);
126  }
127 
128  private function assertProcessedDataMap(array $dataMap, BackendUserAuthentication $backendUser)
129  {
130  $dataHandler = GeneralUtility::makeInstance(DataHandler::class);
131  $dataHandler->start($dataMap, [], $backendUser);
132  $dataHandler->process_datamap();
133  static::assertEmpty($dataHandler->errorLog);
134  }
135 }
static getFileAbsFileName($filename, $_=null, $_2=null)
static makeInstance($className,... $constructorArguments)
assertProcessedDataMap(array $dataMap, BackendUserAuthentication $backendUser)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']