From 5dba0f3bf44559f8932a153257075660daabed51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BCrk?= Date: Mon, 2 Dec 2024 15:30:32 +0100 Subject: [PATCH] [BUGFIX] Enforce classic mode in created TYPO3 entrypoint files `typo3/testing-framework` provides a extended `SystemEnvironmentBuilder` to ensure correct instance initialization as classic mode in different test context environment, allowing to manual set the composer mode flag despite having the PHP define from parent composer installation as source. `Testbase->setUpInstanceCoreLinks()` additionally provides TYPO3 entrypoints in form of index.php files, calling the basic bootstrap, based on template files from system extensions and modified to use the `typo3/testing-framework` `SystemEnvironmentBuilder` but does not enforce non-composer (classic) mode. This does not hurt within functional tests but codeception based accceptance instances misses the enforced classic mode which can lead to several issues, for example normalizedParams path calculation as basis for additional path or link generation. This change modifies the entrypoint creation code to reflect this need and forces non-composer mode. Releases: main, 8 --- Classes/Core/Testbase.php | 47 ++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/Classes/Core/Testbase.php b/Classes/Core/Testbase.php index 62513aca..88b824ec 100644 --- a/Classes/Core/Testbase.php +++ b/Classes/Core/Testbase.php @@ -239,23 +239,50 @@ public function setUpInstanceCoreLinks( $installPhpExists = file_exists($instancePath . '/typo3/sysext/install/Resources/Private/Php/install.php'); if ($hasConsolidatedHttpEntryPoint) { $entryPointsToSet = [ - $instancePath . '/typo3/sysext/core/Resources/Private/Php/index.php' => $instancePath . '/index.php', + [ + 'source' => $instancePath . '/typo3/sysext/core/Resources/Private/Php/index.php', + 'target' => $instancePath . '/index.php', + 'pattern' => '/\\\\TYPO3\\\\CMS\\\\Core\\\\Core\\\\SystemEnvironmentBuilder::run\(\);/', + 'replacement' => '\TYPO3\TestingFramework\Core\SystemEnvironmentBuilder::run(0, 0, false);', + ], ]; if ($installPhpExists && in_array('install', $coreExtensions, true)) { - $entryPointsToSet[$instancePath . '/typo3/sysext/install/Resources/Private/Php/install.php'] = $instancePath . '/typo3/install.php'; + $entryPointsToSet[] = [ + 'source' => $instancePath . '/typo3/sysext/install/Resources/Private/Php/install.php', + 'target' => $instancePath . '/typo3/install.php', + 'pattern' => '/\\\\TYPO3\\\\CMS\\\\Core\\\\Core\\\\SystemEnvironmentBuilder::run\(1\);/', + 'replacement' => '\TYPO3\TestingFramework\Core\SystemEnvironmentBuilder::run(1, 0, false);', + ]; } } else { $entryPointsToSet = [ - $instancePath . '/typo3/sysext/backend/Resources/Private/Php/backend.php' => $instancePath . '/typo3/index.php', - $instancePath . '/typo3/sysext/frontend/Resources/Private/Php/frontend.php' => $instancePath . '/index.php', + [ + 'source' => $instancePath . '/typo3/sysext/backend/Resources/Private/Php/backend.php', + 'target' => $instancePath . '/typo3/index.php', + 'pattern' => '/\\\\TYPO3\\\\CMS\\\\Core\\\\Core\\\\SystemEnvironmentBuilder::run\(1, \\\\TYPO3\\\\CMS\\\\Core\\\\Core\\\\SystemEnvironmentBuilder::REQUESTTYPE_BE\);/', + 'replacement' => '\TYPO3\TestingFramework\Core\SystemEnvironmentBuilder::run(1, \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::REQUESTTYPE_BE, false);', + ], + [ + 'source' => $instancePath . '/typo3/sysext/frontend/Resources/Private/Php/frontend.php', + 'target' => $instancePath . '/index.php', + 'pattern' => '/\\\\TYPO3\\\\CMS\\\\Core\\\\Core\\\\SystemEnvironmentBuilder::run\(0, \\\\TYPO3\\\\CMS\\\\Core\\\\Core\\\\SystemEnvironmentBuilder::REQUESTTYPE_FE\);/', + 'replacement' => '\TYPO3\TestingFramework\Core\SystemEnvironmentBuilder::run(0, \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::REQUESTTYPE_FE, false);', + ], ]; if ($installPhpExists) { - $entryPointsToSet[$instancePath . '/typo3/sysext/install/Resources/Private/Php/install.php'] = $instancePath . '/typo3/install.php'; + $entryPointsToSet[] = [ + 'source' => $instancePath . '/typo3/sysext/install/Resources/Private/Php/install.php', + 'target' => $instancePath . '/typo3/install.php', + 'pattern' => '/\\\\TYPO3\\\\CMS\\\\Core\\\\Core\\\\SystemEnvironmentBuilder::run\(1, \\\\TYPO3\\\\CMS\\\\Core\\\\Core\\\\SystemEnvironmentBuilder::REQUESTTYPE_INSTALL\);/', + 'replacement' => '\TYPO3\TestingFramework\Core\SystemEnvironmentBuilder::run(1, \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::REQUESTTYPE_INSTALL, false);', + ]; } } $autoloadFile = dirname(__DIR__, 4) . '/autoload.php'; - foreach ($entryPointsToSet as $source => $target) { + foreach ($entryPointsToSet as $entryPointToSet) { + $source = $entryPointToSet['source']; + $target = $entryPointToSet['target']; if (($entryPointContent = file_get_contents($source)) === false) { throw new \UnexpectedValueException(sprintf('Source file (%s) was not found.', $source), 1636244753); } @@ -264,11 +291,9 @@ public function setUpInstanceCoreLinks( $this->findShortestPathCode($target, $autoloadFile), $entryPointContent ); - $entryPointContent = (string)preg_replace( - '/\\\\TYPO3\\\\CMS\\\\Core\\\\Core\\\\SystemEnvironmentBuilder::run\(/', - '\TYPO3\TestingFramework\Core\SystemEnvironmentBuilder::run(', - $entryPointContent - ); + $pattern = $entryPointToSet['pattern']; + $replacement = $entryPointToSet['replacement']; + $entryPointContent = (string)preg_replace($pattern, $replacement, $entryPointContent); if ($entryPointContent === '') { throw new \UnexpectedValueException( sprintf('Error while customizing the source file (%s).', $source),