[BUGFIX] Override flex form field label with page TSConfig
[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\Tests\UnitTestCase;
19 use TYPO3\CMS\Lang\LanguageService;
20
21 /**
22 * Test case
23 */
24 class TcaColumnsProcessFieldLabelsTest extends UnitTestCase
25 {
26 /**
27 * @var TcaColumnsProcessFieldLabels
28 */
29 protected $subject;
30
31 protected function setUp()
32 {
33 $this->subject = new TcaColumnsProcessFieldLabels();
34 }
35
36 /**
37 * @test
38 */
39 public function addDataKeepsLabelAsIsIfNoOverrideIsGiven()
40 {
41 $input = [
42 'processedTca' => [
43 'columns' => [
44 'aField' => [
45 'label' => 'foo',
46 ],
47 ],
48 ],
49 ];
50 $languageServiceProphecy = $this->prophesize(LanguageService::class);
51 $languageServiceProphecy->sL('foo')->shouldBeCalled()->willReturnArgument(0);
52 $GLOBALS['LANG'] = $languageServiceProphecy->reveal();
53
54 $expected = $input;
55 $this->assertSame($expected, $this->subject->addData($input));
56 }
57
58 /**
59 * @test
60 */
61 public function addDataSetsLabelFromShowitem()
62 {
63 $input = [
64 'processedTca' => [
65 'columns' => [
66 'aField' => [
67 'label' => 'origLabel',
68 ],
69 ],
70 'types' => [
71 'aType' => [
72 'showitem' => 'aField;aLabelOverride',
73 ],
74 ],
75 ],
76 'recordTypeValue' => 'aType',
77 ];
78 $languageServiceProphecy = $this->prophesize(LanguageService::class);
79 $languageServiceProphecy->sL('aLabelOverride')->shouldBeCalled()->willReturnArgument(0);
80 $GLOBALS['LANG'] = $languageServiceProphecy->reveal();
81
82 $expected = $input;
83 $expected['processedTca']['columns']['aField']['label'] = 'aLabelOverride';
84 $this->assertSame($expected, $this->subject->addData($input));
85 }
86
87 /**
88 * @test
89 */
90 public function addDataSetsLabelFromPalettesShowitem()
91 {
92 $input = [
93 'processedTca' => [
94 'columns' => [
95 'aField' => [
96 'label' => 'origLabel',
97 ],
98 ],
99 'types' => [
100 'aType' => [
101 'showitem' => '--palette--;;aPalette',
102 ],
103 ],
104 'palettes' => [
105 'aPalette' => [
106 'showitem' => 'aField;aLabelOverride',
107 ],
108 ],
109 ],
110 'recordTypeValue' => 'aType',
111 ];
112 $languageServiceProphecy = $this->prophesize(LanguageService::class);
113 $languageServiceProphecy->sL('aLabelOverride')->shouldBeCalled()->willReturnArgument(0);
114 $GLOBALS['LANG'] = $languageServiceProphecy->reveal();
115
116 $expected = $input;
117 $expected['processedTca']['columns']['aField']['label'] = 'aLabelOverride';
118 $this->assertSame($expected, $this->subject->addData($input));
119 }
120
121 /**
122 * @test
123 */
124 public function addDataSetsLabelFromPageTsConfig()
125 {
126 $input = [
127 'tableName' => 'aTable',
128 'processedTca' => [
129 'columns' => [
130 'aField' => [
131 'label' => 'origLabel',
132 ],
133 ],
134 ],
135 'pageTsConfig' => [
136 'TCEFORM.' => [
137 'aTable.' => [
138 'aField.' => [
139 'label' => 'aLabelOverride',
140 ],
141 ],
142 ],
143 ],
144 ];
145 $languageServiceProphecy = $this->prophesize(LanguageService::class);
146 $languageServiceProphecy->sL('aLabelOverride')->shouldBeCalled()->willReturnArgument(0);
147 $GLOBALS['LANG'] = $languageServiceProphecy->reveal();
148
149 $expected = $input;
150 $expected['processedTca']['columns']['aField']['label'] = 'aLabelOverride';
151 $this->assertSame($expected, $this->subject->addData($input));
152 }
153
154 /**
155 * @test
156 */
157 public function addDataSetsLabelFromPageTsConfigForSpecificLanguage()
158 {
159 $input = [
160 'tableName' => 'aTable',
161 'processedTca' => [
162 'columns' => [
163 'aField' => [
164 'label' => 'origLabel',
165 ],
166 ],
167 ],
168 'pageTsConfig' => [
169 'TCEFORM.' => [
170 'aTable.' => [
171 'aField.' => [
172 'label.' => [
173 'fr' => 'aLabelOverride',
174 ],
175 ],
176 ],
177 ],
178 ],
179 ];
180 $languageServiceProphecy = $this->prophesize(LanguageService::class);
181 $languageServiceProphecy->lang = 'fr';
182 $languageServiceProphecy->sL('aLabelOverride')->shouldBeCalled()->willReturnArgument(0);
183 $GLOBALS['LANG'] = $languageServiceProphecy->reveal();
184
185 $expected = $input;
186 $expected['processedTca']['columns']['aField']['label'] = 'aLabelOverride';
187 $this->assertSame($expected, $this->subject->addData($input));
188 }
189 }