[!!!][TASK] Drop PATH_thisScript constant 92/59392/10
authorChristian Kuhn <lolli@schwarzbu.ch>
Wed, 9 Jan 2019 22:17:51 +0000 (23:17 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Fri, 11 Jan 2019 07:37:01 +0000 (08:37 +0100)
The patch removes the definition of constant PATH_thisScript.

* The main change in SystemEnvironmentBuilder splits method
definePaths() into two parts calculateScriptPath() and
calculateRootPath() since definePaths() formerly communicated
the script path using the PATH_thisScript constant to method
initializeEnvironment(), which has to fall now. Note
initializeEnvironment() is now protected, which is ok since
that usage was only internally for the testing framework which
is resolved now, too.

* A raise of the testing framework from 5.0.1 to 5.0.2 is needed.
It also defined that constant and triggered some different code
paths with this in SystemEnvironmentBuilder.
composer require --dev typo3/testing-framework ~5.0.2

* With the changes in SystemEnvironmentBuilder,
Environment::getCurrentScript() now returns '.../bin/phpunit' and
not '.../typo3/index.php' in unit tests, which is more correct. This
however has the side effect that various path related unit tests
need an adaption to properly set up the environment as needed.

Change-Id: I7d16c488a3039b3de689bb8b1b903d989d943c8d
Resolves: #87391
Releases: master
Reviewed-on: https://review.typo3.org/59392
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: TYPO3com <noreply@typo3.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
13 files changed:
composer.json
composer.lock
typo3/sysext/core/Classes/Core/SystemEnvironmentBuilder.php
typo3/sysext/core/Classes/Resource/ResourceCompressor.php
typo3/sysext/core/Classes/Utility/PathUtility.php
typo3/sysext/core/Documentation/Changelog/master/Breaking-87193-DeprecatedFunctionalityRemoved.rst
typo3/sysext/core/Tests/Unit/Resource/ResourceCompressorIntegrationTest.php
typo3/sysext/core/Tests/Unit/Resource/ResourceCompressorTest.php
typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php
typo3/sysext/core/composer.json
typo3/sysext/felogin/Tests/Unit/Controller/FrontendLoginControllerTest.php
typo3/sysext/frontend/Tests/Unit/Typolink/AbstractTypolinkBuilderTest.php
typo3/sysext/install/Configuration/ExtensionScanner/Php/ConstantMatcher.php

index 28f8396..a496188 100644 (file)
@@ -68,7 +68,7 @@
                "fiunchinho/phpunit-randomizer": "^4.0",
                "friendsofphp/php-cs-fixer": "^2.12.2",
                "typo3/cms-styleguide": "~10.0.2",
-               "typo3/testing-framework": "~5.0.1"
+               "typo3/testing-framework": "~5.0.2"
        },
        "suggest": {
                "ext-gd": "GDlib/Freetype is required for building images with text (GIFBUILDER) and can also be used to scale images",
index 2c4f721..aa897e8 100644 (file)
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "10ee465c4239c6820a78cbba36df8523",
+    "content-hash": "aeb31e0c5d202a7441722af3f3bdca32",
     "packages": [
         {
             "name": "cogpowered/finediff",
         },
         {
             "name": "typo3/testing-framework",
-            "version": "5.0.1",
+            "version": "5.0.2",
             "source": {
                 "type": "git",
                 "url": "https://github.com/TYPO3/testing-framework.git",
-                "reference": "555a52baa86b865175b58c1ef457e5122622799e"
+                "reference": "3c533f83d254ebcda7eea0bdbd7f4e2cb30f574b"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/TYPO3/testing-framework/zipball/555a52baa86b865175b58c1ef457e5122622799e",
-                "reference": "555a52baa86b865175b58c1ef457e5122622799e",
+                "url": "https://api.github.com/repos/TYPO3/testing-framework/zipball/3c533f83d254ebcda7eea0bdbd7f4e2cb30f574b",
+                "reference": "3c533f83d254ebcda7eea0bdbd7f4e2cb30f574b",
                 "shasum": ""
             },
             "require": {
                 "tests",
                 "typo3"
             ],
-            "time": "2019-01-07T20:10:58+00:00"
+            "time": "2019-01-10T12:43:35+00:00"
         },
         {
             "name": "webmozart/assert",
index c88a9ac..a468c44 100644 (file)
@@ -16,7 +16,6 @@ namespace TYPO3\CMS\Core\Core;
 
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\PathUtility;
-use TYPO3\CMS\Core\Utility\StringUtility;
 
 /**
  * Class to encapsulate base setup of bootstrap.
@@ -86,13 +85,21 @@ class SystemEnvironmentBuilder
         self::defineTypo3RequestTypes();
         self::setRequestType($requestType | ($requestType === self::REQUESTTYPE_BE && strpos($_REQUEST['route'] ?? '', '/ajax/') === 0 ? TYPO3_REQUESTTYPE_AJAX : 0));
         self::defineLegacyConstants($requestType === self::REQUESTTYPE_FE ? 'FE' : 'BE');
-        self::definePaths($entryPointLevel, $requestType);
+        $scriptPath = self::calculateScriptPath($entryPointLevel, $requestType);
+        $rootPath = self::calculateRootPath($entryPointLevel, $requestType);
+
+        if (!defined('PATH_site')) {
+            // Absolute path of the document root of the instance with trailing slash
+            // @deprecated since TYPO3 v9, will be removed in TYPO3 v10.0
+            define('PATH_site', $rootPath . '/');
+        }
+
         self::initializeGlobalVariables();
         self::initializeGlobalTimeTrackingVariables();
         self::initializeBasicErrorReporting();
 
         $applicationContext = static::createApplicationContext();
-        self::initializeEnvironment($applicationContext, $requestType);
+        self::initializeEnvironment($applicationContext, $requestType, $scriptPath);
         GeneralUtility::presetApplicationContext($applicationContext);
     }
 
@@ -135,15 +142,23 @@ class SystemEnvironmentBuilder
         define('FILE_DENY_PATTERN_DEFAULT', '\\.(php[3-7]?|phpsh|phtml|pht)(\\..*)?$|^\\.htaccess$');
         // Security related constant: List of file extensions that should be registered as php script file extensions
         define('PHP_EXTENSIONS_DEFAULT', 'php,php3,php4,php5,php6,php7,phpsh,inc,phtml,pht');
+
+        // Relative path from document root to typo3/ directory, hardcoded to "typo3/"
+        if (!defined('TYPO3_mainDir')) {
+            define('TYPO3_mainDir', 'typo3/');
+        }
     }
 
     /**
-     * Calculate all required base paths and set as constants.
+     * Calculate script path. This is the absolute path to the entry script.
+     * Can be something like '.../public/index.php' or '.../public/typo3/index.php' for
+     * web calls, or '.../bin/typo3' or similar for cli calls.
      *
      * @param int $entryPointLevel Number of subdirectories where the entry script is located under the document root
      * @param int $requestType
+     * @return string Absolute path to entry script
      */
-    protected static function definePaths(int $entryPointLevel, int $requestType)
+    protected static function calculateScriptPath(int $entryPointLevel, int $requestType): string
     {
         $isCli = self::isCliRequestType($requestType);
         // Absolute path of the entry script that was called
@@ -151,40 +166,45 @@ class SystemEnvironmentBuilder
         $rootPath = self::getRootPathFromScriptPath($scriptPath, $entryPointLevel);
         // Check if the root path has been set in the environment (e.g. by the composer installer)
         if (getenv('TYPO3_PATH_ROOT')) {
-            if ($isCli && self::usesComposerClassLoading() && StringUtility::endsWith($scriptPath, 'typo3')) {
+            if ($isCli && self::usesComposerClassLoading()) {
                 // $scriptPath 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';
+                $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));
-            }
-            $rootPath = GeneralUtility::fixWindowsFilePath(getenv('TYPO3_PATH_ROOT'));
-            $scriptPath = $rootPath . $scriptName;
-        }
-
-        if (!defined('PATH_thisScript')) {
-            // @deprecated since TYPO3 v9, will be removed in TYPO3 v10.0
-            define('PATH_thisScript', $scriptPath);
-            if (!is_file($scriptPath)) {
-                static::exitWithMessage('Unable to determine path to entry script.');
+                $scriptName = ltrim(substr($scriptPath, strlen($rootPath)), '/');
             }
+            $rootPath = rtrim(GeneralUtility::fixWindowsFilePath(getenv('TYPO3_PATH_ROOT')), '/');
+            $scriptPath = $rootPath . '/' . $scriptName;
         }
+        return $scriptPath;
+    }
 
-        // Absolute path of the document root of the instance with trailing slash
-        if (!defined('PATH_site')) {
-            // @deprecated since TYPO3 v9, will be removed in TYPO3 v10.0
-            define('PATH_site', $rootPath . '/');
-        }
-        // Relative path from document root to typo3/ directory
-        // Hardcoded to "typo3/"
-        if (!defined('TYPO3_mainDir')) {
-            define('TYPO3_mainDir', 'typo3/');
+    /**
+     * Absolute path to the root of the typo3 instance. This is often identical to the web document root path (eg. .../public),
+     * but may be different. For instance helhum/typo3-secure-web uses this: Then, rootPath TYPO3_PATH_ROOT is the absolute path to
+     * the private directory where code and runtime files are located (currently typo3/ext, typo3/sysext, fileadmin, typo3temp),
+     * while TYPO3_PATH_WEB is the public/ web document folder that gets assets like filedamin and Resources/Public folders
+     * from extensions linked in.
+     *
+     * @param int $entryPointLevel Number of subdirectories where the entry script is located under the document root
+     * @param int $requestType
+     * @return string Absolute path without trailing slash
+     */
+    protected static function calculateRootPath(int $entryPointLevel, int $requestType): string
+    {
+        // Check if the root path has been set in the environment (e.g. by the composer installer)
+        if (getenv('TYPO3_PATH_ROOT')) {
+            return rtrim(GeneralUtility::fixWindowsFilePath(getenv('TYPO3_PATH_ROOT')), '/');
         }
+        $isCli = self::isCliRequestType($requestType);
+        // Absolute path of the entry script that was called
+        $scriptPath = GeneralUtility::fixWindowsFilePath(self::getPathThisScript($isCli));
+        return self::getRootPathFromScriptPath($scriptPath, $entryPointLevel);
     }
 
     /**
@@ -221,12 +241,12 @@ class SystemEnvironmentBuilder
      * Initialize the Environment class
      *
      * @param ApplicationContext $context
-     * @param int|null $requestType
+     * @param int $requestType
+     * @param string $scriptPath
      */
-    public static function initializeEnvironment(ApplicationContext $context, int $requestType = null)
+    protected static function initializeEnvironment(ApplicationContext $context, int $requestType, string $scriptPath)
     {
         // Absolute path of the entry script that was called
-        $scriptPath = PATH_thisScript;
         $sitePath = rtrim(PATH_site, '/');
 
         if (getenv('TYPO3_PATH_ROOT')) {
@@ -387,7 +407,7 @@ class SystemEnvironmentBuilder
      *
      * @param string $scriptPath Calculated path to the entry script
      * @param int $entryPointLevel Number of subdirectories where the entry script is located under the document root
-     * @return string Absolute path to document root of installation
+     * @return string Absolute path to document root of installation without trailing slash
      */
     protected static function getRootPathFromScriptPath($scriptPath, $entryPointLevel)
     {
index e74b5af..f16cb27 100644 (file)
@@ -474,7 +474,7 @@ class ResourceCompressor
             $file = Environment::getPublicPath() . '/' . $filename;
         }
 
-        // check if the file exists, and if so, return the path relative to PATH_thisScript
+        // check if the file exists, and if so, return the path relative to current PHP script
         if (is_file($file)) {
             return rtrim(PathUtility::getRelativePathTo($file), '/');
         }
index 7b0f7b1..f95e4ce 100644 (file)
@@ -270,7 +270,7 @@ class PathUtility
      *
      * @param string $path
      *
-     * @return string
+     * @return string Path without trailing slash
      */
     public static function dirnameDuringBootstrap($path): string
     {
index 1fc68a4..800af38 100644 (file)
@@ -26,6 +26,11 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
 class ResourceCompressorIntegrationTest extends BaseTestCase
 {
     /**
+     * @var bool Restore Environment after tests
+     */
+    protected $backupEnvironment = true;
+
+    /**
      * @var TestableResourceCompressor
      */
     protected $resourceCompressor;
@@ -42,6 +47,7 @@ class ResourceCompressorIntegrationTest extends BaseTestCase
 
     public function setUp(): void
     {
+        parent::setUp();
         $this->fixtureDir = 'sysext/core/Tests/Unit/Resource/ResourceCompressorTest/Fixtures/';
         $this->fixtureDirFromTest = GeneralUtility::fixWindowsFilePath(__DIR__ . '/ResourceCompressorTest/Fixtures/');
     }
@@ -105,6 +111,17 @@ class ResourceCompressorIntegrationTest extends BaseTestCase
      */
     public function concatenateCssFilesWorksWithFileFromNonRootPath(): void
     {
+        Environment::initialize(
+            Environment::getContext(),
+            true,
+            false,
+            Environment::getProjectPath(),
+            Environment::getPublicPath(),
+            Environment::getVarPath(),
+            Environment::getConfigPath(),
+            Environment::getBackendPath() . '/index.php',
+            Environment::isWindows() ? 'WINDOWS' : 'UNIX'
+        );
         $testFile = Environment::getPublicPath() . '/typo3temp/var/transient/css_input_with_import.css';
         $this->testFilesToDelete[] = $testFile;
         copy(Environment::getBackendPath() . '/' . $this->fixtureDir . 'css_input_with_import.css', $testFile);
index 404fdda..052b6da 100644 (file)
@@ -25,8 +25,7 @@ use TYPO3\CMS\Core\Utility\PathUtility;
 class ResourceCompressorTest extends BaseTestCase
 {
     /**
-     * Restore Environment after the test
-     * @var bool
+     * @var bool Restore Environment after tests
      */
     protected $backupEnvironment = true;
 
@@ -538,7 +537,7 @@ class ResourceCompressorTest extends BaseTestCase
     /**
      * @return array
      */
-    public function getVariousFilenamesFromMainDirInBackendContextDataProvider(): array
+    public function getFilenamesFromMainDirInBackendContextDataProvider(): array
     {
         return [
             // Get filename using EXT:
@@ -564,24 +563,37 @@ class ResourceCompressorTest extends BaseTestCase
 
     /**
      * @test
-     * @dataProvider getVariousFilenamesFromMainDirInBackendContextDataProvider
+     * @dataProvider getFilenamesFromMainDirInBackendContextDataProvider
      * @param string $filename input that will be fired on the extension
      * @param string $expected
      */
-    public function getVariousFilenamesFromMainDirInBackendContext(string $filename, string $expected)
+    public function getFilenamesFromMainDirInBackendContext(string $filename, string $expected)
     {
-        $rootPath = \dirname($_SERVER['SCRIPT_NAME']);
-        $this->subject = $this->getAccessibleMock(ResourceCompressor::class, ['dummy']);
-        $this->subject->setRootPath($rootPath . '/');
-
-        $relativeToRootPath = $this->subject->_call('getFilenameFromMainDir', $filename);
-        $this->assertSame($expected, $relativeToRootPath, 'Path to the file relative to the path converted correctly.');
+        // getCurrentScript() called by PathUtility::getRelativePathTo() is usually something
+        // like '.../bin/phpunit' in testing context, but we want .../typo3/index.php as entry
+        // script point here to fake the backend call.
+        $bePath = Environment::getBackendPath();
+        Environment::initialize(
+            Environment::getContext(),
+            true,
+            false,
+            Environment::getProjectPath(),
+            Environment::getPublicPath(),
+            Environment::getVarPath(),
+            Environment::getConfigPath(),
+            $bePath . '/index.php',
+            Environment::isWindows() ? 'WINDOWS' : 'UNIX'
+        );
+        $subject = $this->getAccessibleMock(ResourceCompressor::class, ['dummy']);
+        $subject->setRootPath($bePath . '/');
+        $relativeToRootPath = $subject->_call('getFilenameFromMainDir', $filename);
+        $this->assertSame($expected, $relativeToRootPath);
     }
 
     /**
      * @return array
      */
-    public function getVariousFilenamesFromMainDirInFrontendContextDataProvider(): array
+    public function getFilenamesFromMainDirInFrontendContextDataProvider(): array
     {
         return [
             // Get filename using EXT:
@@ -603,12 +615,16 @@ class ResourceCompressorTest extends BaseTestCase
 
     /**
      * @test
-     * @dataProvider getVariousFilenamesFromMainDirInFrontendContextDataProvider
+     * @dataProvider getFilenamesFromMainDirInFrontendContextDataProvider
      * @param string $filename input that will be fired on the extension
      * @param string $expected
      */
-    public function getVariousFilenamesFromMainDirInFrontendContext(string $filename, string $expected)
+    public function getFilenamesFromMainDirInFrontendContext(string $filename, string $expected)
     {
+        // getCurrentScript() called by PathUtility::getRelativePathTo() is usually something
+        // like '.../bin/phpunit' in testing context, but we want .../index.php as entry
+        // script point here to fake the frontend call.
+        $fePath = Environment::getPublicPath();
         Environment::initialize(
             Environment::getContext(),
             true,
@@ -617,14 +633,12 @@ class ResourceCompressorTest extends BaseTestCase
             Environment::getPublicPath(),
             Environment::getVarPath(),
             Environment::getConfigPath(),
-            PATH_site . 'index.php',
+            $fePath . '/index.php',
             Environment::isWindows() ? 'WINDOWS' : 'UNIX'
         );
-        $_SERVER['ORIG_SCRIPT_NAME'] = '/index.php';
-        $this->subject = $this->getAccessibleMock(ResourceCompressor::class, ['dummy']);
-        $this->subject->setRootPath(PATH_site);
-
-        $relativeToRootPath = $this->subject->_call('getFilenameFromMainDir', $filename);
-        $this->assertSame($expected, $relativeToRootPath, 'Path to the file relative to the path converted correctly.');
+        $subject = $this->getAccessibleMock(ResourceCompressor::class, ['dummy']);
+        $subject->setRootPath($fePath . '/');
+        $relativeToRootPath = $subject->_call('getFilenameFromMainDir', $filename);
+        $this->assertSame($expected, $relativeToRootPath);
     }
 }
index 0ee4ed9..f532397 100644 (file)
@@ -53,6 +53,11 @@ class GeneralUtilityTest extends UnitTestCase
     protected $resetSingletonInstances = true;
 
     /**
+     * @var bool Restore Environment after tests
+     */
+    protected $backupEnvironment = true;
+
+    /**
      * @var \TYPO3\CMS\Core\Package\PackageManager
      */
     protected $backupPackageManager;
@@ -62,6 +67,7 @@ class GeneralUtilityTest extends UnitTestCase
      */
     protected function setUp()
     {
+        parent::setUp();
         GeneralUtilityFixture::$isAllowedHostHeaderValueCallCount = 0;
         GeneralUtilityFixture::setAllowHostHeaderValue(false);
         $GLOBALS['TYPO3_CONF_VARS']['SYS']['trustedHostsPattern'] = GeneralUtility::ENV_TRUSTED_HOSTS_PATTERN_ALLOW_ALL;
@@ -1459,7 +1465,17 @@ class GeneralUtilityTest extends UnitTestCase
      */
     public function getIndpEnvTypo3SitePathReturnsStringStartingWithSlash()
     {
-        $_SERVER['SCRIPT_NAME'] = '/typo3/';
+        Environment::initialize(
+            Environment::getContext(),
+            true,
+            false,
+            Environment::getProjectPath(),
+            Environment::getPublicPath(),
+            Environment::getVarPath(),
+            Environment::getConfigPath(),
+            Environment::getBackendPath() . '/index.php',
+            Environment::isWindows() ? 'WINDOWS' : 'UNIX'
+        );
         $result = GeneralUtility::getIndpEnv('TYPO3_SITE_PATH');
         $this->assertEquals('/', $result[0]);
     }
@@ -1936,6 +1952,17 @@ class GeneralUtilityTest extends UnitTestCase
      */
     public function sanitizeLocalUrlAcceptsNotEncodedValidPaths($path)
     {
+        Environment::initialize(
+            Environment::getContext(),
+            true,
+            false,
+            Environment::getProjectPath(),
+            Environment::getPublicPath(),
+            Environment::getVarPath(),
+            Environment::getConfigPath(),
+            Environment::getBackendPath() . '/index.php',
+            Environment::isWindows() ? 'WINDOWS' : 'UNIX'
+        );
         $this->assertEquals($path, GeneralUtility::sanitizeLocalUrl($path));
     }
 
@@ -1946,6 +1973,17 @@ class GeneralUtilityTest extends UnitTestCase
      */
     public function sanitizeLocalUrlAcceptsEncodedValidPaths($path)
     {
+        Environment::initialize(
+            Environment::getContext(),
+            true,
+            false,
+            Environment::getProjectPath(),
+            Environment::getPublicPath(),
+            Environment::getVarPath(),
+            Environment::getConfigPath(),
+            Environment::getBackendPath() . '/index.php',
+            Environment::isWindows() ? 'WINDOWS' : 'UNIX'
+        );
         $this->assertEquals(rawurlencode($path), GeneralUtility::sanitizeLocalUrl(rawurlencode($path)));
     }
 
@@ -1956,29 +1994,26 @@ class GeneralUtilityTest extends UnitTestCase
      */
     public function sanitizeLocalUrlValidUrlsDataProvider()
     {
-        $host = 'localhost';
-        $subDirectory = '/cms/';
-
         return [
-            $subDirectory . 'typo3/alt_intro.php' => [
-                $subDirectory . 'typo3/alt_intro.php',
-                $host,
-                $subDirectory,
-            ],
-            $subDirectory . 'index.php' => [
-                $subDirectory . 'index.php',
-                $host,
-                $subDirectory,
-            ],
-            'http://' . $host . '/typo3/alt_intro.php' => [
-                'http://' . $host . '/typo3/alt_intro.php',
-                $host,
+            '/cms/typo3/alt_intro.php' => [
+                '/cms/typo3/alt_intro.php',
+                'localhost',
+                '/cms/',
+            ],
+            '/cms/index.php' => [
+                '/cms/index.php',
+                'localhost',
+                '/cms/',
+            ],
+            'http://localhost/typo3/alt_intro.php' => [
+                'http://localhost/typo3/alt_intro.php',
+                'localhost',
                 '',
             ],
-            'http://' . $host . $subDirectory . 'typo3/alt_intro.php' => [
-                'http://' . $host . $subDirectory . 'typo3/alt_intro.php',
-                $host,
-                $subDirectory,
+            'http://localhost/cms/typo3/alt_intro.php' => [
+                'http://localhost/cms/typo3/alt_intro.php',
+                'localhost',
+                '/cms/',
             ],
         ];
     }
@@ -1992,6 +2027,17 @@ class GeneralUtilityTest extends UnitTestCase
      */
     public function sanitizeLocalUrlAcceptsNotEncodedValidUrls($url, $host, $subDirectory)
     {
+        Environment::initialize(
+            Environment::getContext(),
+            true,
+            false,
+            Environment::getProjectPath(),
+            Environment::getPublicPath(),
+            Environment::getVarPath(),
+            Environment::getConfigPath(),
+            Environment::getBackendPath() . '/index.php',
+            Environment::isWindows() ? 'WINDOWS' : 'UNIX'
+        );
         $_SERVER['HTTP_HOST'] = $host;
         $_SERVER['SCRIPT_NAME'] = $subDirectory . 'typo3/index.php';
         $this->assertEquals($url, GeneralUtility::sanitizeLocalUrl($url));
@@ -2006,6 +2052,17 @@ class GeneralUtilityTest extends UnitTestCase
      */
     public function sanitizeLocalUrlAcceptsEncodedValidUrls($url, $host, $subDirectory)
     {
+        Environment::initialize(
+            Environment::getContext(),
+            true,
+            false,
+            Environment::getProjectPath(),
+            Environment::getPublicPath(),
+            Environment::getVarPath(),
+            Environment::getConfigPath(),
+            Environment::getBackendPath() . '/index.php',
+            Environment::isWindows() ? 'WINDOWS' : 'UNIX'
+        );
         $_SERVER['HTTP_HOST'] = $host;
         $_SERVER['SCRIPT_NAME'] = $subDirectory . 'typo3/index.php';
         $this->assertEquals(rawurlencode($url), GeneralUtility::sanitizeLocalUrl(rawurlencode($url)));
index 254fae6..a2bdccd 100644 (file)
@@ -51,7 +51,7 @@
                "fiunchinho/phpunit-randomizer": "^4.0",
                "friendsofphp/php-cs-fixer": "^2.12.2",
                "typo3/cms-styleguide": "~10.0.2",
-               "typo3/testing-framework": "~5.0.1"
+               "typo3/testing-framework": "~5.0.2"
        },
        "suggest": {
                "ext-fileinfo": "Used for proper file type detection in the file abstraction layer",
index 728bcee..5b3ddff 100644 (file)
@@ -17,6 +17,7 @@ namespace TYPO3\CMS\Felogin\Tests\Unit\Controller;
 
 use Psr\Log\NullLogger;
 use TYPO3\CMS\Core\Authentication\LoginType;
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Site\Entity\Site;
 use TYPO3\CMS\Core\Site\SiteFinder;
 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
@@ -29,6 +30,11 @@ use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
 class FrontendLoginControllerTest extends UnitTestCase
 {
     /**
+     * @var bool Restore Environment after tests
+     */
+    protected $backupEnvironment = true;
+
+    /**
      * @var \TYPO3\CMS\Felogin\Controller\FrontendLoginController|\TYPO3\TestingFramework\Core\AccessibleObjectInterface
      */
     protected $accessibleFixture;
@@ -50,6 +56,7 @@ class FrontendLoginControllerTest extends UnitTestCase
      */
     protected function setUp()
     {
+        parent::setUp();
         $GLOBALS['TSFE'] = new \stdClass();
         $this->testHostName = 'hostname.tld';
         $this->testSitePath = '/';
@@ -137,6 +144,17 @@ class FrontendLoginControllerTest extends UnitTestCase
      */
     public function validateRedirectUrlKeepsCleanUrl($url)
     {
+        Environment::initialize(
+            Environment::getContext(),
+            true,
+            false,
+            Environment::getProjectPath(),
+            Environment::getPublicPath(),
+            Environment::getVarPath(),
+            Environment::getConfigPath(),
+            Environment::getBackendPath() . '/index.php',
+            Environment::isWindows() ? 'WINDOWS' : 'UNIX'
+        );
         $this->assertEquals($url, $this->accessibleFixture->_call('validateRedirectUrl', $url));
     }
 
@@ -194,6 +212,17 @@ class FrontendLoginControllerTest extends UnitTestCase
      */
     public function validateRedirectUrlKeepsCleanUrlInSubdirectory($url)
     {
+        Environment::initialize(
+            Environment::getContext(),
+            true,
+            false,
+            Environment::getProjectPath(),
+            Environment::getPublicPath(),
+            Environment::getVarPath(),
+            Environment::getConfigPath(),
+            Environment::getBackendPath() . '/index.php',
+            Environment::isWindows() ? 'WINDOWS' : 'UNIX'
+        );
         $this->testSitePath = '/subdir/';
         $this->setUpFakeSitePathAndHost();
         $this->assertEquals($url, $this->accessibleFixture->_call('validateRedirectUrl', $url));
@@ -386,6 +415,17 @@ class FrontendLoginControllerTest extends UnitTestCase
      */
     public function isInCurrentDomainIgnoresScheme($host, $https, $url)
     {
+        Environment::initialize(
+            Environment::getContext(),
+            true,
+            false,
+            Environment::getProjectPath(),
+            Environment::getPublicPath(),
+            Environment::getVarPath(),
+            Environment::getConfigPath(),
+            Environment::getBackendPath() . '/index.php',
+            Environment::isWindows() ? 'WINDOWS' : 'UNIX'
+        );
         $_SERVER['HTTP_HOST'] = $host;
         $_SERVER['HTTPS'] = $https;
         $this->assertTrue($this->accessibleFixture->_call('isInCurrentDomain', $url));
index 5d78cba..b40f305 100644 (file)
@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Frontend\Tests\Unit\Typolink;
  */
 
 use Psr\Log\LoggerInterface;
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Log\LogManager;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
@@ -34,6 +35,11 @@ class AbstractTypolinkBuilderTest extends UnitTestCase
     protected $resetSingletonInstances = true;
 
     /**
+     * @var bool Restore Environment after tests
+     */
+    protected $backupEnvironment = true;
+
+    /**
      * @var \PHPUnit_Framework_MockObject_MockObject|TypoScriptFrontendController|\TYPO3\TestingFramework\Core\AccessibleObjectInterface
      */
     protected $frontendControllerMock;
@@ -43,8 +49,8 @@ class AbstractTypolinkBuilderTest extends UnitTestCase
      */
     protected function setUp()
     {
+        parent::setUp();
         $this->createMockedLoggerAndLogManager();
-
         $this->frontendControllerMock = $this->getAccessibleMock(
             TypoScriptFrontendController::class,
             ['dummy'],
@@ -166,6 +172,17 @@ class AbstractTypolinkBuilderTest extends UnitTestCase
      */
     public function forceAbsoluteUrlReturnsCorrectAbsoluteUrl($expected, $url, array $configuration)
     {
+        Environment::initialize(
+            Environment::getContext(),
+            true,
+            false,
+            Environment::getProjectPath(),
+            Environment::getPublicPath(),
+            Environment::getVarPath(),
+            Environment::getConfigPath(),
+            Environment::getBackendPath() . '/index.php',
+            Environment::isWindows() ? 'WINDOWS' : 'UNIX'
+        );
         $this->frontendControllerMock->absRefPrefix = '';
         $contentObjectRendererProphecy = $this->prophesize(ContentObjectRenderer::class);
         $subject = $this->getAccessibleMock(
@@ -184,6 +201,17 @@ class AbstractTypolinkBuilderTest extends UnitTestCase
      */
     public function forceAbsoluteUrlReturnsCorrectAbsoluteUrlWithSubfolder()
     {
+        Environment::initialize(
+            Environment::getContext(),
+            true,
+            false,
+            Environment::getProjectPath(),
+            Environment::getPublicPath(),
+            Environment::getVarPath(),
+            Environment::getConfigPath(),
+            Environment::getBackendPath() . '/index.php',
+            Environment::isWindows() ? 'WINDOWS' : 'UNIX'
+        );
         $contentObjectRendererProphecy = $this->prophesize(ContentObjectRenderer::class);
         $subject = $this->getAccessibleMock(
             AbstractTypolinkBuilder::class,
index 5e2c5b0..c7120c5 100644 (file)
@@ -78,6 +78,7 @@ return [
         'restFiles' => [
             'Feature-84153-IntroduceAGenericEnvironmentClass.rst',
             'Deprecation-85285-DeprecatedSystemConstants.rst',
+            'Breaking-87193-DeprecatedFunctionalityRemoved.rst',
         ],
     ],
     'PATH_typo3' => [