[TASK] Replace TYPO3_OS constant with Environment check 92/56792/6
authorBenni Mack <benni@typo3.org>
Wed, 25 Apr 2018 04:22:15 +0000 (06:22 +0200)
committerTymoteusz Motylewski <t.motylewski@gmail.com>
Thu, 26 Apr 2018 16:37:14 +0000 (18:37 +0200)
In order to move away from using hard-coded constants,
the Environment class method "isWindows" is used.

Resolves: #84854
Releases: master
Change-Id: I30bc72017d00caafe9dfef912c52044a6cd03338
Reviewed-on: https://review.typo3.org/56792
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
Reviewed-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Tested-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
23 files changed:
typo3/sysext/core/Classes/Cache/Backend/SimpleFileBackend.php
typo3/sysext/core/Classes/Utility/CommandUtility.php
typo3/sysext/core/Classes/Utility/ExtensionManagementUtility.php
typo3/sysext/core/Classes/Utility/GeneralUtility.php
typo3/sysext/core/Classes/Utility/PathUtility.php
typo3/sysext/core/Tests/Unit/Locking/SimpleLockStrategyTest.php
typo3/sysext/core/Tests/Unit/Resource/Driver/LocalDriverTest.php
typo3/sysext/core/Tests/Unit/Utility/Fixtures/WindowsPathUtilityFixture.php [deleted file]
typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php
typo3/sysext/core/Tests/Unit/Utility/PathUtilityTest.php
typo3/sysext/extensionmanager/Classes/Utility/FileHandlingUtility.php
typo3/sysext/indexed_search/Classes/FileContentParser.php
typo3/sysext/install/Classes/Configuration/Image/GraphicsMagickPreset.php
typo3/sysext/install/Classes/Configuration/Image/ImageMagick6Preset.php
typo3/sysext/install/Classes/Controller/EnvironmentController.php
typo3/sysext/install/Classes/FolderStructure/AbstractNode.php
typo3/sysext/install/Classes/FolderStructure/DefaultPermissionsCheck.php
typo3/sysext/install/Classes/Service/CoreUpdateService.php
typo3/sysext/install/Classes/SystemEnvironment/SetupCheck.php
typo3/sysext/reports/Classes/Report/Status/ConfigurationStatus.php
typo3/sysext/rsaauth/Classes/Backend/CommandLineBackend.php
typo3/sysext/rsaauth/Tests/Unit/Backend/CommandLineBackendTest.php
typo3/sysext/scheduler/Classes/Controller/SchedulerModuleController.php

index 91acb1f..70993b7 100644 (file)
@@ -118,7 +118,7 @@ class SimpleFileBackend extends \TYPO3\CMS\Core\Cache\Backend\AbstractBackend im
         }
         $documentRoot = PATH_site;
         if ($open_basedir = ini_get('open_basedir')) {
-            if (TYPO3_OS === 'WIN') {
+            if (Environment::isWindows()) {
                 $delimiter = ';';
                 $cacheDirectory = str_replace('\\', '/', $cacheDirectory);
                 if (!preg_match('/[A-Z]:/', substr($cacheDirectory, 0, 2))) {
@@ -134,7 +134,7 @@ class SimpleFileBackend extends \TYPO3\CMS\Core\Cache\Backend\AbstractBackend im
             $basedirs = explode($delimiter, $open_basedir);
             $cacheDirectoryInBaseDir = false;
             foreach ($basedirs as $basedir) {
-                if (TYPO3_OS === 'WIN') {
+                if (Environment::isWindows()) {
                     $basedir = str_replace('\\', '/', $basedir);
                 }
                 if ($basedir[strlen($basedir) - 1] !== '/') {
@@ -158,7 +158,7 @@ class SimpleFileBackend extends \TYPO3\CMS\Core\Cache\Backend\AbstractBackend im
                 // Absolute path to cache directory.
                 $documentRoot = '';
             }
-            if (TYPO3_OS === 'WIN') {
+            if (Environment::isWindows()) {
                 if (substr($cacheDirectory, 0, strlen($documentRoot)) === $documentRoot) {
                     $documentRoot = '';
                 }
index 731ede0..3202ba6 100644 (file)
@@ -14,6 +14,8 @@ namespace TYPO3\CMS\Core\Utility;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Core\Environment;
+
 /**
  * Class to handle system commands.
  * finds executables (programs) on Unix and Windows without knowing where they are
@@ -94,7 +96,7 @@ class CommandUtility
     public static function imageMagickCommand($command, $parameters, $path = '')
     {
         $gfxConf = $GLOBALS['TYPO3_CONF_VARS']['GFX'];
-        $isExt = TYPO3_OS === 'WIN' ? '.exe' : '';
+        $isExt = Environment::isWindows() ? '.exe' : '';
         if (!$path) {
             $path = $gfxConf['processor_path'];
         }
@@ -170,7 +172,7 @@ class CommandUtility
         foreach (self::$paths as $path => $validPath) {
             // Ignore invalid (FALSE) paths
             if ($validPath) {
-                if (TYPO3_OS === 'WIN') {
+                if (Environment::isWindows()) {
                     // Windows OS
                     // @todo Why is_executable() is not called here?
                     if (@is_file($path . $cmd)) {
@@ -200,7 +202,7 @@ class CommandUtility
 
         // Try to get the executable with the command 'which'.
         // It does the same like already done, but maybe on other paths
-        if (TYPO3_OS !== 'WIN') {
+        if (!Environment::isWindows()) {
             $cmd = @self::exec('which ' . $cmd);
             if (@is_executable($cmd)) {
                 self::$applications[$cmd]['app'] = $cmd;
@@ -396,7 +398,7 @@ class CommandUtility
 
         // Add path from environment
         if (!empty($GLOBALS['_SERVER']['PATH']) || !empty($GLOBALS['_SERVER']['Path'])) {
-            $sep = (TYPO3_OS === 'WIN' ? ';' : ':');
+            $sep = Environment::isWindows() ? ';' : ':';
             $serverPath = $GLOBALS['_SERVER']['PATH'] ?? $GLOBALS['_SERVER']['Path'];
             $envPath = GeneralUtility::trimExplode($sep, $serverPath, true);
             foreach ($envPath as $val) {
@@ -406,7 +408,7 @@ class CommandUtility
         }
 
         // Set common paths for Unix (only)
-        if (TYPO3_OS !== 'WIN') {
+        if (!Environment::isWindows()) {
             $sysPathArr = array_merge($sysPathArr, [
                 '/usr/bin/' => '/usr/bin/',
                 '/usr/local/bin/' => '/usr/local/bin/',
index 65c9b47..18b69ce 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Core\Utility;
  */
 
 use TYPO3\CMS\Core\Category\CategoryRegistry;
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Imaging\IconRegistry;
 use TYPO3\CMS\Core\Migrations\TcaMigration;
 use TYPO3\CMS\Core\Package\PackageManager;
@@ -1070,7 +1071,7 @@ class ExtensionManagementUtility
         // OS check
         // Empty $os means 'not limited to one OS', therefore a check is not needed
         if ($GLOBALS['T3_SERVICES'][$serviceType][$serviceKey]['available'] && $GLOBALS['T3_SERVICES'][$serviceType][$serviceKey]['os'] != '') {
-            $os_type = TYPO3_OS === 'WIN' ? 'WIN' : 'UNIX';
+            $os_type = Environment::isWindows() ? 'WIN' : 'UNIX';
             $os = GeneralUtility::trimExplode(',', strtoupper($GLOBALS['T3_SERVICES'][$serviceType][$serviceKey]['os']));
             if (!in_array($os_type, $os, true)) {
                 self::deactivateService($serviceType, $serviceKey);
index 2638d48..baf9930 100644 (file)
@@ -1946,7 +1946,7 @@ class GeneralUtility
      */
     public static function fixPermissions($path, $recursive = false)
     {
-        if (TYPO3_OS === 'WIN') {
+        if (Environment::isWindows()) {
             return true;
         }
         $result = false;
@@ -2159,7 +2159,7 @@ class GeneralUtility
                 if ($OK) {
                     $OK = @rmdir($path);
                 }
-            } elseif (is_link($path) && is_dir($path) && TYPO3_OS === 'WIN') {
+            } elseif (is_link($path) && is_dir($path) && Environment::isWindows()) {
                 $OK = @rmdir($path);
             } else {
                 // If $path is a file, simply remove it
@@ -2168,7 +2168,7 @@ class GeneralUtility
             clearstatcache();
         } elseif (is_link($path)) {
             $OK = @unlink($path);
-            if (!$OK && TYPO3_OS === 'WIN') {
+            if (!$OK && Environment::isWindows()) {
                 // Try to delete dead folder links on Windows systems
                 $OK = @rmdir($path);
             }
@@ -3116,7 +3116,7 @@ class GeneralUtility
      */
     public static function isAbsPath($path)
     {
-        return isset($path[0]) && $path[0] === '/' || TYPO3_OS === 'WIN' && (strpos($path, ':/') === 1 || strpos($path, ':\\') === 1);
+        return isset($path[0]) && $path[0] === '/' || Environment::isWindows() && (strpos($path, ':/') === 1 || strpos($path, ':\\') === 1);
     }
 
     /**
index acfd1e6..9d8a577 100644 (file)
@@ -14,6 +14,8 @@ namespace TYPO3\CMS\Core\Utility;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Core\Environment;
+
 /**
  * Class with helper functions for file paths.
  */
@@ -220,7 +222,7 @@ class PathUtility
     public static function isAbsolutePath($path)
     {
         // On Windows also a path starting with a drive letter is absolute: X:/
-        if (static::isWindows() && (substr($path, 1, 2) === ':/' || substr($path, 1, 2) === ':\\')) {
+        if (Environment::isWindows() && (substr($path, 1, 2) === ':/' || substr($path, 1, 2) === ':\\')) {
             return true;
         }
         // Path starting with a / is always absolute, on every system
@@ -285,7 +287,7 @@ class PathUtility
 
         $absolutePathPrefix = '';
         if (static::isAbsolutePath($path)) {
-            if (static::isWindows() && substr($path, 1, 2) === ':/') {
+            if (Environment::isWindows() && substr($path, 1, 2) === ':/') {
                 $absolutePathPrefix = substr($path, 0, 3);
                 $path = substr($path, 3);
             } else {
@@ -346,20 +348,4 @@ class PathUtility
         }
         return substr($path, $pathSiteLength);
     }
-
-    /*********************
-     *
-     * Helper methods
-     *
-     *********************/
-
-    /**
-     * Wrapper method to be able to test windows path transformation on other systems
-     *
-     * @return bool
-     */
-    protected static function isWindows()
-    {
-        return TYPO3_OS === 'WIN';
-    }
 }
index 95a59ff..2ea1121 100644 (file)
@@ -48,7 +48,7 @@ class SimpleLockStrategyTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestC
      */
     public function acquireFixesPermissionsOnLockFile()
     {
-        if (TYPO3_OS === 'WIN') {
+        if (Environment::isWindows()) {
             $this->markTestSkipped('Test not available on Windows.');
         }
         // Use a very high id to be unique
index a400c8b..7d29990 100644 (file)
@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Core\Tests\Unit\Resource\Driver;
 
 use org\bovigo\vfs\vfsStream;
 use org\bovigo\vfs\vfsStreamWrapper;
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Resource\Exception\InvalidFileNameException;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\TestingFramework\Core\FileStreamWrapper;
@@ -611,7 +612,7 @@ class LocalDriverTest extends \TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase
      */
     public function createFileFixesPermissionsOnCreatedFile()
     {
-        if (TYPO3_OS === 'WIN') {
+        if (Environment::isWindows()) {
             $this->markTestSkipped('createdFilesHaveCorrectRights() tests not available on Windows');
         }
 
@@ -980,7 +981,7 @@ class LocalDriverTest extends \TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase
     {
         if (function_exists('posix_getegid') && posix_getegid() === 0) {
             $this->markTestSkipped('Test skipped if run on linux as root');
-        } elseif (TYPO3_OS === 'WIN') {
+        } elseif (Environment::isWindows()) {
             $this->markTestSkipped('Test skipped if run on Windows system');
         }
         /** @var $subject \TYPO3\CMS\Core\Resource\Driver\LocalDriver */
@@ -1011,7 +1012,7 @@ class LocalDriverTest extends \TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase
     {
         if (function_exists('posix_getegid') && posix_getegid() === 0) {
             $this->markTestSkipped('Test skipped if run on linux as root');
-        } elseif (TYPO3_OS === 'WIN') {
+        } elseif (Environment::isWindows()) {
             $this->markTestSkipped('Test skipped if run on Windows system');
         }
         /** @var $subject \TYPO3\CMS\Core\Resource\Driver\LocalDriver */
@@ -1079,7 +1080,7 @@ class LocalDriverTest extends \TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase
      */
     public function getFilePermissionsReturnsCorrectPermissionsForFilesNotOwnedByCurrentUser($group, $permissions, $expectedResult)
     {
-        if (TYPO3_OS === 'WIN') {
+        if (Environment::isWindows()) {
             $this->markTestSkipped('Test skipped if run on Windows system');
         }
         $this->addToMount([
diff --git a/typo3/sysext/core/Tests/Unit/Utility/Fixtures/WindowsPathUtilityFixture.php b/typo3/sysext/core/Tests/Unit/Utility/Fixtures/WindowsPathUtilityFixture.php
deleted file mode 100644 (file)
index 056f258..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-<?php
-namespace TYPO3\CMS\Core\Tests\Unit\Utility\Fixtures;
-
-/*
- * This file is part of the TYPO3 CMS project.
- *
- * It is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, either version 2
- * of the License, or any later version.
- *
- * For the full copyright and license information, please read the
- * LICENSE.txt file that was distributed with this source code.
- *
- * The TYPO3 project - inspiring people to share!
- */
-
-use TYPO3\CMS\Core\Utility\PathUtility;
-
-/**
- * Fixture for forced windows environment
- */
-class WindowsPathUtilityFixture extends PathUtility
-{
-    /**
-     * Is windows?
-     *
-     * @return bool
-     */
-    public static function isWindows()
-    {
-        return true;
-    }
-}
index 50f1168..b875442 100644 (file)
@@ -21,6 +21,7 @@ use Prophecy\Argument;
 use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\StreamInterface;
 use Psr\Log\LoggerInterface;
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Http\RequestFactory;
 use TYPO3\CMS\Core\Package\Package;
 use TYPO3\CMS\Core\Package\PackageManager;
@@ -1514,7 +1515,7 @@ class GeneralUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
      */
     public function getIndpEnvTypo3SitePathReturnsStringStartingWithDrive()
     {
-        if (TYPO3_OS !== 'WIN') {
+        if (!Environment::isWindows()) {
             $this->markTestSkipped('Test available only on Windows OS.');
         }
         $result = GeneralUtility::getIndpEnv('TYPO3_SITE_PATH');
@@ -2516,7 +2517,7 @@ class GeneralUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
      */
     public function fixPermissionsSetsGroup()
     {
-        if (TYPO3_OS === 'WIN') {
+        if (Environment::isWindows()) {
             $this->markTestSkipped(self::NO_FIX_PERMISSIONS_ON_WINDOWS);
         }
         if (!function_exists('posix_getegid')) {
@@ -2541,7 +2542,7 @@ class GeneralUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
      */
     public function fixPermissionsSetsPermissionsToFile()
     {
-        if (TYPO3_OS === 'WIN') {
+        if (Environment::isWindows()) {
             $this->markTestSkipped(self::NO_FIX_PERMISSIONS_ON_WINDOWS);
         }
         // Create and prepare test file
@@ -2561,7 +2562,7 @@ class GeneralUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
      */
     public function fixPermissionsSetsPermissionsToHiddenFile()
     {
-        if (TYPO3_OS === 'WIN') {
+        if (Environment::isWindows()) {
             $this->markTestSkipped(self::NO_FIX_PERMISSIONS_ON_WINDOWS);
         }
         // Create and prepare test file
@@ -2581,7 +2582,7 @@ class GeneralUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
      */
     public function fixPermissionsSetsPermissionsToDirectory()
     {
-        if (TYPO3_OS === 'WIN') {
+        if (Environment::isWindows()) {
             $this->markTestSkipped(self::NO_FIX_PERMISSIONS_ON_WINDOWS);
         }
         // Create and prepare test directory
@@ -2601,7 +2602,7 @@ class GeneralUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
      */
     public function fixPermissionsSetsPermissionsToDirectoryWithTrailingSlash()
     {
-        if (TYPO3_OS === 'WIN') {
+        if (Environment::isWindows()) {
             $this->markTestSkipped(self::NO_FIX_PERMISSIONS_ON_WINDOWS);
         }
         // Create and prepare test directory
@@ -2622,7 +2623,7 @@ class GeneralUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
      */
     public function fixPermissionsSetsPermissionsToHiddenDirectory()
     {
-        if (TYPO3_OS === 'WIN') {
+        if (Environment::isWindows()) {
             $this->markTestSkipped(self::NO_FIX_PERMISSIONS_ON_WINDOWS);
         }
         // Create and prepare test directory
@@ -2643,7 +2644,7 @@ class GeneralUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
      */
     public function fixPermissionsCorrectlySetsPermissionsRecursive()
     {
-        if (TYPO3_OS === 'WIN') {
+        if (Environment::isWindows()) {
             $this->markTestSkipped(self::NO_FIX_PERMISSIONS_ON_WINDOWS);
         }
         // Create and prepare test directory and file structure
@@ -2694,7 +2695,7 @@ class GeneralUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
      */
     public function fixPermissionsDoesNotSetPermissionsToNotAllowedPath()
     {
-        if (TYPO3_OS === 'WIN') {
+        if (Environment::isWindows()) {
             $this->markTestSkipped(self::NO_FIX_PERMISSIONS_ON_WINDOWS);
         }
         // Create and prepare test file
@@ -2710,7 +2711,7 @@ class GeneralUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
      */
     public function fixPermissionsSetsPermissionsWithRelativeFileReference()
     {
-        if (TYPO3_OS === 'WIN') {
+        if (Environment::isWindows()) {
             $this->markTestSkipped(self::NO_FIX_PERMISSIONS_ON_WINDOWS);
         }
         $filename = 'typo3temp/var/tests/' . $this->getUniqueId('test_');
@@ -2730,7 +2731,7 @@ class GeneralUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
      */
     public function fixPermissionsSetsDefaultPermissionsToFile()
     {
-        if (TYPO3_OS === 'WIN') {
+        if (Environment::isWindows()) {
             $this->markTestSkipped(self::NO_FIX_PERMISSIONS_ON_WINDOWS);
         }
         $filename = $this->getVirtualTestDir() . '/' . $this->getUniqueId('test_');
@@ -2748,7 +2749,7 @@ class GeneralUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
      */
     public function fixPermissionsSetsDefaultPermissionsToDirectory()
     {
-        if (TYPO3_OS === 'WIN') {
+        if (Environment::isWindows()) {
             $this->markTestSkipped(self::NO_FIX_PERMISSIONS_ON_WINDOWS);
         }
         $directory = $this->getVirtualTestDir() . '/' . $this->getUniqueId('test_');
@@ -2805,7 +2806,7 @@ class GeneralUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
      */
     public function mkdirSetsPermissionsOfCreatedDirectory()
     {
-        if (TYPO3_OS === 'WIN') {
+        if (Environment::isWindows()) {
             $this->markTestSkipped(self::NO_FIX_PERMISSIONS_ON_WINDOWS);
         }
         $directory = $this->getVirtualTestDir() . '/' . $this->getUniqueId('test_');
@@ -2846,7 +2847,7 @@ class GeneralUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
      */
     private function checkGroups($methodName)
     {
-        if (TYPO3_OS === 'WIN') {
+        if (Environment::isWindows()) {
             $this->markTestSkipped(self::NO_FIX_PERMISSIONS_ON_WINDOWS);
             return false;
         }
@@ -2927,7 +2928,7 @@ class GeneralUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
      */
     public function mkdirDeepFixesPermissionsOfCreatedDirectory()
     {
-        if (TYPO3_OS === 'WIN') {
+        if (Environment::isWindows()) {
             $this->markTestSkipped(self::NO_FIX_PERMISSIONS_ON_WINDOWS);
         }
         $directory = $this->getUniqueId('mkdirdeeptest_');
@@ -2945,7 +2946,7 @@ class GeneralUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
      */
     public function mkdirDeepFixesPermissionsOnNewParentDirectory()
     {
-        if (TYPO3_OS === 'WIN') {
+        if (Environment::isWindows()) {
             $this->markTestSkipped(self::NO_FIX_PERMISSIONS_ON_WINDOWS);
         }
         $directory = $this->getUniqueId('mkdirdeeptest_');
@@ -2964,7 +2965,7 @@ class GeneralUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
      */
     public function mkdirDeepDoesNotChangePermissionsOfExistingSubDirectories()
     {
-        if (TYPO3_OS === 'WIN') {
+        if (Environment::isWindows()) {
             $this->markTestSkipped(self::NO_FIX_PERMISSIONS_ON_WINDOWS);
         }
         $baseDirectory = PATH_site . 'typo3temp/var/tests/';
index 87196fe..389efcc 100644 (file)
@@ -13,14 +13,22 @@ namespace TYPO3\CMS\Core\Tests\Unit\Utility;
  *
  * The TYPO3 project - inspiring people to share!
  */
-use TYPO3\CMS\Core\Tests\Unit\Utility\Fixtures\WindowsPathUtilityFixture;
+use TYPO3\CMS\Core\Core\Environment;
+use TYPO3\CMS\Core\Utility\PathUtility;
+use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
 
 /**
  * Testcase for class \TYPO3\CMS\Core\Utility\PathUtility
  */
-class PathUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
+class PathUtilityTest extends UnitTestCase
 {
     /**
+     * Restore Environment after the test
+     * @var bool
+     */
+    protected $backupEnvironment = true;
+
+    /**
      * @param array $paths
      * @param string $expected
      * @dataProvider isCommonPrefixResolvedCorrectlyDataProvider
@@ -28,7 +36,7 @@ class PathUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
      */
     public function isCommonPrefixResolvedCorrectly(array $paths, $expected)
     {
-        $commonPrefix = \TYPO3\CMS\Core\Utility\PathUtility::getCommonPrefix($paths);
+        $commonPrefix = PathUtility::getCommonPrefix($paths);
         $this->assertEquals($expected, $commonPrefix);
     }
 
@@ -122,7 +130,7 @@ class PathUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
      */
     public function isRelativePathResolvedCorrectly($source, $target, $expected)
     {
-        $relativePath = \TYPO3\CMS\Core\Utility\PathUtility::getRelativePath($source, $target);
+        $relativePath = PathUtility::getRelativePath($source, $target);
         $this->assertEquals($expected, $relativePath);
     }
 
@@ -174,7 +182,7 @@ class PathUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
      */
     public function isTrailingSeparatorSanitizedCorrectly($path, $separator, $expected)
     {
-        $sanitizedPath = \TYPO3\CMS\Core\Utility\PathUtility::sanitizeTrailingSeparator($path, $separator);
+        $sanitizedPath = PathUtility::sanitizeTrailingSeparator($path, $separator);
         $this->assertEquals($expected, $sanitizedPath);
     }
 
@@ -240,7 +248,7 @@ class PathUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
      */
     public function getAbsolutePathOfRelativeReferencedFileOrPathResolvesFileCorrectly($baseFileName, $includeFileName, $expectedFileName)
     {
-        $resolvedFilename = \TYPO3\CMS\Core\Utility\PathUtility::getAbsolutePathOfRelativeReferencedFileOrPath($baseFileName, $includeFileName);
+        $resolvedFilename = PathUtility::getAbsolutePathOfRelativeReferencedFileOrPath($baseFileName, $includeFileName);
         $this->assertEquals($expectedFileName, $resolvedFilename);
     }
 
@@ -345,9 +353,21 @@ class PathUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
      */
     public function getCanonicalPathCorrectlyCleansPath($inputName, $expectedResult)
     {
+        // Ensure Environment runs as Windows test
+        Environment::initialize(
+            Environment::getContext(),
+            true,
+            false,
+            Environment::getProjectPath(),
+            Environment::getPublicPath(),
+            Environment::getVarPath(),
+            Environment::getConfigPath(),
+            Environment::getCurrentScript(),
+            'WINDOWS'
+        );
         $this->assertEquals(
             $expectedResult,
-            WindowsPathUtilityFixture::getCanonicalPath($inputName)
+            PathUtility::getCanonicalPath($inputName)
         );
     }
 }
index e145861..4251ef3 100644 (file)
@@ -294,7 +294,7 @@ class FileHandlingUtility implements \TYPO3\CMS\Core\SingletonInterface
     {
         $extDirPath = GeneralUtility::fixWindowsFilePath($extDirPath);
         $extensionPathWithoutTrailingSlash = rtrim($extDirPath, '/');
-        if (is_link($extensionPathWithoutTrailingSlash) && TYPO3_OS !== 'WIN') {
+        if (is_link($extensionPathWithoutTrailingSlash) && !Environment::isWindows()) {
             $result = unlink($extensionPathWithoutTrailingSlash);
         } else {
             $result = GeneralUtility::rmdir($extDirPath, true);
index 9b380e0..6036618 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\IndexedSearch;
  */
 
 use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Utility\CommandUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
@@ -79,7 +80,7 @@ class FileContentParser
         // Then read indexer-config and set if appropriate:
         $indexerConfig = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('indexed_search');
         // If windows, apply extension to tool name:
-        $exe = TYPO3_OS === 'WIN' ? '.exe' : '';
+        $exe = Environment::isWindows() ? '.exe' : '';
         // lg
         $extOK = false;
         $mainExtension = '';
index 751781c..e289af8 100644 (file)
@@ -14,6 +14,8 @@ namespace TYPO3\CMS\Install\Configuration\Image;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Core\Environment;
+
 /**
  * Preset for GraphicsMagick
  */
@@ -64,7 +66,7 @@ class GraphicsMagickPreset extends AbstractImagePreset
     {
         $result = false;
         foreach ($searchPaths as $path) {
-            if (TYPO3_OS === 'WIN') {
+            if (Environment::isWindows()) {
                 $executable = 'gm.exe';
             } else {
                 $executable = 'gm';
index 2e7dfff..504e059 100644 (file)
@@ -14,6 +14,8 @@ namespace TYPO3\CMS\Install\Configuration\Image;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Core\Environment;
+
 /**
  * Preset for ImageMagick version 6 or higher
  */
@@ -64,7 +66,7 @@ class ImageMagick6Preset extends AbstractImagePreset
     {
         $result = false;
         foreach ($searchPaths as $path) {
-            if (TYPO3_OS === 'WIN') {
+            if (Environment::isWindows()) {
                 $executable = 'identify.exe';
             } else {
                 $executable = 'identify';
index 7185865..887b865 100644 (file)
@@ -17,6 +17,7 @@ namespace TYPO3\CMS\Install\Controller;
 
 use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\ServerRequestInterface;
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\FormProtection\FormProtectionFactory;
 use TYPO3\CMS\Core\FormProtection\InstallToolFormProtection;
@@ -65,7 +66,7 @@ class EnvironmentController extends AbstractController
 
             'systemInformationCgiDetected', GeneralUtility::isRunningOnCgiServerApi(),
             'systemInformationDatabaseConnections' => $this->getDatabaseConnectionInformation(),
-            'systemInformationOperatingSystem' => TYPO3_OS === 'WIN' ? 'Windows' : 'Unix',
+            'systemInformationOperatingSystem' => Environment::isWindows() ? 'Windows' : 'Unix',
         ]);
         return new JsonResponse([
             'success' => true,
@@ -85,7 +86,7 @@ class EnvironmentController extends AbstractController
         $view->assignMultiple([
             'systemInformationCgiDetected', GeneralUtility::isRunningOnCgiServerApi(),
             'systemInformationDatabaseConnections' => $this->getDatabaseConnectionInformation(),
-            'systemInformationOperatingSystem' => TYPO3_OS === 'WIN' ? 'Windows' : 'Unix',
+            'systemInformationOperatingSystem' => Environment::isWindows() ? 'Windows' : 'Unix',
         ]);
         return new JsonResponse([
             'success' => true,
index 6220f62..8064403 100644 (file)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Install\FolderStructure;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Messaging\FlashMessage;
 
 /**
@@ -194,10 +195,7 @@ abstract class AbstractNode
      */
     protected function isWindowsOs()
     {
-        if (TYPO3_OS === 'WIN') {
-            return true;
-        }
-        return false;
+        return Environment::isWindows();
     }
 
     /**
index 2b9acc9..e54c4b7 100644 (file)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Install\FolderStructure;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Messaging\FlashMessage;
 
 /**
@@ -75,7 +76,7 @@ class DefaultPermissionsCheck
             $permissionStatus = FlashMessage::ERROR;
             $extraMessage = ' (not read or writable by the user)';
         } elseif ($perms['ow']) {
-            if (TYPO3_OS === 'WIN') {
+            if (Environment::isWindows()) {
                 $permissionStatus = FlashMessage::INFO;
                 $extraMessage = ' (writable by anyone on the server). This is the default behavior on a Windows system';
             } else {
index 6f421c6..37e90e5 100644 (file)
@@ -178,7 +178,7 @@ class CoreUpdateService
         }
 
         // No core update on windows
-        if (TYPO3_OS === 'WIN') {
+        if (Environment::isWindows()) {
             $success = false;
             $this->messages->enqueue(new FlashMessage(
                 '',
index 62dc1e2..4b2795e 100644 (file)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Install\SystemEnvironment;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Messaging\FlashMessage;
 use TYPO3\CMS\Core\Messaging\FlashMessageQueue;
 use TYPO3\CMS\Core\Service\OpcodeCacheService;
@@ -117,7 +118,7 @@ class SetupCheck implements CheckInterface
         $currentLocale = setlocale(LC_CTYPE, 0);
 
         // On Windows an empty locale value uses the regional settings from the Control Panel
-        if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLocale'] === '' && TYPO3_OS !== 'WIN') {
+        if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLocale'] === '' && !Environment::isWindows()) {
             $this->messageQueue->enqueue(new FlashMessage(
                 '$GLOBALS[TYPO3_CONF_VARS][SYS][systemLocale] is not set. This is fine as long as no UTF-8 file system is used.',
                 'Empty systemLocale setting',
@@ -147,7 +148,7 @@ class SetupCheck implements CheckInterface
     {
         if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['UTF8filesystem']) {
             // On Windows an empty local value uses the regional settings from the Control Panel
-            if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLocale'] === '' && TYPO3_OS !== 'WIN') {
+            if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLocale'] === '' && !Environment::isWindows()) {
                 $this->messageQueue->enqueue(new FlashMessage(
                     '$GLOBALS[TYPO3_CONF_VARS][SYS][UTF8filesystem] is set, but $GLOBALS[TYPO3_CONF_VARS][SYS][systemLocale]'
                         . ' is empty. Make sure a valid locale which supports UTF-8 is set.',
@@ -157,7 +158,7 @@ class SetupCheck implements CheckInterface
             } else {
                 $testString = 'ÖöĄĆŻĘĆćążąęó.jpg';
                 $currentLocale = setlocale(LC_CTYPE, 0);
-                $quote = TYPO3_OS === 'WIN' ? '"' : '\'';
+                $quote = Environment::isWindows() ? '"' : '\'';
                 setlocale(LC_CTYPE, $GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLocale']);
                 if (escapeshellarg($testString) === $quote . $testString . $quote) {
                     $this->messageQueue->enqueue(new FlashMessage(
index 6b77e2e..7ae1e57 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Reports\Report\Status;
  */
 
 use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Database\Query\QueryBuilder;
 use TYPO3\CMS\Core\Localization\LanguageService;
@@ -41,7 +42,7 @@ class ConfigurationStatus implements StatusProviderInterface
         if ($this->isMemcachedUsed()) {
             $statuses['memcachedConnection'] = $this->getMemcachedConnectionStatus();
         }
-        if (TYPO3_OS !== 'WIN') {
+        if (!Environment::isWindows()) {
             $statuses['createdFilesWorldWritable'] = $this->getCreatedFilesWorldWritableStatus();
             $statuses['createdDirectoriesWorldWritable'] = $this->getCreatedDirectoriesWorldWritableStatus();
         }
index 6170a9c..746d7e9 100644 (file)
@@ -93,7 +93,7 @@ class CommandLineBackend extends AbstractBackend
         // to do the same and use the F4 (0x10001) exponent. This is the most
         // secure.
         $command = $this->opensslPath . ' genrsa -out ' . escapeshellarg($privateKeyFile) . ' 1024';
-        if (TYPO3_OS === 'WIN') {
+        if (Environment::isWindows()) {
             $command .= ' 2>NUL';
         } else {
             $command .= ' 2>/dev/null';
index 0101a0e..f46dee0 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Rsaauth\Tests\Unit\Backend;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Rsaauth\Backend\CommandLineBackend;
 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
 
@@ -30,7 +31,7 @@ class CommandLineBackendTest extends UnitTestCase
 
     protected function setUp()
     {
-        if (TYPO3_OS === 'WIN') {
+        if (Environment::isWindows()) {
             $this->markTestSkipped('This test is not available on Windows as auto-detection of openssl path will fail.');
         }
         $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['rsaauth']['temporaryDirectory'] = '';
index 10f4c5b..f4d6d1a 100644 (file)
@@ -19,6 +19,7 @@ use Psr\Http\Message\ServerRequestInterface;
 use TYPO3\CMS\Backend\Template\Components\ButtonBar;
 use TYPO3\CMS\Backend\Template\ModuleTemplate;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Http\HtmlResponse;
 use TYPO3\CMS\Core\Imaging\Icon;
@@ -353,7 +354,7 @@ class SchedulerModuleController
 
         // Skip this check if running Windows, as rights do not work the same way on this platform
         // (i.e. the script will always appear as *not* executable)
-        if (TYPO3_OS === 'WIN') {
+        if (Environment::isWindows()) {
             $isExecutable = true;
         } else {
             $isExecutable = is_executable($script);