diff --git a/typo3/sysext/core/Tests/FunctionalTestCase.php b/typo3/sysext/core/Tests/FunctionalTestCase.php index 20ee372d10fbcfb22a7ead82a2e0b51e50c444ca..419e6da0b29b8c7eaf71c2a1f6af54a8556d0ac5 100644 --- a/typo3/sysext/core/Tests/FunctionalTestCase.php +++ b/typo3/sysext/core/Tests/FunctionalTestCase.php @@ -97,6 +97,36 @@ abstract class FunctionalTestCase extends BaseTestCase { */ protected $testExtensionsToLoad = array(); + /** + * Array of test/fixture folder or file paths that should be linked for a test. + * + * This property will stay empty in this abstract, so it is possible + * to just overwrite it in extending classes. Path noted here will + * be linked for every test of a test case and it is not possible to change + * the list of folders between single tests of a test case. + * + * array( + * 'link-source' => 'link-destination' + * ); + * + * Given paths are expected to be relative to the test instance root. + * The array keys are the source paths and the array values are the destination + * paths, example: + * + * array( + * 'typo3/sysext/impext/Tests/Functional/Fixtures/Folders/fileadmin/user_upload' => + * 'fileadmin/user_upload', + * 'typo3conf/ext/my_own_ext/Tests/Functional/Fixtures/Folders/uploads/tx_myownext' => + * 'uploads/tx_myownext' + * ); + * + * To be able to link from my_own_ext the extension path needs also to be registered in + * property $testExtensionsToLoad + * + * @var array + */ + protected $pathsToLinkInTestInstance = array(); + /** * Private utility class used in setUp() and tearDown(). Do NOT use in test cases! * @@ -116,7 +146,12 @@ abstract class FunctionalTestCase extends BaseTestCase { $this->markTestSkipped('Functional tests must be called through phpunit on CLI'); } $this->bootstrapUtility = new FunctionalTestCaseBootstrapUtility(); - $this->bootstrapUtility->setUp(get_class($this), $this->coreExtensionsToLoad, $this->testExtensionsToLoad); + $this->bootstrapUtility->setUp( + get_class($this), + $this->coreExtensionsToLoad, + $this->testExtensionsToLoad, + $this->pathsToLinkInTestInstance + ); } /** diff --git a/typo3/sysext/core/Tests/FunctionalTestCaseBootstrapUtility.php b/typo3/sysext/core/Tests/FunctionalTestCaseBootstrapUtility.php index d75ddedfff0db6ca99ee84446431506a90db4242..069a8bf22cbd085ccab7c253513c15d2249e509f 100644 --- a/typo3/sysext/core/Tests/FunctionalTestCaseBootstrapUtility.php +++ b/typo3/sysext/core/Tests/FunctionalTestCaseBootstrapUtility.php @@ -74,12 +74,14 @@ class FunctionalTestCaseBootstrapUtility { * @param string $testCaseClassName Name of test case class * @param array $coreExtensionsToLoad Array of core extensions to load * @param array $testExtensionsToLoad Array of test extensions to load + * @param array $pathsToLinkInTestInstance Array of source => destination path pairs to be linked * @return void */ public function setUp( $testCaseClassName, array $coreExtensionsToLoad, - array $testExtensionsToLoad + array $testExtensionsToLoad, + array $pathsToLinkInTestInstance ) { $this->setUpIdentifier($testCaseClassName); $this->setUpInstancePath(); @@ -87,6 +89,7 @@ class FunctionalTestCaseBootstrapUtility { $this->setUpInstanceDirectories(); $this->setUpInstanceCoreLinks(); $this->linkTestExtensionsToInstance($testExtensionsToLoad); + $this->linkPathsInTestInstance($pathsToLinkInTestInstance); $this->setUpLocalConfiguration(); $this->setUpPackageStates($coreExtensionsToLoad, $testExtensionsToLoad); $this->setUpBasicTypo3Bootstrap(); @@ -220,6 +223,36 @@ class FunctionalTestCaseBootstrapUtility { } } + /** + * Link paths inside the test instance, e.g. from a fixture fileadmin subfolder to the + * test instance fileadmin folder + * + * @param array $pathsToLinkInTestInstance Contains paths as array of source => destination in key => value pairs of folders relative to test instance root + * @throws \TYPO3\CMS\Core\Tests\Exception if a source path could not be found + * @throws \TYPO3\CMS\Core\Tests\Exception on failing creating the symlink + * @return void + * @see \TYPO3\CMS\Core\Tests\FunctionalTestCase::$pathsToLinkInTestInstance + */ + protected function linkPathsInTestInstance(array $pathsToLinkInTestInstance) { + foreach ($pathsToLinkInTestInstance as $sourcePathToLinkInTestInstance => $destinationPathToLinkInTestInstance) { + $sourcePath = $this->instancePath . '/' . ltrim($sourcePathToLinkInTestInstance, '/'); + if (!file_exists($sourcePath)) { + throw new Exception( + 'Path ' . $sourcePath . ' not found', + 1376745645 + ); + } + $destinationPath = $this->instancePath . '/' . ltrim($destinationPathToLinkInTestInstance, '/'); + $success = symlink($sourcePath, $destinationPath); + if (!$success) { + throw new Exception( + 'Can not link the path ' . $sourcePath . ' to ' . $destinationPath, + 1389969623 + ); + } + } + } + /** * Create LocalConfiguration.php file in the test instance *