‪TYPO3CMS  ‪main
ApplicationEnvironment.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;
31 use TYPO3\TestingFramework\Core\Acceptance\Extension\BackendEnvironment;
32 use TYPO3\TestingFramework\Core\Testbase;
33 
37 final class ‪ApplicationEnvironment extends BackendEnvironment
38 {
44  protected ‪$localConfig = [
45  'coreExtensionsToLoad' => [
46  'core',
47  'beuser',
48  'extbase',
49  'fluid',
50  'filelist',
51  'extensionmanager',
52  'setup',
53  'backend',
54  'belog',
55  'install',
56  'impexp',
57  'frontend',
58  'redirects',
59  'reports',
60  'sys_note',
61  'scheduler',
62  'tstemplate',
63  'lowlevel',
64  'dashboard',
65  'workspaces',
66  'info',
67  'fluid_styled_content',
68  'indexed_search',
69  'adminpanel',
70  'form',
71  'felogin',
72  'seo',
73  'recycler',
74  'viewpage',
75  'styleguide',
76  ],
77  'csvDatabaseFixtures' => [
78  __DIR__ . '/../../Fixtures/BackendEnvironment.csv',
79  ],
80  'configurationToUseInTestInstance' => [
81  'MAIL' => [
82  'transport' => NullTransport::class,
83  ],
84  ],
85  'additionalFoldersToCreate' => [
86  '/fileadmin/user_upload/',
87  '/typo3temp/var/lock',
88  ],
89  ];
90 
94  public function ‪bootstrapTypo3Environment(SuiteEvent $suiteEvent): void
95  {
96  parent::bootstrapTypo3Environment($suiteEvent);
97  // styleguide generator uses DataHandler for some parts. DataHandler needs an initialized BE user
98  // with admin right and the live workspace.
99  $request = $this->‪createServerRequest('https://typo3-testing.local/typo3/');
100  ‪Bootstrap::initializeBackendUser(BackendUserAuthentication::class, $request);
101  ‪$GLOBALS['BE_USER']->user['username'] = 'acceptanceTestSetup';
102  ‪$GLOBALS['BE_USER']->user['admin'] = 1;
103  ‪$GLOBALS['BE_USER']->user['uid'] = 1;
104  ‪$GLOBALS['BE_USER']->workspace = 0;
105  ‪$GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageServiceFactory::class)->createFromUserPreferences(‪$GLOBALS['BE_USER']);
106 
107  $faviconLinkPath = '../../../../favicon.ico';
108  if (!is_file($faviconLinkPath)) {
109  symlink('typo3/sysext/backend/Resources/Public/Icons/favicon.ico', $faviconLinkPath);
110  }
111 
112  $styleguideGenerator = new ‪Generator();
113  $styleguideGenerator->create();
114 
115  $styleguideGeneratorFrontend = new ‪GeneratorFrontend();
116  // Force basePath for testing environment, required for the frontend!
117  // Otherwise the page can not be found, also do not set root page to
118  // 'hidden' so menus (e.g. menu_sitemap_pages) are displayed correctly
119  $styleguideGeneratorFrontend->create('/', 0);
120 
121  $testbase = new Testbase();
122  $instancePath = getenv('TYPO3_PATH_ROOT', true);
123  $copyFiles = [
124  // Create favicon.ico to suppress potential javascript errors in console
125  // which are caused by calling a non html in the browser, e.g. seo sitemap xml
126  'typo3/sysext/backend/Resources/Public/Icons/favicon.ico' => [
127  'favicon.ico',
128  ],
129  // Provide some files into the test instance normally added by installer
130  'typo3/sysext/install/Resources/Private/FolderStructureTemplateFiles/root-htaccess' => [
131  '.htaccess',
132  ],
133  'typo3/sysext/install/Resources/Private/FolderStructureTemplateFiles/resources-root-htaccess' => [
134  'fileadmin/.htaccess',
135  ],
136  'typo3/sysext/install/Resources/Private/FolderStructureTemplateFiles/fileadmin-temp-htaccess' => [
137  'fileadmin/_temp_/.htaccess',
138  ],
139  'typo3/sysext/install/Resources/Private/FolderStructureTemplateFiles/fileadmin-temp-index.html' => [
140  'fileadmin/_temp_/index.html',
141  ],
142  'typo3/sysext/install/Resources/Private/FolderStructureTemplateFiles/typo3temp-var-htaccess' => [
143  'typo3temp/var/.htaccess',
144  ],
145  ];
146  foreach ($copyFiles as $sourceFile => $targetFiles) {
147  foreach ($targetFiles as $targetFile) {
148  $testbase->createDirectory(dirname(ltrim($targetFile, '/')));
149  copy(
150  from: ltrim($sourceFile, '/'),
151  to: ltrim($targetFile, '/'),
152  );
153  }
154  }
155  // @todo: ugly workaround for InstallTool/AbstractCest.php
156  putenv('TYPO3_ACCEPTANCE_PATH_WEB=' . $instancePath);
157  putenv('TYPO3_ACCEPTANCE_PATH_VAR=' . $instancePath . '/typo3temp/var');
158  putenv('TYPO3_ACCEPTANCE_PATH_CONFIG=' . $instancePath . '/typo3conf');
159  }
160 
161  // @todo Eventually move this up to TF::BackendEnvironment, but then as protected.
162  private function ‪createServerRequest(string ‪$url, string $method = 'GET'): ServerRequestInterface
163  {
164  $requestUrlParts = parse_url(‪$url);
165  $docRoot = getenv('TYPO3_PATH_APP') ?? '';
166  $serverParams = [
167  'DOCUMENT_ROOT' => $docRoot,
168  'HTTP_USER_AGENT' => 'TYPO3 Functional Test Request',
169  'HTTP_HOST' => $requestUrlParts['host'] ?? 'localhost',
170  'SERVER_NAME' => $requestUrlParts['host'] ?? 'localhost',
171  'SERVER_ADDR' => '127.0.0.1',
172  'REMOTE_ADDR' => '127.0.0.1',
173  'SCRIPT_NAME' => '/index.php',
174  'PHP_SELF' => '/index.php',
175  'SCRIPT_FILENAME' => $docRoot . '/index.php',
176  'QUERY_STRING' => $requestUrlParts['query'] ?? '',
177  'REQUEST_URI' => $requestUrlParts['path'] . (isset($requestUrlParts['query']) ? '?' . $requestUrlParts['query'] : ''),
178  'REQUEST_METHOD' => $method,
179  ];
180  // Define HTTPS and server port
181  if (isset($requestUrlParts['scheme'])) {
182  if ($requestUrlParts['scheme'] === 'https') {
183  $serverParams['HTTPS'] = 'on';
184  $serverParams['SERVER_PORT'] = '443';
185  } else {
186  $serverParams['SERVER_PORT'] = '80';
187  }
188  }
189 
190  // Define a port if used in the URL
191  if (isset($requestUrlParts['port'])) {
192  $serverParams['SERVER_PORT'] = $requestUrlParts['port'];
193  }
194  // set up normalizedParams
195  $request = new ‪ServerRequest(‪$url, $method, null, [], $serverParams);
196  return $request->withAttribute('normalizedParams', ‪NormalizedParams::createFromRequest($request));
197  }
198 }
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory
Definition: LanguageServiceFactory.php:25
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Extension\ApplicationEnvironment
Definition: ApplicationEnvironment.php:38
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Extension\ApplicationEnvironment\createServerRequest
‪createServerRequest(string $url, string $method='GET')
Definition: ApplicationEnvironment.php:161
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Extension\ApplicationEnvironment\$localConfig
‪array $localConfig
Definition: ApplicationEnvironment.php:43
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Extension\ApplicationEnvironment\bootstrapTypo3Environment
‪bootstrapTypo3Environment(SuiteEvent $suiteEvent)
Definition: ApplicationEnvironment.php:93
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Extension
Definition: ApplicationComposerEnvironment.php:18
‪TYPO3\CMS\Core\Core\Bootstrap\initializeBackendUser
‪static initializeBackendUser($className=BackendUserAuthentication::class, ServerRequestInterface $request=null)
Definition: Bootstrap.php:512
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:39
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Webhooks\Message\$url
‪identifier readonly UriInterface $url
Definition: LoginErrorOccurredMessage.php:36
‪TYPO3\CMS\Styleguide\TcaDataGenerator\Generator
Definition: Generator.php:34
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Core\Bootstrap
Definition: Bootstrap.php:62
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Styleguide\TcaDataGenerator\GeneratorFrontend
Definition: GeneratorFrontend.php:33
‪TYPO3\CMS\Core\Http\NormalizedParams\createFromRequest
‪static static createFromRequest(ServerRequestInterface $request, array $systemConfiguration=null)
Definition: NormalizedParams.php:840
‪TYPO3\CMS\Core\Http\NormalizedParams
Definition: NormalizedParams.php:38