4987aa2d233e35f5a880e316638047ea5ea7c66f
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Form / Container / PaletteAndSingleContainerTest.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\PaletteAndSingleContainer;
20 use TYPO3\CMS\Backend\Form\Container\SingleFieldContainer;
21 use TYPO3\CMS\Backend\Form\NodeFactory;
22 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
23 use TYPO3\CMS\Core\Localization\LanguageService;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25
26 /**
27 * Test case
28 */
29 class PaletteAndSingleContainerTest extends UnitTestCase
30 {
31 /**
32 * Subject is not notice free, disable E_NOTICES
33 */
34 protected static $suppressNotices = true;
35
36 /**
37 * @test
38 */
39 public function renderUsesPaletteLabelFromFieldArray()
40 {
41 $nodeFactoryProphecy = $this->prophesize(NodeFactory::class);
42 $singleFieldContainerProphecy = $this->prophesize(SingleFieldContainer::class);
43 $singleFieldContainerReturn = [
44 'additionalJavaScriptPost' => [],
45 'additionalJavaScriptSubmit' => [],
46 'additionalHiddenFields' => [],
47 'additionalInlineLanguageLabelFiles' => [],
48 'stylesheetFiles' => [],
49 'requireJsModules' => [],
50 'inlineData' => [],
51 'html' => 'aFieldRenderedHtml',
52 ];
53 $singleFieldContainerProphecy->render(Argument::cetera())->shouldBeCalled()->willReturn($singleFieldContainerReturn);
54
55 $labelReference = 'LLL:EXT:Resources/Private/Language/locallang.xlf:aLabel';
56 $input = [
57 'recordTypeValue' => 'aType',
58 'processedTca' => [
59 'columns' => [
60 'aField' => []
61 ],
62 'palettes' => [
63 'aPalette' => [
64 'showitem' => 'aField',
65 ],
66 ],
67 ],
68 'fieldsArray' => [
69 '--palette--;' . $labelReference . ';aPalette',
70 ]
71 ];
72
73 $languageService = $this->prophesize(LanguageService::class);
74 $GLOBALS['LANG'] = $languageService->reveal();
75 $backendUserAuthentication = $this->prophesize(BackendUserAuthentication::class);
76 $GLOBALS['BE_USER'] = $backendUserAuthentication->reveal();
77 $languageService->loadSingleTableDescription(Argument::cetera())->willReturn('');
78
79 // Expect translation call to the label reference
80 $languageService->sL($labelReference)->willReturnArgument(0);
81
82 $expectedChildDataArray = $input;
83 $expectedChildDataArray['renderType'] = 'singleFieldContainer';
84 $expectedChildDataArray['fieldName'] = 'aField';
85
86 $nodeFactoryProphecy->create($expectedChildDataArray)->willReturn($singleFieldContainerProphecy->reveal());
87 $containerResult = (new PaletteAndSingleContainer($nodeFactoryProphecy->reveal(), $input))->render();
88 // Expect label is in answer HTML
89 $this->stringContains($labelReference, $containerResult['html']);
90 }
91
92 /**
93 * @test
94 */
95 public function renderUsesPaletteLabelFromPaletteArray()
96 {
97 $nodeFactoryProphecy = $this->prophesize(NodeFactory::class);
98 $singleFieldContainerProphecy = $this->prophesize(SingleFieldContainer::class);
99 $singleFieldContainerReturn = [
100 'additionalJavaScriptPost' => [],
101 'additionalJavaScriptSubmit' => [],
102 'additionalHiddenFields' => [],
103 'additionalInlineLanguageLabelFiles' => [],
104 'stylesheetFiles' => [],
105 'requireJsModules' => [],
106 'inlineData' => [],
107 'html' => 'aFieldRenderedHtml',
108 ];
109 $singleFieldContainerProphecy->render(Argument::cetera())->shouldBeCalled()->willReturn($singleFieldContainerReturn);
110
111 $labelReference = 'LLL:EXT:Resources/Private/Language/locallang.xlf:aLabel';
112 $input = [
113 'recordTypeValue' => 'aType',
114 'processedTca' => [
115 'columns' => [
116 'aField' => []
117 ],
118 'palettes' => [
119 'aPalette' => [
120 'label' => $labelReference,
121 'showitem' => 'aField',
122 ],
123 ],
124 ],
125 'fieldsArray' => [
126 '--palette--;;aPalette',
127 ]
128 ];
129
130 $languageService = $this->prophesize(LanguageService::class);
131 $GLOBALS['LANG'] = $languageService->reveal();
132 $backendUserAuthentication = $this->prophesize(BackendUserAuthentication::class);
133 $GLOBALS['BE_USER'] = $backendUserAuthentication->reveal();
134 $languageService->loadSingleTableDescription(Argument::cetera())->willReturn('');
135
136 // Expect translation call to the label reference
137 $languageService->sL($labelReference)->willReturnArgument(0);
138
139 $expectedChildDataArray = $input;
140 $expectedChildDataArray['renderType'] = 'singleFieldContainer';
141 $expectedChildDataArray['fieldName'] = 'aField';
142
143 $nodeFactoryProphecy->create($expectedChildDataArray)->willReturn($singleFieldContainerProphecy->reveal());
144 $containerResult = (new PaletteAndSingleContainer($nodeFactoryProphecy->reveal(), $input))->render();
145 // Expect label is in answer HTML
146 $this->stringContains($labelReference, $containerResult['html']);
147 }
148
149 /**
150 * @test
151 */
152 public function renderPrefersFieldArrayPaletteLabelOverPaletteLabel()
153 {
154 $nodeFactoryProphecy = $this->prophesize(NodeFactory::class);
155 $singleFieldContainerProphecy = $this->prophesize(SingleFieldContainer::class);
156 $singleFieldContainerReturn = [
157 'additionalJavaScriptPost' => [],
158 'additionalJavaScriptSubmit' => [],
159 'additionalHiddenFields' => [],
160 'additionalInlineLanguageLabelFiles' => [],
161 'stylesheetFiles' => [],
162 'requireJsModules' => [],
163 'inlineData' => [],
164 'html' => 'aFieldRenderedHtml',
165 ];
166 $singleFieldContainerProphecy->render(Argument::cetera())->shouldBeCalled()->willReturn($singleFieldContainerReturn);
167
168 $labelReferenceFieldArray = 'LLL:EXT:Resources/Private/Language/locallang.xlf:aLabel';
169 $labelReferencePaletteArray = 'LLL:EXT:Resources/Private/Language/locallang.xlf:aLabel';
170 $input = [
171 'recordTypeValue' => 'aType',
172 'processedTca' => [
173 'columns' => [
174 'aField' => []
175 ],
176 'palettes' => [
177 'aPalette' => [
178 'label' => $labelReferencePaletteArray,
179 'showitem' => 'aField',
180 ],
181 ],
182 ],
183 'fieldsArray' => [
184 '--palette--;' . $labelReferenceFieldArray . ';aPalette',
185 ]
186 ];
187
188 $languageService = $this->prophesize(LanguageService::class);
189 $GLOBALS['LANG'] = $languageService->reveal();
190 $backendUserAuthentication = $this->prophesize(BackendUserAuthentication::class);
191 $GLOBALS['BE_USER'] = $backendUserAuthentication->reveal();
192 $languageService->loadSingleTableDescription(Argument::cetera())->willReturn('');
193
194 // Expect translation call to the label reference
195 $languageService->sL($labelReferenceFieldArray)->willReturnArgument(0);
196
197 $expectedChildDataArray = $input;
198 $expectedChildDataArray['renderType'] = 'singleFieldContainer';
199 $expectedChildDataArray['fieldName'] = 'aField';
200
201 $nodeFactoryProphecy->create($expectedChildDataArray)->willReturn($singleFieldContainerProphecy->reveal());
202 $containerResult = (new PaletteAndSingleContainer($nodeFactoryProphecy->reveal(), $input))->render();
203 // Expect label is in answer HTML
204 $this->stringContains($labelReferenceFieldArray, $containerResult['html']);
205 }
206 }