TYPO3 CMS  TYPO3_7-6
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 
24 
29 {
33  protected $subject;
34 
35  public function setUp()
36  {
37  $this->subject = new TcaInputPlaceholders();
38  }
39 
44  {
45  $input = [
46  'tableName' => 'aTable',
47  'databaseRow' => [],
48  'processedTca' => [
49  'columns' => [
50  'aField' => [
51  'config' => [
52  'type' => 'input',
53  'placeholder' => '',
54  ]
55  ]
56  ],
57  ],
58  ];
59 
60  $expected = $input;
61  unset($expected['processedTca']['columns']['aField']['config']['placeholder']);
62 
63  $this->assertSame($expected, $this->subject->addData($input));
64  }
65 
70  {
71  $input = [
72  'tableName' => 'aTable',
73  'databaseRow' => [],
74  'processedTca' => [
75  'columns' => [
76  'aField' => [
77  'config' => [
78  'type' => 'input',
79  'placeholder' => 'aPlaceholder',
80  ]
81  ]
82  ],
83  ],
84  ];
85 
86  $expected = $input;
87 
88  $this->assertSame($expected, $this->subject->addData($input));
89  }
90 
95  {
96  $input = [
97  'tableName' => 'aTable',
98  'databaseRow' => [
99  'anotherField' => 'anotherPlaceholder'
100  ],
101  'processedTca' => [
102  'columns' => [
103  'aField' => [
104  'config' => [
105  'type' => 'input',
106  'placeholder' => '__row|anotherField',
107  ]
108  ]
109  ],
110  ],
111  ];
112 
113  $expected = $input;
114  $expected['processedTca']['columns']['aField']['config']['placeholder'] = 'anotherPlaceholder';
115 
116  $this->assertSame($expected, $this->subject->addData($input));
117  }
118 
122  public function addDataReturnsValueFromSelectTypeRelation()
123  {
124  $input = [
125  'tableName' => 'aTable',
126  'databaseRow' => [
127  'aField' => '',
128  'aRelationField' => ['42'],
129  ],
130  'processedTca' => [
131  'columns' => [
132  'aField' => [
133  'config' => [
134  'type' => 'input',
135  'placeholder' => '__row|aRelationField|aForeignField',
136  ]
137  ],
138  'aRelationField' => [
139  'config' => [
140  'type' => 'select',
141  'foreign_table' => 'aForeignTable'
142  ]
143  ]
144  ],
145  ],
146  ];
147 
148  $aForeignTableInput = [
149  'tableName' => 'aForeignTable',
150  'databaseRow' => [
151  'aForeignField' => 'aForeignValue',
152  ],
153  'processedTca' => [
154  'columns' => [
155  'aForeignField' => [
156  'config' => [
157  'type' => 'input',
158  ]
159  ],
160  ],
161  ],
162  ];
163 
165  $formDataCompilerProphecy = $this->prophesize(FormDataCompiler::class);
166  GeneralUtility::addInstance(FormDataCompiler::class, $formDataCompilerProphecy->reveal());
167  $formDataCompilerProphecy->compile([
168  'command' => 'edit',
169  'vanillaUid' => 42,
170  'tableName' => 'aForeignTable',
171  'inlineCompileExistingChildren' => false,
172  'columnsToProcess' => ['aForeignField']
173  ])
174  ->shouldBeCalled()
175  ->willReturn($aForeignTableInput);
176 
177  $expected = $input;
178  $expected['processedTca']['columns']['aField']['config']['placeholder'] = $aForeignTableInput['databaseRow']['aForeignField'];
179 
180  $this->assertSame($expected, $this->subject->addData($input));
181  }
182 
187  {
188  $input = [
189  'tableName' => 'aTable',
190  'databaseRow' => [
191  'aField' => '',
192  'aRelationField' => [],
193  ],
194  'processedTca' => [
195  'columns' => [
196  'aField' => [
197  'config' => [
198  'type' => 'input',
199  'placeholder' => '__row|aRelationField|aForeignField',
200  ]
201  ],
202  'aRelationField' => [
203  'config' => [
204  'type' => 'select',
205  'foreign_table' => 'aForeignTable'
206  ]
207  ]
208  ],
209  ],
210  ];
211 
212  $expected = $input;
213  unset($expected['processedTca']['columns']['aField']['config']['placeholder']);
214 
215  $this->assertSame($expected, $this->subject->addData($input));
216  }
217 
221  public function addDataReturnsValueFromGroupTypeRelation()
222  {
223  $input = [
224  'tableName' => 'aTable',
225  'databaseRow' => [
226  'aField' => '',
227  'uid_local' => 'sys_file_3|aLabel,sys_file_5|anotherLabel',
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  $this->assertSame($expected, $this->subject->addData($input));
281  }
282 
286  public function addDataReturnsValueFromInlineTypeRelation()
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' => 1,
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  $this->assertSame($expected, $this->subject->addData($input));
347  }
348 
353  {
354  $input = [
355  'tableName' => 'aTable',
356  'databaseRow' => [
357  'aField' => '',
358  'uid_local' => 'sys_file_3|aLabel,sys_file_5|anotherLabel',
359  ],
360  'processedTca' => [
361  'columns' => [
362  'aField' => [
363  'config' => [
364  'type' => 'input',
365  'placeholder' => '__row|uid_local|metadata|title',
366  ]
367  ],
368  'uid_local' => [
369  'config' => [
370  'type' => 'group',
371  'internal_type' => 'db',
372  'allowed' => 'sys_file'
373  ]
374  ]
375  ],
376  ],
377  ];
378 
379  $sysFileProphecyResult = [
380  'tableName' => 'sys_file',
381  'databaseRow' => [
382  'metadata' => '7',
383  ],
384  'processedTca' => [
385  'columns' => [
386  'metadata' => [
387  'config' => [
388  'readOnly' => 1,
389  'type' => 'inline',
390  'foreign_table' => 'sys_file_metadata',
391  'foreign_field' => 'file',
392  ]
393  ]
394  ],
395  ],
396  ];
397 
398  $sysFileMetadataProphecyResult = [
399  'tableName' => 'sys_file_metadata',
400  'databaseRow' => [
401  'title' => 'aTitle',
402  ],
403  'processedTca' => [
404  'columns' => [
405  'sha1' => [
406  'config' => [
407  'type' => 'input',
408  ]
409  ],
410  ],
411  ],
412  ];
413 
414  $sysFileFormDataCompilerProphecy = $this->prophesize(FormDataCompiler::class);
415  GeneralUtility::addInstance(FormDataCompiler::class, $sysFileFormDataCompilerProphecy->reveal());
416  $sysFileFormDataCompilerProphecy->compile([
417  'command' => 'edit',
418  'vanillaUid' => 3,
419  'tableName' => 'sys_file',
420  'inlineCompileExistingChildren' => false,
421  'columnsToProcess' => ['metadata']
422  ])
423  ->shouldBeCalled()
424  ->willReturn($sysFileProphecyResult);
425 
426  $sysFileMetaDataFormDataCompilerProphecy = $this->prophesize(FormDataCompiler::class);
427  GeneralUtility::addInstance(FormDataCompiler::class, $sysFileMetaDataFormDataCompilerProphecy->reveal());
428  $sysFileMetaDataFormDataCompilerProphecy->compile([
429  'command' => 'edit',
430  'vanillaUid' => 7,
431  'tableName' => 'sys_file_metadata',
432  'inlineCompileExistingChildren' => false,
433  'columnsToProcess' => ['title']
434  ])
435  ->shouldBeCalled()
436  ->willReturn($sysFileMetadataProphecyResult);
437 
438  $expected = $input;
439  $expected['processedTca']['columns']['aField']['config']['placeholder'] = $sysFileMetadataProphecyResult['databaseRow']['title'];
440 
441  $this->assertSame($expected, $this->subject->addData($input));
442  }
443 
447  public function addDataCallsLanguageServiceForLocalizedPlaceholders()
448  {
449  $labelString = 'LLL:EXT:some_ext/Resources/Private/Language/locallang.xlf:my_placeholder';
450  $localizedString = 'My Placeholder';
451  $input = [
452  'tableName' => 'aTable',
453  'databaseRow' => [],
454  'processedTca' => [
455  'columns' => [
456  'aField' => [
457  'config' => [
458  'type' => 'input',
459  'placeholder' => $labelString,
460  ]
461  ]
462  ],
463  ],
464  ];
465  $expected = $input;
466  $expected['processedTca']['columns']['aField']['config']['placeholder'] = $localizedString;
467 
469  $languageService = $this->prophesize(LanguageService::class);
470  $GLOBALS['LANG'] = $languageService->reveal();
471  $languageService->sL($labelString)->shouldBeCalled()->willReturn($localizedString);
472 
473  $this->assertSame($expected, $this->subject->addData($input));
474  }
475 }
static addInstance($className, $instance)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']