‪TYPO3CMS  10.4
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 Prophecy\Argument;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 class ‪ListOfFieldsContainerTest extends UnitTestCase
30 {
35  {
36  $nodeFactoryProphecy = $this->prophesize(NodeFactory::class);
37  $paletteAndSingleContainerProphecy = $this->prophesize(PaletteAndSingleContainer::class);
38  $paletteAndSingleContainerProphecy->render(Argument::cetera())->shouldBeCalled()->willReturn('');
39 
40  $input = [
41  'tableName' => 'aTable',
42  'recordTypeValue' => 'aType',
43  'processedTca' => [
44  'types' => [
45  'aType' => [
46  'showitem' => 'aField',
47  ],
48  ],
49  ],
50  'fieldListToRender' => 'aField',
51  ];
52 
53  $expected = $input;
54  $expected['renderType'] = 'paletteAndSingleContainer';
55 
56  // Verify 'fieldArray' contains 'aField' since that is a showitem field of this type
57  $expected['fieldsArray'] = [
58  'aField;;',
59  ];
60 
61  $nodeFactoryProphecy->create($expected)->willReturn($paletteAndSingleContainerProphecy->reveal());
62  (new ‪ListOfFieldsContainer($nodeFactoryProphecy->reveal(), $input))->render();
63  }
64 
69  {
70  $nodeFactoryProphecy = $this->prophesize(NodeFactory::class);
71  $paletteAndSingleContainerProphecy = $this->prophesize(PaletteAndSingleContainer::class);
72  $paletteAndSingleContainerProphecy->render(Argument::cetera())->shouldBeCalled()->willReturn('');
73 
74  $input = [
75  'tableName' => 'aTable',
76  'recordTypeValue' => 'aType',
77  'processedTca' => [
78  'types' => [
79  'aType' => [
80  'showitem' => 'aField, bField;bLabel, cField',
81  ],
82  ],
83  ],
84  'fieldListToRender' => 'aField, bField, aField',
85  ];
86 
87  $expected = $input;
88  $expected['renderType'] = 'paletteAndSingleContainer';
89  // Duplicates are suppressed but label is kept
90  $expected['fieldsArray'] = [
91  'aField;;',
92  'bField;bLabel;',
93  ];
94 
95  $nodeFactoryProphecy->create($expected)->willReturn($paletteAndSingleContainerProphecy->reveal());
96  (new ‪ListOfFieldsContainer($nodeFactoryProphecy->reveal(), $input))->render();
97  }
98 
103  {
104  $nodeFactoryProphecy = $this->prophesize(NodeFactory::class);
105  $paletteAndSingleContainerProphecy = $this->prophesize(PaletteAndSingleContainer::class);
106  $paletteAndSingleContainerProphecy->render(Argument::cetera())->shouldBeCalled()->willReturn('');
107 
108  $input = [
109  'tableName' => 'aTable',
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 
145  {
146  $nodeFactoryProphecy = $this->prophesize(NodeFactory::class);
147  $paletteAndSingleContainerProphecy = $this->prophesize(PaletteAndSingleContainer::class);
148  $paletteAndSingleContainerProphecy->render(Argument::cetera())->shouldBeCalled()->willReturn('');
149 
150  $input = [
151  'tableName' => 'aTable',
152  'recordTypeValue' => 'aType',
153  'processedTca' => [
154  'types' => [
155  'aType' => [
156  'showitem' => '--palette--;;aPalette',
157  ],
158  ],
159  'palettes' => [
160  'aPalette' => [
161  'showitem' => 'aField',
162  ],
163  ],
164  ],
165  'fieldListToRender' => 'aField, iDontExist',
166  ];
167 
168  $expected = $input;
169  $expected['renderType'] = 'paletteAndSingleContainer';
170  // Duplicates are suppressed but label is kept
171  $expected['fieldsArray'] = [
172  'aField;;',
173  ];
174 
175  $nodeFactoryProphecy->create($expected)->willReturn($paletteAndSingleContainerProphecy->reveal());
176  (new ‪ListOfFieldsContainer($nodeFactoryProphecy->reveal(), $input))->render();
177  }
178 }
‪TYPO3\CMS\Backend\Tests\Unit\Form\Container
Definition: ListOfFieldsContainerTest.php:18
‪TYPO3\CMS\Backend\Tests\Unit\Form\Container\ListOfFieldsContainerTest\renderRemovesNotExistingTypesField
‪renderRemovesNotExistingTypesField()
Definition: ListOfFieldsContainerTest.php:144
‪TYPO3\CMS\Backend\Form\Container\ListOfFieldsContainer
Definition: ListOfFieldsContainer.php:29
‪TYPO3\CMS\Backend\Tests\Unit\Form\Container\ListOfFieldsContainerTest\renderDelegatesShowitemField
‪renderDelegatesShowitemField()
Definition: ListOfFieldsContainerTest.php:34
‪TYPO3\CMS\Backend\Tests\Unit\Form\Container\ListOfFieldsContainerTest\renderDelegatesPaletteFields
‪renderDelegatesPaletteFields()
Definition: ListOfFieldsContainerTest.php:102
‪TYPO3\CMS\Backend\Form\NodeFactory
Definition: NodeFactory.php:37
‪TYPO3\CMS\Backend\Tests\Unit\Form\Container\ListOfFieldsContainerTest\renderDelegatesShowitemFieldAndRemovesDuplicates
‪renderDelegatesShowitemFieldAndRemovesDuplicates()
Definition: ListOfFieldsContainerTest.php:68
‪TYPO3\CMS\Backend\Tests\Unit\Form\Container\ListOfFieldsContainerTest
Definition: ListOfFieldsContainerTest.php:30
‪TYPO3\CMS\Backend\Form\Container\PaletteAndSingleContainer
Definition: PaletteAndSingleContainer.php:33