‪TYPO3CMS  10.4
SystemEnvironmentBuilderTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
20 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
21 
25 class ‪SystemEnvironmentBuilderTest extends UnitTestCase
26 {
30  protected ‪$subject;
31 
35  protected function ‪setUp(): void
36  {
37  parent::setUp();
38  $this->subject = $this->getAccessibleMock(SystemEnvironmentBuilder::class, ['dummy']);
39  }
40 
47  {
48  $fileName = ‪StringUtility::getUniqueId('filename');
49  $data = [];
50  $phpExtensions = ['php', 'php3', 'php4', 'php5', 'php7', 'phpsh', 'phtml', 'pht'];
51  foreach ($phpExtensions as $extension) {
52  $data[] = [$fileName . '.' . $extension];
53  $data[] = [$fileName . '.' . $extension . '.txt'];
54  }
55  return $data;
56  }
57 
65  public function ‪fileDenyPatternMatchesPhpExtension($phpExtension)
66  {
67  self::assertGreaterThan(0, preg_match('/' . FILE_DENY_PATTERN_DEFAULT . '/', $phpExtension), $phpExtension);
68  }
69 
74  {
75  $fakedLocalPart = ‪StringUtility::getUniqueId('Test');
76  ‪$GLOBALS['_SERVER']['argv'][0] = $fakedLocalPart;
77  self::assertStringEndsWith($fakedLocalPart, $this->subject->_call('getPathThisScriptCli'));
78  }
79 
84  {
85  $fakedLocalPart = ‪StringUtility::getUniqueId('Test');
86  unset(‪$GLOBALS['_SERVER']['argv']);
87  ‪$GLOBALS['_ENV']['_'] = $fakedLocalPart;
88  self::assertStringEndsWith($fakedLocalPart, $this->subject->_call('getPathThisScriptCli'));
89  }
90 
95  {
96  $fakedLocalPart = ‪StringUtility::getUniqueId('Test');
97  unset(‪$GLOBALS['_SERVER']['argv']);
98  unset(‪$GLOBALS['_ENV']['_']);
99  ‪$GLOBALS['_SERVER']['_'] = $fakedLocalPart;
100  self::assertStringEndsWith($fakedLocalPart, $this->subject->_call('getPathThisScriptCli'));
101  }
102 
107  {
108  ‪$GLOBALS['_SERVER']['argv'][0] = 'foo';
109  $fakedAbsolutePart = '/' . ‪StringUtility::getUniqueId('Absolute') . '/';
110  $_SERVER['PWD'] = $fakedAbsolutePart;
111  self::assertStringStartsWith($fakedAbsolutePart, $this->subject->_call('getPathThisScriptCli'));
112  }
113 
118  {
119  unset(‪$GLOBALS['T3_SERVICES']);
120  $this->subject->_call('initializeGlobalVariables');
121  self::assertIsArray(‪$GLOBALS['T3_SERVICES']);
122  }
123 
130  {
131  return [
132  'EXEC_TIME' => ['EXEC_TIME'],
133  'ACCESS_TIME' => ['ACCESS_TIME'],
134  'SIM_EXEC_TIME' => ['SIM_EXEC_TIME'],
135  'SIM_ACCESS_TIME' => ['SIM_ACCESS_TIME']
136  ];
137  }
138 
145  {
146  unset(‪$GLOBALS[$variable]);
147  $this->subject->_call('initializeGlobalTimeTrackingVariables');
148  self::assertTrue(isset(‪$GLOBALS[$variable]));
149  }
150 
155  {
156  $this->subject->_call('initializeGlobalTimeTrackingVariables');
157  self::assertEquals(0, ‪$GLOBALS['ACCESS_TIME'] % 60);
158  }
159 
164  {
165  $this->subject->_call('initializeGlobalTimeTrackingVariables');
166  self::assertEquals(0, ‪$GLOBALS['SIM_ACCESS_TIME'] % 60);
167  }
168 }
‪TYPO3\CMS\Core\Tests\Unit\Core\SystemEnvironmentBuilderTest\getPathThisScriptCliAddsCurrentWorkingDirectoryFromServerEnvironmentToLocalPathOnUnix
‪getPathThisScriptCliAddsCurrentWorkingDirectoryFromServerEnvironmentToLocalPathOnUnix()
Definition: SystemEnvironmentBuilderTest.php:105
‪TYPO3\CMS\Core\Tests\Unit\Core\SystemEnvironmentBuilderTest\initializeGlobalVariablesSetsGlobalT3ServicesArray
‪initializeGlobalVariablesSetsGlobalT3ServicesArray()
Definition: SystemEnvironmentBuilderTest.php:116
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder
Definition: SystemEnvironmentBuilder.php:42
‪TYPO3\CMS\Core\Tests\Unit\Core\SystemEnvironmentBuilderTest\getPathThisScriptCliReadsLocalPartFromArgv
‪getPathThisScriptCliReadsLocalPartFromArgv()
Definition: SystemEnvironmentBuilderTest.php:72
‪TYPO3\CMS\Core\Tests\Unit\Core\SystemEnvironmentBuilderTest\initializeGlobalTimeTrackingVariablesRoundsSimAccessTimeToSixtySeconds
‪initializeGlobalTimeTrackingVariablesRoundsSimAccessTimeToSixtySeconds()
Definition: SystemEnvironmentBuilderTest.php:162
‪TYPO3\CMS\Core\Tests\Unit\Core\SystemEnvironmentBuilderTest\getPathThisScriptCliReadsLocalPartFromEnv
‪getPathThisScriptCliReadsLocalPartFromEnv()
Definition: SystemEnvironmentBuilderTest.php:82
‪TYPO3\CMS\Core\Tests\Unit\Core\SystemEnvironmentBuilderTest\$subject
‪TYPO3 CMS Core Core SystemEnvironmentBuilder TYPO3 TestingFramework Core AccessibleObjectInterface $subject
Definition: SystemEnvironmentBuilderTest.php:29
‪TYPO3\CMS\Core\Tests\Unit\Core
Definition: ApplicationContextTest.php:16
‪TYPO3\CMS\Core\Tests\Unit\Core\SystemEnvironmentBuilderTest\fileDenyPatternMatchesPhpExtension
‪fileDenyPatternMatchesPhpExtension($phpExtension)
Definition: SystemEnvironmentBuilderTest.php:64
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static string getUniqueId($prefix='')
Definition: StringUtility.php:92
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Tests\Unit\Core\SystemEnvironmentBuilderTest\initializeGlobalTimeTrackingVariablesSetsGlobalVariables
‪initializeGlobalTimeTrackingVariablesSetsGlobalVariables($variable)
Definition: SystemEnvironmentBuilderTest.php:143
‪TYPO3\CMS\Core\Tests\Unit\Core\SystemEnvironmentBuilderTest\initializeGlobalTimeTrackingVariablesSetsGlobalVariablesDataProvider
‪array initializeGlobalTimeTrackingVariablesSetsGlobalVariablesDataProvider()
Definition: SystemEnvironmentBuilderTest.php:128
‪TYPO3\CMS\Core\Tests\Unit\Core\SystemEnvironmentBuilderTest\getPathThisScriptCliReadsLocalPartFromServer
‪getPathThisScriptCliReadsLocalPartFromServer()
Definition: SystemEnvironmentBuilderTest.php:93
‪TYPO3\CMS\Core\Tests\Unit\Core\SystemEnvironmentBuilderTest\initializeGlobalTimeTrackingVariablesRoundsAccessTimeToSixtySeconds
‪initializeGlobalTimeTrackingVariablesRoundsAccessTimeToSixtySeconds()
Definition: SystemEnvironmentBuilderTest.php:153
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:22
‪TYPO3\CMS\Core\Tests\Unit\Core\SystemEnvironmentBuilderTest\setUp
‪setUp()
Definition: SystemEnvironmentBuilderTest.php:34
‪TYPO3\CMS\Core\Tests\Unit\Core\SystemEnvironmentBuilderTest\fileDenyPatternMatchesPhpExtensionDataProvider
‪array fileDenyPatternMatchesPhpExtensionDataProvider()
Definition: SystemEnvironmentBuilderTest.php:45
‪TYPO3\CMS\Core\Tests\Unit\Core\SystemEnvironmentBuilderTest
Definition: SystemEnvironmentBuilderTest.php:26