[!!!][TASK] Remove global variable PARSETIME_START
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Core / SystemEnvironmentBuilderTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Core;
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 /**
18 * Testcase
19 */
20 class SystemEnvironmentBuilderTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
21 {
22 /**
23 * @var \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder|\TYPO3\TestingFramework\Core\AccessibleObjectInterface
24 */
25 protected $subject = null;
26
27 /**
28 * Set up testcase
29 */
30 protected function setUp()
31 {
32 $this->subject = $this->getAccessibleMock(\TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::class, ['dummy']);
33 }
34
35 /**
36 * Data provider for 'fileDenyPatternMatchesPhpExtension' test case.
37 *
38 * @return array
39 */
40 public function fileDenyPatternMatchesPhpExtensionDataProvider()
41 {
42 $fileName = $this->getUniqueId('filename');
43 $data = [];
44 $phpExtensions = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', 'php,php3,php4,php5,php6,phpsh,phtml,pht', true);
45 foreach ($phpExtensions as $extension) {
46 $data[] = [$fileName . '.' . $extension];
47 $data[] = [$fileName . '.' . $extension . '.txt'];
48 }
49 return $data;
50 }
51
52 /**
53 * Tests whether an accordant PHP extension is denied.
54 *
55 * @test
56 * @dataProvider fileDenyPatternMatchesPhpExtensionDataProvider
57 * @param string $phpExtension
58 */
59 public function fileDenyPatternMatchesPhpExtension($phpExtension)
60 {
61 $this->assertGreaterThan(0, preg_match('/' . FILE_DENY_PATTERN_DEFAULT . '/', $phpExtension), $phpExtension);
62 }
63
64 /**
65 * @test
66 */
67 public function getPathThisScriptCliReadsLocalPartFromArgv()
68 {
69 $fakedLocalPart = $this->getUniqueId('Test');
70 $GLOBALS['_SERVER']['argv'][0] = $fakedLocalPart;
71 $this->assertStringEndsWith($fakedLocalPart, $this->subject->_call('getPathThisScriptCli'));
72 }
73
74 /**
75 * @test
76 */
77 public function getPathThisScriptCliReadsLocalPartFromEnv()
78 {
79 $fakedLocalPart = $this->getUniqueId('Test');
80 unset($GLOBALS['_SERVER']['argv']);
81 $GLOBALS['_ENV']['_'] = $fakedLocalPart;
82 $this->assertStringEndsWith($fakedLocalPart, $this->subject->_call('getPathThisScriptCli'));
83 }
84
85 /**
86 * @test
87 */
88 public function getPathThisScriptCliReadsLocalPartFromServer()
89 {
90 $fakedLocalPart = $this->getUniqueId('Test');
91 unset($GLOBALS['_SERVER']['argv']);
92 unset($GLOBALS['_ENV']['_']);
93 $GLOBALS['_SERVER']['_'] = $fakedLocalPart;
94 $this->assertStringEndsWith($fakedLocalPart, $this->subject->_call('getPathThisScriptCli'));
95 }
96
97 /**
98 * @test
99 */
100 public function getPathThisScriptCliAddsCurrentWorkingDirectoryFromServerEnvironmentToLocalPathOnUnix()
101 {
102 $GLOBALS['_SERVER']['argv'][0] = 'foo';
103 $fakedAbsolutePart = '/' . $this->getUniqueId('Absolute') . '/';
104 $_SERVER['PWD'] = $fakedAbsolutePart;
105 $this->assertStringStartsWith($fakedAbsolutePart, $this->subject->_call('getPathThisScriptCli'));
106 }
107
108 /**
109 * @test
110 */
111 public function initializeGlobalVariablesSetsGlobalTypo3MiscArray()
112 {
113 unset($GLOBALS['TYPO3_MISC']);
114 $this->subject->_call('initializeGlobalVariables');
115 $this->assertInternalType('array', $GLOBALS['TYPO3_MISC']);
116 }
117
118 /**
119 * @test
120 */
121 public function initializeGlobalVariablesSetsGlobalT3VarArray()
122 {
123 unset($GLOBALS['T3_VAR']);
124 $this->subject->_call('initializeGlobalVariables');
125 $this->assertInternalType('array', $GLOBALS['T3_VAR']);
126 }
127
128 /**
129 * @test
130 */
131 public function initializeGlobalVariablesSetsGlobalT3ServicesArray()
132 {
133 unset($GLOBALS['T3_SERVICES']);
134 $this->subject->_call('initializeGlobalVariables');
135 $this->assertInternalType('array', $GLOBALS['T3_SERVICES']);
136 }
137
138 /**
139 * Data provider for initializeGlobalTimeTrackingVariablesSetsGlobalVariables
140 *
141 * @return array
142 */
143 public function initializeGlobalTimeTrackingVariablesSetsGlobalVariablesDataProvider()
144 {
145 return [
146 'EXEC_TIME' => ['EXEC_TIME'],
147 'ACCESS_TIME' => ['ACCESS_TIME'],
148 'SIM_EXEC_TIME' => ['SIM_EXEC_TIME'],
149 'SIM_ACCESS_TIME' => ['SIM_ACCESS_TIME']
150 ];
151 }
152
153 /**
154 * @test
155 * @dataProvider initializeGlobalTimeTrackingVariablesSetsGlobalVariablesDataProvider
156 * @param string $variable Variable to check for in $GLOBALS
157 */
158 public function initializeGlobalTimeTrackingVariablesSetsGlobalVariables($variable)
159 {
160 unset($GLOBALS[$variable]);
161 $this->subject->_call('initializeGlobalTimeTrackingVariables');
162 $this->assertTrue(isset($GLOBALS[$variable]));
163 }
164
165 /**
166 * @test
167 */
168 public function initializeGlobalTimeTrackingVariablesSetsGlobalTypo3MiscMicrotimeStart()
169 {
170 unset($GLOBALS['TYPO3_MISC']['microtime_start']);
171 $this->subject->_call('initializeGlobalTimeTrackingVariables');
172 $this->assertTrue(isset($GLOBALS['TYPO3_MISC']['microtime_start']));
173 }
174
175 /**
176 * @test
177 */
178 public function initializeGlobalTimeTrackingVariablesRoundsAccessTimeToSixtySeconds()
179 {
180 $this->subject->_call('initializeGlobalTimeTrackingVariables');
181 $this->assertEquals(0, $GLOBALS['ACCESS_TIME'] % 60);
182 }
183
184 /**
185 * @test
186 */
187 public function initializeGlobalTimeTrackingVariablesRoundsSimAccessTimeToSixtySeconds()
188 {
189 $this->subject->_call('initializeGlobalTimeTrackingVariables');
190 $this->assertEquals(0, $GLOBALS['SIM_ACCESS_TIME'] % 60);
191 }
192
193 /**
194 * @test
195 */
196 public function initializeBasicErrorReportingExcludesStrict()
197 {
198 $backupReporting = error_reporting();
199 $this->subject->_call('initializeBasicErrorReporting');
200 $actualReporting = error_reporting();
201 error_reporting($backupReporting);
202 $this->assertEquals(0, $actualReporting & E_STRICT);
203 }
204
205 /**
206 * @test
207 */
208 public function initializeBasicErrorReportingExcludesNotice()
209 {
210 $backupReporting = error_reporting();
211 $this->subject->_call('initializeBasicErrorReporting');
212 $actualReporting = error_reporting();
213 error_reporting($backupReporting);
214 $this->assertEquals(0, $actualReporting & E_NOTICE);
215 }
216
217 /**
218 * @test
219 */
220 public function initializeBasicErrorReportingExcludesDeprecated()
221 {
222 $backupReporting = error_reporting();
223 $this->subject->_call('initializeBasicErrorReporting');
224 $actualReporting = error_reporting();
225 error_reporting($backupReporting);
226 $this->assertEquals(0, $actualReporting & E_DEPRECATED);
227 }
228 }