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