2 namespace TYPO3\CMS\Core\Tests\Unit
;
4 /***************************************************************
7 * (c) 2011 Andreas Wolf <andreas.wolf@ikt-werk.de>
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
28 * Testcase for TYPO3\CMS\Core\Autoloader
32 * @author Andreas Wolf <andreas.wolf@ikt-werk.de>
34 class AutoloaderTest
extends \Tx_Phpunit_TestCase
{
37 * @var boolean Enable backup of global and system variables
39 protected $backupGlobals = TRUE;
42 * Exclude TYPO3_DB from backup/ restore of $GLOBALS
43 * because resource types cannot be handled during serializing
47 protected $backupGlobalsBlacklist = array('TYPO3_DB');
50 * @var array Backup of typo3CacheManager
52 protected $typo3CacheManager = NULL;
55 * @var array Register of temporary extensions in typo3temp
57 protected $fakedExtensions = array();
60 * Fix a race condition that t3lib_div is not available
61 * during tearDown if fiddling with the autoloader where
62 * backupGlobals is not set up again yet
64 public function setUp() {
65 $this->typo3CacheManager
= $GLOBALS['typo3CacheManager'];
70 * Warning: Since phpunit itself is php and we are fiddling with php
71 * autoloader code here, the tests are a bit fragile. This tearDown
72 * method ensures that all main classes are available again during
73 * tear down of a testcase.
74 * This construct will fail if the class under test is changed and
75 * not compatible anymore. Make sure to always run the whole test
76 * suite if fiddling with the autoloader unit tests to ensure that
77 * there is no fatal error thrown in other unit test classes triggered
78 * by errors in this one.
80 public function tearDown() {
81 $GLOBALS['typo3CacheManager'] = $this->typo3CacheManager
;
82 \TYPO3\CMS\Core\Autoloader
::unregisterAutoloader();
83 \TYPO3\CMS\Core\Autoloader
::registerAutoloader();
84 foreach ($this->fakedExtensions
as $extension) {
85 \TYPO3\CMS\Core\Utility\GeneralUtility
::rmdir((PATH_site
. 'typo3temp/') . $extension, TRUE);
90 * Creates a fake extension inside typo3temp/. No configuration is created,
91 * just the folder, plus the extension is registered in $TYPO3_LOADED_EXT
93 * @return string The extension key
95 protected function createFakeExtension() {
96 $extKey = strtolower(uniqid('testing'));
97 $absExtPath = ((PATH_site
. 'typo3temp/') . $extKey) . '/';
98 $relPath = ('typo3temp/' . $extKey) . '/';
99 \TYPO3\CMS\Core\Utility\GeneralUtility
::mkdir($absExtPath);
100 $GLOBALS['TYPO3_LOADED_EXT'][$extKey] = array(
101 'siteRelPath' => $relPath
103 $GLOBALS['TYPO3_CONF_VARS']['EXT']['extListArray'][] = $extKey;
104 $this->fakedExtensions
[] = $extKey;
105 \TYPO3\CMS\Core\Extension\ExtensionManager
::clearExtensionKeyMap();
112 public function unregisterAndRegisterAgainDoesNotFatal() {
113 \TYPO3\CMS\Core\Autoloader
::unregisterAutoloader();
114 \TYPO3\CMS\Core\Autoloader
::registerAutoloader();
115 // If this fatals the autoload re registering went wrong
116 \TYPO3\CMS\Core\Utility\GeneralUtility
::makeInstance('TYPO3\\CMS\\Core\\TimeTracker\\NullTimeTracker');
122 public function unregisterAutoloaderSetsCacheEntryWithT3libNoTags() {
123 $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
124 // Expect the mock cache set method to be called
125 // once with t3lib_autoloader as third parameter
126 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->anything(), array());
127 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
128 $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
129 \TYPO3\CMS\Core\Autoloader
::unregisterAutoloader();
135 public function autoloadFindsClassFileDefinedInExtAutoloadFile() {
136 $extKey = $this->createFakeExtension();
137 $extPath = ((PATH_site
. 'typo3temp/') . $extKey) . '/';
138 $autoloaderFile = $extPath . 'ext_autoload.php';
139 $class = strtolower("tx_{$extKey}_" . uniqid(''));
140 $file = ($extPath . uniqid('')) . '.php';
141 file_put_contents($file, '<?php
143 throw new \\RuntimeException(\'\', 1310203812);
146 file_put_contents($autoloaderFile, ((('<?php
148 return array(\'' . $class) . '\' => \'') . $file) . '\');
151 // Inject a dummy for the core_phpcode cache to force the autoloader
152 // to re calculate the registry
153 $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
154 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
155 $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
156 // Re-initialize autoloader registry to force it to recognize the new extension
157 \TYPO3\CMS\Core\Autoloader
::unregisterAutoloader();
158 \TYPO3\CMS\Core\Autoloader
::registerAutoloader();
159 // Expect the exception of the file to be thrown
160 $this->setExpectedException('\\RuntimeException', '', 1310203812);
161 \TYPO3\CMS\Core\Autoloader
::autoload($class);
167 public function unregisterAutoloaderWritesLowerCasedClassFileToCache() {
168 $extKey = $this->createFakeExtension();
169 $extPath = ((PATH_site
. 'typo3temp/') . $extKey) . '/';
170 $autoloaderFile = $extPath . 'ext_autoload.php';
171 // A case sensitive key (FooBar) in ext_autoload file
172 $class = "tx_{$extKey}_" . uniqid('FooBar');
173 $file = ($extPath . uniqid('')) . '.php';
174 file_put_contents($autoloaderFile, ((('<?php
176 return array(\'' . $class) . '\' => \'') . $file) . '\');
179 // Inject a dummy for the core_phpcode cache to force the autoloader
180 // to re calculate the registry
181 $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
182 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
183 $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
184 // Expect that the lower case version of the class name is written to cache
185 $mockCache->expects($this->at(2))->method('set')->with($this->anything(), $this->stringContains(strtolower($class), FALSE));
186 // Re-initialize autoloader registry to force it to recognize the new extension
187 \TYPO3\CMS\Core\Autoloader
::unregisterAutoloader();
188 \TYPO3\CMS\Core\Autoloader
::registerAutoloader();
189 \TYPO3\CMS\Core\Autoloader
::unregisterAutoloader();
194 * @expectedException \RuntimeException
196 public function autoloadFindsClassFileIfExtAutoloadEntryIsCamelCased() {
197 $extKey = $this->createFakeExtension();
198 $extPath = ((PATH_site
. 'typo3temp/') . $extKey) . '/';
199 // A case sensitive key (FooBar) in ext_autoload file
200 $class = "tx_{$extKey}_" . uniqid('FooBar');
201 $file = ($extPath . uniqid('')) . '.php';
202 file_put_contents($file, '<?php
204 throw new \\RuntimeException(\'\', 1336756850);
207 $extAutoloadFile = $extPath . 'ext_autoload.php';
208 file_put_contents($extAutoloadFile, ((('<?php
210 return array(\'' . $class) . '\' => \'') . $file) . '\');
213 // Inject cache and return false, so autoloader is forced to read ext_autoloads from extensions
214 $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
215 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
216 $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
217 $mockCache->expects($this->any())->method('has')->will($this->returnValue(FALSE));
218 // Re-initialize autoloader registry to force it to recognize the new extension
219 \TYPO3\CMS\Core\Autoloader
::unregisterAutoloader();
220 \TYPO3\CMS\Core\Autoloader
::registerAutoloader();
221 \TYPO3\CMS\Core\Autoloader
::autoload($class);
226 * @expectedException \RuntimeException
228 public function autoloadFindsCamelCasedClassFileIfExtAutoloadEntryIsReadLowerCasedFromCache() {
229 $extKey = $this->createFakeExtension();
230 $extPath = ((PATH_site
. 'typo3temp/') . $extKey) . '/';
231 // A case sensitive key (FooBar) in ext_autoload file
232 $class = "tx_{$extKey}_" . uniqid('FooBar');
233 $file = ($extPath . uniqid('')) . '.php';
234 file_put_contents($file, '<?php
236 throw new \RuntimeException(\'\', 1336756850);
239 // Inject cache mock and let the cache entry return the lowercased class name as key
240 $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
241 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
242 $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
243 $mockCache->expects($this->any())->method('has')->will($this->returnValue(TRUE));
244 $mockCache->expects($this->once())->method('requireOnce')->will($this->returnValue(array(strtolower($class) => $file)));
245 // Re-initialize autoloader registry to force it to recognize the new extension
246 \TYPO3\CMS\Core\Autoloader
::unregisterAutoloader();
247 \TYPO3\CMS\Core\Autoloader
::registerAutoloader();
248 \TYPO3\CMS\Core\Autoloader
::autoload($class);
254 public function autoloadFindsClassFileThatRespectsExtbaseNamingSchemeWithoutExtAutoloadFile() {
255 $this->markTestSkipped('This test was a blocker for other namespaced tests.');
256 $extKey = $this->createFakeExtension();
257 $extPath = ((PATH_site
. 'typo3temp/') . $extKey) . '/';
258 // Create a class named Tx_Extension_Foo123_Bar456
259 // to find file extension/Classes/Foo123/Bar456.php
260 $pathSegment = 'Foo' . uniqid();
261 $fileName = 'Bar' . uniqid();
262 $class = (((('Tx_' . $extKey) . '_') . $pathSegment) . '_') . $fileName;
264 $file = (((($extPath . 'Classes/') . $pathSegment) . '/') . $fileName) . '.php';
265 \TYPO3\CMS\Core\Utility\GeneralUtility
::mkdir_deep(($extPath . 'Classes/') . $pathSegment);
266 file_put_contents($file, '<?php
268 throw new \\RuntimeException(\'\', 1310203813);
271 // Inject a dummy for the core_phpcode cache to cache
272 // the calculated cache entry to a dummy cache
273 $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
274 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
275 $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
276 // Expect the exception of the file to be thrown
277 $this->setExpectedException('RuntimeException', '', 1310203813);
278 \TYPO3\CMS\Core\Autoloader
::autoload($class);
284 public function unregisterAutoloaderWritesClassFileThatRespectsExtbaseNamingSchemeToCacheFile() {
285 $this->markTestSkipped('This test was a blocker for other namespaced tests.');
286 $extKey = $this->createFakeExtension();
287 $extPath = ((PATH_site
. 'typo3temp/') . $extKey) . '/';
288 $pathSegment = 'Foo' . uniqid();
289 $fileName = 'Bar' . uniqid();
290 $class = (((('Tx_' . $extKey) . '_') . $pathSegment) . '_') . $fileName;
291 $file = (((($extPath . 'Classes/') . $pathSegment) . '/') . $fileName) . '.php';
292 \TYPO3\CMS\Core\Utility\GeneralUtility
::mkdir_deep(($extPath . 'Classes/') . $pathSegment);
293 file_put_contents($file, '<?php
298 $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
299 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
300 $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
301 // Expect that an entry to the cache is written containing the newly found class
302 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->stringContains(strtolower($class), $this->anything()));
303 \TYPO3\CMS\Core\Autoloader
::autoload($class);
304 \TYPO3\CMS\Core\Autoloader
::unregisterAutoloader();
310 public function unregisterAutoloaderWritesClassFileLocationOfClassRespectingExtbaseNamingSchemeToCacheFile() {
311 $this->markTestSkipped('This test was a blocker for other namespaced tests.');
312 $extKey = $this->createFakeExtension();
313 $extPath = ((PATH_site
. 'typo3temp/') . $extKey) . '/';
314 $pathSegment = 'Foo' . uniqid();
315 $fileName = 'Bar' . uniqid();
316 $class = (((('Tx_' . $extKey) . '_') . $pathSegment) . '_') . $fileName;
317 $file = (((($extPath . 'Classes/') . $pathSegment) . '/') . $fileName) . '.php';
318 \TYPO3\CMS\Core\Utility\GeneralUtility
::mkdir_deep(($extPath . 'Classes/') . $pathSegment);
319 file_put_contents($file, '<?php
324 $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
325 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
326 $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
327 // Expect that an entry to the cache is written containing the newly found class
328 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->stringContains(strtolower($file), $this->anything()));
329 \TYPO3\CMS\Core\Autoloader
::autoload($class);
330 \TYPO3\CMS\Core\Autoloader
::unregisterAutoloader();
336 public function getClassPathByRegistryLookupFindsClassPrefixedWithUxRegisteredInExtAutoloadFile() {
337 // Create a dummy extension with a path to a 'ux_' prefixed php file
338 $extKey = $this->createFakeExtension();
339 $extPath = ((PATH_site
. 'typo3temp/') . $extKey) . '/';
340 $autoloaderFile = $extPath . 'ext_autoload.php';
341 $class = strtolower("ux_tx_{$extKey}_" . uniqid(''));
342 $file = ($extPath . uniqid('')) . '.php';
343 file_put_contents($autoloaderFile, ((('<?php
345 return array(\'' . $class) . '\' => \'') . $file) . '\');
348 // Inject a dummy for the core_phpcode cache to force the autoloader
349 // to re calculate the registry
350 $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
351 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
352 $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
353 // Re-initialize autoloader registry to force it to recognize the new extension with the ux_ autoload definition
354 \TYPO3\CMS\Core\Autoloader
::unregisterAutoloader();
355 \TYPO3\CMS\Core\Autoloader
::registerAutoloader();
356 $this->assertSame($file, \TYPO3\CMS\Core\Autoloader
::getClassPathByRegistryLookup($class));
362 public function unregisterAutoloaderWritesNotExistingUxCLassLookupFromGetClassPathByRegistryLookupToCache() {
363 $uxClassName = 'ux_Tx_Foo' . uniqid();
364 $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
365 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
366 $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
367 \TYPO3\CMS\Core\Autoloader
::unregisterAutoloader();
368 \TYPO3\CMS\Core\Autoloader
::registerAutoloader();
369 // Class is not found by returning NULL
370 $this->assertSame(NULL, \TYPO3\CMS\Core\Autoloader
::getClassPathByRegistryLookup($uxClassName));
371 // Expect NULL lookup is cached
372 $expectedCacheString = ('\'' . strtolower($uxClassName)) . '\' => NULL,';
373 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->stringContains($expectedCacheString));
374 // Trigger writing new cache file
375 \TYPO3\CMS\Core\Autoloader
::unregisterAutoloader();
381 public function unregisterAutoloaderWritesDeprecatedTypo3ConfVarsRegisteredXclassClassFoundByGetClassPathByRegistryLookupToCache() {
382 // Create a fake extension
383 $extKey = $this->createFakeExtension();
384 $extPath = ((PATH_site
. 'typo3temp/') . $extKey) . '/';
385 $autoloaderFile = $extPath . 'ext_autoload.php';
386 // Feed ext_autoload with a base file and the class file
387 $class = strtolower("tx_{$extKey}_" . uniqid(''));
388 $fileName = uniqid('') . '.php';
389 $file = $extPath . $fileName;
390 $xClassFile = ('typo3temp/' . $extKey) . '/xclassFile';
391 file_put_contents($autoloaderFile, ((('<?php
393 return array(\'' . $class) . '\' => \'') . $file) . '\');
396 file_put_contents(PATH_site
. $xClassFile, '<?php
401 // Register a xclass for the base file
402 $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['XCLASS'][(('typo3temp/' . $extKey) . '/') . $fileName] = $xClassFile;
403 // Inject a dummy for the core_phpcode cache to force the autoloader
404 // to re calculate the registry
405 $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
406 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
407 $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
408 // Excpect the cache entry to be called once with the new class name
409 $mockCache->expects($this->at(2))->method('set')->with($this->anything(), $this->stringContains('ux_' . $class));
410 \TYPO3\CMS\Core\Autoloader
::unregisterAutoloader();
411 \TYPO3\CMS\Core\Autoloader
::registerAutoloader();
412 \TYPO3\CMS\Core\Autoloader
::getClassPathByRegistryLookup('ux_' . $class);
413 \TYPO3\CMS\Core\Autoloader
::unregisterAutoloader();
419 public function autoloadFindsClassFileThatRespectsExtbaseNamingSchemeWithNamespace() {
420 $this->markTestSkipped('This test was a blocker for other namespaced tests.');
421 $extKey = $this->createFakeExtension();
422 $extPath = ((PATH_site
. 'typo3temp/') . $extKey) . '/';
423 // Create a class named \Tx\Extension\Foo123\Bar456
424 // to find file extension/Classes/Foo123/Bar456.php
425 $pathSegment = 'Foo' . uniqid();
426 $fileName = 'Bar' . uniqid();
427 $namespacedClass = (((('\\Vendor\\' . $extKey) . '\\') . $pathSegment) . '\\') . $fileName;
428 $file = (((($extPath . 'Classes/') . $pathSegment) . '/') . $fileName) . '.php';
429 \TYPO3\CMS\Core\Utility\GeneralUtility
::mkdir_deep(($extPath . 'Classes/') . $pathSegment);
430 file_put_contents($file, ((('<?php' . LF
) . 'throw new RuntimeException(\'\', 1342800577);') . LF
) . '?>');
431 // Re-initialize autoloader registry to force it to recognize the new extension
432 \TYPO3\CMS\Core\Autoloader
::unregisterAutoloader();
433 \TYPO3\CMS\Core\Autoloader
::registerAutoloader();
434 // Expect the exception of the file to be thrown
435 $this->setExpectedException('\\RuntimeException', '', 1342800577);
436 \TYPO3\CMS\Core\Autoloader
::autoload($namespacedClass);
442 public function unregisterAutoloaderWritesClassFileLocationOfClassRespectingExtbaseNamingSchemeWithNamespaceToCacheFile() {
443 $this->markTestSkipped('This test was a blocker for other namespaced tests.');
444 $extKey = $this->createFakeExtension();
445 $extPath = ((PATH_site
. 'typo3temp/') . $extKey) . '/';
446 $pathSegment = 'Foo' . uniqid();
447 $fileName = 'Bar' . uniqid();
448 $namespacedClass = (((('\\Tx\\' . $extKey) . '\\') . $pathSegment) . '\\') . $fileName;
449 $file = (((($extPath . 'Classes/') . $pathSegment) . '/') . $fileName) . '.php';
450 \TYPO3\CMS\Core\Utility\GeneralUtility
::mkdir_deep(($extPath . 'Classes/') . $pathSegment);
451 file_put_contents($file, ('<?php' . LF
) . ($foo = ('bar;' . LF
) . '?>'));
452 $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
453 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
454 $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
455 // Expect that an entry to the cache is written containing the newly found class
456 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->stringContains(strtolower($file), $this->anything()));
457 \TYPO3\CMS\Core\Autoloader
::autoload($namespacedClass);
458 \TYPO3\CMS\Core\Autoloader
::unregisterAutoloader();
464 public function checkClassNamesNotExtbaseSchemePassAutoloaderUntouched() {
465 $class = '\\Symfony\\Foo\\Bar';
466 $this->assertNull(\TYPO3\CMS\Core\Autoloader
::getClassPathByRegistryLookup($class));
472 public function checkAutoloaderSetsNamespacedClassnamesInExtAutoloadAreWrittenToCache() {
473 $extKey = $this->createFakeExtension();
474 $extPath = ((PATH_site
. 'typo3temp/') . $extKey) . '/';
475 $pathSegment = 'Foo' . uniqid();
476 $fileName = 'Bar' . uniqid();
477 $autoloaderFile = $extPath . 'ext_autoload.php';
478 // A case sensitive key (FooBar) in ext_autoload file
479 $namespacedClass = (((('\\Tx\\' . $extKey) . '\\') . $pathSegment) . '\\') . $fileName;
480 file_put_contents($autoloaderFile, ((((('<?php' . LF
) . 'return array(\'') . $namespacedClass) . '\' => \'EXT:someExt/Classes/Foo/bar.php\');') . LF
) . '?>');
481 // Inject a dummy for the core_phpcode cache to force the autoloader
482 // to re calculate the registry
483 $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
484 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
485 $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
486 // Expect that the lower case version of the class name is written to cache
487 $mockCache->expects($this->at(2))->method('set')->with($this->anything(), $this->stringContains(strtolower($namespacedClass), FALSE));
488 // Re-initialize autoloader registry to force it to recognize the new extension
489 \TYPO3\CMS\Core\Autoloader
::unregisterAutoloader();
490 \TYPO3\CMS\Core\Autoloader
::registerAutoloader();
491 \TYPO3\CMS\Core\Autoloader
::unregisterAutoloader();