92988a39f01747e44a5845a4597a9b0e530a0938
[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 'PARSETIME_START' => ['PARSETIME_START'],
147 'EXEC_TIME' => ['EXEC_TIME'],
148 'ACCESS_TIME' => ['ACCESS_TIME'],
149 'SIM_EXEC_TIME' => ['SIM_EXEC_TIME'],
150 'SIM_ACCESS_TIME' => ['SIM_ACCESS_TIME']
151 ];
152 }
153
154 /**
155 * @test
156 * @dataProvider initializeGlobalTimeTrackingVariablesSetsGlobalVariablesDataProvider
157 * @param string $variable Variable to check for in $GLOBALS
158 */
159 public function initializeGlobalTimeTrackingVariablesSetsGlobalVariables($variable)
160 {
161 unset($GLOBALS[$variable]);
162 $this->subject->_call('initializeGlobalTimeTrackingVariables');
163 $this->assertTrue(isset($GLOBALS[$variable]));
164 }
165
166 /**
167 * @test
168 */
169 public function initializeGlobalTimeTrackingVariablesSetsGlobalTypo3MiscMicrotimeStart()
170 {
171 unset($GLOBALS['TYPO3_MISC']['microtime_start']);
172 $this->subject->_call('initializeGlobalTimeTrackingVariables');
173 $this->assertTrue(isset($GLOBALS['TYPO3_MISC']['microtime_start']));
174 }
175
176 /**
177 * @test
178 */
179 public function initializeGlobalTimeTrackingVariablesRoundsAccessTimeToSixtySeconds()
180 {
181 $this->subject->_call('initializeGlobalTimeTrackingVariables');
182 $this->assertEquals(0, $GLOBALS['ACCESS_TIME'] % 60);
183 }
184
185 /**
186 * @test
187 */
188 public function initializeGlobalTimeTrackingVariablesRoundsSimAccessTimeToSixtySeconds()
189 {
190 $this->subject->_call('initializeGlobalTimeTrackingVariables');
191 $this->assertEquals(0, $GLOBALS['SIM_ACCESS_TIME'] % 60);
192 }
193
194 /**
195 * @test
196 */
197 public function initializeBasicErrorReportingExcludesStrict()
198 {
199 $backupReporting = error_reporting();
200 $this->subject->_call('initializeBasicErrorReporting');
201 $actualReporting = error_reporting();
202 error_reporting($backupReporting);
203 $this->assertEquals(0, $actualReporting & E_STRICT);
204 }
205
206 /**
207 * @test
208 */
209 public function initializeBasicErrorReportingExcludesNotice()
210 {
211 $backupReporting = error_reporting();
212 $this->subject->_call('initializeBasicErrorReporting');
213 $actualReporting = error_reporting();
214 error_reporting($backupReporting);
215 $this->assertEquals(0, $actualReporting & E_NOTICE);
216 }
217
218 /**
219 * @test
220 */
221 public function initializeBasicErrorReportingExcludesDeprecated()
222 {
223 $backupReporting = error_reporting();
224 $this->subject->_call('initializeBasicErrorReporting');
225 $actualReporting = error_reporting();
226 error_reporting($backupReporting);
227 $this->assertEquals(0, $actualReporting & E_DEPRECATED);
228 }
229 }