‪TYPO3CMS  ‪main
TcaColumnsProcessFieldLabelsTest.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 PHPUnit\Framework\Attributes\Test;
26 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
27 
28 final class ‪TcaColumnsProcessFieldLabelsTest extends UnitTestCase
29 {
30  #[Test]
32  {
33  $input = [
34  'tableName' => 'aTable',
35  'processedTca' => [
36  'columns' => [
37  'aField' => [
38  'label' => 'foo',
39  ],
40  ],
41  ],
42  'recordTypeValue' => 'aType',
43  ];
44 
45  ‪$GLOBALS['LANG'] = new ‪LanguageService(
46  new ‪Locales(),
47  $this->createMock(LocalizationFactory::class),
48  $this->createMock(FrontendInterface::class)
49  );
50 
51  $expected = $input;
52  self::assertSame($expected, (new ‪TcaColumnsProcessFieldLabels())->addData($input));
53  }
54 
55  #[Test]
56  public function ‪addDataSetsLabelFromShowitem(): void
57  {
58  $input = [
59  'tableName' => 'aTable',
60  'processedTca' => [
61  'columns' => [
62  'aField' => [
63  'label' => 'origLabel',
64  ],
65  ],
66  'types' => [
67  'aType' => [
68  'showitem' => 'aField;aLabelOverride',
69  ],
70  ],
71  ],
72  'recordTypeValue' => 'aType',
73  ];
74  ‪$GLOBALS['LANG'] = new ‪LanguageService(
75  new ‪Locales(),
76  $this->createMock(LocalizationFactory::class),
77  $this->createMock(FrontendInterface::class)
78  );
79 
80  $expected = $input;
81  $expected['processedTca']['columns']['aField']['label'] = 'aLabelOverride';
82  self::assertSame($expected, (new ‪TcaColumnsProcessFieldLabels())->addData($input));
83  }
84 
85  #[Test]
87  {
88  $input = [
89  'tableName' => 'aTable',
90  'processedTca' => [
91  'columns' => [
92  'aField' => [
93  'label' => 'origLabel',
94  ],
95  ],
96  'types' => [
97  'aType' => [
98  'showitem' => '--palette--;;aPalette',
99  ],
100  ],
101  'palettes' => [
102  'aPalette' => [
103  'showitem' => 'aField;aLabelOverride',
104  ],
105  ],
106  ],
107  'recordTypeValue' => 'aType',
108  ];
109 
110  ‪$GLOBALS['LANG'] = new ‪LanguageService(
111  new ‪Locales(),
112  $this->createMock(LocalizationFactory::class),
113  $this->createMock(FrontendInterface::class)
114  );
115 
116  $expected = $input;
117  $expected['processedTca']['columns']['aField']['label'] = 'aLabelOverride';
118  self::assertSame($expected, (new ‪TcaColumnsProcessFieldLabels())->addData($input));
119  }
120 
121  #[Test]
122  public function ‪addDataSetsLabelFromPageTsConfig(): void
123  {
124  $input = [
125  'tableName' => 'aTable',
126  'processedTca' => [
127  'columns' => [
128  'aField' => [
129  'label' => 'origLabel',
130  ],
131  ],
132  ],
133  'pageTsConfig' => [
134  'TCEFORM.' => [
135  'aTable.' => [
136  'aField.' => [
137  'label' => 'aLabelOverride',
138  ],
139  ],
140  ],
141  ],
142  'recordTypeValue' => 'aType',
143  ];
144  ‪$GLOBALS['LANG'] = new ‪LanguageService(
145  new ‪Locales(),
146  $this->createMock(LocalizationFactory::class),
147  $this->createMock(FrontendInterface::class)
148  );
149 
150  $expected = $input;
151  $expected['processedTca']['columns']['aField']['label'] = 'aLabelOverride';
152  self::assertSame($expected, (new ‪TcaColumnsProcessFieldLabels())->addData($input));
153  }
154 
155  #[Test]
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  'recordTypeValue' => 'aType',
179  ];
180  ‪$GLOBALS['LANG'] = new ‪LanguageService(
181  new ‪Locales(),
182  $this->createMock(LocalizationFactory::class),
183  $this->createMock(FrontendInterface::class)
184  );
185  ‪$GLOBALS['LANG']->init('fr');
186 
187  $expected = $input;
188  $expected['processedTca']['columns']['aField']['label'] = 'aLabelOverride';
189  self::assertSame($expected, (new ‪TcaColumnsProcessFieldLabels())->addData($input));
190  }
191 }
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaColumnsProcessFieldLabelsTest
Definition: TcaColumnsProcessFieldLabelsTest.php:29
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaColumnsProcessFieldLabels
Definition: TcaColumnsProcessFieldLabels.php:28
‪TYPO3\CMS\Core\Localization\LocalizationFactory
Definition: LocalizationFactory.php:31
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaColumnsProcessFieldLabelsTest\addDataSetsLabelFromShowitem
‪addDataSetsLabelFromShowitem()
Definition: TcaColumnsProcessFieldLabelsTest.php:56
‪TYPO3\CMS\Core\Localization\Locales
Definition: Locales.php:36
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaColumnsProcessFieldLabelsTest\addDataSetsLabelFromPageTsConfigForSpecificLanguage
‪addDataSetsLabelFromPageTsConfigForSpecificLanguage()
Definition: TcaColumnsProcessFieldLabelsTest.php:156
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaColumnsProcessFieldLabelsTest\addDataSetsLabelFromPalettesShowitem
‪addDataSetsLabelFromPalettesShowitem()
Definition: TcaColumnsProcessFieldLabelsTest.php:86
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaColumnsProcessFieldLabelsTest\addDataSetsLabelFromPageTsConfig
‪addDataSetsLabelFromPageTsConfig()
Definition: TcaColumnsProcessFieldLabelsTest.php:122
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaColumnsProcessFieldLabelsTest\addDataKeepsLabelAsIsIfNoOverrideIsGiven
‪addDataKeepsLabelAsIsIfNoOverrideIsGiven()
Definition: TcaColumnsProcessFieldLabelsTest.php:31
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:22
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider
Definition: DatabaseDefaultLanguagePageRowTest.php:18