[BUGFIX] Processed folder in a sub folder is shown 32/19732/6
authorNicole Cordes <typo3@cordes.co>
Sun, 7 Apr 2013 11:17:36 +0000 (13:17 +0200)
committerBenjamin Mack <benni@typo3.org>
Sat, 4 May 2013 10:35:49 +0000 (12:35 +0200)
In the function fetchFolderListFromDriver of the ResourceStorage class the
processed folder is expected to be in root folder. If it is not the
case the processing folder is shown in all filelists and gets processed
as well. The function has to split the processed folder identifier and
compare it to the current path. To secure the patch also the missing Unit
Tests were added.

Change-Id: I7ebde8488938a7000dcfdb99da8c34ee988b666f
Fixes: #47019
Releases: 6.1, 6.0
Reviewed-on: https://review.typo3.org/19732
Reviewed-by: Alexander Opitz
Reviewed-by: Philipp Gampe
Tested-by: Philipp Gampe
Reviewed-by: Benjamin Mack
Tested-by: Benjamin Mack
typo3/sysext/core/Classes/Resource/ResourceStorage.php
typo3/sysext/core/Tests/Unit/Resource/ResourceStorageTest.php

index 721916f..f96987c 100644 (file)
@@ -1546,16 +1546,22 @@ class ResourceStorage {
         */
        public function fetchFolderListFromDriver($path, $start = 0, $numberOfItems = 0, array $folderFilterCallbacks = array(), $recursive = FALSE) {
                $items = $this->driver->getFolderList($path, $start, $numberOfItems, $folderFilterCallbacks, $recursive);
-               // Exclude the _processed_ folder, so it won't get indexed etc
-               $processingFolder = $this->getProcessingFolder();
-               if ($processingFolder && $path == '/') {
-                       $processedFolderIdentifier = $this->processingFolder->getIdentifier();
-                       $processedFolderIdentifier = trim($processedFolderIdentifier, '/');
-                       if (isset($items[$processedFolderIdentifier])) {
-                               unset($items[$processedFolderIdentifier]);
+               if (!empty($items)) {
+                       // Exclude the _processed_ folder, so it won't get indexed etc
+                       // The processed folder might be any sub folder in storage
+                       $processingFolder = $this->getProcessingFolder();
+                       if ($processingFolder) {
+                               $processedFolderIdentifier = $this->processingFolder->getIdentifier();
+                               $processedFolderIdentifier = trim($processedFolderIdentifier, '/');
+                               $processedFolderIdentifierParts = explode('/', $processedFolderIdentifier);
+                               $processedFolderName = array_pop($processedFolderIdentifierParts);
+                               $processedFolderParent = implode('/', $processedFolderIdentifierParts);
+                               if ($processedFolderParent === trim($path, '/') && isset($items[$processedFolderName])) {
+                                       unset($items[$processedFolderName]);
+                               }
                        }
+                       uksort($items, 'strnatcasecmp');
                }
-               uksort($items, 'strnatcasecmp');
                return $items;
        }
 
@@ -2039,4 +2045,4 @@ class ResourceStorage {
        }
 }
 
-?>
\ No newline at end of file
+?>
index 02efa45..c142546 100644 (file)
@@ -688,6 +688,99 @@ class ResourceStorageTest extends \TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCa
 
                $this->assertSame(\TYPO3\CMS\Core\Resource\FolderInterface::ROLE_PROCESSING, $role);
        }
+
+       /**
+        * Data provider for fetchFolderListFromDriverReturnsFolderWithoutProcessedFolder function
+        */
+       public function fetchFolderListFromDriverReturnsFolderWithoutProcessedFolderDataProvider() {
+               return array(
+                       'Empty folderList returned' => array(
+                               'path' => '/',
+                               'processingFolder' => '_processed_',
+                               'folderList' => array(),
+                               'expectedItems' => array()
+                       ),
+                       'Empty _processed_ folder' => array(
+                               'path' => '/',
+                               'processingFolder' => '',
+                               'folderList' => array(
+                                       '_processed_' => array(),
+                                       '_temp_' => array(),
+                                       'user_upload' => array()
+                               ),
+                               'expectedItems' => array(
+                                       'user_upload' => array(),
+                                       '_temp_' => array()
+                               )
+                       ),
+                       '_processed_ folder not in folder list' => array(
+                               'path' => '/',
+                               'processingFolder' => '_processed_',
+                               'folderList' => array(
+                                       '_temp_' => array()
+                               ),
+                               'expectedItems' => array(
+                                       '_temp_' => array()
+                               )
+                       ),
+                       '_processed_ folder on root level' => array(
+                               'path' => '/',
+                               'processingFolder' => '_processed_',
+                               'folderList' => array(
+                                       '_processed_' => array(),
+                                       '_temp_' => array(),
+                                       'user_upload' => array()
+                               ),
+                               'expectedItems' => array(
+                                       'user_upload' => array(),
+                                       '_temp_' => array()
+                               )
+                       ),
+                       '_processed_ folder on second level' => array(
+                               'path' => 'Public/',
+                               'processingFolder' => 'Public/_processed_',
+                               'folderList' => array(
+                                       '_processed_' => array(),
+                                       '_temp_' => array(),
+                                       'user_upload' => array()
+                               ),
+                               'expectedItems' => array(
+                                       'user_upload' => array(),
+                                       '_temp_' => array()
+                               )
+                       ),
+                       '_processed_ folder on third level' => array(
+                               'path' => 'Public/Files/',
+                               'processingFolder' => 'Public/Files/_processed_',
+                               'folderList' => array(
+                                       '_processed_' => array(),
+                                       '_temp_' => array(),
+                                       'user_upload' => array()
+                               ),
+                               'expectedItems' => array(
+                                       'user_upload' => array(),
+                                       '_temp_' => array()
+                               )
+                       )
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider fetchFolderListFromDriverReturnsFolderWithoutProcessedFolderDataProvider
+        */
+       public function fetchFolderListFromDriverReturnsFolderWithoutProcessedFolder($path, $processingFolder, $folderList, $expectedItems) {
+               $driverMock = $this->createDriverMock(array(), NULL, array('getFolderList', 'folderExists'));
+               $driverMock->expects($this->once())->method('getFolderList')->will($this->returnValue($folderList));
+               if (!empty($expectedItems)) {
+                       // This function is called only if there were any folders retrieved
+                       $driverMock->expects($this->once())->method('folderExists')->will($this->returnValue(TRUE));
+               }
+
+               $this->prepareFixture(array(), FALSE, $driverMock, array('processingfolder' => $processingFolder));
+
+               $this->assertSame($expectedItems, $this->fixture->fetchFolderListFromDriver($path));
+       }
 }
 
 ?>