diff --git a/t3lib/class.t3lib_autoloader.php b/t3lib/class.t3lib_autoloader.php index fc432268a4a141638e26bbec518ef87c5becdcf2..f641ae01b0e2db5cdd1afbc3232397c359bee6a8 100644 --- a/t3lib/class.t3lib_autoloader.php +++ b/t3lib/class.t3lib_autoloader.php @@ -324,7 +324,7 @@ class t3lib_autoloader { protected static function updateRegistryCacheEntry(array $registry) { $cachedFileContent = 'return array('; foreach ($registry as $className => $classLocation) { - $cachedFileContent .= LF . '\'' . $className . '\' => \'' . $classLocation . '\','; + $cachedFileContent .= LF . '\'' . strtolower($className) . '\' => \'' . $classLocation . '\','; } $cachedFileContent .= LF . ');'; $GLOBALS['typo3CacheManager']->getCache('cache_phpcode')->set( diff --git a/tests/Unit/t3lib/class.t3lib_autoloaderTest.php b/tests/Unit/t3lib/class.t3lib_autoloaderTest.php index 4ddd0fa09bfba6e4c4f35bb254aff527f5660b4b..aae0643883dc1b31d97f921c9e9fc5f6bdf44c13 100644 --- a/tests/Unit/t3lib/class.t3lib_autoloaderTest.php +++ b/tests/Unit/t3lib/class.t3lib_autoloaderTest.php @@ -161,6 +161,64 @@ class t3lib_autoloaderTest extends Tx_Phpunit_TestCase { t3lib_autoloader::autoload($class); } + /** + * @test + */ + public function autoloadWritesLowerCasedClassFileToCache() { + $extKey = $this->createFakeExtension(); + $extPath = PATH_site . "typo3temp/$extKey/"; + $autoloaderFile = $extPath . "ext_autoload.php"; + + // A case sensitive key (FooBar) in ext_autoload file + $class = "tx_${extKey}_" . uniqid('FooBar'); + $file = $extPath . uniqid('') . '.php'; + + file_put_contents($autoloaderFile, "<?php\n\nreturn array('$class' => '$file');\n\n?>"); + + // Inject a dummy for the core_phpcode cache to force the autoloader + // to re calculate the registry + $mockCache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE); + $GLOBALS['typo3CacheManager'] = $this->getMock('t3lib_cache_Manager', array('getCache')); + $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache)); + + // Expect that the lower case version of the class name is written to cache + $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->stringContains(strtolower($class), FALSE)); + + // Re-initialize autoloader registry to force it to recognize the new extension + t3lib_autoloader::unregisterAutoloader(); + t3lib_autoloader::registerAutoloader(); + } + + /** + * @test + * @expectedException RuntimeException + */ + public function autoloadFindsCamelCasedClassFileIfExtAutoloadEntryIsLowerCased() { + $extKey = $this->createFakeExtension(); + $extPath = PATH_site . "typo3temp/$extKey/"; + + // A case sensitive key (FooBar) in ext_autoload file + $class = "tx_${extKey}_" . uniqid('FooBar'); + $file = $extPath . uniqid('') . '.php'; + + file_put_contents($file, "<?php\n\nthrow new RuntimeException('', 1336756850);\n\n?>"); + + // Inject a dummy for the core_phpcode cache to force the autoloader + // to re calculate the registry + $mockCache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE); + $GLOBALS['typo3CacheManager'] = $this->getMock('t3lib_cache_Manager', array('getCache')); + $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache)); + + // Let cache access give back lowercased class name + $mockCache->expects($this->any())->method('has')->will($this->returnValue(TRUE)); + $mockCache->expects($this->once())->method('requireOnce')->will($this->returnValue(array(strtolower($class) => $file))); + + // Re-initialize autoloader registry to force it to recognize the new extension + t3lib_autoloader::unregisterAutoloader(); + t3lib_autoloader::registerAutoloader(); + t3lib_autoloader::autoload($class); + } + /** * @test */