From 741714f3be04b6baf485a51118f36245221f1277 Mon Sep 17 00:00:00 2001 From: Marc Bastian Heinrichs <typo3@mbh-software.de> Date: Fri, 17 Jan 2014 16:09:18 +0100 Subject: [PATCH] [TASK] Extend functional tests with linked paths Extends the functional tests with the possibility to link folders or files inside the TYPO3 CMS test instance created within typo3temp. For example you are able to link a folder inside the fixture data of the functional tests to the fileadmin folder of the test instance. Resolves: #55111 Releases: 6.2 Change-Id: Ic41809e7642756b7c5eb1e0d717ef3cbd6d81e1d Reviewed-on: https://review.typo3.org/26904 Reviewed-by: Oliver Hader Tested-by: Oliver Hader --- .../sysext/core/Tests/FunctionalTestCase.php | 37 ++++++++++++++++++- .../FunctionalTestCaseBootstrapUtility.php | 35 +++++++++++++++++- 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/typo3/sysext/core/Tests/FunctionalTestCase.php b/typo3/sysext/core/Tests/FunctionalTestCase.php index 20ee372d10fb..419e6da0b29b 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 d75ddedfff0d..069a8bf22cbd 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 * -- GitLab