[BUGFIX] Processed folder in a sub folder is shown 90/20490/3
authorBenjamin Mack <benni@typo3.org>
Sat, 4 May 2013 10:41:35 +0000 (12:41 +0200)
committerPhilipp Gampe <philipp.gampe@typo3.org>
Sun, 19 May 2013 16:11:39 +0000 (18:11 +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.2, 6.1, 6.0
Reviewed-on: https://review.typo3.org/20490
Reviewed-by: Philipp Gampe
Tested-by: Philipp Gampe
typo3/sysext/core/Classes/Resource/ResourceStorage.php
typo3/sysext/core/Tests/Unit/Resource/ResourceStorageTest.php

index e6881f7..cd15440 100644 (file)
@@ -1549,16 +1549,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;
        }
 
index 30022fb..381b042 100644 (file)
@@ -1,10 +1,12 @@
 <?php
 namespace TYPO3\CMS\Core\Tests\Unit\Resource;
 
+use TYPO3\CMS\Core\Resource\ResourceStorage;
+
 /***************************************************************
  * Copyright notice
  *
- * (c) 2011 Andreas Wolf <andreas.wolf@ikt-werk.de>
+ * (c) 2011-2013 Andreas Wolf <andreas.wolf@ikt-werk.de>
  * All rights reserved
  *
  * This script is part of the TYPO3 project. The TYPO3 project is
@@ -23,7 +25,6 @@ namespace TYPO3\CMS\Core\Tests\Unit\Resource;
  *
  * This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
-
 require_once 'vfsStream/vfsStream.php';
 
 /**
@@ -647,6 +648,98 @@ class ResourceStorageTest extends \TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCa
                $this->fixture->getFileList('/', 0, 0, TRUE, TRUE, TRUE);
        }
 
+       /**
+        * 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));
+       }
 }
 
 ?>
\ No newline at end of file