‪TYPO3CMS  11.5
BackendCoreEnvironment.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 Codeception\Event\SuiteEvent;
21 use Psr\Http\Message\ServerRequestInterface;
22 use Symfony\Component\Mailer\Transport\NullTransport;
27 use TYPO3\CMS\Styleguide\TcaDataGenerator\Generator;
28 use TYPO3\CMS\Styleguide\TcaDataGenerator\GeneratorFrontend;
29 use TYPO3\TestingFramework\Core\Acceptance\Extension\BackendEnvironment;
30 
34 class ‪BackendCoreEnvironment extends BackendEnvironment
35 {
41  protected ‪$localConfig = [
42  'coreExtensionsToLoad' => [
43  'core',
44  'beuser',
45  'extbase',
46  'fluid',
47  'filelist',
48  'extensionmanager',
49  'setup',
50  'backend',
51  'belog',
52  'install',
53  'impexp',
54  'frontend',
55  'recordlist',
56  'redirects',
57  'reports',
58  'sys_note',
59  'scheduler',
60  'tstemplate',
61  'lowlevel',
62  'dashboard',
63  'workspaces',
64  'info',
65  'fluid_styled_content',
66  'indexed_search',
67  'adminpanel',
68  'form',
69  'felogin',
70  'seo',
71  'recycler',
72  ],
73  'testExtensionsToLoad' => [
74  'typo3conf/ext/styleguide',
75  ],
76  'xmlDatabaseFixtures' => [
77  'PACKAGE:typo3/testing-framework/Resources/Core/Acceptance/Fixtures/be_users.xml',
78  'PACKAGE:typo3/testing-framework/Resources/Core/Acceptance/Fixtures/be_groups.xml',
79  'PACKAGE:typo3/testing-framework/Resources/Core/Acceptance/Fixtures/sys_category.xml',
80  'PACKAGE:typo3/testing-framework/Resources/Core/Acceptance/Fixtures/tx_extensionmanager_domain_model_extension.xml',
81  'typo3/sysext/core/Tests/Acceptance/Fixtures/pages.xml',
82  'typo3/sysext/core/Tests/Acceptance/Fixtures/workspaces.xml',
83  ],
84  'configurationToUseInTestInstance' => [
85  'MAIL' => [
86  'transport' => NullTransport::class,
87  ],
88  'SYS' => [
89  // @todo: Set these two in testing-framework Classes/Core/Acceptance/Extension/BackendEnvironment.php
90  // Catch *all* errors
91  'errorHandlerErrors' => E_ALL,
92  // Turn *all* errors into exceptions
93  'exceptionalErrors' => E_ALL,
94  ],
95  'BE' => [
96  'HTTP' => [
97  'Response' => [
98  'Headers' => [
99  'csp-report' => "Content-Security-Policy-Report-Only: default-src 'self'; style-src-attr 'unsafe-inline'; style-src-elem 'self' 'unsafe-inline'; img-src 'self' data:; worker-src 'self' blob:;",
100  ],
101  ],
102  ],
103  ],
104  ],
105  ];
106 
112  public function ‪bootstrapTypo3Environment(SuiteEvent $suiteEvent): void
113  {
114  parent::bootstrapTypo3Environment($suiteEvent);
115  // styleguide generator uses DataHandler for some parts. DataHandler needs an initialized BE user
116  // with admin right and the live workspace.
117  $request = $this->‪createServerRequest('https://typo3-testing.local/typo3/');
118  ‪Bootstrap::initializeBackendUser(BackendUserAuthentication::class, $request);
119  ‪$GLOBALS['BE_USER']->user['username'] = 'acceptanceTestSetup';
120  ‪$GLOBALS['BE_USER']->user['admin'] = 1;
121  ‪$GLOBALS['BE_USER']->user['uid'] = 1;
122  ‪$GLOBALS['BE_USER']->workspace = 0;
124 
125  // Create favicon.ico to suppress potential javascript errors in console
126  // which are caused by calling a non html in the browser, e.g. seo sitemap xml
127  $faviconTargetPath = '../../../../favicon.ico';
128  if (!is_file($faviconTargetPath)) {
129  symlink('typo3/sysext/backend/Resources/Public/Icons/favicon.ico', '../../../../favicon.ico');
130  }
131 
132  $styleguideGenerator = new Generator();
133  $styleguideGenerator->create();
134 
135  $styleguideGeneratorFrontend = new GeneratorFrontend();
136  // Force basePath for testing environment, required for the frontend!
137  // Otherwise the page can not be found, also do not set root page to
138  // 'hidden' so menus (e.g. menu_sitemap_pages) are displayed correctly
139  $styleguideGeneratorFrontend->create('/typo3temp/var/tests/acceptance/', 0);
140 
141  // @todo: ugly workaround for InstallTool/AbstractCest.php
142  $instancePath = getenv('TYPO3_PATH_ROOT', true);
143  putenv('TYPO3_ACCEPTANCE_PATH_WEB=' . $instancePath);
144  putenv('TYPO3_ACCEPTANCE_PATH_CONFIG=' . $instancePath . '/typo3conf');
145  }
146 
147  // @todo Eventually move this up to TF::BackendEnvironment, but then as protected.
148  private function ‪createServerRequest(string $url, string $method = 'GET'): ServerRequestInterface
149  {
150  $requestUrlParts = parse_url($url);
151  $docRoot = getenv('TYPO3_PATH_APP') ?? '';
152  $serverParams = [
153  'DOCUMENT_ROOT' => $docRoot,
154  'HTTP_USER_AGENT' => 'TYPO3 Functional Test Request',
155  'HTTP_HOST' => $requestUrlParts['host'] ?? 'localhost',
156  'SERVER_NAME' => $requestUrlParts['host'] ?? 'localhost',
157  'SERVER_ADDR' => '127.0.0.1',
158  'REMOTE_ADDR' => '127.0.0.1',
159  'SCRIPT_NAME' => '/typo3/index.php',
160  'PHP_SELF' => '/typo3/index.php',
161  'SCRIPT_FILENAME' => $docRoot . '/index.php',
162  'QUERY_STRING' => $requestUrlParts['query'] ?? '',
163  'REQUEST_URI' => $requestUrlParts['path'] . (isset($requestUrlParts['query']) ? '?' . $requestUrlParts['query'] : ''),
164  'REQUEST_METHOD' => $method,
165  ];
166  // Define HTTPS and server port
167  if (isset($requestUrlParts['scheme'])) {
168  if ($requestUrlParts['scheme'] === 'https') {
169  $serverParams['HTTPS'] = 'on';
170  $serverParams['SERVER_PORT'] = '443';
171  } else {
172  $serverParams['SERVER_PORT'] = '80';
173  }
174  }
175 
176  // Define a port if used in the URL
177  if (isset($requestUrlParts['port'])) {
178  $serverParams['SERVER_PORT'] = $requestUrlParts['port'];
179  }
180  // set up normalizedParams
181  $request = new ‪ServerRequest($url, $method, null, [], $serverParams);
182  return $request->withAttribute('normalizedParams', ‪NormalizedParams::createFromRequest($request));
183  }
184 }
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Extension\BackendCoreEnvironment\createServerRequest
‪createServerRequest(string $url, string $method='GET')
Definition: BackendCoreEnvironment.php:147
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Extension
Definition: ApplicationComposerEnvironment.php:18
‪TYPO3\CMS\Core\Core\Bootstrap\initializeLanguageObject
‪static initializeLanguageObject()
Definition: Bootstrap.php:598
‪TYPO3\CMS\Core\Core\Bootstrap\initializeBackendUser
‪static initializeBackendUser($className=BackendUserAuthentication::class, ?ServerRequestInterface $request=null)
Definition: Bootstrap.php:572
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:37
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Core\Http\NormalizedParams\createFromRequest
‪static static createFromRequest(ServerRequestInterface $request, ?array $systemConfiguration=null)
Definition: NormalizedParams.php:843
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Extension\BackendCoreEnvironment\bootstrapTypo3Environment
‪bootstrapTypo3Environment(SuiteEvent $suiteEvent)
Definition: BackendCoreEnvironment.php:111
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Extension\BackendCoreEnvironment
Definition: BackendCoreEnvironment.php:35
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Core\Bootstrap
Definition: Bootstrap.php:70
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Extension\BackendCoreEnvironment\$localConfig
‪array $localConfig
Definition: BackendCoreEnvironment.php:40
‪TYPO3\CMS\Core\Http\NormalizedParams
Definition: NormalizedParams.php:35