‪TYPO3CMS  11.5
PaletteAndSingleContainerTest.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;
27 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
28 
32 class ‪PaletteAndSingleContainerTest extends UnitTestCase
33 {
34  use ProphecyTrait;
35 
39  public function ‪renderUsesPaletteLabelFromFieldArray(): void
40  {
41  $nodeFactoryProphecy = $this->prophesize(NodeFactory::class);
42  $singleFieldContainerProphecy = $this->prophesize(SingleFieldContainer::class);
43  $singleFieldContainerReturn = [
44  'additionalJavaScriptPost' => [],
45  'additionalHiddenFields' => [],
46  'additionalInlineLanguageLabelFiles' => [],
47  'stylesheetFiles' => [],
48  'requireJsModules' => [],
49  'inlineData' => [],
50  'html' => 'aFieldRenderedHtml',
51  ];
52  $singleFieldContainerProphecy->render(Argument::cetera())->shouldBeCalled()->willReturn($singleFieldContainerReturn);
53 
54  $labelReference = 'LLL:EXT:Resources/Private/Language/locallang.xlf:aLabel';
55  $input = [
56  'tableName' => 'aTable',
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  $backendUserAuthentication->shallDisplayDebugInformation()->willReturn(true);
77  ‪$GLOBALS['BE_USER'] = $backendUserAuthentication->reveal();
78  $languageService->loadSingleTableDescription(Argument::cetera())->willReturn('');
79 
80  // Expect translation call to the label reference and empty description
81  $languageService->sL($labelReference)->willReturnArgument(0);
82  $languageService->sL('')->willReturnArgument(0);
83 
84  $expectedChildDataArray = $input;
85  $expectedChildDataArray['renderType'] = 'singleFieldContainer';
86  $expectedChildDataArray['fieldName'] = 'aField';
87 
88  $nodeFactoryProphecy->create($expectedChildDataArray)->willReturn($singleFieldContainerProphecy->reveal());
89  $containerResult = (new ‪PaletteAndSingleContainer($nodeFactoryProphecy->reveal(), $input))->render();
90  // Expect label is in answer HTML
91  self::assertStringContainsString($labelReference, $containerResult['html']);
92  }
93 
97  public function ‪renderUsesPaletteValuesFromPaletteArray(): void
98  {
99  $nodeFactoryProphecy = $this->prophesize(NodeFactory::class);
100  $singleFieldContainerProphecy = $this->prophesize(SingleFieldContainer::class);
101  $singleFieldContainerReturn = [
102  'additionalJavaScriptPost' => [],
103  'additionalHiddenFields' => [],
104  'additionalInlineLanguageLabelFiles' => [],
105  'stylesheetFiles' => [],
106  'requireJsModules' => [],
107  'inlineData' => [],
108  'html' => 'aFieldRenderedHtml',
109  ];
110  $singleFieldContainerProphecy->render(Argument::cetera())->shouldBeCalled()->willReturn($singleFieldContainerReturn);
111 
112  $labelReference = 'LLL:EXT:Resources/Private/Language/locallang.xlf:aLabel';
113  $descriptionReference = 'LLL:EXT:Resources/Private/Language/locallang.xlf:aDescription';
114  $input = [
115  'tableName' => 'aTable',
116  'recordTypeValue' => 'aType',
117  'processedTca' => [
118  'columns' => [
119  'aField' => [],
120  ],
121  'palettes' => [
122  'aPalette' => [
123  'label' => $labelReference,
124  'description' => $descriptionReference,
125  'showitem' => 'aField',
126  ],
127  ],
128  ],
129  'fieldsArray' => [
130  '--palette--;;aPalette',
131  ],
132  ];
133 
134  $languageService = $this->prophesize(LanguageService::class);
135  ‪$GLOBALS['LANG'] = $languageService->reveal();
136  $backendUserAuthentication = $this->prophesize(BackendUserAuthentication::class);
137  $backendUserAuthentication->shallDisplayDebugInformation()->willReturn(true);
138  ‪$GLOBALS['BE_USER'] = $backendUserAuthentication->reveal();
139  $languageService->loadSingleTableDescription(Argument::cetera())->willReturn('');
140 
141  // Expect translation call to the label and description references
142  $languageService->sL($labelReference)->willReturnArgument(0);
143  $languageService->sL($descriptionReference)->willReturnArgument(0);
144 
145  $expectedChildDataArray = $input;
146  $expectedChildDataArray['renderType'] = 'singleFieldContainer';
147  $expectedChildDataArray['fieldName'] = 'aField';
148 
149  $nodeFactoryProphecy->create($expectedChildDataArray)->willReturn($singleFieldContainerProphecy->reveal());
150  $containerResult = (new ‪PaletteAndSingleContainer($nodeFactoryProphecy->reveal(), $input))->render();
151  // Expect label and description are in answer HTML
152  self::assertStringContainsString($labelReference, $containerResult['html']);
153  self::assertStringContainsString($descriptionReference, $containerResult['html']);
154  }
155 
160  {
161  $nodeFactoryProphecy = $this->prophesize(NodeFactory::class);
162  $singleFieldContainerProphecy = $this->prophesize(SingleFieldContainer::class);
163  $singleFieldContainerReturn = [
164  'additionalJavaScriptPost' => [],
165  'additionalHiddenFields' => [],
166  'additionalInlineLanguageLabelFiles' => [],
167  'stylesheetFiles' => [],
168  'requireJsModules' => [],
169  'inlineData' => [],
170  'html' => 'aFieldRenderedHtml',
171  ];
172  $singleFieldContainerProphecy->render(Argument::cetera())->shouldBeCalled()->willReturn($singleFieldContainerReturn);
173 
174  $labelReferenceFieldArray = 'LLL:EXT:Resources/Private/Language/locallang.xlf:aLabel';
175  $labelReferencePaletteArray = 'LLL:EXT:Resources/Private/Language/locallang.xlf:aLabelPalette';
176  $descriptionReferencePaletteArray = 'LLL:EXT:Resources/Private/Language/locallang.xlf:aDescriptionPalette';
177  $input = [
178  'tableName' => 'aTable',
179  'recordTypeValue' => 'aType',
180  'processedTca' => [
181  'columns' => [
182  'aField' => [],
183  ],
184  'palettes' => [
185  'aPalette' => [
186  'label' => $labelReferencePaletteArray,
187  'description' => $descriptionReferencePaletteArray,
188  'showitem' => 'aField',
189  ],
190  ],
191  ],
192  'fieldsArray' => [
193  '--palette--;' . $labelReferenceFieldArray . ';aPalette',
194  ],
195  ];
196 
197  $languageService = $this->prophesize(LanguageService::class);
198  ‪$GLOBALS['LANG'] = $languageService->reveal();
199  $backendUserAuthentication = $this->prophesize(BackendUserAuthentication::class);
200  $backendUserAuthentication->shallDisplayDebugInformation()->willReturn(true);
201  ‪$GLOBALS['BE_USER'] = $backendUserAuthentication->reveal();
202  $languageService->loadSingleTableDescription(Argument::cetera())->willReturn('');
203 
204  // Expect translation call to the label and description references
205  $languageService->sL($labelReferenceFieldArray)->willReturnArgument(0);
206  $languageService->sL($descriptionReferencePaletteArray)->willReturnArgument(0);
207 
208  $expectedChildDataArray = $input;
209  $expectedChildDataArray['renderType'] = 'singleFieldContainer';
210  $expectedChildDataArray['fieldName'] = 'aField';
211 
212  $nodeFactoryProphecy->create($expectedChildDataArray)->willReturn($singleFieldContainerProphecy->reveal());
213  $containerResult = (new ‪PaletteAndSingleContainer($nodeFactoryProphecy->reveal(), $input))->render();
214  // Expect label and description are in answer HTML
215  self::assertStringContainsString($labelReferenceFieldArray, $containerResult['html']);
216  self::assertStringContainsString($descriptionReferencePaletteArray, $containerResult['html']);
217  }
218 }
‪TYPO3\CMS\Backend\Tests\Unit\Form\Container\PaletteAndSingleContainerTest\renderUsesPaletteLabelFromFieldArray
‪renderUsesPaletteLabelFromFieldArray()
Definition: PaletteAndSingleContainerTest.php:38
‪TYPO3\CMS\Backend\Tests\Unit\Form\Container
Definition: ListOfFieldsContainerTest.php:18
‪TYPO3\CMS\Backend\Tests\Unit\Form\Container\PaletteAndSingleContainerTest
Definition: PaletteAndSingleContainerTest.php:33
‪TYPO3\CMS\Backend\Tests\Unit\Form\Container\PaletteAndSingleContainerTest\renderUsesPaletteValuesFromPaletteArray
‪renderUsesPaletteValuesFromPaletteArray()
Definition: PaletteAndSingleContainerTest.php:96
‪TYPO3\CMS\Backend\Form\Container\SingleFieldContainer
Definition: SingleFieldContainer.php:36
‪TYPO3\CMS\Backend\Tests\Unit\Form\Container\PaletteAndSingleContainerTest\renderPrefersFieldArrayPaletteValuesOverPaletteValues
‪renderPrefersFieldArrayPaletteValuesOverPaletteValues()
Definition: PaletteAndSingleContainerTest.php:158
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Form\NodeFactory
Definition: NodeFactory.php:37
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Backend\Form\Container\PaletteAndSingleContainer
Definition: PaletteAndSingleContainer.php:33