[BUGFIX] Incorrect check for empty folder 74/22674/4
authorPhilipp Gampe <philipp.gampe@typo3.org>
Mon, 29 Jul 2013 20:15:32 +0000 (22:15 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Tue, 6 Aug 2013 18:44:53 +0000 (20:44 +0200)
The condition in ResourceStorage::deleteFolder is wrong.
Negate the isFolderEmpty() clause.

Resolves: #50125
Releases: 6.2, 6.1, 6.0
Change-Id: Ia60f3e97ff8d1e0cc2671cec1b31cfc995c235b1
Reviewed-on: https://review.typo3.org/22674
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
typo3/sysext/core/Classes/Resource/ResourceStorage.php
typo3/sysext/core/Tests/Unit/Resource/ResourceStorageTest.php

index 64865c8..f244b2b 100644 (file)
@@ -1508,7 +1508,7 @@ class ResourceStorage {
                if (!$this->checkFolderActionPermission('remove', $folderObject)) {
                        throw new Exception\InsufficientFileAccessPermissionsException('You are not allowed to access the folder "' . $folderObject->getIdentifier() . '\'', 1323423953);
                }
-               if ($this->driver->isFolderEmpty($folderObject) && !$deleteRecursively) {
+               if (!$this->driver->isFolderEmpty($folderObject) && !$deleteRecursively) {
                        throw new \RuntimeException('Could not delete folder "' . $folderObject->getIdentifier() . '" because it is not empty.', 1325952534);
                }
 
index 9faa1c5..90e2516 100644 (file)
@@ -533,6 +533,23 @@ class ResourceStorageTest extends \TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCa
 
        /**
         * @test
+        * @expectedException \RuntimeException
+        */
+       public function deleteFolderThrowsExceptionIfFolderIsNotEmptyAndRecursiveDeleteIsDisabled() {
+               /** @var \TYPO3\CMS\Core\Resource\Folder|\PHPUnit_Framework_MockObject_MockObject $folderMock */
+               $folderMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Folder', array(), array(), '', FALSE);
+               /** @var \TYPO3\CMS\Core\Resource\Driver\AbstractDriver|\PHPUnit_Framework_MockObject_MockObject $driverMock */
+               $driverMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Driver\\AbstractDriver', array(), array(), '', FALSE);
+               $driverMock->expects($this->once())->method('isFolderEmpty')->will($this->returnValue(FALSE));
+               /** @var \TYPO3\CMS\Core\Resource\ResourceStorage|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $fixture */
+               $fixture = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array('checkFolderActionPermission'), array(), '', FALSE);
+               $fixture->expects($this->any())->method('checkFolderActionPermission')->will($this->returnValue(TRUE));
+               $fixture->_set('driver', $driverMock);
+               $fixture->deleteFolder($folderMock, FALSE);
+       }
+
+       /**
+        * @test
         */
        public function createFolderCallsDriverForFolderCreation() {
                $mockedParentFolder = $this->getSimpleFolderMock('/someFolder/');