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