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