[BUGFIX] Get folder object if a path is given 90/18690/9
authorIvan Kartolo <ivan.kartolo@dkd.de>
Tue, 5 Mar 2013 04:50:07 +0000 (11:50 +0700)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sat, 6 Apr 2013 12:42:18 +0000 (14:42 +0200)
Get folder instead file object if a path is given to FAL.

Change-Id: I6d183d319eacbab403079b126685a13eb3ae7d5c
Resolves: #45748
Releases: 6.1, 6.0
Reviewed-on: https://review.typo3.org/18690
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
Reviewed-by: Alexander Opitz
Tested-by: Alexander Opitz
Reviewed-by: Steffen Ritter
Tested-by: Steffen Ritter
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
typo3/sysext/core/Classes/Resource/ResourceFactory.php
typo3/sysext/core/Tests/Unit/Resource/FactoryTest.php

index c13bd1d..de81336 100644 (file)
@@ -329,14 +329,18 @@ class ResourceFactory implements \TYPO3\CMS\Core\SingletonInterface {
                                $input = PathUtility::getRelativePath(PATH_site, PathUtility::dirname($input)) . PathUtility::basename($input);
                                return $this->getFileObjectFromCombinedIdentifier($input);
                        }
-               } else {
-                       // only the path
+               // this is a backwards-compatible way to access "0-storage" files or folders
+               } elseif (@is_file(PATH_site . $input)) {
+                       // only the local file
                        return $this->getFileObjectFromCombinedIdentifier($input);
+               } else {
+                       // only the local path
+                       return $this->getFolderObjectFromCombinedIdentifier($input);
                }
        }
 
        /**
-        * Gets an file object from an identifier [storage]:[fileId]
+        * Gets a folder object from an identifier [storage]:[fileId]
         *
         * @TODO check naming, inserted by SteffenR while working on filelist
         * @param string $identifier
index e1c4261..6e386da 100644 (file)
@@ -48,13 +48,21 @@ class FactoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         */
        private $objectCreated = FALSE;
 
+       /**
+        * @var array
+        */
+       private $filesCreated = array();
+
        public function setUp() {
                $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
                $this->fixture = new \TYPO3\CMS\Core\Resource\ResourceFactory();
        }
 
-       protected function tearDown() {
+       public function tearDown() {
                \TYPO3\CMS\Core\Utility\GeneralUtility::resetSingletonInstances($this->singletonInstances);
+               foreach ($this->filesCreated as $file) {
+                       unlink($file);
+               }
        }
 
        /**********************************
@@ -91,6 +99,35 @@ class FactoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $this->assertInstanceOf('TYPO3\\CMS\\Core\\Resource\\Driver\\AbstractDriver', $obj);
        }
 
+       /***********************************
+        *  File Handling
+        ***********************************/
+
+       public function directoryDataProviderValidFolderValues() {
+               return array(
+                       'relative path' => array('fileadmin'),
+                       'path with PATH_site' => array(PATH_site . 'fileadmin')
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider directoryDataProviderValidFolderValues
+        */
+       public function retrieveFileOrFolderObjectReturnsFolderIfPathIsGiven($source) {
+               $this->assertInstanceOf('TYPO3\\CMS\\Core\\Resource\\Folder', $this->fixture->retrieveFileOrFolderObject($source), 'No Folder Object can be retrieved');
+       }
+
+       /**
+        * @test
+        */
+       public function retrieveFileOrFolderObjectReturnsFileIfPathIsGiven() {
+               // Create and prepare test file
+               $filename = 'typo3temp/' . uniqid('test_') . '.txt';
+               \TYPO3\CMS\Core\Utility\GeneralUtility::writeFileToTypo3tempDir(PATH_site . $filename, '42');
+               $this->filesCreated[] = PATH_site . $filename;
+               $this->assertInstanceOf('TYPO3\\CMS\\Core\\Resource\\File', $this->fixture->retrieveFileOrFolderObject($filename), 'No File Object can be retrieved');
+       }
 }
 
 ?>
\ No newline at end of file