[BUGFIX] Get folder object if a path is given 75/19675/3
authorIvan Kartolo <ivan.kartolo@dkd.de>
Tue, 5 Mar 2013 04:50:07 +0000 (11:50 +0700)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sat, 6 Apr 2013 14:19:23 +0000 (16:19 +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/19675
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/core/Classes/Resource/ResourceFactory.php
typo3/sysext/core/Tests/Unit/Resource/FactoryTest.php

index f8fa0d7..6cbb5b7 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
@@ -463,4 +467,4 @@ class ResourceFactory implements \TYPO3\CMS\Core\SingletonInterface {
 }
 
 
-?>
\ No newline at end of file
+?>
index c7e4240..09af9c8 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();
+               $this->fixture = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Resource\\ResourceFactory', array('dummy'));
        }
 
-       protected function tearDown() {
+       public function tearDown() {
                \TYPO3\CMS\Core\Utility\GeneralUtility::resetSingletonInstances($this->singletonInstances);
+               foreach ($this->filesCreated as $file) {
+                       unlink($file);
+               }
        }
 
        /**********************************
@@ -91,6 +99,45 @@ 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) {
+               $storage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array('getFile', 'getFolder'), array(), '', FALSE);
+               $storage->expects($this->once())
+                       ->method('getFolder')
+                       ->with('fileadmin');
+               $this->fixture->_set('storageInstances', array(0 => $storage));
+               $this->fixture->retrieveFileOrFolderObject($source);
+       }
+
+       /**
+        * @test
+        */
+       public function retrieveFileOrFolderObjectReturnsFileIfPathIsGiven() {
+               $filename = 'typo3temp/4711.txt';
+               $storage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array('getFile', 'getFolder'), array(), '', FALSE);
+               $storage->expects($this->once())
+                       ->method('getFile')
+                       ->with($filename);
+               $this->fixture->_set('storageInstances', array(0 => $storage));
+               // Create and prepare test file
+               \TYPO3\CMS\Core\Utility\GeneralUtility::writeFileToTypo3tempDir(PATH_site . $filename, '42');
+               $this->filesCreated[] = PATH_site . $filename;
+               $this->fixture->retrieveFileOrFolderObject($filename);
+       }
 }
 
-?>
\ No newline at end of file
+?>