[TASK] Performance optimizations for the form manager module
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Tests / Unit / Controller / FormManagerControllerTest.php
index d4ee020..ce57de4 100644 (file)
@@ -26,6 +26,7 @@ use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
 use TYPO3\CMS\Extbase\Object\ObjectManager;
 use TYPO3\CMS\Form\Controller\FormManagerController;
 use TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManager;
+use TYPO3\CMS\Form\Service\DatabaseService;
 use TYPO3\CMS\Form\Service\TranslationService;
 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
 
@@ -175,12 +176,15 @@ class FormManagerControllerTest extends UnitTestCase
     public function getAvailableFormDefinitionsReturnsProcessedArray(): void
     {
         $mockController = $this->getAccessibleMock(FormManagerController::class, [
-            'getReferences'
+            'dummy'
         ], [], '', false);
 
         $formPersistenceManagerProphecy = $this->prophesize(FormPersistenceManager::class);
         $mockController->_set('formPersistenceManager', $formPersistenceManagerProphecy->reveal());
 
+        $databaseService = $this->prophesize(DatabaseService::class);
+        $mockController->_set('databaseService', $databaseService->reveal());
+
         $formPersistenceManagerProphecy->listForms(Argument::cetera())->willReturn([
             0 => [
                 'identifier' => 'ext-form-identifier',
@@ -193,13 +197,13 @@ class FormManagerControllerTest extends UnitTestCase
             ],
         ]);
 
-        $mockController
-            ->expects($this->any())
-            ->method('getReferences')
-            ->willReturn([
-                'someRow',
-                'anotherRow',
-            ]);
+        $databaseService->getAllReferencesForFileUid(Argument::cetera())->willReturn([
+            0 => 0,
+        ]);
+
+        $databaseService->getAllReferencesForPersistenceIdentifier(Argument::cetera())->willReturn([
+            '1:/user_uploads/someFormName.yaml' => 2,
+        ]);
 
         $expected = [
             0 => [
@@ -247,9 +251,18 @@ class FormManagerControllerTest extends UnitTestCase
             'getModuleUrl',
             'getRecord',
             'getRecordTitle',
-            'getReferences',
         ], [], '', false);
 
+        $databaseService = $this->prophesize(DatabaseService::class);
+        $mockController->_set('databaseService', $databaseService->reveal());
+
+        $databaseService->getReferencesByPersistenceIdentifier(Argument::cetera())->willReturn([
+            0 => [
+                'tablename' => 'tt_content',
+                'recuid' => -1,
+            ],
+        ]);
+
         $mockController
             ->expects($this->any())
             ->method('getModuleUrl')
@@ -265,16 +278,6 @@ class FormManagerControllerTest extends UnitTestCase
             ->method('getRecordTitle')
             ->willReturn('record title');
 
-        $mockController
-            ->expects($this->any())
-            ->method('getReferences')
-            ->willReturn([
-                0 => [
-                    'tablename' => 'tt_content',
-                    'recuid' => -1,
-                ],
-            ]);
-
         $expected = [
             0 => [
                 'recordPageTitle' => 'record title',