‪TYPO3CMS  9.5
TcaGroupTest.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;
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26 
30 class ‪TcaGroupTest extends UnitTestCase
31 {
35  protected ‪$resetSingletonInstances = true;
36 
41  {
42  $input = [
43  'databaseRow' => [
44  'aField' => 'aValue',
45  ],
46  'processedTca' => [
47  'columns' => [
48  'aField' => [
49  'config' => [
50  'type' => 'foo',
51  ],
52  ],
53  ],
54  ],
55  ];
56  $expected = $input;
57  $this->assertSame($expected, (new ‪TcaGroup)->addData($input));
58  }
59 
64  {
65  $input = [
66  'tableName' => 'aTable',
67  'processedTca' => [
68  'columns' => [
69  'aField' => [
70  'config' => [
71  'type' => 'group',
72  'internal_type' => 'foo',
73  ],
74  ],
75  ],
76  ],
77  ];
78  $this->expectException(\UnexpectedValueException::class);
79  $this->expectExceptionCode(1438780511);
80  (new ‪TcaGroup)->addData($input);
81  }
82 
87  {
88  $input = [
89  'databaseRow' => [
90  'aField' => '',
91  ],
92  'processedTca' => [
93  'columns' => [
94  'aField' => [
95  'config' => [
96  'type' => 'group',
97  'internal_type' => 'file_reference',
98  'maxitems' => 99999,
99  ],
100  ],
101  ],
102  ],
103  ];
104 
105  $expected = $input;
106  $expected['databaseRow']['aField'] = [];
107  $expected['processedTca']['columns']['aField']['config']['allowed'] = '*';
108  $expected['processedTca']['columns']['aField']['config']['clipboardElements'] = [];
109  $expected['processedTca']['columns']['aField']['config']['uploadfolder'] = '';
110 
111  $clipboardProphecy = $this->prophesize(Clipboard::class);
112  GeneralUtility::addInstance(Clipboard::class, $clipboardProphecy->reveal());
113  $clipboardProphecy->initializeClipboard()->shouldBeCalled();
114  $clipboardProphecy->elFromTable('_FILE')->shouldBeCalled()->willReturn([]);
115 
116  $this->assertEquals($expected, (new ‪TcaGroup)->addData($input));
117  }
118 
122  public function ‪addDataSetsFileData()
123  {
124  $input = [
125  'databaseRow' => [
126  'aField' => '/aDir/aFile.txt,/anotherDir/anotherFile.css',
127  ],
128  'processedTca' => [
129  'columns' => [
130  'aField' => [
131  'config' => [
132  'type' => 'group',
133  'internal_type' => 'file',
134  'maxitems' => 99999,
135  ],
136  ],
137  ],
138  ],
139  ];
140 
141  $clipboardProphecy = $this->prophesize(Clipboard::class);
142  GeneralUtility::addInstance(Clipboard::class, $clipboardProphecy->reveal());
143  $clipboardProphecy->initializeClipboard()->shouldBeCalled();
144  $clipboardProphecy->elFromTable('_FILE')->shouldBeCalled()->willReturn([]);
145 
146  $expected = $input;
147  $expected['databaseRow']['aField'] = [
148  [
149  'uidOrPath' => '/aDir/aFile.txt',
150  'title' => '/aDir/aFile.txt',
151  ],
152  [
153  'uidOrPath' => '/anotherDir/anotherFile.css',
154  'title' => '/anotherDir/anotherFile.css',
155  ],
156  ];
157  $expected['processedTca']['columns']['aField']['config']['clipboardElements'] = [];
158  $expected['processedTca']['columns']['aField']['config']['allowed'] = '*';
159  $this->assertEquals($expected, (new ‪TcaGroup)->addData($input));
160  }
161 
165  public function ‪addDataSetsFolderData()
166  {
167  $input = [
168  'databaseRow' => [
169  'aField' => '1:/aFolder/anotherFolder/',
170  ],
171  'processedTca' => [
172  'columns' => [
173  'aField' => [
174  'config' => [
175  'type' => 'group',
176  'internal_type' => 'folder',
177  'maxitems' => 99999,
178  ],
179  ],
180  ],
181  ],
182  ];
183 
185  $folderProphecy = $this->prophesize(Folder::class);
186 
188  $resourceFactoryProphecy = $this->prophesize(ResourceFactory::class);
189  GeneralUtility::setSingletonInstance(ResourceFactory::class, $resourceFactoryProphecy->reveal());
190  $resourceFactoryProphecy->retrieveFileOrFolderObject('1:/aFolder/anotherFolder/')
191  ->shouldBeCalled()
192  ->willReturn($folderProphecy->reveal());
193 
194  $expected = $input;
195  $expected['databaseRow']['aField'] = [
196  [
197  'folder' => '1:/aFolder/anotherFolder/',
198  ]
199  ];
200  $expected['processedTca']['columns']['aField']['config']['clipboardElements'] = [];
201  $this->assertSame($expected, (new ‪TcaGroup)->addData($input));
202  }
203 
207  public function ‪addDataSetsDatabaseData()
208  {
209  $aFieldConfig = [
210  'type' => 'group',
211  'internal_type' => 'db',
212  'MM' => 'mmTableName',
213  'allowed' => 'aForeignTable',
214  'maxitems' => 99999,
215  ];
216  $input = [
217  'tableName' => 'aTable',
218  'databaseRow' => [
219  'uid' => 42,
220  'aField' => '1,2',
221  ],
222  'processedTca' => [
223  'columns' => [
224  'aField' => [
225  'config' => $aFieldConfig,
226  ],
227  ],
228  ],
229  ];
230 
231  $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
232  ‪$GLOBALS['BE_USER'] = $backendUserProphecy->reveal();
233 
234  $clipboardProphecy = $this->prophesize(Clipboard::class);
235  GeneralUtility::addInstance(Clipboard::class, $clipboardProphecy->reveal());
236  $clipboardProphecy->initializeClipboard()->shouldBeCalled();
237  $clipboardProphecy->elFromTable('aForeignTable')->shouldBeCalled()->willReturn([]);
238 
240  $relationHandlerProphecy = $this->prophesize(RelationHandler::class);
241  GeneralUtility::addInstance(RelationHandler::class, $relationHandlerProphecy->reveal());
242  $relationHandlerProphecy->start('1,2', 'aForeignTable', 'mmTableName', 42, 'aTable', $aFieldConfig)->shouldBeCalled();
243  $relationHandlerProphecy->getFromDB()->shouldBeCalled();
244  $relationHandlerProphecy->getResolvedItemArray()->shouldBeCalled()->willReturn([
245  [
246  'table' => 'aForeignTable',
247  'uid' => 1,
248  ],
249  [
250  'table' => 'aForeignTable',
251  'uid' => 2,
252  ],
253  ]);
254 
255  $expected = $input;
256  $expected['databaseRow']['aField'] = [
257  [
258  'table' => 'aForeignTable',
259  'uid' => null,
260  'title' => '',
261  'row' => null,
262  ],
263  [
264  'table' => 'aForeignTable',
265  'uid' => null,
266  'title' => '',
267  'row' => null,
268  ]
269  ];
270  $expected['processedTca']['columns']['aField']['config']['clipboardElements'] = [];
271 
272  $this->assertSame($expected, (new ‪TcaGroup)->addData($input));
273  }
274 }
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaGroup
Definition: TcaGroup.php:31
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaGroupTest
Definition: TcaGroupTest.php:31
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaGroupTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: TcaGroupTest.php:34
‪TYPO3\CMS\Backend\Clipboard\Clipboard
Definition: Clipboard.php:38
‪TYPO3\CMS\Core\Database\RelationHandler
Definition: RelationHandler.php:32
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaGroupTest\addDataSetsFileData
‪addDataSetsFileData()
Definition: TcaGroupTest.php:121
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaGroupTest\addDataThrowsExceptionWithTypeGroupAndNoValidInternalType
‪addDataThrowsExceptionWithTypeGroupAndNoValidInternalType()
Definition: TcaGroupTest.php:62
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaGroupTest\addDataReturnsFieldUnchangedIfFieldIsNotTypeGroup
‪addDataReturnsFieldUnchangedIfFieldIsNotTypeGroup()
Definition: TcaGroupTest.php:39
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaGroupTest\addDataSetsFolderData
‪addDataSetsFolderData()
Definition: TcaGroupTest.php:164
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:34
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:33
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:45
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaGroupTest\addDataSetsUploadFolderForFileReference
‪addDataSetsUploadFolderForFileReference()
Definition: TcaGroupTest.php:85
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaGroupTest\addDataSetsDatabaseData
‪addDataSetsDatabaseData()
Definition: TcaGroupTest.php:206
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider
Definition: DatabaseDefaultLanguagePageRowTest.php:3