TYPO3 CMS  TYPO3_8-7
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 
20 class SystemEnvironmentBuilderTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
21 {
25  protected $subject = null;
26 
30  protected function setUp()
31  {
32  $this->subject = $this->getAccessibleMock(\TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::class, ['dummy']);
33  }
34 
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 
59  public function fileDenyPatternMatchesPhpExtension($phpExtension)
60  {
61  $this->assertGreaterThan(0, preg_match('/' . FILE_DENY_PATTERN_DEFAULT . '/', $phpExtension), $phpExtension);
62  }
63 
68  {
69  $fakedLocalPart = $this->getUniqueId('Test');
70  $GLOBALS['_SERVER']['argv'][0] = $fakedLocalPart;
71  $this->assertStringEndsWith($fakedLocalPart, $this->subject->_call('getPathThisScriptCli'));
72  }
73 
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 
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 
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 
112  {
113  $GLOBALS['error'] = 'foo';
114  $this->subject->_call('initializeGlobalVariables');
115  $this->assertFalse(isset($GLOBALS['error']));
116  }
117 
122  {
123  unset($GLOBALS['TYPO3_MISC']);
124  $this->subject->_call('initializeGlobalVariables');
125  $this->assertInternalType('array', $GLOBALS['TYPO3_MISC']);
126  }
127 
132  {
133  unset($GLOBALS['T3_VAR']);
134  $this->subject->_call('initializeGlobalVariables');
135  $this->assertInternalType('array', $GLOBALS['T3_VAR']);
136  }
137 
142  {
143  unset($GLOBALS['T3_SERVICES']);
144  $this->subject->_call('initializeGlobalVariables');
145  $this->assertInternalType('array', $GLOBALS['T3_SERVICES']);
146  }
147 
154  {
155  return [
156  'PARSETIME_START' => ['PARSETIME_START'],
157  'EXEC_TIME' => ['EXEC_TIME'],
158  'ACCESS_TIME' => ['ACCESS_TIME'],
159  'SIM_EXEC_TIME' => ['SIM_EXEC_TIME'],
160  'SIM_ACCESS_TIME' => ['SIM_ACCESS_TIME']
161  ];
162  }
163 
170  {
171  unset($GLOBALS[$variable]);
172  $this->subject->_call('initializeGlobalTimeTrackingVariables');
173  $this->assertTrue(isset($GLOBALS[$variable]));
174  }
175 
180  {
181  unset($GLOBALS['TYPO3_MISC']['microtime_start']);
182  $this->subject->_call('initializeGlobalTimeTrackingVariables');
183  $this->assertTrue(isset($GLOBALS['TYPO3_MISC']['microtime_start']));
184  }
185 
190  {
191  $this->subject->_call('initializeGlobalTimeTrackingVariables');
192  $this->assertEquals(0, $GLOBALS['ACCESS_TIME'] % 60);
193  }
194 
199  {
200  $this->subject->_call('initializeGlobalTimeTrackingVariables');
201  $this->assertEquals(0, $GLOBALS['SIM_ACCESS_TIME'] % 60);
202  }
203 
208  {
209  $backupReporting = error_reporting();
210  $this->subject->_call('initializeBasicErrorReporting');
211  $actualReporting = error_reporting();
212  error_reporting($backupReporting);
213  $this->assertEquals(0, $actualReporting & E_STRICT);
214  }
215 
220  {
221  $backupReporting = error_reporting();
222  $this->subject->_call('initializeBasicErrorReporting');
223  $actualReporting = error_reporting();
224  error_reporting($backupReporting);
225  $this->assertEquals(0, $actualReporting & E_NOTICE);
226  }
227 
232  {
233  $backupReporting = error_reporting();
234  $this->subject->_call('initializeBasicErrorReporting');
235  $actualReporting = error_reporting();
236  error_reporting($backupReporting);
237  $this->assertEquals(0, $actualReporting & E_DEPRECATED);
238  }
239 }
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']