TYPO3 CMS  TYPO3_7-6
DatabaseRecordTypeValueTest.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 
21 
26 {
30  protected $subject;
31 
35  protected $dbProphecy;
36 
37  protected function setUp()
38  {
39  $this->dbProphecy = $this->prophesize(DatabaseConnection::class);
40  $GLOBALS['TYPO3_DB'] = $this->dbProphecy->reveal();
41 
42  $this->subject = new DatabaseRecordTypeValue();
43  }
44 
49  {
50  $input = [
51  'processedTca' => [
52  'types' => [],
53  ],
54  ];
55 
56  $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1438185331);
57 
58  $this->subject->addData($input);
59  }
60 
65  {
66  $input = [
67  'processedTca' => [
68  'types' => [
69  '1' => 'foo',
70  ],
71  ],
72  ];
73  $expected = $input;
74  $expected['recordTypeValue'] = '1';
75  $this->assertSame($expected, $this->subject->addData($input));
76  }
77 
82  {
83  $input = [
84  'processedTca' => [
85  'types' => [
86  '0' => 'foo',
87  ],
88  ],
89  ];
90 
91  $expected = $input;
92  $expected['recordTypeValue'] = '0';
93 
94  $this->assertSame($expected, $this->subject->addData($input));
95  }
96 
101  {
102  $input = [
103  'processedTca' => [
104  'ctrl' => [
105  'type' => 'notExists',
106  ],
107  'types' => [
108  '0' => 'foo',
109  ],
110  ],
111  'databaseRow' => [
112  'uid' => 23,
113  ],
114  ];
115 
116  $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1438183881);
117 
118  $this->subject->addData($input);
119  }
120 
125  {
126  $input = [
127  'processedTca' => [
128  'ctrl' => [
129  'type' => 'aField',
130  ],
131  'types' => [
132  '3' => 'foo',
133  ],
134  ],
135  'databaseRow' => [
136  'aField' => 3,
137  ],
138  ];
139 
140  $expected = $input;
141  $expected['recordTypeValue'] = '3';
142 
143  $this->assertSame($expected, $this->subject->addData($input));
144  }
145 
150  {
151  $input = [
152  'processedTca' => [
153  'ctrl' => [
154  'type' => 'aField',
155  ],
156  'types' => [
157  '0' => 'foo',
158  ],
159  ],
160  'databaseRow' => [
161  'aField' => 3,
162  ],
163  ];
164 
165  $expected = $input;
166  $expected['recordTypeValue'] = '0';
167 
168  $this->assertSame($expected, $this->subject->addData($input));
169  }
170 
175  {
176  $input = [
177  'processedTca' => [
178  'ctrl' => [
179  'type' => 'aField',
180  ],
181  'types' => [
182  '0' => 'foo',
183  ],
184  ],
185  'databaseRow' => [
186  'aField' => '',
187  ],
188  ];
189 
190  $expected = $input;
191  $expected['recordTypeValue'] = '0';
192 
193  $this->assertSame($expected, $this->subject->addData($input));
194  }
195 
200  {
201  $input = [
202  'processedTca' => [
203  'ctrl' => [
204  'type' => 'aField',
205  ],
206  'types' => [
207  '42' => 'foo',
208  ],
209  ],
210  'databaseRow' => [
211  'aField' => 23,
212  ],
213  ];
214 
215  $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1438185437);
216 
217  $this->subject->addData($input);
218  }
219 
224  {
225  $input = [
226  'processedTca' => [
227  'ctrl' => [
228  'languageField' => 'sys_language_uid',
229  'type' => 'aField',
230  ],
231  'columns' => [
232  'aField' => [
233  'l10n_mode' => 'exclude',
234  ],
235  ],
236  'types' => [
237  '3' => 'foo',
238  ],
239  ],
240  'databaseRow' => [
241  'sys_language_uid' => 2,
242  'aField' => 4,
243  ],
244  'defaultLanguageRow' => [
245  'aField' => 3,
246  ],
247  ];
248 
249  $expected = $input;
250  $expected['recordTypeValue'] = '3';
251 
252  $this->assertSame($expected, $this->subject->addData($input));
253  }
254 
259  {
260  $input = [
261  'processedTca' => [
262  'ctrl' => [
263  'languageField' => 'sys_language_uid',
264  'type' => 'aField',
265  ],
266  'columns' => [
267  'aField' => [
268  'l10n_mode' => 'mergeIfNotBlank',
269  ],
270  ],
271  'types' => [
272  '3' => 'foo',
273  ],
274  ],
275  'databaseRow' => [
276  'sys_language_uid' => 2,
277  'aField' => '',
278  ],
279  'defaultLanguageRow' => [
280  'aField' => 3,
281  ],
282  ];
283 
284  $expected = $input;
285  $expected['recordTypeValue'] = '3';
286 
287  $this->assertSame($expected, $this->subject->addData($input));
288  }
289 
294  {
295  $input = [
296  'processedTca' => [
297  'ctrl' => [
298  'languageField' => 'sys_language_uid',
299  'type' => 'aField',
300  ],
301  'columns' => [
302  'aField' => [
303  'l10n_mode' => 'mergeIfNotBlank',
304  ],
305  ],
306  'types' => [
307  '3' => 'foo',
308  ],
309  ],
310  'databaseRow' => [
311  'sys_language_uid' => 2,
312  'aField' => 3,
313  ],
314  'defaultLanguageRow' => [
315  'aField' => 4,
316  ],
317  ];
318 
319  $expected = $input;
320  $expected['recordTypeValue'] = '3';
321 
322  $this->assertSame($expected, $this->subject->addData($input));
323  }
324 
329  {
330  $input = [
331  'processedTca' => [
332  'ctrl' => [
333  'type' => 'localField:foreignField',
334  ],
335  'columns' => [
336  'localField' => [
337  'config' => [
338  'type' => 'input',
339  ],
340  ],
341  ],
342  'types' => [
343  '3' => 'foo',
344  ],
345  ],
346  ];
347 
348  $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1325862241);
349 
350  $this->subject->addData($input);
351  }
352 
357  {
358  $input = [
359  'processedTca' => [
360  'ctrl' => [
361  'type' => 'localField:foreignField',
362  ],
363  'columns' => [
364  'localField' => [
365  'config' => [
366  'type' => 'select',
367  ],
368  ],
369  ],
370  'types' => [
371  '3' => 'foo',
372  ],
373  ],
374  'databaseRow' => [
375  'localField' => 3,
376  ],
377  ];
378 
379  $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1438253614);
380 
381  $this->subject->addData($input);
382  }
383 
388  {
389  $input = [
390  'processedTca' => [
391  'ctrl' => [
392  'type' => 'localField:foreignField',
393  ],
394  'columns' => [
395  'localField' => [
396  'config' => [
397  'type' => 'select',
398  'foreign_table' => 'foreignTable',
399  ],
400  ],
401  ],
402  'types' => [
403  '3' => 'foo',
404  ],
405  ],
406  'databaseRow' => [
407  // Point to record 42 in foreignTable
408  'localField' => 42,
409  ],
410  ];
411 
412  $foreignRecordResult = [
413  'foreignField' => 3,
414  ];
415  // Required for BackendUtility::getRecord
416  $GLOBALS['TCA']['foreignTable'] = ['foo'];
417 
418  $this->dbProphecy->exec_SELECTgetSingleRow('foreignField', 'foreignTable', 'uid=42')->shouldBeCalled()->willReturn($foreignRecordResult);
419 
420  $expected = $input;
421  $expected['recordTypeValue'] = '3';
422 
423  $this->assertSame($expected, $this->subject->addData($input));
424  }
425 
430  {
431  $input = [
432  'processedTca' => [
433  'ctrl' => [
434  'type' => 'uid_local:type',
435  ],
436  'columns' => [
437  'uid_local' => [
438  'config' => [
439  'type' => 'group',
440  'internal_type' => 'db',
441  'size' => 1,
442  'maxitems' => 1,
443  'minitems' => 0,
444  'allowed' => 'sys_file'
445  ],
446  ],
447  ],
448  'types' => [
449  '2' => 'foo',
450  ],
451  ],
452  'databaseRow' => [
453  // Processed group field
454  'uid_local' => 'sys_file_222|my_test.jpg',
455  ],
456  ];
457 
458  $foreignRecordResult = [
459  'type' => 2,
460  ];
461  // Required for BackendUtility::getRecord
462  $GLOBALS['TCA']['sys_file'] = ['foo'];
463 
464  $this->dbProphecy->exec_SELECTgetSingleRow('type', 'sys_file', 'uid=222')->shouldBeCalled()->willReturn($foreignRecordResult);
465 
466  $expected = $input;
467  $expected['recordTypeValue'] = '2';
468 
469  $this->assertSame($expected, $this->subject->addData($input));
470  }
471 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']