‪TYPO3CMS  10.4
TcaInputPlaceholdersTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Prophecy\Prophecy\ObjectProphecy;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 class ‪TcaInputPlaceholdersTest extends UnitTestCase
30 {
35  {
36  $input = [
37  'tableName' => 'aTable',
38  'databaseRow' => [],
39  'processedTca' => [
40  'columns' => [
41  'aField' => [
42  'config' => [
43  'type' => 'input',
44  'placeholder' => '',
45  ]
46  ]
47  ],
48  ],
49  ];
50 
51  $expected = $input;
52  unset($expected['processedTca']['columns']['aField']['config']['placeholder']);
53 
54  self::assertSame($expected, (new ‪TcaInputPlaceholders())->addData($input));
55  }
56 
61  {
62  $input = [
63  'tableName' => 'aTable',
64  'databaseRow' => [],
65  'processedTca' => [
66  'columns' => [
67  'aField' => [
68  'config' => [
69  'type' => 'input',
70  'placeholder' => 'aPlaceholder',
71  ]
72  ]
73  ],
74  ],
75  ];
76 
77  $expected = $input;
78 
79  self::assertSame($expected, (new ‪TcaInputPlaceholders())->addData($input));
80  }
81 
86  {
87  $input = [
88  'tableName' => 'aTable',
89  'databaseRow' => [
90  'anotherField' => 'anotherPlaceholder'
91  ],
92  'processedTca' => [
93  'columns' => [
94  'aField' => [
95  'config' => [
96  'type' => 'input',
97  'placeholder' => '__row|anotherField',
98  ]
99  ]
100  ],
101  ],
102  ];
103 
104  $expected = $input;
105  $expected['processedTca']['columns']['aField']['config']['placeholder'] = 'anotherPlaceholder';
106 
107  self::assertSame($expected, (new ‪TcaInputPlaceholders())->addData($input));
108  }
109 
114  {
115  $input = [
116  'tableName' => 'aTable',
117  'databaseRow' => [
118  'aField' => '',
119  'aRelationField' => ['42'],
120  ],
121  'processedTca' => [
122  'columns' => [
123  'aField' => [
124  'config' => [
125  'type' => 'input',
126  'placeholder' => '__row|aRelationField|aForeignField',
127  ]
128  ],
129  'aRelationField' => [
130  'config' => [
131  'type' => 'select',
132  'foreign_table' => 'aForeignTable'
133  ]
134  ]
135  ],
136  ],
137  ];
138 
139  $aForeignTableInput = [
140  'tableName' => 'aForeignTable',
141  'databaseRow' => [
142  'aForeignField' => 'aForeignValue',
143  ],
144  'processedTca' => [
145  'columns' => [
146  'aForeignField' => [
147  'config' => [
148  'type' => 'input',
149  ]
150  ],
151  ],
152  ],
153  ];
154 
156  $formDataCompilerProphecy = $this->prophesize(FormDataCompiler::class);
157  GeneralUtility::addInstance(FormDataCompiler::class, $formDataCompilerProphecy->reveal());
158  $formDataCompilerProphecy->compile([
159  'command' => 'edit',
160  'vanillaUid' => 42,
161  'tableName' => 'aForeignTable',
162  'inlineCompileExistingChildren' => false,
163  'columnsToProcess' => ['aForeignField']
164  ])
165  ->shouldBeCalled()
166  ->willReturn($aForeignTableInput);
167 
168  $expected = $input;
169  $expected['processedTca']['columns']['aField']['config']['placeholder'] = $aForeignTableInput['databaseRow']['aForeignField'];
170 
171  self::assertSame($expected, (new ‪TcaInputPlaceholders())->addData($input));
172  }
173 
178  {
179  $input = [
180  'tableName' => 'aTable',
181  'databaseRow' => [
182  'aField' => '',
183  'aRelationField' => [],
184  ],
185  'processedTca' => [
186  'columns' => [
187  'aField' => [
188  'config' => [
189  'type' => 'input',
190  'placeholder' => '__row|aRelationField|aForeignField',
191  ]
192  ],
193  'aRelationField' => [
194  'config' => [
195  'type' => 'select',
196  'foreign_table' => 'aForeignTable'
197  ]
198  ]
199  ],
200  ],
201  ];
202 
203  $expected = $input;
204  unset($expected['processedTca']['columns']['aField']['config']['placeholder']);
205 
206  self::assertSame($expected, (new ‪TcaInputPlaceholders())->addData($input));
207  }
208 
213  {
214  $input = [
215  'tableName' => 'aTable',
216  'databaseRow' => [
217  'aField' => '',
218  'uid_local' => [
219  [
220  'uid' => 3,
221  'table' => 'sys_file',
222  ],
223  [
224  'uid' => 5,
225  'table' => 'sys_file',
226  ],
227  ],
228  ],
229  'processedTca' => [
230  'columns' => [
231  'aField' => [
232  'config' => [
233  'type' => 'input',
234  'placeholder' => '__row|uid_local|sha1',
235  ]
236  ],
237  'uid_local' => [
238  'config' => [
239  'type' => 'group',
240  'internal_type' => 'db',
241  'allowed' => 'sys_file'
242  ]
243  ]
244  ],
245  ],
246  ];
247 
248  $sysFileProphecyResult = [
249  'tableName' => 'sys_file',
250  'databaseRow' => [
251  'sha1' => 'aSha1Value',
252  ],
253  'processedTca' => [
254  'columns' => [
255  'sha1' => [
256  'config' => [
257  'type' => 'input',
258  ]
259  ],
260  ],
261  ],
262  ];
263 
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 
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 
331  $formDataCompilerProphecy = $this->prophesize(FormDataCompiler::class);
332  GeneralUtility::addInstance(FormDataCompiler::class, $formDataCompilerProphecy->reveal());
333  $formDataCompilerProphecy->compile([
334  'command' => 'edit',
335  'vanillaUid' => 2,
336  'tableName' => 'sys_file_metadata',
337  'inlineCompileExistingChildren' => false,
338  'columnsToProcess' => ['title']
339  ])
340  ->shouldBeCalled()
341  ->willReturn($sysFileMetadataProphecyResult);
342 
343  $expected = $input;
344  $expected['processedTca']['columns']['aField']['config']['placeholder'] = $sysFileMetadataProphecyResult['databaseRow']['title'];
345 
346  self::assertSame($expected, (new ‪TcaInputPlaceholders())->addData($input));
347  }
348 
353  {
354  $input = [
355  'tableName' => 'aTable',
356  'databaseRow' => [
357  'aField' => '',
358  'uid_local' => [
359  [
360  'uid' => 3,
361  'table' => 'sys_file',
362  ],
363  [
364  'uid' => 5,
365  'table' => 'sys_file',
366  ],
367  ],
368  ],
369  'processedTca' => [
370  'columns' => [
371  'aField' => [
372  'config' => [
373  'type' => 'input',
374  'placeholder' => '__row|uid_local|metadata|title',
375  ]
376  ],
377  'uid_local' => [
378  'config' => [
379  'type' => 'group',
380  'internal_type' => 'db',
381  'allowed' => 'sys_file'
382  ]
383  ]
384  ],
385  ],
386  ];
387 
388  $sysFileProphecyResult = [
389  'tableName' => 'sys_file',
390  'databaseRow' => [
391  'metadata' => '7',
392  ],
393  'processedTca' => [
394  'columns' => [
395  'metadata' => [
396  'config' => [
397  'readOnly' => true,
398  'type' => 'inline',
399  'foreign_table' => 'sys_file_metadata',
400  'foreign_field' => 'file',
401  ]
402  ]
403  ],
404  ],
405  ];
406 
407  $sysFileMetadataProphecyResult = [
408  'tableName' => 'sys_file_metadata',
409  'databaseRow' => [
410  'title' => 'aTitle',
411  ],
412  'processedTca' => [
413  'columns' => [
414  'sha1' => [
415  'config' => [
416  'type' => 'input',
417  ]
418  ],
419  ],
420  ],
421  ];
422 
423  $sysFileFormDataCompilerProphecy = $this->prophesize(FormDataCompiler::class);
424  GeneralUtility::addInstance(FormDataCompiler::class, $sysFileFormDataCompilerProphecy->reveal());
425  $sysFileFormDataCompilerProphecy->compile([
426  'command' => 'edit',
427  'vanillaUid' => 3,
428  'tableName' => 'sys_file',
429  'inlineCompileExistingChildren' => false,
430  'columnsToProcess' => ['metadata']
431  ])
432  ->shouldBeCalled()
433  ->willReturn($sysFileProphecyResult);
434 
435  $sysFileMetaDataFormDataCompilerProphecy = $this->prophesize(FormDataCompiler::class);
436  GeneralUtility::addInstance(FormDataCompiler::class, $sysFileMetaDataFormDataCompilerProphecy->reveal());
437  $sysFileMetaDataFormDataCompilerProphecy->compile([
438  'command' => 'edit',
439  'vanillaUid' => 7,
440  'tableName' => 'sys_file_metadata',
441  'inlineCompileExistingChildren' => false,
442  'columnsToProcess' => ['title']
443  ])
444  ->shouldBeCalled()
445  ->willReturn($sysFileMetadataProphecyResult);
446 
447  $expected = $input;
448  $expected['processedTca']['columns']['aField']['config']['placeholder'] = $sysFileMetadataProphecyResult['databaseRow']['title'];
449 
450  self::assertSame($expected, (new ‪TcaInputPlaceholders())->addData($input));
451  }
452 
457  {
458  $labelString = 'LLL:EXT:some_ext/Resources/Private/Language/locallang.xlf:my_placeholder';
459  $localizedString = 'My Placeholder';
460  $input = [
461  'tableName' => 'aTable',
462  'databaseRow' => [],
463  'processedTca' => [
464  'columns' => [
465  'aField' => [
466  'config' => [
467  'type' => 'input',
468  'placeholder' => $labelString,
469  ]
470  ]
471  ],
472  ],
473  ];
474  $expected = $input;
475  $expected['processedTca']['columns']['aField']['config']['placeholder'] = $localizedString;
476 
478  $languageService = $this->prophesize(LanguageService::class);
479  ‪$GLOBALS['LANG'] = $languageService->reveal();
480  $languageService->sL($labelString)->shouldBeCalled()->willReturn($localizedString);
481 
482  self::assertSame($expected, (new ‪TcaInputPlaceholders())->addData($input));
483  }
484 }
‪TYPO3\CMS\Backend\Form\FormDataGroup\TcaInputPlaceholderRecord
Definition: TcaInputPlaceholderRecord.php:25
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInputPlaceholdersTest\addDataReturnsValueFromSelectTypeRelation
‪addDataReturnsValueFromSelectTypeRelation()
Definition: TcaInputPlaceholdersTest.php:113
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaInputPlaceholders
Definition: TcaInputPlaceholders.php:32
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInputPlaceholdersTest
Definition: TcaInputPlaceholdersTest.php:30
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInputPlaceholdersTest\addDataReturnsUnmodifiedSimpleStringPlaceholder
‪addDataReturnsUnmodifiedSimpleStringPlaceholder()
Definition: TcaInputPlaceholdersTest.php:60
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInputPlaceholdersTest\addDataRemovesEmptyPlaceholderOption
‪addDataRemovesEmptyPlaceholderOption()
Definition: TcaInputPlaceholdersTest.php:34
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInputPlaceholdersTest\addDataCallsLanguageServiceForLocalizedPlaceholders
‪addDataCallsLanguageServiceForLocalizedPlaceholders()
Definition: TcaInputPlaceholdersTest.php:456
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInputPlaceholdersTest\addDataReturnsValueFromRelationsRecursively
‪addDataReturnsValueFromRelationsRecursively()
Definition: TcaInputPlaceholdersTest.php:352
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInputPlaceholdersTest\addDataReturnsValueFromDatabaseRowAsPlaceholder
‪addDataReturnsValueFromDatabaseRowAsPlaceholder()
Definition: TcaInputPlaceholdersTest.php:85
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInputPlaceholdersTest\addDataReturnsValueFromGroupTypeRelation
‪addDataReturnsValueFromGroupTypeRelation()
Definition: TcaInputPlaceholdersTest.php:212
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Backend\Form\FormDataCompiler
Definition: FormDataCompiler.php:25
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInputPlaceholdersTest\addDataReturnsValueFromInlineTypeRelation
‪addDataReturnsValueFromInlineTypeRelation()
Definition: TcaInputPlaceholdersTest.php:286
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInputPlaceholdersTest\addDataReturnsNoPlaceholderForNewSelectTypeRelation
‪addDataReturnsNoPlaceholderForNewSelectTypeRelation()
Definition: TcaInputPlaceholdersTest.php:177
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider
Definition: DatabaseDefaultLanguagePageRowTest.php:18