[BUGFIX] Skip some permissions tests if run as root
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Configuration / ConfigurationManagerTest.php
index 95ee559..e2ce155 100644 (file)
@@ -4,7 +4,7 @@ namespace TYPO3\CMS\Core\Tests\Unit\Configuration;
 /***************************************************************
  *  Copyright notice
  *
- *  (c) 2012 Christian Kuhn <lolli@schwarzbu.ch>
+ *  (c) 2012-2013 Christian Kuhn <lolli@schwarzbu.ch>
  *  All rights reserved
  *
  *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -25,11 +25,9 @@ namespace TYPO3\CMS\Core\Tests\Unit\Configuration;
  ***************************************************************/
 
 /**
- * Testcase for class \TYPO3\CMS\Core\Configuration\ConfigurationManager
+ * Test case
  *
  * @author Christian Kuhn <lolli@schwarzbu.ch>
- * @package TYPO3
- * @subpackage t3lib
  */
 class ConfigurationManagerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 
@@ -40,6 +38,20 @@ class ConfigurationManagerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        protected $testFilesToDelete = array();
 
        /**
+        * @var \TYPO3\CMS\Core\Configuration\ConfigurationManager|\PHPUnit_Framework_MockObject_MockObject
+        */
+       protected $fixture;
+
+       public function setUp() {
+               $this->createFixtureWithMockedMethods(
+                       array(
+                               'getDefaultConfigurationFileLocation',
+                               'getLocalConfigurationFileLocation',
+                       )
+               );
+       }
+
+       /**
         * Tear down test case
         */
        public function tearDown() {
@@ -49,314 +61,373 @@ class ConfigurationManagerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        }
 
        /**
-        * Tests concerning getDefaultConfiguration
-        *
+        * @param array $methods
         */
+       protected function createFixtureWithMockedMethods(array $methods) {
+               $this->fixture = $this->getMock(
+                       'TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager',
+                       $methods
+               );
+       }
+
        /**
         * @test
         * @expectedException \RuntimeException
         */
        public function getDefaultConfigurationExecutesDefinedDefaultConfigurationFile() {
-               $defaultConfigurationFile = 'typo3temp/' . uniqid('defaultConfiguration');
-               $namespace = 'TYPO3\\CMS\\Core\\Configuration';
-               $className = uniqid('ConfigurationManager');
-               eval(
-                       'namespace ' . $namespace . ';' .
-                       'class ' . $className . ' extends \\TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager {' .
-                       '  const DEFAULT_CONFIGURATION_FILE = \'' . $defaultConfigurationFile . '\';' .
-                       '}'
+               $defaultConfigurationFile = PATH_site . 'typo3temp/' . uniqid('defaultConfiguration');
+               file_put_contents(
+                       $defaultConfigurationFile,
+                       '<?php throw new \RuntimeException(\'foo\', 1310203814); ?>'
                );
-               $className = $namespace . '\\' . $className;
-               file_put_contents(PATH_site . $defaultConfigurationFile, '<?php throw new RuntimeException(\'foo\', 1310203814); ?>');
-               $this->testFilesToDelete[] = PATH_site . $defaultConfigurationFile;
-               $className::getDefaultConfiguration();
+               $this->testFilesToDelete[] = $defaultConfigurationFile;
+
+               $this->fixture
+                       ->expects($this->once())
+                       ->method('getDefaultConfigurationFileLocation')
+                       ->will($this->returnValue($defaultConfigurationFile));
+               $this->fixture->getDefaultConfiguration();
        }
 
        /**
-        * Tests concerning getLocalConfiguration
-        */
-       /**
         * @test
         * @expectedException \RuntimeException
         */
        public function getLocalConfigurationExecutesDefinedConfigurationFile() {
-               $configurationFile = 'typo3temp/' . uniqid('localConfiguration');
-               $namespace = 'TYPO3\\CMS\\Core\\Configuration';
-               $className = uniqid('ConfigurationManager');
-               eval(
-                       'namespace ' . $namespace . ';' .
-                       'class ' . $className . ' extends \\TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager {' .
-                       '  const LOCAL_CONFIGURATION_FILE = \'' . $configurationFile . '\';' .
-                       '}'
+               $configurationFile = PATH_site . 'typo3temp/' . uniqid('localConfiguration');
+               file_put_contents(
+                       $configurationFile,
+                       '<?php throw new \RuntimeException(\'foo\', 1310203815); ?>'
                );
-               $className = $namespace . '\\' . $className;
-               file_put_contents(PATH_site . $configurationFile, '<?php throw new RuntimeException(\'foo\', 1310203815); ?>');
-               $this->testFilesToDelete[] = PATH_site . $configurationFile;
-               $className::getLocalConfiguration();
+               $this->testFilesToDelete[] = $configurationFile;
+
+               $this->fixture
+                       ->expects($this->once())
+                       ->method('getLocalConfigurationFileLocation')
+                       ->will($this->returnValue($configurationFile));
+               $this->fixture->getLocalConfiguration();
        }
 
        /**
-        * Tests concerning updateLocalConfiguration
-        */
-       /**
         * @test
         */
        public function updateLocalConfigurationWritesNewMergedLocalConfigurationArray() {
-               $namespace = 'TYPO3\\CMS\\Core\\Configuration';
-               $className = uniqid('ConfigurationManager');
-               eval(
-                       'namespace ' . $namespace . '; ' .
-                       'class ' . $className . ' extends \\TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager {' .
-                       '  public static function getLocalConfiguration() {' .
-                       '    $currentLocalConfiguration = array(' .
-                       '      \'notChanged\' => 23,' .
-                       '      \'changed\' => \'unChanged\',' .
-                       '    );' .
-                       '    return $currentLocalConfiguration;' .
-                       '  }' .
-                       '  public static function writeLocalConfiguration($conf) {' .
-                       '    $expectedConfiguration = array(' .
-                       '      \'notChanged\' => 23,' .
-                       '      \'changed\' => \'changed\',' .
-                       '      \'new\' => \'new\',' . '    );' .
-                       '    if (!($conf === $expectedConfiguration)) {' .
-                       '      throw new Exception(\'broken\');' .
-                       '    }' .
-                       '  }' .
-                       '}'
+               $currentLocalConfiguration = array(
+                       'notChanged' => 23,
+                       'changed' => 'unChanged',
                );
-               $className = $namespace . '\\' . $className;
                $overrideConfiguration = array(
                        'changed' => 'changed',
                        'new' => 'new'
                );
-               $className::updateLocalConfiguration($overrideConfiguration);
+               $expectedConfiguration = array(
+                       'notChanged' => 23,
+                       'changed' => 'changed',
+                       'new' => 'new',
+               );
+
+               $this->createFixtureWithMockedMethods(
+                       array(
+                               'getLocalConfiguration',
+                               'writeLocalConfiguration',
+                       )
+               );
+               $this->fixture->expects($this->once())
+                               ->method('getLocalConfiguration')
+                               ->will($this->returnValue($currentLocalConfiguration));
+               $this->fixture->expects($this->once())
+                               ->method('writeLocalConfiguration')
+                               ->with($expectedConfiguration);
+
+               $this->fixture->updateLocalConfiguration($overrideConfiguration);
        }
 
        /**
-        * Tests concerning getDefaultConfigurationValueByPath
-        */
-       /**
         * @test
         */
        public function getDefaultConfigurationValueByPathReturnsCorrectValue() {
-               $namespace = 'TYPO3\\CMS\\Core\\Configuration';
-               $className = uniqid('ConfigurationManager');
-               eval(
-                       'namespace ' . $namespace . ';' .
-                       'class ' . $className . ' extends \\TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager {' .
-                       '  public static function getDefaultConfiguration() {' .
-                       '    return array(\'path\' => \'value\');' .
-                       '  }' .
-                       '}'
+               $this->createFixtureWithMockedMethods(
+                       array(
+                               'getDefaultConfiguration',
+                       )
                );
-               $className = $namespace . '\\' . $className;
-               $this->assertSame('value', $className::getDefaultConfigurationValueByPath('path'));
+               $this->fixture->expects($this->once())
+                               ->method('getDefaultConfiguration')
+                               ->will($this->returnValue(array(
+                                       'path' => 'value',
+                               )
+                       ));
+
+               $this->assertSame('value', $this->fixture->getDefaultConfigurationValueByPath('path'));
        }
 
        /**
-        * Tests concerning getLocalConfigurationValueByPath
-        */
-       /**
         * @test
         */
        public function getLocalConfigurationValueByPathReturnsCorrectValue() {
-               $namespace = 'TYPO3\\CMS\\Core\\Configuration';
-               $className = uniqid('ConfigurationManager');
-               eval(
-                       'namespace ' . $namespace . ';' .
-                       'class ' . $className . ' extends \\TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager {' .
-                       '  public static function getLocalConfiguration() {' .
-                       '    return array(\'path\' => \'value\');' .
-                       '  }' .
-                       '}'
+               $this->createFixtureWithMockedMethods(
+                       array(
+                               'getLocalConfiguration',
+                       )
                );
-               $className = $namespace . '\\' . $className;
-               $this->assertSame('value', $className::getLocalConfigurationValueByPath('path'));
+               $this->fixture->expects($this->once())
+                               ->method('getLocalConfiguration')
+                               ->will($this->returnValue(array(
+                                       'path' => 'value',
+                               )
+                       ));
+
+               $this->assertSame('value', $this->fixture->getLocalConfigurationValueByPath('path'));
        }
 
        /**
-        * Tests concerning getConfigurationValueByPath
-        */
-       /**
         * @test
         */
        public function getConfigurationValueByPathReturnsCorrectValue() {
-               $namespace = 'TYPO3\\CMS\\Core\\Configuration';
-               $className = uniqid('ConfigurationManager');
-               eval(
-                       'namespace ' . $namespace . ';' .
-                       'class ' . $className . ' extends \\TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager {' .
-                       '  public static function getDefaultConfiguration() {' .
-                       '    return array(\'path\' => \'value\');' .
-                       '  }' .
-                       '  public static function getLocalConfiguration() {' .
-                       '    return array(\'path\' => \'valueOverride\');' .
-                       '  }' .
-                       '}'
+               $this->createFixtureWithMockedMethods(
+                       array(
+                               'getDefaultConfiguration',
+                               'getLocalConfiguration',
+                       )
                );
-               $className = $namespace . '\\' . $className;
-               $this->assertSame('valueOverride', $className::getConfigurationValueByPath('path'));
+               $this->fixture->expects($this->once())
+                               ->method('getDefaultConfiguration')
+                               ->will($this->returnValue(array(
+                                       'path' => 'value',
+                               )
+                       ));
+               $this->fixture->expects($this->once())
+                               ->method('getLocalConfiguration')
+                               ->will($this->returnValue(array(
+                                       'path' => 'valueOverride',
+                               )
+                       ));
+
+               $this->assertSame('valueOverride', $this->fixture->getConfigurationValueByPath('path'));
        }
 
        /**
-        * Tests concerning setLocalConfigurationValueByPath
-        */
-       /**
         * @test
         */
        public function setLocalConfigurationValueByPathReturnFalseIfPathIsNotValid() {
-               $namespace = 'TYPO3\\CMS\\Core\\Configuration';
-               $className = uniqid('ConfigurationManager');
-               eval(
-                       'namespace ' . $namespace . ';' .
-                       'class ' . $className . ' extends \\TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager {' .
-                       '  public static function isValidLocalConfigurationPath() {' .
-                       '    return FALSE;' .
-                       '  }' .
-                       '}'
-               );
-               $className = $namespace . '\\' . $className;
-               $this->assertFalse($className::setLocalConfigurationValueByPath('path', 'value'));
+               $this->createFixtureWithMockedMethods(array(
+                               'isValidLocalConfigurationPath',
+                       ));
+               $this->fixture->expects($this->once())
+                               ->method('isValidLocalConfigurationPath')
+                               ->will($this->returnValue(FALSE));
+
+               $this->assertFalse($this->fixture->setLocalConfigurationValueByPath('path', 'value'));
        }
 
        /**
         * @test
         */
        public function setLocalConfigurationValueByPathUpdatesValueDefinedByPath() {
-               $namespace = 'TYPO3\\CMS\\Core\\Configuration';
-               $className = uniqid('ConfigurationManager');
-               eval(
-                       'namespace ' . $namespace . ';' .
-                       'class ' . $className . ' extends \\TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager {' .
-                       '  public static function isValidLocalConfigurationPath() {' .
-                       '    return TRUE;' .
-                       '  }' .
-                       '  public static function getLocalConfiguration() {' .
-                       '    $currentLocalConfiguration = array(' .
-                       '      \'notChanged\' => 23,' .
-                       '      \'toUpdate\' => \'notUpdated\',' .
-                       '    );' .
-                       '    return $currentLocalConfiguration;' .
-                       '  }' .
-                       '  public static function writeLocalConfiguration($conf) {' .
-                       '    $expectedConfiguration = array(' .
-                       '      \'notChanged\' => 23,' .
-                       '      \'toUpdate\' => \'updated\',' .
-                       '    );' .
-                       '    if (!($conf === $expectedConfiguration)) {' .
-                       '      throw new Exception(\'broken\');' .
-                       '    }' .
-                       '    return TRUE;' .
-                       '  }' .
-                       '}'
+               $currentLocalConfiguration = array(
+                       'notChanged' => 23,
+                       'toUpdate' => 'notUpdated',
                );
-               $className = $namespace . '\\' . $className;
-               $pathToUpdate = 'toUpdate';
-               $valueToUpdate = 'updated';
-               $this->assertTrue($className::setLocalConfigurationValueByPath($pathToUpdate, $valueToUpdate));
+               $expectedConfiguration = array(
+                       'notChanged' => 23,
+                       'toUpdate' => 'updated',
+               );
+
+               $this->createFixtureWithMockedMethods(
+                       array(
+                               'isValidLocalConfigurationPath',
+                               'getLocalConfiguration',
+                               'writeLocalConfiguration',
+                       )
+               );
+               $this->fixture->expects($this->once())
+                               ->method('isValidLocalConfigurationPath')
+                               ->will($this->returnValue(TRUE));
+               $this->fixture->expects($this->once())
+                               ->method('getLocalConfiguration')
+                               ->will($this->returnValue($currentLocalConfiguration));
+               $this->fixture->expects($this->once())
+                               ->method('writeLocalConfiguration')
+                               ->with($expectedConfiguration);
+
+               $this->fixture->setLocalConfigurationValueByPath('toUpdate', 'updated');
        }
 
        /**
-        * Tests concerning setLocalConfigurationValuesByPathValuePairs
-        */
-       /**
         * @test
         */
        public function setLocalConfigurationValuesByPathValuePairsSetsPathValuePairs() {
-               $namespace = 'TYPO3\\CMS\\Core\\Configuration';
-               $className = uniqid('ConfigurationManager');
-               eval(
-                       'namespace ' . $namespace . ';' .
-                       'class ' . $className .
-                       ' extends \\TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager {' .
-                       '  public static function isValidLocalConfigurationPath() {' .
-                       '    return TRUE;' .
-                       '  }' .
-                       '  public static function getLocalConfiguration() {' .
-                       '    $currentLocalConfiguration = array(' .
-                       '      \'notChanged\' => 23,' .
-                       '      \'toUpdate\' => \'notUpdated\',' .
-                       '    );' .
-                       '    return $currentLocalConfiguration;' .
-                       '  }' .
-                       '  public static function writeLocalConfiguration($conf) {' .
-                       '    $expectedConfiguration = array(' .
-                       '      \'notChanged\' => 23,' .
-                       '      \'toUpdate\' => \'updated\',' .
-                       '      \'new\' => \'new\',' .
-                       '    );' .
-                       '    if (!($conf === $expectedConfiguration)) {' .
-                       '      throw new Exception(\'broken\');' .
-                       '    }' .
-                       '    return TRUE;' .
-                       '  }' .
-                       '}'
+               $currentLocalConfiguration = array(
+                       'notChanged' => 23,
+                       'toUpdate' => 'notUpdated',
+               );
+               $expectedConfiguration = array(
+                       'notChanged' => 23,
+                       'toUpdate' => 'updated',
+                       'new' => 'new',
                );
-               $className = $namespace . '\\' . $className;
+
+               $this->createFixtureWithMockedMethods(
+                       array(
+                               'isValidLocalConfigurationPath',
+                               'getLocalConfiguration',
+                               'writeLocalConfiguration',
+                       )
+               );
+               $this->fixture->expects($this->any())
+                               ->method('isValidLocalConfigurationPath')
+                               ->will($this->returnValue(TRUE));
+               $this->fixture->expects($this->once())
+                               ->method('getLocalConfiguration')
+                               ->will($this->returnValue($currentLocalConfiguration));
+               $this->fixture->expects($this->once())
+                               ->method('writeLocalConfiguration')
+                               ->with($expectedConfiguration);
+
                $pairs = array(
                        'toUpdate' => 'updated',
                        'new' => 'new'
                );
-               $this->assertTrue($className::setLocalConfigurationValuesByPathValuePairs($pairs));
+               $this->fixture->setLocalConfigurationValuesByPathValuePairs($pairs);
        }
 
        /**
-        * Tests concerning writeLocalConfiguration
+        * @test
         */
+       public function canWriteConfigurationReturnsFalseIfDirectoryIsNotWritable() {
+               if (function_exists('posix_getegid') && posix_getegid() === 0) {
+                       $this->markTestSkipped('Test skipped if run on linux as root');
+               } elseif (TYPO3_OS == 'WIN') {
+                       $this->markTestSkipped('Not available on Windows');
+               }
+               /** @var $fixture \TYPO3\CMS\Core\Configuration\ConfigurationManager|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
+               $fixture = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager', array('dummy'));
+
+               $directory = 'typo3temp/' . uniqid('test_');
+               $absoluteDirectory = PATH_site . $directory;
+               mkdir($absoluteDirectory);
+               chmod($absoluteDirectory, 0544);
+               clearstatcache();
+
+               $fixture->_set('pathTypo3Conf', $directory);
+
+               $result = $fixture->canWriteConfiguration();
+
+               chmod($absoluteDirectory, 0755);
+               rmdir($absoluteDirectory);
+
+               $this->assertFalse($result);
+       }
+
        /**
         * @test
-        * @expectedException \RuntimeException
         */
-       public function writeLocalConfigurationThrowsExceptionForInvalidFile() {
-               $configurationFile = 'typo3temp/' . uniqid('localConfiguration');
-               $namespace = 'TYPO3\\CMS\\Core\\Configuration';
-               $className = uniqid('ConfigurationManager');
-               eval(
-                       'namespace ' . $namespace . ';' .
-                       'class ' . $className . ' extends \\TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager {' .
-                       '  const LOCAL_CONFIGURATION_FILE = \'' . $configurationFile . '\';' .
-                       '  public static function writeLocalConfiguration($conf) {' .
-                       '    return parent::writeLocalConfiguration($conf);' .
-                       '  }' .
-                       '}'
-               );
-               $className = $namespace . '\\' . $className;
-               $pairs = array(
-                       'foo' => 42,
-                       'bar' => 23
-               );
-               $className::writeLocalConfiguration($pairs);
+       public function canWriteConfigurationReturnsFalseIfLocalConfigurationFileIsNotWritable() {
+               if (function_exists('posix_getegid') && posix_getegid() === 0) {
+                       $this->markTestSkipped('Test skipped if run on linux as root');
+               } elseif (TYPO3_OS == 'WIN') {
+                       $this->markTestSkipped('Not available on Windows');
+               }
+               /** @var $fixture \TYPO3\CMS\Core\Configuration\ConfigurationManager|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
+               $fixture = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager', array('dummy'));
+
+               $file = 'typo3temp/' . uniqid('test_');
+               $absoluteFile = PATH_site . $file;
+               touch($absoluteFile);
+               $this->testFilesToDelete[] = $absoluteFile;
+               chmod($absoluteFile, 0444);
+               clearstatcache();
+
+               $fixture->_set('localConfigurationFile', $file);
+
+               $result = $fixture->canWriteConfiguration();
+
+               chmod($absoluteFile, 0644);
+
+               $this->assertFalse($result);
+       }
+
+       /**
+        * @test
+        */
+       public function canWriteConfigurationReturnsFalseIfLocalconfFileIsNotWritable() {
+               if (function_exists('posix_getegid') && posix_getegid() === 0) {
+                       $this->markTestSkipped('Test skipped if run on linux as root');
+               } elseif (TYPO3_OS == 'WIN') {
+                       $this->markTestSkipped('Not available on Windows');
+               }
+               /** @var $fixture \TYPO3\CMS\Core\Configuration\ConfigurationManager|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
+               $fixture = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager', array('dummy'));
+
+               $file = 'typo3temp/' . uniqid('test_');
+               $absoluteFile = PATH_site . $file;
+               touch($absoluteFile);
+               $this->testFilesToDelete[] = $absoluteFile;
+               chmod($absoluteFile, 0444);
+               clearstatcache();
+
+               $fixture->_set('localconfFile', $file);
+
+               $result = $fixture->canWriteConfiguration();
+
+               chmod($absoluteFile, 0644);
+
+               $this->assertFalse($result);
+       }
+
+       /**
+        * @test
+        */
+       public function canWriteConfigurationReturnsTrueIfDirectoryAndFilesAreWritable() {
+               /** @var $fixture \TYPO3\CMS\Core\Configuration\ConfigurationManager|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
+               $fixture = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager', array('dummy'));
+
+               $directory = 'typo3temp/' . uniqid('test_');
+               $absoluteDirectory = PATH_site . $directory;
+               mkdir($absoluteDirectory);
+               $fixture->_set('pathTypo3Conf', $directory);
+
+               $file1 = 'typo3temp/' . uniqid('test_');
+               $absoluteFile1 = PATH_site . $file1;
+               touch($absoluteFile1);
+               $this->testFilesToDelete[] = $absoluteFile1;
+               $fixture->_set('localConfigurationFile', $file1);
+
+               $file2 = 'typo3temp/' . uniqid('test_');
+               $absoluteFile2 = PATH_site . $file2;
+               touch($absoluteFile2);
+               $this->testFilesToDelete[] = $absoluteFile2;
+               $fixture->_set('localconfFile', $file2);
+
+               clearstatcache();
+
+               $result = $fixture->canWriteConfiguration();
+
+               $this->assertTrue($result);
        }
 
        /**
         * @test
         */
        public function writeLocalConfigurationWritesSortedContentToConfigurationFile() {
-               $configurationFile = 'typo3temp/' . uniqid('localConfiguration');
-               if (!is_file(PATH_site . $configurationFile)) {
-                       if (!$fh = fopen(PATH_site . $configurationFile, 'wb')) {
+               $configurationFile = PATH_site . 'typo3temp/' . uniqid('localConfiguration');
+               if (!is_file($configurationFile)) {
+                       if (!$fh = fopen($configurationFile, 'wb')) {
                                $this->markTestSkipped('Can not create file ' . $configurationFile . '. Please check your write permissions.');
                        }
                        fclose($fh);
                }
 
-               if (!@is_file(PATH_site . $configurationFile)) {
+               if (!@is_file($configurationFile)) {
                        throw new \RuntimeException('File ' . $configurationFile . ' could not be found. Please check your write permissions', 1346364362);
                }
-               $this->testFilesToDelete[] = PATH_site . $configurationFile;
-               $namespace = 'TYPO3\\CMS\\Core\\Configuration';
-               $className = uniqid('ConfigurationManager');
-               eval(
-                       'namespace ' . $namespace . ';' .
-                       'class ' . $className . ' extends \\TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager {' .
-                       '  const LOCAL_CONFIGURATION_FILE = \'' . $configurationFile . '\';' .
-                       '  public static function writeLocalConfiguration($conf) {' .
-                       '    return parent::writeLocalConfiguration($conf);' .
-                       '  }' .
-                       '}'
-               );
-               $className = $namespace . '\\' . $className;
+               $this->testFilesToDelete[] = $configurationFile;
+
+               $this->fixture
+                       ->expects($this->any())
+                       ->method('getLocalConfigurationFileLocation')
+                       ->will($this->returnValue($configurationFile));
+
                $pairs = array(
                        'foo' => 42,
                        'bar' => 23
@@ -369,33 +440,121 @@ class ConfigurationManagerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                                ');' . LF .
                        '?>';
 
-               $className::writeLocalConfiguration($pairs);
-               $this->assertSame($expectedContent, file_get_contents(PATH_site . $configurationFile));
+               $this->fixture->writeLocalConfiguration($pairs);
+               $this->assertSame($expectedContent, file_get_contents($configurationFile));
        }
 
        /**
-        * Tests concerning isValidLocalConfigurationPath
+        * @test
+        * @expectedException \RuntimeException
         */
+       public function createLocalConfigurationFromFactoryConfigurationThrowsExceptionIfFileExists() {
+               /** @var $fixture \TYPO3\CMS\Core\Configuration\ConfigurationManager|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
+               $fixture = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager', array('dummy'));
+
+               $file = 'typo3temp/' . uniqid('test_');
+               $absoluteFile = PATH_site . $file;
+               touch($absoluteFile);
+               $this->testFilesToDelete[] = $absoluteFile;
+               $fixture->_set('localConfigurationFile', $file);
+
+               $fixture->createLocalConfigurationFromFactoryConfiguration();
+       }
+
        /**
         * @test
         */
-       public function isValidLocalConfigurationPathAcceptsWhitelistedPath() {
-               $namespace = 'TYPO3\\CMS\\Core\\Configuration';
-               $className = uniqid('ConfigurationManager');
-               eval(
-                       'namespace ' . $namespace . ';' .
-                       'class ' . $className . ' extends \\TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager {' .
-                       '  protected static $whiteListedLocalConfigurationPaths = array(' .
-                       '    \'foo\',' .
-                       '  );' .
-                       '  public static function isValidLocalConfigurationPath($path) {' .
-                       '    return parent::isValidLocalConfigurationPath($path);' .
-                       '  }' .
-                       '}'
+       public function createLocalConfigurationFromFactoryConfigurationWritesContentFromFactoryFile() {
+               /** @var $fixture \TYPO3\CMS\Core\Configuration\ConfigurationManager|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
+               $fixture = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager', array('writeLocalConfiguration'));
+               $fixture->_set('localConfigurationFile', 'typo3temp/' . uniqid('dummy_'));
+
+               $factoryConfigurationFile = 'typo3temp/' . uniqid('test_') . '.php';
+               $factoryConfigurationAbsoluteFile = PATH_site . $factoryConfigurationFile;
+               $uniqueContentString = uniqid('string_');
+               $validFactoryConfigurationFileContent =
+                       '<?php' . LF .
+                               'return array(' . LF .
+                                       $uniqueContentString . ' => foo,' . LF .
+                               ');' . LF .
+                       '?>';
+               file_put_contents(
+                       $factoryConfigurationAbsoluteFile,
+                       $validFactoryConfigurationFileContent
+               );
+               $this->testFilesToDelete[] = $factoryConfigurationAbsoluteFile;
+
+               $fixture->_set('factoryConfigurationFile', $factoryConfigurationFile);
+
+               $fixture
+                       ->expects($this->once())
+                       ->method('writeLocalConfiguration')
+                       ->with($this->arrayHasKey($uniqueContentString));
+               $fixture->createLocalConfigurationFromFactoryConfiguration();
+       }
+
+       /**
+        * @test
+        */
+       public function createLocalConfigurationFromFactoryConfigurationMergesConfigurationWithAdditionalFactoryFile() {
+               /** @var $fixture \TYPO3\CMS\Core\Configuration\ConfigurationManager|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
+               $fixture = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager', array('writeLocalConfiguration'));
+               $fixture->_set('localConfigurationFile', 'typo3temp/' . uniqid('dummy_'));
+
+               $factoryConfigurationFile = 'typo3temp/' . uniqid('test_') . '.php';
+               $factoryConfigurationAbsoluteFile = PATH_site . $factoryConfigurationFile;
+               $validFactoryConfigurationFileContent =
+                       '<?php' . LF .
+                               'return array();' . LF .
+                       '?>';
+               file_put_contents(
+                       $factoryConfigurationAbsoluteFile,
+                       $validFactoryConfigurationFileContent
+               );
+               $this->testFilesToDelete[] = $factoryConfigurationAbsoluteFile;
+               $fixture->_set('factoryConfigurationFile', $factoryConfigurationFile);
+
+               $additionalFactoryConfigurationFile = 'typo3temp/' . uniqid('test_') . '.php';
+               $additionalFactoryConfigurationAbsoluteFile = PATH_site . $additionalFactoryConfigurationFile;
+               $uniqueContentString = uniqid('string_');
+               $validAdditionalFactoryConfigurationFileContent =
+                       '<?php' . LF .
+                               'return array(' . LF .
+                                       $uniqueContentString . ' => foo,' . LF .
+                               ');' . LF .
+                       '?>';
+               file_put_contents(
+                       $additionalFactoryConfigurationAbsoluteFile,
+                       $validAdditionalFactoryConfigurationFileContent
                );
-               $className = $namespace . '\\' . $className;
-               $this->assertTrue($className::isValidLocalConfigurationPath('foo'));
+               $this->testFilesToDelete[] = $additionalFactoryConfigurationAbsoluteFile;
+               $fixture->_set('additionalFactoryConfigurationFile', $additionalFactoryConfigurationFile);
+
+               $fixture
+                       ->expects($this->once())
+                       ->method('writeLocalConfiguration')
+                       ->with($this->arrayHasKey($uniqueContentString));
+               $fixture->createLocalConfigurationFromFactoryConfiguration();
+       }
+
+       /**
+        * @test
+        */
+       public function isValidLocalConfigurationPathAcceptsWhitelistedPath() {
+               /** @var $fixture \TYPO3\CMS\Core\Configuration\ConfigurationManager|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
+               $fixture = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager', array('dummy'));
+               $fixture->_set('whiteListedLocalConfigurationPaths', array('foo/bar'));
+               $this->assertTrue($fixture->_call('isValidLocalConfigurationPath', 'foo/bar/baz'));
        }
 
+       /**
+        * @test
+        */
+       public function isValidLocalConfigurationPathDeniesNotWhitelistedPath() {
+               /** @var $fixture \TYPO3\CMS\Core\Configuration\ConfigurationManager|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
+               $fixture = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager', array('dummy'));
+               $fixture->_set('whiteListedLocalConfigurationPaths', array('foo/bar'));
+               $this->assertFalse($fixture->_call('isValidLocalConfigurationPath', 'bar/baz'));
+       }
 }
 ?>
\ No newline at end of file