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