[TASK] Migrate ResourceStorage unit tests to functional tests 65/49365/9
authorThomas Schlumberger <thomas@b13.de>
Wed, 3 Aug 2016 18:57:44 +0000 (20:57 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 4 Aug 2016 11:39:48 +0000 (13:39 +0200)
This patch migrates further unit test of the ResourceStorage
to functional tests

Resloves: #77401
Releases: master
Change-Id: I292b05c6f81c4e0bc7ccf5692e3660e85c887997
Reviewed-on: https://review.typo3.org/49365
Tested-by: Bamboo TYPO3com <info@typo3.com>
Reviewed-by: Sebastian Bumann <bumann.sebastian@gmail.com>
Tested-by: Sebastian Bumann <bumann.sebastian@gmail.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Tests/Functional/Resource/ResourceStorageTest.php
typo3/sysext/core/Tests/Unit/Resource/ResourceStorageTest.php

index aebf220..3e9327c 100644 (file)
@@ -14,7 +14,9 @@ namespace TYPO3\CMS\Core\Tests\Functional\Resource;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Resource\File;
 use TYPO3\CMS\Core\Resource\Folder;
+use TYPO3\CMS\Core\Resource\FolderInterface;
 use TYPO3\CMS\Core\Resource\ResourceFactory;
 use TYPO3\CMS\Core\Resource\ResourceStorage;
 use TYPO3\CMS\Core\Resource\StorageRepository;
@@ -27,6 +29,14 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
 class ResourceStorageTest extends FunctionalTestCase
 {
 
+    protected function tearDown()
+    {
+        // cleanup manually created folders
+        foreach (glob(PATH_site . 'fileadmin/*') as $folderToRemove) {
+            GeneralUtility::rmdir($folderToRemove, true);
+        }
+    }
+
     /**
      * @test
      */
@@ -138,4 +148,68 @@ class ResourceStorageTest extends FunctionalTestCase
             ],
         ];
     }
+
+    /**
+     * @test
+     */
+    public function getProcessingRootFolderTest()
+    {
+        $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/core/Tests/Functional/Fixtures/sys_file_storage.xml');
+        $this->setUpBackendUserFromFixture(1);
+
+        $subject = (new StorageRepository())->findByUid(1);
+        $processingFolder = $subject->getProcessingFolder();
+
+        $this->assertInstanceOf(Folder::class, $processingFolder);
+    }
+
+    /**
+     * @test
+     */
+    public function getRoleReturnsDefaultForRegularFolders()
+    {
+        $folderIdentifier = $this->getUniqueId();
+        $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/core/Tests/Functional/Fixtures/sys_file_storage.xml');
+        $this->setUpBackendUserFromFixture(1);
+
+        $subject = (new StorageRepository())->findByUid(1);
+        $folder = new Folder($subject, '/foo/' . $folderIdentifier . '/', $folderIdentifier);
+
+        $role = $subject->getRole($folder);
+
+        $this->assertSame(FolderInterface::ROLE_DEFAULT, $role);
+    }
+
+    /**
+     * @test
+     */
+    public function replaceFileFailsIfLocalFileDoesNotExist()
+    {
+        $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/core/Tests/Functional/Fixtures/sys_file_storage.xml');
+        $this->setUpBackendUserFromFixture(1);
+        $subject = (new StorageRepository())->findByUid(1);
+
+        GeneralUtility::mkdir_deep(PATH_site . 'fileadmin/foo');
+        file_put_contents(PATH_site . 'fileadmin/foo/bar.txt', 'myData');
+        clearstatcache();
+        $file = ResourceFactory::getInstance()->getFileObjectFromCombinedIdentifier('1:/foo/bar.txt');
+
+        $this->expectException(\InvalidArgumentException::class);
+        $this->expectExceptionCode(1325842622);
+        $subject->replaceFile($file, PATH_site . $this->getUniqueId());
+    }
+
+    /**
+     * @test
+     */
+    public function createFolderThrowsExceptionIfParentFolderDoesNotExist()
+    {
+        $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/core/Tests/Functional/Fixtures/sys_file_storage.xml');
+        $this->setUpBackendUserFromFixture(1);
+        $subject = (new StorageRepository())->findByUid(1);
+
+        $this->expectException(\InvalidArgumentException::class);
+        $this->expectExceptionCode(1325689164);
+        $subject->createFolder('newFolder', new Folder($subject, '/foo/', 'foo'));
+    }
 }
index e5c170d..c94c493 100644 (file)
@@ -20,7 +20,6 @@ use TYPO3\CMS\Core\Resource\Driver\LocalDriver;
 use TYPO3\CMS\Core\Resource\File;
 use TYPO3\CMS\Core\Resource\FileRepository;
 use TYPO3\CMS\Core\Resource\Folder;
-use TYPO3\CMS\Core\Resource\FolderInterface;
 use TYPO3\CMS\Core\Resource\Index\FileIndexRepository;
 use TYPO3\CMS\Core\Resource\ResourceStorage;
 use TYPO3\CMS\Core\Utility\ArrayUtility;
@@ -710,45 +709,4 @@ class ResourceStorageTest extends BaseTestCase
         $mockedDriver->expects($this->once())->method('folderExists')->with($this->equalTo('/someFolder/'))->will($this->returnValue(false));
         $this->subject->createFolder('newFolder', $mockedParentFolder);
     }
-
-    /**
-     * @test
-     */
-    public function replaceFileFailsIfLocalFileDoesNotExist()
-    {
-        $this->expectException(\InvalidArgumentException::class);
-        $this->expectExceptionCode(1325842622);
-        $this->prepareSubject(array(), true);
-        $mockedFile = $this->getSimpleFileMock('/someFile');
-        $this->subject->replaceFile($mockedFile, PATH_site . $this->getUniqueId());
-    }
-
-    /**
-     * @test
-     * @TODO: Rewrite or move to functional suite
-     */
-    public function getRoleReturnsDefaultForRegularFolders()
-    {
-        $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
-        $folderIdentifier = $this->getUniqueId();
-        $this->addToMount(array(
-            $folderIdentifier => array()
-        ));
-        $this->prepareSubject(array());
-
-        $role = $this->subject->getRole($this->getSimpleFolderMock('/' . $folderIdentifier . '/'));
-
-        $this->assertSame(FolderInterface::ROLE_DEFAULT, $role);
-    }
-
-    /**
-     * @test
-     */
-    public function getProcessingRootFolderTest()
-    {
-        $this->prepareSubject(array());
-        $processingFolder = $this->subject->getProcessingFolder();
-
-        $this->assertInstanceOf(Folder::class, $processingFolder);
-    }
 }