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