‪TYPO3CMS  ‪main
ListOfFieldsContainerTest.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\Test;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
26 final class ‪ListOfFieldsContainerTest extends UnitTestCase
27 {
28  #[Test]
29  public function ‪renderDelegatesShowitemField(): void
30  {
31  $nodeFactoryMock = $this->createMock(NodeFactory::class);
32  $paletteAndSingleContainerMock = $this->createMock(PaletteAndSingleContainer::class);
33  $paletteAndSingleContainerMock->expects(self::atLeastOnce())->method('render')->withAnyParameters()->willReturn([]);
34 
35  $input = [
36  'tableName' => 'aTable',
37  'recordTypeValue' => 'aType',
38  'processedTca' => [
39  'types' => [
40  'aType' => [
41  'showitem' => 'aField',
42  ],
43  ],
44  ],
45  'fieldListToRender' => 'aField',
46  ];
47 
48  $expected = $input;
49  $expected['renderType'] = 'paletteAndSingleContainer';
50 
51  // Verify 'fieldArray' contains 'aField' since that is a showitem field of this type
52  $expected['fieldsArray'] = [
53  'aField;;',
54  ];
55 
56  $nodeFactoryMock->method('create')->with($expected)->willReturn($paletteAndSingleContainerMock);
57 
58  $subject = new ‪ListOfFieldsContainer();
59  $subject->injectNodeFactory($nodeFactoryMock);
60  $subject->setData($input);
61  $subject->render();
62  }
63 
64  #[Test]
66  {
67  $nodeFactoryMock = $this->createMock(NodeFactory::class);
68  $paletteAndSingleContainerMock = $this->createMock(PaletteAndSingleContainer::class);
69  $paletteAndSingleContainerMock->expects(self::atLeastOnce())->method('render')->withAnyParameters()->willReturn([]);
70 
71  $input = [
72  'tableName' => 'aTable',
73  'recordTypeValue' => 'aType',
74  'processedTca' => [
75  'types' => [
76  'aType' => [
77  'showitem' => 'aField, bField;bLabel, cField',
78  ],
79  ],
80  ],
81  'fieldListToRender' => 'aField, bField, aField',
82  ];
83 
84  $expected = $input;
85  $expected['renderType'] = 'paletteAndSingleContainer';
86  // Duplicates are suppressed but label is kept
87  $expected['fieldsArray'] = [
88  'aField;;',
89  'bField;bLabel;',
90  ];
91 
92  $nodeFactoryMock->method('create')->with($expected)->willReturn($paletteAndSingleContainerMock);
93 
94  $subject = new ‪ListOfFieldsContainer();
95  $subject->injectNodeFactory($nodeFactoryMock);
96  $subject->setData($input);
97  $subject->render();
98  }
99 
100  #[Test]
101  public function ‪renderDelegatesPaletteFields(): void
102  {
103  $nodeFactoryMock = $this->createMock(NodeFactory::class);
104  $paletteAndSingleContainerMock = $this->createMock(PaletteAndSingleContainer::class);
105  $paletteAndSingleContainerMock->expects(self::atLeastOnce())->method('render')->withAnyParameters()->willReturn([]);
106 
107  $input = [
108  'tableName' => 'aTable',
109  'recordTypeValue' => 'aType',
110  'processedTca' => [
111  'types' => [
112  'aType' => [
113  'showitem' => '--palette--;;aPalette, --palette--;;anotherPalette',
114  ],
115  ],
116  'palettes' => [
117  'aPalette' => [
118  'showitem' => 'aField',
119  ],
120  'anotherPalette' => [
121  'showitem' => 'bField;bLabel, cField',
122  ],
123  ],
124  ],
125  'fieldListToRender' => 'aField, bField',
126  ];
127 
128  $expected = $input;
129  $expected['renderType'] = 'paletteAndSingleContainer';
130  // Both palette fields are found
131  $expected['fieldsArray'] = [
132  'aField;;',
133  'bField;bLabel;',
134  ];
135 
136  $nodeFactoryMock->method('create')->with($expected)->willReturn($paletteAndSingleContainerMock);
137 
138  $subject = new ‪ListOfFieldsContainer();
139  $subject->injectNodeFactory($nodeFactoryMock);
140  $subject->setData($input);
141  $subject->render();
142  }
143 
144  #[Test]
146  {
147  $nodeFactoryMock = $this->createMock(NodeFactory::class);
148  $paletteAndSingleContainerMock = $this->createMock(PaletteAndSingleContainer::class);
149  $paletteAndSingleContainerMock->expects(self::atLeastOnce())->method('render')->withAnyParameters()->willReturn([]);
150 
151  $input = [
152  'tableName' => 'aTable',
153  'recordTypeValue' => 'aType',
154  'processedTca' => [
155  'types' => [
156  'aType' => [
157  'showitem' => '--palette--;;aPalette',
158  ],
159  ],
160  'palettes' => [
161  'aPalette' => [
162  'showitem' => 'aField',
163  ],
164  ],
165  ],
166  'fieldListToRender' => 'aField, iDontExist',
167  ];
168 
169  $expected = $input;
170  $expected['renderType'] = 'paletteAndSingleContainer';
171  // Duplicates are suppressed but label is kept
172  $expected['fieldsArray'] = [
173  'aField;;',
174  ];
175 
176  $nodeFactoryMock->method('create')->with($expected)->willReturn($paletteAndSingleContainerMock);
177 
178  $subject = new ‪ListOfFieldsContainer();
179  $subject->injectNodeFactory($nodeFactoryMock);
180  $subject->setData($input);
181  $subject->render();
182  }
183 }
‪TYPO3\CMS\Backend\Tests\Unit\Form\Container
Definition: ListOfFieldsContainerTest.php:18
‪TYPO3\CMS\Backend\Tests\Unit\Form\Container\ListOfFieldsContainerTest\renderRemovesNotExistingTypesField
‪renderRemovesNotExistingTypesField()
Definition: ListOfFieldsContainerTest.php:145
‪TYPO3\CMS\Backend\Form\Container\ListOfFieldsContainer
Definition: ListOfFieldsContainer.php:29
‪TYPO3\CMS\Backend\Tests\Unit\Form\Container\ListOfFieldsContainerTest\renderDelegatesShowitemField
‪renderDelegatesShowitemField()
Definition: ListOfFieldsContainerTest.php:29
‪TYPO3\CMS\Backend\Tests\Unit\Form\Container\ListOfFieldsContainerTest\renderDelegatesPaletteFields
‪renderDelegatesPaletteFields()
Definition: ListOfFieldsContainerTest.php:101
‪TYPO3\CMS\Backend\Form\NodeFactory
Definition: NodeFactory.php:40
‪TYPO3\CMS\Backend\Tests\Unit\Form\Container\ListOfFieldsContainerTest\renderDelegatesShowitemFieldAndRemovesDuplicates
‪renderDelegatesShowitemFieldAndRemovesDuplicates()
Definition: ListOfFieldsContainerTest.php:65
‪TYPO3\CMS\Backend\Tests\Unit\Form\Container\ListOfFieldsContainerTest
Definition: ListOfFieldsContainerTest.php:27
‪TYPO3\CMS\Backend\Form\Container\PaletteAndSingleContainer
Definition: PaletteAndSingleContainer.php:33