[TASK] Deprecate BackendUtility::getTCAtypes
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / UnitDeprecated / Utility / BackendUtilityTest.php
index db88adf..3f9c725 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Backend\Tests\UnitDeprecated\Utility;
  */
 
 use TYPO3\CMS\Backend\Tests\UnitDeprecated\Utility\Fixtures\BackendUtilityFixture;
+use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
 
@@ -47,4 +48,262 @@ class BackendUtilityTest extends UnitTestCase
 
         $this->assertSame($completeConfiguration, BackendUtilityFixture::getModTSconfig(42, 'notrelevant'));
     }
+
+    ///////////////////////////////////////
+    // Tests concerning getTCAtypes
+    ///////////////////////////////////////
+
+    /**
+     * @test
+     */
+    public function getTCAtypesReturnsCorrectValuesDataProvider()
+    {
+        return [
+            'no input' => [
+                '', // table
+                [], // rec
+                '', // useFieldNameAsKey
+                null // expected
+            ],
+            'non-existant table' => [
+                'fooBar', // table
+                [], // rec
+                '', // useFieldNameAsKey
+                null // expected
+            ],
+            'Doktype=1: one simple field' => [
+                'pages',
+                [
+                    'uid' => '1',
+                    'doktype' => '1'
+                ],
+                false,
+                [
+                    0 => [
+                        'field' => 'title',
+                        'title' => null,
+                        'palette' => null,
+                        'spec' => [],
+                        'origString' => 'title'
+                    ]
+                ]
+            ],
+            'non-existant type given: Return for type 1' => [
+                'pages', // table
+                [
+                    'uid' => '1',
+                    'doktype' => '999'
+                ], // rec
+                '', // useFieldNameAsKey
+                [
+                    0 => [
+                        'field' => 'title',
+                        'title' => null,
+                        'palette' => null,
+                        'spec' => [],
+                        'origString' => 'title'
+                    ]
+                ] // expected
+            ],
+            'Doktype=1: one simple field, useFieldNameAsKey=true' => [
+                'pages',
+                [
+                    'uid' => '1',
+                    'doktype' => '1'
+                ],
+                true,
+                [
+                    'title' => [
+                        'field' => 'title',
+                        'title' => null,
+                        'palette' => null,
+                        'spec' => [],
+                        'origString' => 'title'
+                    ]
+                ]
+            ],
+            'Empty showitem Field' => [
+                'test',
+                [
+                    'uid' => '1',
+                    'fooBar' => '99'
+                ],
+                true,
+                [
+                    '' => [
+                        'field' => '',
+                        'title' => null,
+                        'palette' => null,
+                        'spec' => [],
+                        'origString' => ''
+                    ]
+                ]
+            ],
+            'RTE field within a palette' => [
+                'pages',
+                [
+                    'uid' => '1',
+                    'doktype' => '10',
+                ],
+                false,
+                [
+                    0 => [
+                        'field' => '--div--',
+                        'title' => 'General',
+                        'palette' => null,
+                        'spec' => [],
+                        'origString' => '--div--;General'
+                    ],
+                    1 => [
+                        'field' => '--palette--',
+                        'title' => 'Palette',
+                        'palette' => '123',
+                        'spec' => [],
+                        'origString' => '--palette--;Palette;123'
+                    ],
+                    2 => [
+                        'field' => 'title',
+                        'title' => null,
+                        'palette' => null,
+                        'spec' => [],
+                        'origString' => 'title'
+                    ],
+                    3 => [
+                        'field' => 'text',
+                        'title' => null,
+                        'palette' => null,
+                        'spec' => [],
+                        'origString' => 'text'
+                    ],
+                    4 => [
+                        'field' => 'select',
+                        'title' => 'Select field',
+                        'palette' => null,
+                        'spec' => [],
+                        'origString' => 'select;Select field'
+                    ]
+                ]
+            ],
+            'RTE field with more settings within a palette' => [
+                'pages',
+                [
+                    'uid' => 1,
+                    'doktype' => 2
+                ],
+                false,
+                [
+                    0 => [
+                        'field' => '--div--',
+                        'title' => 'General',
+                        'palette' => null,
+                        'spec' => [],
+                        'origString' => '--div--;General'
+                    ],
+                    1 => [
+                        'field' => '--palette--',
+                        'title' => 'RTE palette',
+                        'palette' => '456',
+                        'spec' => [],
+                        'origString' => '--palette--;RTE palette;456'
+                    ],
+                    2 => [
+                        'field' => 'text2',
+                        'title' => null,
+                        'palette' => null,
+                        'spec' => [],
+                        'origString' => 'text2'
+                    ]
+                ]
+            ]
+        ];
+    }
+
+    /**
+     * @test
+     * @dataProvider getTCAtypesReturnsCorrectValuesDataProvider
+     *
+     * @param string $table
+     * @param array $rec
+     * @param bool $useFieldNameAsKey
+     * @param array $expected
+     */
+    public function getTCAtypesReturnsCorrectValues($table, $rec, $useFieldNameAsKey, $expected)
+    {
+        $GLOBALS['TCA'] = [
+            'pages' => [
+                'ctrl' => [
+                    'type' => 'doktype'
+                ],
+                'columns' => [
+                    'title' => [
+                        'label' => 'Title test',
+                        'config' => [
+                            'type' => 'input'
+                        ]
+                    ],
+                    'text' => [
+                        'label' => 'RTE Text',
+                        'config' => [
+                            'type' => 'text',
+                            'cols' => 40,
+                            'rows' => 5
+                        ],
+                    ],
+                    'text2' => [
+                        'label' => 'RTE Text 2',
+                        'config' => [
+                            'type' => 'text',
+                            'cols' => 40,
+                            'rows' => 5
+                        ],
+                    ],
+                    'select' => [
+                        'label' => 'Select test',
+                        'config' => [
+                            'items' => [
+                                ['Please select', 0],
+                                ['Option 1', 1],
+                                ['Option 2', 2]
+                            ]
+                        ],
+                        'maxitems' => 1,
+                        'renderType' => 'selectSingle'
+                    ]
+                ],
+                'types' => [
+                    '1' => [
+                        'showitem' => 'title'
+                    ],
+                    '2' => [
+                        'showitem' => '--div--;General,--palette--;RTE palette;456'
+                    ],
+                    '10' => [
+                        'showitem' => '--div--;General,--palette--;Palette;123,title'
+                    ],
+                    '14' => [
+                        'showitem' => '--div--;General,title'
+                    ]
+                ],
+                'palettes' => [
+                    '123' => [
+                        'showitem' => 'text,select;Select field'
+                    ],
+                    '456' => [
+                        'showitem' => 'text2'
+                    ]
+                ]
+            ],
+            'test' => [
+                'ctrl' => [
+                    'type' => 'fooBar'
+                ],
+                'types' => [
+                    '99' => [ 'showitem' => '']
+                ]
+            ]
+        ];
+
+        $return = BackendUtility::getTCAtypes($table, $rec, $useFieldNameAsKey);
+        $this->assertSame($expected, $return);
+    }
 }