[TASK] Performance optimizations for the form manager module
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Tests / Unit / Mvc / Persistence / FormPersistenceManagerTest.php
index 0826601..18054f2 100644 (file)
@@ -15,7 +15,9 @@ namespace TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Cache\Frontend\VariableFrontend;
 use TYPO3\CMS\Core\Resource\File;
+use TYPO3\CMS\Core\Resource\ResourceFactory;
 use TYPO3\CMS\Core\Resource\ResourceStorage;
 use TYPO3\CMS\Core\Resource\StorageRepository;
 use TYPO3\CMS\Form\Mvc\Persistence\Exception\NoUniqueIdentifierException;
@@ -40,6 +42,18 @@ class FormPersistenceManagerTest extends UnitTestCase
             'dummy'
         ], [], '', false);
 
+        $runtimeCache= $this->getMockBuilder(VariableFrontend::class)
+            ->setMethods(['get', 'set'])
+            ->disableOriginalConstructor()
+            ->getMock();
+
+        $runtimeCache
+            ->expects($this->any())
+            ->method('get')
+            ->willReturn(false);
+
+        $mockFormPersistenceManager->_set('runtimeCache', $runtimeCache);
+
         $input = '-1:/user_uploads/_example.php';
         $mockFormPersistenceManager->_call('load', $input);
     }
@@ -56,6 +70,18 @@ class FormPersistenceManagerTest extends UnitTestCase
             'dummy'
         ], [], '', false);
 
+        $runtimeCache= $this->getMockBuilder(VariableFrontend::class)
+            ->setMethods(['get', 'set'])
+            ->disableOriginalConstructor()
+            ->getMock();
+
+        $runtimeCache
+            ->expects($this->any())
+            ->method('get')
+            ->willReturn(false);
+
+        $mockFormPersistenceManager->_set('runtimeCache', $runtimeCache);
+
         $mockFormPersistenceManager->_set('formSettings', [
             'persistenceManager' => [
                 'allowedExtensionPaths' => [],
@@ -116,6 +142,18 @@ class FormPersistenceManagerTest extends UnitTestCase
             'dummy'
         ], [], '', false);
 
+        $runtimeCache= $this->getMockBuilder(VariableFrontend::class)
+            ->setMethods(['get', 'set'])
+            ->disableOriginalConstructor()
+            ->getMock();
+
+        $runtimeCache
+            ->expects($this->any())
+            ->method('get')
+            ->willReturn(false);
+
+        $mockFormPersistenceManager->_set('runtimeCache', $runtimeCache);
+
         $mockFormPersistenceManager->_set('formSettings', [
             'persistenceManager' => [
                 'allowSaveToExtensionPaths' => true,
@@ -203,6 +241,18 @@ class FormPersistenceManagerTest extends UnitTestCase
             'exists'
         ], [], '', false);
 
+        $runtimeCache= $this->getMockBuilder(VariableFrontend::class)
+            ->setMethods(['get', 'set'])
+            ->disableOriginalConstructor()
+            ->getMock();
+
+        $runtimeCache
+            ->expects($this->any())
+            ->method('get')
+            ->willReturn(false);
+
+        $mockFormPersistenceManager->_set('runtimeCache', $runtimeCache);
+
         $mockFormPersistenceManager
             ->expects($this->any())
             ->method('exists')
@@ -270,6 +320,18 @@ class FormPersistenceManagerTest extends UnitTestCase
             'dummy'
         ], [], '', false);
 
+        $runtimeCache= $this->getMockBuilder(VariableFrontend::class)
+            ->setMethods(['get', 'set'])
+            ->disableOriginalConstructor()
+            ->getMock();
+
+        $runtimeCache
+            ->expects($this->any())
+            ->method('get')
+            ->willReturn(false);
+
+        $mockFormPersistenceManager->_set('runtimeCache', $runtimeCache);
+
         $mockFormPersistenceManager->_set('formSettings', [
             'persistenceManager' => [
                 'allowedExtensionPaths' => [
@@ -558,37 +620,39 @@ class FormPersistenceManagerTest extends UnitTestCase
     /**
      * @test
      */
-    public function getFileByIdentifierThrowsExceptionIfReadFromStorageIsNotAllowed(): void
+    public function retrieveFileByPersistenceIdentifierThrowsExceptionIfReadFromStorageIsNotAllowed(): void
     {
         $this->expectException(PersistenceManagerException::class);
         $this->expectExceptionCode(1471630578);
 
         $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
-            'getStorageByUid',
+            'dummy',
         ], [], '', false);
 
-        $mockStorage = $this->getMockBuilder(ResourceStorage::class)
+        $storage = $this->getMockBuilder(ResourceStorage::class)
             ->disableOriginalConstructor()
             ->getMock();
 
-        $mockStorage
+        $storage
             ->expects($this->any())
             ->method('checkFileActionPermission')
             ->willReturn(false);
 
-        $file = new File(['name' => 'foo', 'identifier' => '', 'mime_type' => ''], $mockStorage);
-        $mockStorage
+        $file = new File(['name' => 'foo', 'identifier' => '', 'mime_type' => ''], $storage);
+
+        $resourceFactory = $this->getMockBuilder(ResourceFactory::class)
+            ->disableOriginalConstructor()
+            ->getMock();
+
+        $resourceFactory
             ->expects($this->any())
-            ->method('getFile')
+            ->method('retrieveFileOrFolderObject')
             ->willReturn($file);
 
-        $mockFormPersistenceManager
-            ->expects($this->any())
-            ->method('getStorageByUid')
-            ->willReturn($mockStorage);
+        $mockFormPersistenceManager->_set('resourceFactory', $resourceFactory);
 
         $input = '-1:/user_uploads/example.yaml';
-        $mockFormPersistenceManager->_call('getFileByIdentifier', $input);
+        $mockFormPersistenceManager->_call('retrieveFileByPersistenceIdentifier', $input);
     }
 
     /**