[TASK] Clean up unit tests on Windows
[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\CMS\Core\Tests\UnitTestCase
21 {
22 /**
23 * @var \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
24 */
25 protected $subject = null;
26
27 /**
28 * Set up testcase
29 *
30 * @return void
31 */
32 protected function setUp()
33 {
34 $this->subject = $this->getAccessibleMock(\TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::class, array('dummy'));
35 }
36
37 /**
38 * Data provider for 'fileDenyPatternMatchesPhpExtension' test case.
39 *
40 * @return array
41 */
42 public function fileDenyPatternMatchesPhpExtensionDataProvider()
43 {
44 $fileName = $this->getUniqueId('filename');
45 $data = array();
46 $phpExtensions = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', 'php,php3,php4,php5,php6,phpsh,phtml', true);
47 foreach ($phpExtensions as $extension) {
48 $data[] = array($fileName . '.' . $extension);
49 $data[] = array($fileName . '.' . $extension . '.txt');
50 }
51 return $data;
52 }
53
54 /**
55 * Tests whether an accordant PHP extension is denied.
56 *
57 * @test
58 * @dataProvider fileDenyPatternMatchesPhpExtensionDataProvider
59 * @param string $phpExtension
60 */
61 public function fileDenyPatternMatchesPhpExtension($phpExtension)
62 {
63 $this->assertGreaterThan(0, preg_match('/' . FILE_DENY_PATTERN_DEFAULT . '/', $phpExtension), $phpExtension);
64 }
65
66 /**
67 * @test
68 */
69 public function getPathThisScriptCliReadsLocalPartFromArgv()
70 {
71 $fakedLocalPart = $this->getUniqueId('Test');
72 $GLOBALS['_SERVER']['argv'][0] = $fakedLocalPart;
73 $this->assertStringEndsWith($fakedLocalPart, $this->subject->_call('getPathThisScriptCli'));
74 }
75
76 /**
77 * @test
78 */
79 public function getPathThisScriptCliReadsLocalPartFromEnv()
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
87 /**
88 * @test
89 */
90 public function getPathThisScriptCliReadsLocalPartFromServer()
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
99 /**
100 * @test
101 */
102 public function getPathThisScriptCliAddsCurrentWorkingDirectoryFromServerEnvironmentToLocalPathOnUnix()
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
110 /**
111 * @test
112 */
113 public function getUnifiedDirectoryNameReturnsCorrectPathOnUnix()
114 {
115 $input = '/foo/bar/test.php';
116 $expected = '/foo/bar';
117 $actual = $this->subject->_call('getUnifiedDirectoryName', $input);
118 $this->assertEquals($expected, $actual);
119 }
120
121 /**
122 * @test
123 */
124 public function initializeGlobalVariablesUnsetsGlobalErrorArray()
125 {
126 $GLOBALS['error'] = 'foo';
127 $this->subject->_call('initializeGlobalVariables');
128 $this->assertFalse(isset($GLOBALS['error']));
129 }
130
131 /**
132 * @test
133 */
134 public function initializeGlobalVariablesSetsGlobalTypo3MiscArray()
135 {
136 unset($GLOBALS['TYPO3_MISC']);
137 $this->subject->_call('initializeGlobalVariables');
138 $this->assertInternalType('array', $GLOBALS['TYPO3_MISC']);
139 }
140
141 /**
142 * @test
143 */
144 public function initializeGlobalVariablesSetsGlobalT3VarArray()
145 {
146 unset($GLOBALS['T3_VAR']);
147 $this->subject->_call('initializeGlobalVariables');
148 $this->assertInternalType('array', $GLOBALS['T3_VAR']);
149 }
150
151 /**
152 * @test
153 */
154 public function initializeGlobalVariablesSetsGlobalT3ServicesArray()
155 {
156 unset($GLOBALS['T3_SERVICES']);
157 $this->subject->_call('initializeGlobalVariables');
158 $this->assertInternalType('array', $GLOBALS['T3_SERVICES']);
159 }
160
161 /**
162 * Data provider for initializeGlobalTimeTrackingVariablesSetsGlobalVariables
163 *
164 * @return array
165 */
166 public function initializeGlobalTimeTrackingVariablesSetsGlobalVariablesDataProvider()
167 {
168 return array(
169 'PARSETIME_START' => array('PARSETIME_START'),
170 'EXEC_TIME' => array('EXEC_TIME'),
171 'ACCESS_TIME' => array('ACCESS_TIME'),
172 'SIM_EXEC_TIME' => array('SIM_EXEC_TIME'),
173 'SIM_ACCESS_TIME' => array('SIM_ACCESS_TIME')
174 );
175 }
176
177 /**
178 * @test
179 * @dataProvider initializeGlobalTimeTrackingVariablesSetsGlobalVariablesDataProvider
180 * @param string $variable Variable to check for in $GLOBALS
181 */
182 public function initializeGlobalTimeTrackingVariablesSetsGlobalVariables($variable)
183 {
184 unset($GLOBALS[$variable]);
185 $this->subject->_call('initializeGlobalTimeTrackingVariables');
186 $this->assertTrue(isset($GLOBALS[$variable]));
187 }
188
189 /**
190 * @test
191 */
192 public function initializeGlobalTimeTrackingVariablesSetsGlobalTypo3MiscMicrotimeStart()
193 {
194 unset($GLOBALS['TYPO3_MISC']['microtime_start']);
195 $this->subject->_call('initializeGlobalTimeTrackingVariables');
196 $this->assertTrue(isset($GLOBALS['TYPO3_MISC']['microtime_start']));
197 }
198
199 /**
200 * @test
201 */
202 public function initializeGlobalTimeTrackingVariablesRoundsAccessTimeToSixtySeconds()
203 {
204 $this->subject->_call('initializeGlobalTimeTrackingVariables');
205 $this->assertEquals(0, $GLOBALS['ACCESS_TIME'] % 60);
206 }
207
208 /**
209 * @test
210 */
211 public function initializeGlobalTimeTrackingVariablesRoundsSimAccessTimeToSixtySeconds()
212 {
213 $this->subject->_call('initializeGlobalTimeTrackingVariables');
214 $this->assertEquals(0, $GLOBALS['SIM_ACCESS_TIME'] % 60);
215 }
216
217 /**
218 * @test
219 */
220 public function initializeBasicErrorReportingExcludesStrict()
221 {
222 $backupReporting = error_reporting();
223 $this->subject->_call('initializeBasicErrorReporting');
224 $actualReporting = error_reporting();
225 error_reporting($backupReporting);
226 $this->assertEquals(0, $actualReporting & E_STRICT);
227 }
228
229 /**
230 * @test
231 */
232 public function initializeBasicErrorReportingExcludesNotice()
233 {
234 $backupReporting = error_reporting();
235 $this->subject->_call('initializeBasicErrorReporting');
236 $actualReporting = error_reporting();
237 error_reporting($backupReporting);
238 $this->assertEquals(0, $actualReporting & E_NOTICE);
239 }
240
241 /**
242 * @test
243 */
244 public function initializeBasicErrorReportingExcludesDeprecated()
245 {
246 $backupReporting = error_reporting();
247 $this->subject->_call('initializeBasicErrorReporting');
248 $actualReporting = error_reporting();
249 error_reporting($backupReporting);
250 $this->assertEquals(0, $actualReporting & E_DEPRECATED);
251 }
252 }