[BUGFIX] Make functional frontend tests work again 94/57894/2
authorHelmut Hummel <typo3@helhum.io>
Tue, 14 Aug 2018 13:31:26 +0000 (15:31 +0200)
committerAndreas Fernandez <a.fernandez@scripting-base.de>
Thu, 16 Aug 2018 10:19:40 +0000 (12:19 +0200)
On systems that populate $_ENV['_'] with the path
to the PHP binary, frontend functional tests fail.

This is due to the fact that TYPO3 tries to determine paths
based on a cli environment, while we in fact emulate
a frontend (HTTP server) environment in this scenario.

This can be fixed with checking for the "magic"
context "Testing/Frontend", which was added beforehand
already in a different place.

At the same time we simplify the code used to make
functional tests work without process isolation, to
make it better communicate the intention and also
make it more robust.

Resolves: #85842
Related: #85712
Related: #85649
Releases: master
Change-Id: Ie1f9d220f70ecfe5ff00d8bf421e58df2b411d23
Reviewed-on: https://review.typo3.org/57894
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Riny van Tiggelen <info@online-gamer.nl>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
typo3/sysext/core/Classes/Core/SystemEnvironmentBuilder.php

index 9ed3250..5719ed1 100644 (file)
@@ -174,7 +174,7 @@ class SystemEnvironmentBuilder
      */
     protected static function definePaths($entryPointLevel = 0)
     {
-        $isCli = PHP_SAPI === 'cli';
+        $isCli = PHP_SAPI === 'cli' && getenv('TYPO3_CONTEXT') !== 'Testing/Frontend';
         // Absolute path of the entry script that was called
         $scriptPath = GeneralUtility::fixWindowsFilePath(self::getPathThisScript($isCli));
         $rootPath = self::getRootPathFromScriptPath($scriptPath, $entryPointLevel);
@@ -276,27 +276,19 @@ class SystemEnvironmentBuilder
         $isCli = PHP_SAPI === 'cli' && (string)$context !== 'Testing/Frontend';
         // Absolute path of the entry script that was called
         $scriptPath = PATH_thisScript;
-        $rootPath = rtrim(PATH_site, '/');
+        $sitePath = rtrim(PATH_site, '/');
+
         if (getenv('TYPO3_PATH_ROOT')) {
-            $rootPath = GeneralUtility::fixWindowsFilePath(getenv('TYPO3_PATH_ROOT'));
-            $rootPath = rtrim($rootPath, '/');
-            // Check if the root path has been set in the environment (e.g. by the composer installer)
-            if ($isCli && self::usesComposerClassLoading() && StringUtility::endsWith($scriptPath, 'typo3')) {
-                // PATH_thisScript is used for various path calculations based on the document root
-                // Therefore we assume it is always a subdirectory of the document root, which is not the case
-                // in composer mode on cli, as the binary is in the composer bin directory.
-                // Because of that, we enforce the document root path of this binary to be set
-                $scriptName = '/typo3/sysext/core/bin/typo3';
-            } else {
-                // Base the script path on the path taken from the environment
-                // to make relative path calculations work in case only one of both is symlinked
-                // or has the real path
-                $scriptName = substr($scriptPath, strlen($rootPath));
+            $rootPathFromEnvironment = GeneralUtility::fixWindowsFilePath(getenv('TYPO3_PATH_ROOT'));
+            if ($sitePath !== $rootPathFromEnvironment) {
+                // This means, that we re-initialized the environment during a single request
+                // This currently only happens in custom code or during functional testing
+                // Once the constants are removed, we might be able to remove this code here as well and directly pass an environment to the application
+                $scriptPath = $rootPathFromEnvironment . substr($scriptPath, strlen($sitePath));
+                $sitePath = $rootPathFromEnvironment;
             }
-            $scriptPath = $rootPath . $scriptName;
         }
 
-        $sitePath = rtrim($rootPath, '/');
         $projectRootPath = GeneralUtility::fixWindowsFilePath(getenv('TYPO3_PATH_APP'));
         $isDifferentRootPath = ($projectRootPath && $projectRootPath !== $sitePath);
         Environment::initialize(