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