‪TYPO3CMS  ‪main
TcaSelectTreeItemsTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\Attributes\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
26 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
27 
32 final class ‪TcaSelectTreeItemsTest extends FunctionalTestCase
33 {
34  protected array ‪$testExtensionsToLoad = ['typo3/sysext/backend/Tests/Functional/Fixtures/Extensions/test_tca_select_tree_items'];
35 
36  public function ‪setUp(): void
37  {
38  parent::setUp();
39  $this->importCSVDataSet(__DIR__ . '/../../Fixtures/be_users.csv');
40  $this->importCSVDataSet(__DIR__ . '/../Fixtures/TcaSelectTreeItems/base.csv');
41  ‪$GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageServiceFactory::class)->create('default');
42  ‪$GLOBALS['BE_USER'] = $this->setUpBackendUser(1);
43  }
44 
45  #[Test]
47  {
48  $input = [
49  'tableName' => 'tca_select_tree_items',
50  'effectivePid' => 1,
51  'databaseRow' => [
52  'uid' => 1,
53  'select_tree' => '1',
54  ],
55  'processedTca' => [
56  'columns' => [
57  'select_tree' => [
58  'config' => [
59  'type' => 'select',
60  'renderType' => 'selectTree',
61  'treeConfig' => [
62  'childrenField' => 'children_field',
63  'startingPoints' => 1,
64  ],
65  'foreign_table' => 'foreign_table',
66  'items' => [],
67  'maxitems' => 1,
68  ],
69  ],
70  ],
71  ],
72  'site' => null,
73  'selectTreeCompileItems' => true,
74  ];
75 
76  $expected = $input;
77  $expected['databaseRow']['select_tree'] = ['1'];
78  $expected['processedTca']['columns']['select_tree']['config']['items'] = [
79  [
80  'identifier' => '1',
81  'name' => 'Item 1',
82  'icon' => 'default-not-found',
83  'overlayIcon' => '',
84  'depth' => 0,
85  'hasChildren' => true,
86  'selectable' => true,
87  'checked' => true,
88  ],
89  [
90  'identifier' => '2',
91  'name' => 'Item 2',
92  'icon' => 'default-not-found',
93  'overlayIcon' => '',
94  'depth' => 1,
95  'hasChildren' => true,
96  'selectable' => true,
97  'checked' => false,
98  ],
99  [
100  'identifier' => '4',
101  'name' => 'Item 4',
102  'icon' => 'default-not-found',
103  'overlayIcon' => '',
104  'depth' => 2,
105  'hasChildren' => false,
106  'selectable' => true,
107  'checked' => false,
108  ],
109  [
110  'identifier' => '3',
111  'name' => 'Item 3',
112  'icon' => 'default-not-found',
113  'overlayIcon' => '',
114  'depth' => 1,
115  'hasChildren' => true,
116  'selectable' => true,
117  'checked' => false,
118  ],
119  [
120  'identifier' => '5',
121  'name' => 'Item 5',
122  'icon' => 'default-not-found',
123  'overlayIcon' => '',
124  'depth' => 2,
125  'hasChildren' => false,
126  'selectable' => true,
127  'checked' => false,
128  ],
129  ];
130  self::assertEquals($expected, (new ‪TcaSelectTreeItems())->addData($input));
131  }
132 
133  #[Test]
135  {
136  $input = [
137  'tableName' => 'tca_select_tree_items',
138  'effectivePid' => 1,
139  'databaseRow' => [
140  'uid' => 1,
141  'select_tree' => '1',
142  ],
143  'processedTca' => [
144  'columns' => [
145  'select_tree' => [
146  'config' => [
147  'type' => 'select',
148  'renderType' => 'selectTree',
149  'treeConfig' => [
150  'childrenField' => 'children_field',
151  ],
152  'foreign_table' => 'foreign_table',
153  'items' => [
154  ['label' => 'static item foo', 'value' => 1, 'icon' => 'foo-icon'],
155  ['label' => 'static item bar', 'value' => 2, 'icon' => 'bar-icon'],
156  ],
157  'maxitems' => 1,
158  ],
159  ],
160  ],
161  ],
162  'pageTsConfig' => [
163  'TCEFORM.' => [
164  'tca_select_tree_items.' => [
165  'select_tree.' => [
166  'config.' => [
167  'treeConfig.' => [
168  'startingPoints' => '1',
169  'appearance.' => [
170  'expandAll' => 1,
171  'maxLevels' => 1,
172  'nonSelectableLevels' => '0,1',
173  ],
174  ],
175  ],
176  'altLabels.' => [
177  1 => 'alt static item foo',
178  2 => 'alt static item bar',
179  ],
180  'altIcons.' => [
181  1 => 'foo-alt-icon',
182  2 => 'bar-alt-icon',
183  ],
184  ],
185  ],
186  ],
187  ],
188  'site' => null,
189  'selectTreeCompileItems' => true,
190  ];
191 
192  $result = (new ‪TcaSelectTreeItems())->addData($input);
193 
194  $resultItems = $result['processedTca']['columns']['select_tree']['config']['items'];
195  $expectedItems = [
196  [
197  'identifier' => 1,
198  'name' => 'alt static item foo',
199  'icon' => 'foo-alt-icon',
200  'iconOverlay' => '', // @todo for non-static items this is called `overlayIcon`. Bug?
201  'depth' => 0,
202  'hasChildren' => false,
203  'selectable' => true,
204  'checked' => true,
205  ],
206  [
207  'identifier' => 2,
208  'name' => 'alt static item bar',
209  'icon' => 'bar-alt-icon',
210  'iconOverlay' => '', // @todo for non-static items this is called `overlayIcon`. Bug?
211  'depth' => 0,
212  'hasChildren' => false,
213  'selectable' => true,
214  'checked' => false,
215  ],
216  [
217  'identifier' => '1',
218  'name' => 'Item 1',
219  'icon' => 'default-not-found',
220  'overlayIcon' => '',
221  'depth' => 0,
222  'hasChildren' => true,
223  'selectable' => false,
224  'checked' => false,
225  ],
226  [
227  'identifier' => '2',
228  'name' => 'Item 2',
229  'icon' => 'default-not-found',
230  'overlayIcon' => '',
231  'depth' => 1,
232  'hasChildren' => false,
233  'selectable' => false,
234  'checked' => false,
235  ],
236  [
237  'identifier' => '3',
238  'name' => 'Item 3',
239  'icon' => 'default-not-found',
240  'overlayIcon' => '',
241  'depth' => 1,
242  'hasChildren' => false,
243  'selectable' => false,
244  'checked' => false,
245  ],
246  ];
247 
248  self::assertTrue($result['processedTca']['columns']['select_tree']['config']['treeConfig']['appearance']['expandAll']);
249  self::assertEquals($expectedItems, $resultItems);
250  }
251 
253  {
254  return [
255  'one setting' => [
256  'inputStartingPoints' => '42,###SITE:categories.contentCategory###,12',
257  'expectedStartingPoints' => '42,4711,12',
258  'site' => new ‪Site('some-site', 1, ['rootPageId' => 1, 'categories' => ['contentCategory' => 4711]]),
259  ],
260  'two settings' => [
261  'inputStartingPoints' => '42,###SITE:categories.contentCategory###,12,###SITE:foobar###',
262  'expectedStartingPoints' => '42,4711,12,1',
263  'site' => new ‪Site('some-site', 1, ['rootPageId' => 1, 'foobar' => 1, 'categories' => ['contentCategory' => 4711]]),
264  ],
265  ];
266  }
267 
268  #[DataProvider('addDataHandsSiteConfigurationOverToTableConfigurationTreeDataProvider')]
269  #[Test]
270  public function ‪addDataHandsSiteConfigurationOverToTableConfigurationTree(string $inputStartingPoints, string $expectedStartingPoints, ‪Site $site): void
271  {
272  $input = [
273  'tableName' => 'tca_select_tree_items',
274  'effectivePid' => 1,
275  'databaseRow' => [
276  'uid' => 1,
277  'select_tree' => '1',
278  ],
279  'processedTca' => [
280  'columns' => [
281  'select_tree' => [
282  'config' => [
283  'type' => 'select',
284  'renderType' => 'selectTree',
285  'treeConfig' => [
286  'childrenField' => 'children_field',
287  'startingPoints' => $inputStartingPoints,
288  'appearance' => [
289  'expandAll' => true,
290  'maxLevels' => 4,
291  ],
292  ],
293  'foreign_table' => 'foreign_table',
294  'maxitems' => 1,
295  ],
296  ],
297  ],
298  ],
299  'site' => $site,
300  'selectTreeCompileItems' => true,
301  ];
302 
303  $result = (new ‪TcaSelectTreeItems())->addData($input);
304 
305  $resultStartingPoints = $result['processedTca']['columns']['select_tree']['config']['treeConfig']['startingPoints'];
306  self::assertSame($expectedStartingPoints, $resultStartingPoints);
307  }
308 }
‪TYPO3\CMS\Backend\Tests\Functional\Form\FormDataProvider\TcaSelectTreeItemsTest\addDataHandsSiteConfigurationOverToTableConfigurationTreeDataProvider
‪static addDataHandsSiteConfigurationOverToTableConfigurationTreeDataProvider()
Definition: TcaSelectTreeItemsTest.php:252
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory
Definition: LanguageServiceFactory.php:25
‪TYPO3\CMS\Backend\Tests\Functional\Form\FormDataProvider\TcaSelectTreeItemsTest\addDataHandsPageTsConfigSettingsOverToTableConfigurationTree
‪addDataHandsPageTsConfigSettingsOverToTableConfigurationTree()
Definition: TcaSelectTreeItemsTest.php:134
‪TYPO3\CMS\Core\Site\Entity\Site
Definition: Site.php:42
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaSelectTreeItems
Definition: TcaSelectTreeItems.php:39
‪TYPO3\CMS\Backend\Tests\Functional\Form\FormDataProvider\TcaSelectTreeItemsTest\$testExtensionsToLoad
‪array $testExtensionsToLoad
Definition: TcaSelectTreeItemsTest.php:34
‪TYPO3\CMS\Backend\Tests\Functional\Form\FormDataProvider\TcaSelectTreeItemsTest\addDataAddsTreeConfigurationForSelectTreeElement
‪addDataAddsTreeConfigurationForSelectTreeElement()
Definition: TcaSelectTreeItemsTest.php:46
‪TYPO3\CMS\Backend\Tests\Functional\Form\FormDataProvider\TcaSelectTreeItemsTest\setUp
‪setUp()
Definition: TcaSelectTreeItemsTest.php:36
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Backend\Tests\Functional\Form\FormDataProvider\TcaSelectTreeItemsTest
Definition: TcaSelectTreeItemsTest.php:33
‪TYPO3\CMS\Backend\Tests\Functional\Form\FormDataProvider
Definition: TcaCategoryTest.php:18
‪TYPO3\CMS\Backend\Tests\Functional\Form\FormDataProvider\TcaSelectTreeItemsTest\addDataHandsSiteConfigurationOverToTableConfigurationTree
‪addDataHandsSiteConfigurationOverToTableConfigurationTree(string $inputStartingPoints, string $expectedStartingPoints, Site $site)
Definition: TcaSelectTreeItemsTest.php:270