[TASK] Extend functional tests with linked paths 04/26904/10
authorMarc Bastian Heinrichs <typo3@mbh-software.de>
Fri, 17 Jan 2014 15:09:18 +0000 (16:09 +0100)
committerOliver Hader <oliver.hader@typo3.org>
Thu, 13 Feb 2014 10:37:11 +0000 (11:37 +0100)
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
typo3/sysext/core/Tests/FunctionalTestCase.php
typo3/sysext/core/Tests/FunctionalTestCaseBootstrapUtility.php

index 20ee372..419e6da 100644 (file)
@@ -98,6 +98,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!
         *
         * @var \TYPO3\CMS\Core\Tests\FunctionalTestCaseBootstrapUtility
@@ -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
+               );
        }
 
        /**
index d75dded..069a8bf 100644 (file)
@@ -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();
@@ -221,6 +224,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
         *
         * @throws Exception