[BUGFIX] LocalDriver can be instantiated without basePath
authorAndreas Wolf <andreas.wolf@typo3.org>
Sat, 1 Sep 2012 14:50:41 +0000 (16:50 +0200)
committerSteffen Ritter <info@rs-websystems.de>
Fri, 12 Oct 2012 10:40:49 +0000 (12:40 +0200)
The Local driver of FAL does not check if its configuration contains a
base path, leading to some hard-to-track errors when no path is given.

Resolves: #40505
Releases: 6.0
Change-Id: Id90a005f6cc9c167e3ab8df06a896cd078867e0a
Reviewed-on: http://review.typo3.org/14258
Reviewed-by: Steffen Ritter
Tested-by: Steffen Ritter
typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php
typo3/sysext/core/Tests/Unit/Resource/Driver/LocalDriverTest.php
typo3/sysext/core/Tests/Unit/Resource/ResourceStorageTest.php

index bffb6df..e90eabc 100644 (file)
@@ -115,11 +115,15 @@ class LocalDriver extends \TYPO3\CMS\Core\Resource\Driver\AbstractDriver {
        /**
         * Calculates the absolute path to this drivers storage location.
         *
-        * @throws \RuntimeException
+        * @throws \TYPO3\CMS\Core\Resource\Exception\InvalidConfigurationException
         * @param array $configuration
         * @return string
         */
        protected function calculateBasePath(array $configuration) {
+               if (!array_key_exists('basePath', $configuration) || empty($configuration['basePath'])) {
+                       throw new \TYPO3\CMS\Core\Resource\Exception\InvalidConfigurationException('Configuration must contain base path.', 1346510477);
+               }
+
                if ($configuration['pathType'] === 'relative') {
                        $relativeBasePath = $configuration['basePath'];
                        $absoluteBasePath = PATH_site . $relativeBasePath;
index fdfdd5c..4471ae1 100644 (file)
@@ -131,7 +131,7 @@ class LocalDriverTest extends \TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase {
         */
        public function rootLevelFolderIsCreatedWithCorrectArguments() {
                $mockedMount = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
-               $fixture = $this->createDriverFixture(array(), $mockedMount);
+               $fixture = $this->createDriverFixture(array('basePath' => $this->getMountRootUrl()), $mockedMount);
                $mockedFactory = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceFactory');
                $mockedFactory->expects($this->once())->method('createFolderObject')->with($this->equalTo($mockedMount), $this->equalTo('/'), $this->equalTo(''));
                \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Resource\\ResourceFactory', $mockedFactory);
index fd46ff7..d916fc9 100644 (file)
@@ -118,6 +118,11 @@ class ResourceStorageTest extends \TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCa
                if ($storageObject == NULL) {
                        $storageObject = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
                }
+
+               if (!isset($driverConfiguration['basePath'])) {
+                       $driverConfiguration['basePath'] = $this->getMountRootUrl();
+               }
+
                if ($mockedDriverMethods === NULL) {
                        $driver = new \TYPO3\CMS\Core\Resource\Driver\LocalDriver($driverConfiguration);
                } else {