‪TYPO3CMS  10.4
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;
26 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
27 
31 class ‪PaletteAndSingleContainerTest extends UnitTestCase
32 {
37  {
38  $nodeFactoryProphecy = $this->prophesize(NodeFactory::class);
39  $singleFieldContainerProphecy = $this->prophesize(SingleFieldContainer::class);
40  $singleFieldContainerReturn = [
41  'additionalJavaScriptPost' => [],
42  'additionalHiddenFields' => [],
43  'additionalInlineLanguageLabelFiles' => [],
44  'stylesheetFiles' => [],
45  'requireJsModules' => [],
46  'inlineData' => [],
47  'html' => 'aFieldRenderedHtml',
48  ];
49  $singleFieldContainerProphecy->render(Argument::cetera())->shouldBeCalled()->willReturn($singleFieldContainerReturn);
50 
51  $labelReference = 'LLL:EXT:Resources/Private/Language/locallang.xlf:aLabel';
52  $input = [
53  'tableName' => 'aTable',
54  'recordTypeValue' => 'aType',
55  'processedTca' => [
56  'columns' => [
57  'aField' => []
58  ],
59  'palettes' => [
60  'aPalette' => [
61  'showitem' => 'aField',
62  ],
63  ],
64  ],
65  'fieldsArray' => [
66  '--palette--;' . $labelReference . ';aPalette',
67  ]
68  ];
69 
70  $languageService = $this->prophesize(LanguageService::class);
71  ‪$GLOBALS['LANG'] = $languageService->reveal();
72  $backendUserAuthentication = $this->prophesize(BackendUserAuthentication::class);
73  ‪$GLOBALS['BE_USER'] = $backendUserAuthentication->reveal();
74  $languageService->loadSingleTableDescription(Argument::cetera())->willReturn('');
75 
76  // Expect translation call to the label reference
77  $languageService->sL($labelReference)->willReturnArgument(0);
78 
79  $expectedChildDataArray = $input;
80  $expectedChildDataArray['renderType'] = 'singleFieldContainer';
81  $expectedChildDataArray['fieldName'] = 'aField';
82 
83  $nodeFactoryProphecy->create($expectedChildDataArray)->willReturn($singleFieldContainerProphecy->reveal());
84  $containerResult = (new ‪PaletteAndSingleContainer($nodeFactoryProphecy->reveal(), $input))->render();
85  // Expect label is in answer HTML
86  self::assertStringContainsString($labelReference, $containerResult['html']);
87  }
88 
93  {
94  $nodeFactoryProphecy = $this->prophesize(NodeFactory::class);
95  $singleFieldContainerProphecy = $this->prophesize(SingleFieldContainer::class);
96  $singleFieldContainerReturn = [
97  'additionalJavaScriptPost' => [],
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  self::assertStringContainsString($labelReference, $containerResult['html']);
144  }
145 
150  {
151  $nodeFactoryProphecy = $this->prophesize(NodeFactory::class);
152  $singleFieldContainerProphecy = $this->prophesize(SingleFieldContainer::class);
153  $singleFieldContainerReturn = [
154  'additionalJavaScriptPost' => [],
155  'additionalHiddenFields' => [],
156  'additionalInlineLanguageLabelFiles' => [],
157  'stylesheetFiles' => [],
158  'requireJsModules' => [],
159  'inlineData' => [],
160  'html' => 'aFieldRenderedHtml',
161  ];
162  $singleFieldContainerProphecy->render(Argument::cetera())->shouldBeCalled()->willReturn($singleFieldContainerReturn);
163 
164  $labelReferenceFieldArray = 'LLL:EXT:Resources/Private/Language/locallang.xlf:aLabel';
165  $labelReferencePaletteArray = 'LLL:EXT:Resources/Private/Language/locallang.xlf:aLabel';
166  $input = [
167  'tableName' => 'aTable',
168  'recordTypeValue' => 'aType',
169  'processedTca' => [
170  'columns' => [
171  'aField' => []
172  ],
173  'palettes' => [
174  'aPalette' => [
175  'label' => $labelReferencePaletteArray,
176  'showitem' => 'aField',
177  ],
178  ],
179  ],
180  'fieldsArray' => [
181  '--palette--;' . $labelReferenceFieldArray . ';aPalette',
182  ]
183  ];
184 
185  $languageService = $this->prophesize(LanguageService::class);
186  ‪$GLOBALS['LANG'] = $languageService->reveal();
187  $backendUserAuthentication = $this->prophesize(BackendUserAuthentication::class);
188  ‪$GLOBALS['BE_USER'] = $backendUserAuthentication->reveal();
189  $languageService->loadSingleTableDescription(Argument::cetera())->willReturn('');
190 
191  // Expect translation call to the label reference
192  $languageService->sL($labelReferenceFieldArray)->willReturnArgument(0);
193 
194  $expectedChildDataArray = $input;
195  $expectedChildDataArray['renderType'] = 'singleFieldContainer';
196  $expectedChildDataArray['fieldName'] = 'aField';
197 
198  $nodeFactoryProphecy->create($expectedChildDataArray)->willReturn($singleFieldContainerProphecy->reveal());
199  $containerResult = (new ‪PaletteAndSingleContainer($nodeFactoryProphecy->reveal(), $input))->render();
200  // Expect label is in answer HTML
201  self::assertStringContainsString($labelReferenceFieldArray, $containerResult['html']);
202  }
203 }
‪TYPO3\CMS\Backend\Tests\Unit\Form\Container\PaletteAndSingleContainerTest\renderUsesPaletteLabelFromFieldArray
‪renderUsesPaletteLabelFromFieldArray()
Definition: PaletteAndSingleContainerTest.php:36
‪TYPO3\CMS\Backend\Tests\Unit\Form\Container
Definition: ListOfFieldsContainerTest.php:18
‪TYPO3\CMS\Backend\Tests\Unit\Form\Container\PaletteAndSingleContainerTest
Definition: PaletteAndSingleContainerTest.php:32
‪TYPO3\CMS\Backend\Tests\Unit\Form\Container\PaletteAndSingleContainerTest\renderPrefersFieldArrayPaletteLabelOverPaletteLabel
‪renderPrefersFieldArrayPaletteLabelOverPaletteLabel()
Definition: PaletteAndSingleContainerTest.php:149
‪TYPO3\CMS\Backend\Form\Container\SingleFieldContainer
Definition: SingleFieldContainer.php:35
‪TYPO3\CMS\Backend\Tests\Unit\Form\Container\PaletteAndSingleContainerTest\renderUsesPaletteLabelFromPaletteArray
‪renderUsesPaletteLabelFromPaletteArray()
Definition: PaletteAndSingleContainerTest.php:92
‪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:5
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Backend\Form\Container\PaletteAndSingleContainer
Definition: PaletteAndSingleContainer.php:33