‪TYPO3CMS  9.5
SystemEnvironmentBuilderTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
17 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
18 
22 class ‪SystemEnvironmentBuilderTest extends UnitTestCase
23 {
27  protected ‪$subject;
28 
32  protected function ‪setUp()
33  {
34  $this->subject = $this->getAccessibleMock(\‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::class, ['dummy']);
35  }
36 
43  {
44  $fileName = $this->getUniqueId('filename');
45  $data = [];
46  $phpExtensions = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', 'php,php3,php4,php5,php6,phpsh,phtml,pht', true);
47  foreach ($phpExtensions as $extension) {
48  $data[] = [$fileName . '.' . $extension];
49  $data[] = [$fileName . '.' . $extension . '.txt'];
50  }
51  return $data;
52  }
53 
61  public function ‪fileDenyPatternMatchesPhpExtension($phpExtension)
62  {
63  $this->assertGreaterThan(0, preg_match('/' . FILE_DENY_PATTERN_DEFAULT . '/', $phpExtension), $phpExtension);
64  }
65 
70  {
71  $fakedLocalPart = $this->getUniqueId('Test');
72  ‪$GLOBALS['_SERVER']['argv'][0] = $fakedLocalPart;
73  $this->assertStringEndsWith($fakedLocalPart, $this->subject->_call('getPathThisScriptCli'));
74  }
75 
80  {
81  $fakedLocalPart = $this->getUniqueId('Test');
82  unset(‪$GLOBALS['_SERVER']['argv']);
83  ‪$GLOBALS['_ENV']['_'] = $fakedLocalPart;
84  $this->assertStringEndsWith($fakedLocalPart, $this->subject->_call('getPathThisScriptCli'));
85  }
86 
91  {
92  $fakedLocalPart = $this->getUniqueId('Test');
93  unset(‪$GLOBALS['_SERVER']['argv']);
94  unset(‪$GLOBALS['_ENV']['_']);
95  ‪$GLOBALS['_SERVER']['_'] = $fakedLocalPart;
96  $this->assertStringEndsWith($fakedLocalPart, $this->subject->_call('getPathThisScriptCli'));
97  }
98 
103  {
104  ‪$GLOBALS['_SERVER']['argv'][0] = 'foo';
105  $fakedAbsolutePart = '/' . $this->getUniqueId('Absolute') . '/';
106  $_SERVER['PWD'] = $fakedAbsolutePart;
107  $this->assertStringStartsWith($fakedAbsolutePart, $this->subject->_call('getPathThisScriptCli'));
108  }
109 
114  {
115  unset(‪$GLOBALS['TYPO3_MISC']);
116  $this->subject->_call('initializeGlobalVariables');
117  $this->assertInternalType('array', ‪$GLOBALS['TYPO3_MISC']);
118  }
119 
124  {
125  unset(‪$GLOBALS['T3_VAR']);
126  $this->subject->_call('initializeGlobalVariables');
127  $this->assertInternalType('array', ‪$GLOBALS['T3_VAR']);
128  }
129 
134  {
135  unset(‪$GLOBALS['T3_SERVICES']);
136  $this->subject->_call('initializeGlobalVariables');
137  $this->assertInternalType('array', ‪$GLOBALS['T3_SERVICES']);
138  }
139 
146  {
147  return [
148  'EXEC_TIME' => ['EXEC_TIME'],
149  'ACCESS_TIME' => ['ACCESS_TIME'],
150  'SIM_EXEC_TIME' => ['SIM_EXEC_TIME'],
151  'SIM_ACCESS_TIME' => ['SIM_ACCESS_TIME']
152  ];
153  }
154 
161  {
162  unset(‪$GLOBALS[$variable]);
163  $this->subject->_call('initializeGlobalTimeTrackingVariables');
164  $this->assertTrue(isset(‪$GLOBALS[$variable]));
165  }
166 
171  {
172  unset(‪$GLOBALS['TYPO3_MISC']['microtime_start']);
173  $this->subject->_call('initializeGlobalTimeTrackingVariables');
174  $this->assertTrue(isset(‪$GLOBALS['TYPO3_MISC']['microtime_start']));
175  }
176 
181  {
182  $this->subject->_call('initializeGlobalTimeTrackingVariables');
183  $this->assertEquals(0, ‪$GLOBALS['ACCESS_TIME'] % 60);
184  }
185 
190  {
191  $this->subject->_call('initializeGlobalTimeTrackingVariables');
192  $this->assertEquals(0, ‪$GLOBALS['SIM_ACCESS_TIME'] % 60);
193  }
194 
199  {
200  $backupReporting = error_reporting();
201  $this->subject->_call('initializeBasicErrorReporting');
202  $actualReporting = error_reporting();
203  error_reporting($backupReporting);
204  $this->assertEquals(0, $actualReporting & E_STRICT);
205  }
206 
211  {
212  $backupReporting = error_reporting();
213  $this->subject->_call('initializeBasicErrorReporting');
214  $actualReporting = error_reporting();
215  error_reporting($backupReporting);
216  $this->assertEquals(0, $actualReporting & E_NOTICE);
217  }
218 
223  {
224  $backupReporting = error_reporting();
225  $this->subject->_call('initializeBasicErrorReporting');
226  $actualReporting = error_reporting();
227  error_reporting($backupReporting);
228  $this->assertEquals(0, $actualReporting & E_DEPRECATED);
229  }
230 }
‪TYPO3\CMS\Core\Tests\Unit\Core\SystemEnvironmentBuilderTest\initializeGlobalVariablesSetsGlobalTypo3MiscArray
‪initializeGlobalVariablesSetsGlobalTypo3MiscArray()
Definition: SystemEnvironmentBuilderTest.php:112
‪TYPO3\CMS\Core\Tests\Unit\Core\SystemEnvironmentBuilderTest\getPathThisScriptCliAddsCurrentWorkingDirectoryFromServerEnvironmentToLocalPathOnUnix
‪getPathThisScriptCliAddsCurrentWorkingDirectoryFromServerEnvironmentToLocalPathOnUnix()
Definition: SystemEnvironmentBuilderTest.php:101
‪TYPO3\CMS\Core\Tests\Unit\Core\SystemEnvironmentBuilderTest\initializeGlobalVariablesSetsGlobalT3ServicesArray
‪initializeGlobalVariablesSetsGlobalT3ServicesArray()
Definition: SystemEnvironmentBuilderTest.php:132
‪TYPO3\CMS\Core\Tests\Unit\Core\SystemEnvironmentBuilderTest\initializeGlobalTimeTrackingVariablesSetsGlobalTypo3MiscMicrotimeStart
‪initializeGlobalTimeTrackingVariablesSetsGlobalTypo3MiscMicrotimeStart()
Definition: SystemEnvironmentBuilderTest.php:169
‪TYPO3
‪TYPO3\CMS\Core\Tests\Unit\Core\SystemEnvironmentBuilderTest\getPathThisScriptCliReadsLocalPartFromArgv
‪getPathThisScriptCliReadsLocalPartFromArgv()
Definition: SystemEnvironmentBuilderTest.php:68
‪TYPO3\CMS\Core\Tests\Unit\Core\SystemEnvironmentBuilderTest\initializeGlobalTimeTrackingVariablesRoundsSimAccessTimeToSixtySeconds
‪initializeGlobalTimeTrackingVariablesRoundsSimAccessTimeToSixtySeconds()
Definition: SystemEnvironmentBuilderTest.php:188
‪TYPO3\CMS\Core\Tests\Unit\Core\SystemEnvironmentBuilderTest\initializeGlobalVariablesSetsGlobalT3VarArray
‪initializeGlobalVariablesSetsGlobalT3VarArray()
Definition: SystemEnvironmentBuilderTest.php:122
‪TYPO3\CMS\Core\Tests\Unit\Core\SystemEnvironmentBuilderTest\initializeBasicErrorReportingExcludesNotice
‪initializeBasicErrorReportingExcludesNotice()
Definition: SystemEnvironmentBuilderTest.php:209
‪TYPO3\CMS\Core\Tests\Unit\Core\SystemEnvironmentBuilderTest\initializeBasicErrorReportingExcludesDeprecated
‪initializeBasicErrorReportingExcludesDeprecated()
Definition: SystemEnvironmentBuilderTest.php:221
‪TYPO3\CMS\Core\Tests\Unit\Core\SystemEnvironmentBuilderTest\getPathThisScriptCliReadsLocalPartFromEnv
‪getPathThisScriptCliReadsLocalPartFromEnv()
Definition: SystemEnvironmentBuilderTest.php:78
‪TYPO3\CMS\Core\Tests\Unit\Core\SystemEnvironmentBuilderTest\$subject
‪TYPO3 CMS Core Core SystemEnvironmentBuilder TYPO3 TestingFramework Core AccessibleObjectInterface $subject
Definition: SystemEnvironmentBuilderTest.php:26
‪TYPO3\CMS\Core\Tests\Unit\Core
Definition: ApplicationContextTest.php:2
‪TYPO3\CMS\Core\Tests\Unit\Core\SystemEnvironmentBuilderTest\fileDenyPatternMatchesPhpExtension
‪fileDenyPatternMatchesPhpExtension($phpExtension)
Definition: SystemEnvironmentBuilderTest.php:60
‪TYPO3\CMS\Core\Tests\Unit\Core\SystemEnvironmentBuilderTest\initializeBasicErrorReportingExcludesStrict
‪initializeBasicErrorReportingExcludesStrict()
Definition: SystemEnvironmentBuilderTest.php:197
‪$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:159
‪TYPO3\CMS\Core\Tests\Unit\Core\SystemEnvironmentBuilderTest\initializeGlobalTimeTrackingVariablesSetsGlobalVariablesDataProvider
‪array initializeGlobalTimeTrackingVariablesSetsGlobalVariablesDataProvider()
Definition: SystemEnvironmentBuilderTest.php:144
‪TYPO3\CMS\Core\Tests\Unit\Core\SystemEnvironmentBuilderTest\getPathThisScriptCliReadsLocalPartFromServer
‪getPathThisScriptCliReadsLocalPartFromServer()
Definition: SystemEnvironmentBuilderTest.php:89
‪TYPO3\CMS\Core\Tests\Unit\Core\SystemEnvironmentBuilderTest\initializeGlobalTimeTrackingVariablesRoundsAccessTimeToSixtySeconds
‪initializeGlobalTimeTrackingVariablesRoundsAccessTimeToSixtySeconds()
Definition: SystemEnvironmentBuilderTest.php:179
‪TYPO3\CMS\Core\Tests\Unit\Core\SystemEnvironmentBuilderTest\setUp
‪setUp()
Definition: SystemEnvironmentBuilderTest.php:31
‪TYPO3\CMS\Core\Tests\Unit\Core\SystemEnvironmentBuilderTest\fileDenyPatternMatchesPhpExtensionDataProvider
‪array fileDenyPatternMatchesPhpExtensionDataProvider()
Definition: SystemEnvironmentBuilderTest.php:41
‪TYPO3\CMS\Core\Tests\Unit\Core\SystemEnvironmentBuilderTest
Definition: SystemEnvironmentBuilderTest.php:23