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