‪TYPO3CMS  11.5
TcaInputPlaceholdersTest.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 Prophecy\PhpUnit\ProphecyTrait;
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26 
30 class ‪TcaInputPlaceholdersTest extends UnitTestCase
31 {
32  use ProphecyTrait;
33 
37  public function ‪addDataRemovesEmptyPlaceholderOption(): void
38  {
39  $input = [
40  'tableName' => 'aTable',
41  'databaseRow' => [],
42  'processedTca' => [
43  'columns' => [
44  'aField' => [
45  'config' => [
46  'type' => 'input',
47  'placeholder' => '',
48  ],
49  ],
50  ],
51  ],
52  ];
53 
54  $expected = $input;
55  unset($expected['processedTca']['columns']['aField']['config']['placeholder']);
56 
57  self::assertSame($expected, (new ‪TcaInputPlaceholders())->addData($input));
58  }
59 
64  {
65  $input = [
66  'tableName' => 'aTable',
67  'databaseRow' => [],
68  'processedTca' => [
69  'columns' => [
70  'aField' => [
71  'config' => [
72  'type' => 'input',
73  'placeholder' => 'aPlaceholder',
74  ],
75  ],
76  ],
77  ],
78  ];
79 
80  $expected = $input;
81 
82  self::assertSame($expected, (new ‪TcaInputPlaceholders())->addData($input));
83  }
84 
89  {
90  $input = [
91  'tableName' => 'aTable',
92  'databaseRow' => [
93  'anotherField' => 'anotherPlaceholder',
94  ],
95  'processedTca' => [
96  'columns' => [
97  'aField' => [
98  'config' => [
99  'type' => 'input',
100  'placeholder' => '__row|anotherField',
101  ],
102  ],
103  ],
104  ],
105  ];
106 
107  $expected = $input;
108  $expected['processedTca']['columns']['aField']['config']['placeholder'] = 'anotherPlaceholder';
109 
110  self::assertSame($expected, (new ‪TcaInputPlaceholders())->addData($input));
111  }
112 
116  public function ‪addDataReturnsValueFromSelectTypeRelation(): void
117  {
118  $input = [
119  'tableName' => 'aTable',
120  'databaseRow' => [
121  'aField' => '',
122  'aRelationField' => ['42'],
123  ],
124  'processedTca' => [
125  'columns' => [
126  'aField' => [
127  'config' => [
128  'type' => 'input',
129  'placeholder' => '__row|aRelationField|aForeignField',
130  ],
131  ],
132  'aRelationField' => [
133  'config' => [
134  'type' => 'select',
135  'foreign_table' => 'aForeignTable',
136  ],
137  ],
138  ],
139  ],
140  ];
141 
142  $aForeignTableInput = [
143  'tableName' => 'aForeignTable',
144  'databaseRow' => [
145  'aForeignField' => 'aForeignValue',
146  ],
147  'processedTca' => [
148  'columns' => [
149  'aForeignField' => [
150  'config' => [
151  'type' => 'input',
152  ],
153  ],
154  ],
155  ],
156  ];
157 
158  $formDataCompilerProphecy = $this->prophesize(FormDataCompiler::class);
159  GeneralUtility::addInstance(FormDataCompiler::class, $formDataCompilerProphecy->reveal());
160  $formDataCompilerProphecy->compile([
161  'command' => 'edit',
162  'vanillaUid' => 42,
163  'tableName' => 'aForeignTable',
164  'inlineCompileExistingChildren' => false,
165  'columnsToProcess' => ['aForeignField'],
166  ])
167  ->shouldBeCalled()
168  ->willReturn($aForeignTableInput);
169 
170  $expected = $input;
171  $expected['processedTca']['columns']['aField']['config']['placeholder'] = $aForeignTableInput['databaseRow']['aForeignField'];
172 
173  self::assertSame($expected, (new ‪TcaInputPlaceholders())->addData($input));
174  }
175 
180  {
181  $input = [
182  'tableName' => 'aTable',
183  'databaseRow' => [
184  'aField' => '',
185  'aRelationField' => [],
186  ],
187  'processedTca' => [
188  'columns' => [
189  'aField' => [
190  'config' => [
191  'type' => 'input',
192  'placeholder' => '__row|aRelationField|aForeignField',
193  ],
194  ],
195  'aRelationField' => [
196  'config' => [
197  'type' => 'select',
198  'foreign_table' => 'aForeignTable',
199  ],
200  ],
201  ],
202  ],
203  ];
204 
205  $expected = $input;
206  unset($expected['processedTca']['columns']['aField']['config']['placeholder']);
207 
208  self::assertSame($expected, (new ‪TcaInputPlaceholders())->addData($input));
209  }
210 
214  public function ‪addDataReturnsValueFromGroupTypeRelation(): void
215  {
216  $input = [
217  'tableName' => 'aTable',
218  'databaseRow' => [
219  'aField' => '',
220  'uid_local' => [
221  [
222  'uid' => 3,
223  'table' => 'sys_file',
224  ],
225  [
226  'uid' => 5,
227  'table' => 'sys_file',
228  ],
229  ],
230  ],
231  'processedTca' => [
232  'columns' => [
233  'aField' => [
234  'config' => [
235  'type' => 'input',
236  'placeholder' => '__row|uid_local|sha1',
237  ],
238  ],
239  'uid_local' => [
240  'config' => [
241  'type' => 'group',
242  'allowed' => 'sys_file',
243  ],
244  ],
245  ],
246  ],
247  ];
248 
249  $sysFileProphecyResult = [
250  'tableName' => 'sys_file',
251  'databaseRow' => [
252  'sha1' => 'aSha1Value',
253  ],
254  'processedTca' => [
255  'columns' => [
256  'sha1' => [
257  'config' => [
258  'type' => 'input',
259  ],
260  ],
261  ],
262  ],
263  ];
264 
265  $formDataCompilerProphecy = $this->prophesize(FormDataCompiler::class);
266  GeneralUtility::addInstance(FormDataCompiler::class, $formDataCompilerProphecy->reveal());
267  $formDataCompilerProphecy->compile([
268  'command' => 'edit',
269  'vanillaUid' => 3,
270  'tableName' => 'sys_file',
271  'inlineCompileExistingChildren' => false,
272  'columnsToProcess' => ['sha1'],
273  ])
274  ->shouldBeCalled()
275  ->willReturn($sysFileProphecyResult);
276 
277  $expected = $input;
278  $expected['processedTca']['columns']['aField']['config']['placeholder'] = $sysFileProphecyResult['databaseRow']['sha1'];
279 
280  self::assertSame($expected, (new ‪TcaInputPlaceholders())->addData($input));
281  }
282 
286  public function ‪addDataReturnsValueFromInlineTypeRelation(): void
287  {
288  $input = [
289  'tableName' => 'aTable',
290  'databaseRow' => [
291  'aField' => '',
292  'metadata' => '2',
293  ],
294  'processedTca' => [
295  'columns' => [
296  'aField' => [
297  'config' => [
298  'type' => 'input',
299  'placeholder' => '__row|metadata|title',
300  ],
301  ],
302  'metadata' => [
303  'config' => [
304  'readOnly' => true,
305  'type' => 'inline',
306  'foreign_table' => 'sys_file_metadata',
307  'foreign_field' => 'file',
308  ],
309  ],
310  ],
311  ],
312  ];
313 
314  $sysFileMetadataProphecyResult = [
315  'tableName' => 'sys_file_metadata',
316  'databaseRow' => [
317  'title' => 'aTitle',
318  ],
319  'processedTca' => [
320  'columns' => [
321  'sha1' => [
322  'config' => [
323  'type' => 'input',
324  ],
325  ],
326  ],
327  ],
328  ];
329 
330  $formDataCompilerProphecy = $this->prophesize(FormDataCompiler::class);
331  GeneralUtility::addInstance(FormDataCompiler::class, $formDataCompilerProphecy->reveal());
332  $formDataCompilerProphecy->compile([
333  'command' => 'edit',
334  'vanillaUid' => 2,
335  'tableName' => 'sys_file_metadata',
336  'inlineCompileExistingChildren' => false,
337  'columnsToProcess' => ['title'],
338  ])
339  ->shouldBeCalled()
340  ->willReturn($sysFileMetadataProphecyResult);
341 
342  $expected = $input;
343  $expected['processedTca']['columns']['aField']['config']['placeholder'] = $sysFileMetadataProphecyResult['databaseRow']['title'];
344 
345  self::assertSame($expected, (new ‪TcaInputPlaceholders())->addData($input));
346  }
347 
351  public function ‪addDataReturnsValueFromRelationsRecursively(): void
352  {
353  $input = [
354  'tableName' => 'aTable',
355  'databaseRow' => [
356  'aField' => '',
357  'uid_local' => [
358  [
359  'uid' => 3,
360  'table' => 'sys_file',
361  ],
362  [
363  'uid' => 5,
364  'table' => 'sys_file',
365  ],
366  ],
367  ],
368  'processedTca' => [
369  'columns' => [
370  'aField' => [
371  'config' => [
372  'type' => 'input',
373  'placeholder' => '__row|uid_local|metadata|title',
374  ],
375  ],
376  'uid_local' => [
377  'config' => [
378  'type' => 'group',
379  'allowed' => 'sys_file',
380  ],
381  ],
382  ],
383  ],
384  ];
385 
386  $sysFileProphecyResult = [
387  'tableName' => 'sys_file',
388  'databaseRow' => [
389  'metadata' => '7',
390  ],
391  'processedTca' => [
392  'columns' => [
393  'metadata' => [
394  'config' => [
395  'readOnly' => true,
396  'type' => 'inline',
397  'foreign_table' => 'sys_file_metadata',
398  'foreign_field' => 'file',
399  ],
400  ],
401  ],
402  ],
403  ];
404 
405  $sysFileMetadataProphecyResult = [
406  'tableName' => 'sys_file_metadata',
407  'databaseRow' => [
408  'title' => 'aTitle',
409  ],
410  'processedTca' => [
411  'columns' => [
412  'sha1' => [
413  'config' => [
414  'type' => 'input',
415  ],
416  ],
417  ],
418  ],
419  ];
420 
421  $sysFileFormDataCompilerProphecy = $this->prophesize(FormDataCompiler::class);
422  GeneralUtility::addInstance(FormDataCompiler::class, $sysFileFormDataCompilerProphecy->reveal());
423  $sysFileFormDataCompilerProphecy->compile([
424  'command' => 'edit',
425  'vanillaUid' => 3,
426  'tableName' => 'sys_file',
427  'inlineCompileExistingChildren' => false,
428  'columnsToProcess' => ['metadata'],
429  ])
430  ->shouldBeCalled()
431  ->willReturn($sysFileProphecyResult);
432 
433  $sysFileMetaDataFormDataCompilerProphecy = $this->prophesize(FormDataCompiler::class);
434  GeneralUtility::addInstance(FormDataCompiler::class, $sysFileMetaDataFormDataCompilerProphecy->reveal());
435  $sysFileMetaDataFormDataCompilerProphecy->compile([
436  'command' => 'edit',
437  'vanillaUid' => 7,
438  'tableName' => 'sys_file_metadata',
439  'inlineCompileExistingChildren' => false,
440  'columnsToProcess' => ['title'],
441  ])
442  ->shouldBeCalled()
443  ->willReturn($sysFileMetadataProphecyResult);
444 
445  $expected = $input;
446  $expected['processedTca']['columns']['aField']['config']['placeholder'] = $sysFileMetadataProphecyResult['databaseRow']['title'];
447 
448  self::assertSame($expected, (new ‪TcaInputPlaceholders())->addData($input));
449  }
450 
455  {
456  $labelString = 'LLL:EXT:some_ext/Resources/Private/Language/locallang.xlf:my_placeholder';
457  $localizedString = 'My Placeholder';
458  $input = [
459  'tableName' => 'aTable',
460  'databaseRow' => [],
461  'processedTca' => [
462  'columns' => [
463  'aField' => [
464  'config' => [
465  'type' => 'input',
466  'placeholder' => $labelString,
467  ],
468  ],
469  ],
470  ],
471  ];
472  $expected = $input;
473  $expected['processedTca']['columns']['aField']['config']['placeholder'] = $localizedString;
474 
475  $languageService = $this->prophesize(LanguageService::class);
476  ‪$GLOBALS['LANG'] = $languageService->reveal();
477  $languageService->sL($labelString)->shouldBeCalled()->willReturn($localizedString);
478 
479  self::assertSame($expected, (new ‪TcaInputPlaceholders())->addData($input));
480  }
481 }
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInputPlaceholdersTest\addDataReturnsValueFromSelectTypeRelation
‪addDataReturnsValueFromSelectTypeRelation()
Definition: TcaInputPlaceholdersTest.php:115
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaInputPlaceholders
Definition: TcaInputPlaceholders.php:32
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInputPlaceholdersTest
Definition: TcaInputPlaceholdersTest.php:31
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInputPlaceholdersTest\addDataReturnsUnmodifiedSimpleStringPlaceholder
‪addDataReturnsUnmodifiedSimpleStringPlaceholder()
Definition: TcaInputPlaceholdersTest.php:62
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInputPlaceholdersTest\addDataRemovesEmptyPlaceholderOption
‪addDataRemovesEmptyPlaceholderOption()
Definition: TcaInputPlaceholdersTest.php:36
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInputPlaceholdersTest\addDataCallsLanguageServiceForLocalizedPlaceholders
‪addDataCallsLanguageServiceForLocalizedPlaceholders()
Definition: TcaInputPlaceholdersTest.php:453
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInputPlaceholdersTest\addDataReturnsValueFromRelationsRecursively
‪addDataReturnsValueFromRelationsRecursively()
Definition: TcaInputPlaceholdersTest.php:350
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInputPlaceholdersTest\addDataReturnsValueFromDatabaseRowAsPlaceholder
‪addDataReturnsValueFromDatabaseRowAsPlaceholder()
Definition: TcaInputPlaceholdersTest.php:87
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInputPlaceholdersTest\addDataReturnsValueFromGroupTypeRelation
‪addDataReturnsValueFromGroupTypeRelation()
Definition: TcaInputPlaceholdersTest.php:213
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Backend\Form\FormDataCompiler
Definition: FormDataCompiler.php:25
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInputPlaceholdersTest\addDataReturnsValueFromInlineTypeRelation
‪addDataReturnsValueFromInlineTypeRelation()
Definition: TcaInputPlaceholdersTest.php:285
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInputPlaceholdersTest\addDataReturnsNoPlaceholderForNewSelectTypeRelation
‪addDataReturnsNoPlaceholderForNewSelectTypeRelation()
Definition: TcaInputPlaceholdersTest.php:178
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider
Definition: DatabaseDefaultLanguagePageRowTest.php:18