[TASK] Re-work/simplify copyright header in PHP files - Part 4
[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 * Testcase
18 *
19 * @author Christia Kuhn <lolli@schwarzbu.ch>
20 */
21 class SystemEnvironmentBuilderTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
22
23 /**
24 * @var \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
25 */
26 protected $fixture = NULL;
27
28 /**
29 * Set up testcase
30 *
31 * @return void
32 */
33 public function setUp() {
34 $this->fixture = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Core\\SystemEnvironmentBuilder', array('dummy'));
35 }
36
37 /**
38 * Data provider for 'fileDenyPatternMatchesPhpExtension' test case.
39 *
40 * @return array
41 */
42 public function fileDenyPatternMatchesPhpExtensionDataProvider() {
43 $fileName = uniqid('filename');
44 $data = array();
45 $phpExtensions = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', 'php,php3,php4,php5,php6,phpsh,phtml', TRUE);
46 foreach ($phpExtensions as $extension) {
47 $data[] = array($fileName . '.' . $extension);
48 $data[] = array($fileName . '.' . $extension . '.txt');
49 }
50 return $data;
51 }
52
53 /**
54 * Tests whether an accordant PHP extension is denied.
55 *
56 * @test
57 * @dataProvider fileDenyPatternMatchesPhpExtensionDataProvider
58 * @param string $phpExtension
59 */
60 public function fileDenyPatternMatchesPhpExtension($phpExtension) {
61 $this->assertGreaterThan(0, preg_match('/' . FILE_DENY_PATTERN_DEFAULT . '/', $phpExtension), $phpExtension);
62 }
63
64 /**
65 * @test
66 */
67 public function getPathThisScriptCliReadsLocalPartFromArgv() {
68 $fakedLocalPart = uniqid('Test');
69 $GLOBALS['_SERVER']['argv'][0] = $fakedLocalPart;
70 $this->assertStringEndsWith($fakedLocalPart, $this->fixture->_call('getPathThisScriptCli'));
71 }
72
73 /**
74 * @test
75 */
76 public function getPathThisScriptCliReadsLocalPartFromEnv() {
77 $fakedLocalPart = uniqid('Test');
78 unset($GLOBALS['_SERVER']['argv']);
79 $GLOBALS['_ENV']['_'] = $fakedLocalPart;
80 $this->assertStringEndsWith($fakedLocalPart, $this->fixture->_call('getPathThisScriptCli'));
81 }
82
83 /**
84 * @test
85 */
86 public function getPathThisScriptCliReadsLocalPartFromServer() {
87 $fakedLocalPart = uniqid('Test');
88 unset($GLOBALS['_SERVER']['argv']);
89 unset($GLOBALS['_ENV']['_']);
90 $GLOBALS['_SERVER']['_'] = $fakedLocalPart;
91 $this->assertStringEndsWith($fakedLocalPart, $this->fixture->_call('getPathThisScriptCli'));
92 }
93
94 /**
95 * @test
96 */
97 public function getPathThisScriptCliAddsCurrentWorkingDirectoryFromServerEnvironmentToLocalPathOnUnix() {
98 if (TYPO3_OS === 'WIN') {
99 $this->markTestSkipped('Test not available on Windows OS.');
100 }
101 $GLOBALS['_SERVER']['argv'][0] = 'foo';
102 $fakedAbsolutePart = '/' . uniqid('Absolute') . '/';
103 $_SERVER['PWD'] = $fakedAbsolutePart;
104 $this->assertStringStartsWith($fakedAbsolutePart, $this->fixture->_call('getPathThisScriptCli'));
105 }
106
107 /**
108 * @test
109 */
110 public function getUnifiedDirectoryNameWithTrailingSlashReturnsCorrectPathOnUnix() {
111 if (TYPO3_OS === 'WIN') {
112 $this->markTestSkipped('Test not available on Windows OS.');
113 }
114 $input = '/foo/bar/test.php';
115 $expected = '/foo/bar/';
116 $actual = $this->fixture->_call('getUnifiedDirectoryNameWithTrailingSlash', $input);
117 $this->assertEquals($expected, $actual);
118 }
119
120 /**
121 * @test
122 */
123 public function addCorePearPathToIncludePathAddsTypo3ContribPearToPathAsFirstEntry() {
124 $backupPath = get_include_path();
125 $this->fixture->_call('addCorePearPathToIncludePath');
126 $actualValue = get_include_path();
127 set_include_path($backupPath);
128 $this->assertStringStartsWith(PATH_typo3 . 'contrib/pear/' . PATH_SEPARATOR, $actualValue);
129 }
130
131 /**
132 * @test
133 */
134 public function initializeGlobalVariablesUnsetsGlobalErrorArray() {
135 $GLOBALS['error'] = 'foo';
136 $this->fixture->_call('initializeGlobalVariables');
137 $this->assertFalse(isset($GLOBALS['error']));
138 }
139
140 /**
141 * @test
142 */
143 public function initializeGlobalVariablesSetsGlobalClientArray() {
144 unset($GLOBALS['CLIENT']);
145 $this->fixture->_call('initializeGlobalVariables');
146 $this->assertArrayHasKey('CLIENT', $GLOBALS);
147 }
148
149 /**
150 * @test
151 */
152 public function initializeGlobalVariablesSetsGlobalTypo3MiscArray() {
153 unset($GLOBALS['TYPO3_MISC']);
154 $this->fixture->_call('initializeGlobalVariables');
155 $this->assertInternalType('array', $GLOBALS['TYPO3_MISC']);
156 }
157
158 /**
159 * @test
160 */
161 public function initializeGlobalVariablesSetsGlobalT3VarArray() {
162 unset($GLOBALS['T3_VAR']);
163 $this->fixture->_call('initializeGlobalVariables');
164 $this->assertInternalType('array', $GLOBALS['T3_VAR']);
165 }
166
167 /**
168 * @test
169 */
170 public function initializeGlobalVariablesSetsGlobalT3ServicesArray() {
171 unset($GLOBALS['T3_SERVICES']);
172 $this->fixture->_call('initializeGlobalVariables');
173 $this->assertInternalType('array', $GLOBALS['T3_SERVICES']);
174 }
175
176 /**
177 * Data provider for initializeGlobalTimeTrackingVariablesSetsGlobalVariables
178 *
179 * @return array
180 */
181 public function initializeGlobalTimeTrackingVariablesSetsGlobalVariablesDataProvider() {
182 return array(
183 'PARSETIME_START' => array('PARSETIME_START'),
184 'EXEC_TIME' => array('EXEC_TIME'),
185 'ACCESS_TIME' => array('ACCESS_TIME'),
186 'SIM_EXEC_TIME' => array('SIM_EXEC_TIME'),
187 'SIM_ACCESS_TIME' => array('SIM_ACCESS_TIME')
188 );
189 }
190
191 /**
192 * @test
193 * @dataProvider initializeGlobalTimeTrackingVariablesSetsGlobalVariablesDataProvider
194 * @param string $variable Variable to check for in $GLOBALS
195 */
196 public function initializeGlobalTimeTrackingVariablesSetsGlobalVariables($variable) {
197 unset($GLOBALS[$variable]);
198 $this->fixture->_call('initializeGlobalTimeTrackingVariables');
199 $this->assertTrue(isset($GLOBALS[$variable]));
200 }
201
202 /**
203 * @test
204 */
205 public function initializeGlobalTimeTrackingVariablesSetsGlobalTypo3MiscMicrotimeStart() {
206 unset($GLOBALS['TYPO3_MISC']['microtime_start']);
207 $this->fixture->_call('initializeGlobalTimeTrackingVariables');
208 $this->assertTrue(isset($GLOBALS['TYPO3_MISC']['microtime_start']));
209 }
210
211 /**
212 * @test
213 */
214 public function initializeGlobalTimeTrackingVariablesRoundsAccessTimeToSixtySeconds() {
215 $this->fixture->_call('initializeGlobalTimeTrackingVariables');
216 $this->assertEquals(0, $GLOBALS['ACCESS_TIME'] % 60);
217 }
218
219 /**
220 * @test
221 */
222 public function initializeGlobalTimeTrackingVariablesRoundsSimAccessTimeToSixtySeconds() {
223 $this->fixture->_call('initializeGlobalTimeTrackingVariables');
224 $this->assertEquals(0, $GLOBALS['SIM_ACCESS_TIME'] % 60);
225 }
226
227 /**
228 * @test
229 */
230 public function initializeBasicErrorReportingExcludesStrict() {
231 $backupReporting = error_reporting();
232 $this->fixture->_call('initializeBasicErrorReporting');
233 $actualReporting = error_reporting();
234 error_reporting($backupReporting);
235 $this->assertEquals(0, $actualReporting & E_STRICT);
236 }
237
238 /**
239 * @test
240 */
241 public function initializeBasicErrorReportingExcludesNotice() {
242 $backupReporting = error_reporting();
243 $this->fixture->_call('initializeBasicErrorReporting');
244 $actualReporting = error_reporting();
245 error_reporting($backupReporting);
246 $this->assertEquals(0, $actualReporting & E_NOTICE);
247 }
248
249 /**
250 * @test
251 */
252 public function initializeBasicErrorReportingExcludesDeprecated() {
253 $backupReporting = error_reporting();
254 $this->fixture->_call('initializeBasicErrorReporting');
255 $actualReporting = error_reporting();
256 error_reporting($backupReporting);
257 $this->assertEquals(0, $actualReporting & E_DEPRECATED);
258 }
259
260 }