[BUGFIX] Notice free FormEngine testing
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Form / FormDataProvider / TcaColumnsProcessFieldLabelsTest.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Form\FormDataProvider\TcaColumnsProcessFieldLabels;
18 use TYPO3\CMS\Core\Localization\LanguageService;
19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
20
21 /**
22 * Test case
23 */
24 class TcaColumnsProcessFieldLabelsTest extends UnitTestCase
25 {
26 /**
27 * @test
28 */
29 public function addDataKeepsLabelAsIsIfNoOverrideIsGiven()
30 {
31 $input = [
32 'tableName' => 'aTable',
33 'processedTca' => [
34 'columns' => [
35 'aField' => [
36 'label' => 'foo',
37 ],
38 ],
39 ],
40 'recordTypeValue' => 'aType',
41 ];
42 $languageServiceProphecy = $this->prophesize(LanguageService::class);
43 $languageServiceProphecy->sL('foo')->shouldBeCalled()->willReturnArgument(0);
44 $GLOBALS['LANG'] = $languageServiceProphecy->reveal();
45
46 $expected = $input;
47 $this->assertSame($expected, (new TcaColumnsProcessFieldLabels)->addData($input));
48 }
49
50 /**
51 * @test
52 */
53 public function addDataSetsLabelFromShowitem()
54 {
55 $input = [
56 'tableName' => 'aTable',
57 'processedTca' => [
58 'columns' => [
59 'aField' => [
60 'label' => 'origLabel',
61 ],
62 ],
63 'types' => [
64 'aType' => [
65 'showitem' => 'aField;aLabelOverride',
66 ],
67 ],
68 ],
69 'recordTypeValue' => 'aType',
70 ];
71 $languageServiceProphecy = $this->prophesize(LanguageService::class);
72 $languageServiceProphecy->sL('aLabelOverride')->shouldBeCalled()->willReturnArgument(0);
73 $GLOBALS['LANG'] = $languageServiceProphecy->reveal();
74
75 $expected = $input;
76 $expected['processedTca']['columns']['aField']['label'] = 'aLabelOverride';
77 $this->assertSame($expected, (new TcaColumnsProcessFieldLabels)->addData($input));
78 }
79
80 /**
81 * @test
82 */
83 public function addDataSetsLabelFromPalettesShowitem()
84 {
85 $input = [
86 'tableName' => 'aTable',
87 'processedTca' => [
88 'columns' => [
89 'aField' => [
90 'label' => 'origLabel',
91 ],
92 ],
93 'types' => [
94 'aType' => [
95 'showitem' => '--palette--;;aPalette',
96 ],
97 ],
98 'palettes' => [
99 'aPalette' => [
100 'showitem' => 'aField;aLabelOverride',
101 ],
102 ],
103 ],
104 'recordTypeValue' => 'aType',
105 ];
106 $languageServiceProphecy = $this->prophesize(LanguageService::class);
107 $languageServiceProphecy->sL('aLabelOverride')->shouldBeCalled()->willReturnArgument(0);
108 $GLOBALS['LANG'] = $languageServiceProphecy->reveal();
109
110 $expected = $input;
111 $expected['processedTca']['columns']['aField']['label'] = 'aLabelOverride';
112 $this->assertSame($expected, (new TcaColumnsProcessFieldLabels)->addData($input));
113 }
114
115 /**
116 * @test
117 */
118 public function addDataSetsLabelFromPageTsConfig()
119 {
120 $input = [
121 'tableName' => 'aTable',
122 'processedTca' => [
123 'columns' => [
124 'aField' => [
125 'label' => 'origLabel',
126 ],
127 ],
128 ],
129 'pageTsConfig' => [
130 'TCEFORM.' => [
131 'aTable.' => [
132 'aField.' => [
133 'label' => 'aLabelOverride',
134 ],
135 ],
136 ],
137 ],
138 'recordTypeValue' => 'aType',
139 ];
140 $languageServiceProphecy = $this->prophesize(LanguageService::class);
141 $languageServiceProphecy->sL('aLabelOverride')->shouldBeCalled()->willReturnArgument(0);
142 $GLOBALS['LANG'] = $languageServiceProphecy->reveal();
143
144 $expected = $input;
145 $expected['processedTca']['columns']['aField']['label'] = 'aLabelOverride';
146 $this->assertSame($expected, (new TcaColumnsProcessFieldLabels)->addData($input));
147 }
148
149 /**
150 * @test
151 */
152 public function addDataSetsLabelFromPageTsConfigForSpecificLanguage()
153 {
154 $input = [
155 'tableName' => 'aTable',
156 'processedTca' => [
157 'columns' => [
158 'aField' => [
159 'label' => 'origLabel',
160 ],
161 ],
162 ],
163 'pageTsConfig' => [
164 'TCEFORM.' => [
165 'aTable.' => [
166 'aField.' => [
167 'label.' => [
168 'fr' => 'aLabelOverride',
169 ],
170 ],
171 ],
172 ],
173 ],
174 'recordTypeValue' => 'aType',
175 ];
176 $languageServiceProphecy = $this->prophesize(LanguageService::class);
177 $languageServiceProphecy->lang = 'fr';
178 $languageServiceProphecy->sL('aLabelOverride')->shouldBeCalled()->willReturnArgument(0);
179 $GLOBALS['LANG'] = $languageServiceProphecy->reveal();
180
181 $expected = $input;
182 $expected['processedTca']['columns']['aField']['label'] = 'aLabelOverride';
183 $this->assertSame($expected, (new TcaColumnsProcessFieldLabels)->addData($input));
184 }
185 }