106ee1152fe93f5b2a43fd19016c6413436f4f4b
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Form / Container / ListOfFieldsContainerTest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Backend\Tests\Unit\Form\Container;
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
18 use Prophecy\Argument;
19 use TYPO3\CMS\Backend\Form\Container\ListOfFieldsContainer;
20 use TYPO3\CMS\Backend\Form\Container\PaletteAndSingleContainer;
21 use TYPO3\CMS\Backend\Form\NodeFactory;
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23
24 /**
25 * Test case
26 */
27 class ListOfFieldsContainerTest extends UnitTestCase
28 {
29 /**
30 * Subject is not notice free, disable E_NOTICES
31 */
32 protected static $suppressNotices = true;
33
34 /**
35 * @test
36 */
37 public function renderDelegatesShowitemField()
38 {
39 $nodeFactoryProphecy = $this->prophesize(NodeFactory::class);
40 $paletteAndSingleContainerProphecy = $this->prophesize(PaletteAndSingleContainer::class);
41 $paletteAndSingleContainerProphecy->render(Argument::cetera())->shouldBeCalled()->willReturn('');
42
43 $input = [
44 'recordTypeValue' => 'aType',
45 'processedTca' => [
46 'types' => [
47 'aType' => [
48 'showitem' => 'aField',
49 ],
50 ],
51 ],
52 'fieldListToRender' => 'aField',
53 ];
54
55 $expected = $input;
56 $expected['renderType'] = 'paletteAndSingleContainer';
57
58 // Verify 'fieldArray' contains 'aField' since that is a showitem field of this type
59 $expected['fieldsArray'] = [
60 'aField;;',
61 ];
62
63 $nodeFactoryProphecy->create($expected)->willReturn($paletteAndSingleContainerProphecy->reveal());
64 (new ListOfFieldsContainer($nodeFactoryProphecy->reveal(), $input))->render();
65 }
66
67 /**
68 * @test
69 */
70 public function renderDelegatesShowitemFieldAndRemovesDuplicates()
71 {
72 $nodeFactoryProphecy = $this->prophesize(NodeFactory::class);
73 $paletteAndSingleContainerProphecy = $this->prophesize(PaletteAndSingleContainer::class);
74 $paletteAndSingleContainerProphecy->render(Argument::cetera())->shouldBeCalled()->willReturn('');
75
76 $input = [
77 'recordTypeValue' => 'aType',
78 'processedTca' => [
79 'types' => [
80 'aType' => [
81 'showitem' => 'aField, bField;bLabel, cField',
82 ],
83 ],
84 ],
85 'fieldListToRender' => 'aField, bField, aField',
86 ];
87
88 $expected = $input;
89 $expected['renderType'] = 'paletteAndSingleContainer';
90 // Duplicates are suppressed but label is kept
91 $expected['fieldsArray'] = [
92 'aField;;',
93 'bField;bLabel;',
94 ];
95
96 $nodeFactoryProphecy->create($expected)->willReturn($paletteAndSingleContainerProphecy->reveal());
97 (new ListOfFieldsContainer($nodeFactoryProphecy->reveal(), $input))->render();
98 }
99
100 /**
101 * @test
102 */
103 public function renderDelegatesPaletteFields()
104 {
105 $nodeFactoryProphecy = $this->prophesize(NodeFactory::class);
106 $paletteAndSingleContainerProphecy = $this->prophesize(PaletteAndSingleContainer::class);
107 $paletteAndSingleContainerProphecy->render(Argument::cetera())->shouldBeCalled()->willReturn('');
108
109 $input = [
110 'recordTypeValue' => 'aType',
111 'processedTca' => [
112 'types' => [
113 'aType' => [
114 'showitem' => '--palette--;;aPalette, --palette--;;anotherPalette',
115 ],
116 ],
117 'palettes' => [
118 'aPalette' => [
119 'showitem' => 'aField',
120 ],
121 'anotherPalette' => [
122 'showitem' => 'bField;bLabel, cField',
123 ]
124 ],
125 ],
126 'fieldListToRender' => 'aField, bField',
127 ];
128
129 $expected = $input;
130 $expected['renderType'] = 'paletteAndSingleContainer';
131 // Both palette fields are found
132 $expected['fieldsArray'] = [
133 'aField;;',
134 'bField;bLabel;',
135 ];
136
137 $nodeFactoryProphecy->create($expected)->willReturn($paletteAndSingleContainerProphecy->reveal());
138 (new ListOfFieldsContainer($nodeFactoryProphecy->reveal(), $input))->render();
139 }
140
141 /**
142 * @test
143 */
144 public function renderRemovesNotExistingTypesField()
145 {
146 $nodeFactoryProphecy = $this->prophesize(NodeFactory::class);
147 $paletteAndSingleContainerProphecy = $this->prophesize(PaletteAndSingleContainer::class);
148 $paletteAndSingleContainerProphecy->render(Argument::cetera())->shouldBeCalled()->willReturn('');
149
150 $input = [
151 'recordTypeValue' => 'aType',
152 'processedTca' => [
153 'types' => [
154 'aType' => [
155 'showitem' => '--palette--;;aPalette',
156 ],
157 ],
158 'palettes' => [
159 'aPalette' => [
160 'showitem' => 'aField',
161 ],
162 ],
163 ],
164 'fieldListToRender' => 'aField, iDontExist',
165 ];
166
167 $expected = $input;
168 $expected['renderType'] = 'paletteAndSingleContainer';
169 // Duplicates are suppressed but label is kept
170 $expected['fieldsArray'] = [
171 'aField;;',
172 ];
173
174 $nodeFactoryProphecy->create($expected)->willReturn($paletteAndSingleContainerProphecy->reveal());
175 (new ListOfFieldsContainer($nodeFactoryProphecy->reveal(), $input))->render();
176 }
177 }