[TASK] Add unit tests for BackendUtiily::resolveFileReferences 58/58758/4
authorAnja <aleichsenring@ab-softlab.de>
Sun, 28 Oct 2018 12:28:45 +0000 (13:28 +0100)
committerBenni Mack <benni@typo3.org>
Sun, 28 Oct 2018 13:10:14 +0000 (14:10 +0100)
This tests are a left over from a patch being abandoned.
Keeping them should not be wrong, they help identify notices
thrown, if nothing else.

Change-Id: If88d0f60f8b5bef9ce34b628b5fb46b86d2ae36f
Resolves: #86779
Releases: master
Reviewed-on: https://review.typo3.org/58758
Reviewed-by: Richard Haeser <richard@maxserv.com>
Tested-by: Richard Haeser <richard@maxserv.com>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/backend/Classes/Utility/BackendUtility.php
typo3/sysext/backend/Tests/Unit/Utility/BackendUtilityTest.php

index 7300d6d..40fa487 100644 (file)
@@ -1272,7 +1272,7 @@ class BackendUtility
         $relationHandler->start(
             $element[$fieldName],
             $configuration['foreign_table'],
-            $configuration['MM'],
+            $configuration['MM'] ?? '',
             $element['uid'],
             $tableName,
             $configuration
index b5b142a..375ee3c 100644 (file)
@@ -1052,4 +1052,94 @@ class BackendUtilityTest extends UnitTestCase
         $result = BackendUtility::getPagesTSconfig($pageId);
         $this->assertEquals($expected, $result);
     }
+
+    /**
+     * @test
+     */
+    public function returnNullForMissingTcaConfigInResolveFileReferences()
+    {
+        $tableName = 'table_a';
+        $fieldName = 'field_a';
+        $GLOBALS['TCA'][$tableName]['columns'][$fieldName]['config'] = [];
+        $this->assertNull(BackendUtility::resolveFileReferences($tableName, $fieldName, []));
+    }
+
+    /**
+     * @test
+     * @dataProvider unfitResolveFileReferencesTableConfig
+     */
+    public function returnNullForUnfitTableConfigInResolveFileReferences(array $config)
+    {
+        $tableName = 'table_a';
+        $fieldName = 'field_a';
+        $GLOBALS['TCA'][$tableName]['columns'][$fieldName]['config'] = $config;
+        $this->assertNull(BackendUtility::resolveFileReferences($tableName, $fieldName, []));
+    }
+
+    public function unfitResolveFileReferencesTableConfig(): array
+    {
+        return [
+            'invalid table' => [
+                [
+                    'type' => 'inline',
+                    'foreign_table' => 'table_b',
+                ],
+            ],
+            'empty table' => [
+                [
+                    'type' => 'inline',
+                    'foreign_table' => '',
+                ],
+            ],
+            'invalid type' => [
+                [
+                    'type' => 'select',
+                    'foreign_table' => 'sys_file_reference',
+                ],
+            ],
+            'empty type' => [
+                [
+                    'type' => '',
+                    'foreign_table' => 'sys_file_reference',
+                ],
+            ],
+            'empty' => [
+                [
+                    'type' => '',
+                    'foreign_table' => '',
+                ],
+            ],
+        ];
+    }
+
+    /**
+     * @test
+     */
+    public function resolveFileReferencesReturnsEmptyResultForNoReferencesAvailable()
+    {
+        $tableName = 'table_a';
+        $fieldName = 'field_a';
+        $relationHandler = $this->prophesize(RelationHandler::class);
+        $relationHandler->start(
+            'foo',
+            'sys_file_reference',
+            '',
+            42,
+            $tableName,
+            ['type' => 'inline', 'foreign_table' => 'sys_file_reference']
+        )->shouldBeCalled();
+        $relationHandler->tableArray = ['sys_file_reference' => []];
+        $relationHandler->processDeletePlaceholder()->shouldBeCalled();
+        GeneralUtility::addInstance(RelationHandler::class, $relationHandler->reveal());
+        $GLOBALS['TCA'][$tableName]['columns'][$fieldName]['config'] = [
+            'type' => 'inline',
+            'foreign_table' => 'sys_file_reference',
+        ];
+        $elementData = [
+            $fieldName => 'foo',
+            'uid' => 42,
+        ];
+
+        $this->assertEmpty(BackendUtility::resolveFileReferences($tableName, $fieldName, $elementData));
+    }
 }