‪TYPO3CMS  11.5
TcaGroupTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Prophecy\PhpUnit\ProphecyTrait;
28 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
29 
33 class ‪TcaGroupTest extends UnitTestCase
34 {
35  use ProphecyTrait;
36 
40  protected ‪$resetSingletonInstances = true;
41 
46  {
47  $input = [
48  'databaseRow' => [
49  'aField' => 'aValue',
50  ],
51  'processedTca' => [
52  'columns' => [
53  'aField' => [
54  'config' => [
55  'type' => 'foo',
56  ],
57  ],
58  ],
59  ],
60  ];
61  $expected = $input;
62  self::assertSame($expected, (new ‪TcaGroup())->addData($input));
63  }
64 
69  {
70  $input = [
71  'tableName' => 'aTable',
72  'processedTca' => [
73  'columns' => [
74  'aField' => [
75  'config' => [
76  'type' => 'group',
77  'internal_type' => 'foo',
78  ],
79  ],
80  ],
81  ],
82  ];
83  $this->expectException(\UnexpectedValueException::class);
84  $this->expectExceptionCode(1438780511);
85  (new ‪TcaGroup())->addData($input);
86  }
87 
91  public function ‪addDataSetsFolderData(): void
92  {
93  $input = [
94  'databaseRow' => [
95  'aField' => '1:/aFolder/anotherFolder/',
96  ],
97  'processedTca' => [
98  'columns' => [
99  'aField' => [
100  'config' => [
101  'type' => 'group',
102  'internal_type' => 'folder',
103  'maxitems' => 99999,
104  ],
105  ],
106  ],
107  ],
108  ];
109 
110  $folderProphecy = $this->prophesize(Folder::class);
111 
112  $resourceFactoryProphecy = $this->prophesize(ResourceFactory::class);
113  GeneralUtility::setSingletonInstance(ResourceFactory::class, $resourceFactoryProphecy->reveal());
114  $resourceFactoryProphecy->retrieveFileOrFolderObject('1:/aFolder/anotherFolder/')
115  ->shouldBeCalled()
116  ->willReturn($folderProphecy->reveal());
117 
118  $expected = $input;
119  $expected['databaseRow']['aField'] = [
120  [
121  'folder' => '1:/aFolder/anotherFolder/',
122  ],
123  ];
124  $expected['processedTca']['columns']['aField']['config']['clipboardElements'] = [];
125  self::assertSame($expected, (new ‪TcaGroup())->addData($input));
126  }
127 
131  public function ‪addDataSetsDatabaseData(): void
132  {
133  $aFieldConfig = [
134  'type' => 'group',
135  'MM' => 'mmTableName',
136  'allowed' => 'aForeignTable',
137  'maxitems' => 99999,
138  ];
139  $input = [
140  'tableName' => 'aTable',
141  'databaseRow' => [
142  'uid' => 42,
143  'aField' => '1,2',
144  ],
145  'processedTca' => [
146  'columns' => [
147  'aField' => [
148  'config' => $aFieldConfig,
149  ],
150  ],
151  ],
152  ];
153 
154  $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
155  ‪$GLOBALS['BE_USER'] = $backendUserProphecy->reveal();
156 
157  $clipboardProphecy = $this->prophesize(Clipboard::class);
158  GeneralUtility::addInstance(Clipboard::class, $clipboardProphecy->reveal());
159  $clipboardProphecy->initializeClipboard()->shouldBeCalled();
160  $clipboardProphecy->elFromTable('aForeignTable')->shouldBeCalled()->willReturn([]);
161 
162  $relationHandlerProphecy = $this->prophesize(RelationHandler::class);
163  GeneralUtility::addInstance(RelationHandler::class, $relationHandlerProphecy->reveal());
164  $relationHandlerProphecy->start('1,2', 'aForeignTable', 'mmTableName', 42, 'aTable', $aFieldConfig)->shouldBeCalled();
165  $relationHandlerProphecy->getFromDB()->shouldBeCalled();
166  $relationHandlerProphecy->processDeletePlaceholder()->shouldBeCalled();
167  $relationHandlerProphecy->getResolvedItemArray()->shouldBeCalled()->willReturn([
168  [
169  'table' => 'aForeignTable',
170  'uid' => 1,
171  'record' => [
172  'uid' => 1,
173  ],
174  ],
175  [
176  'table' => 'aForeignTable',
177  'uid' => 2,
178  'record' => [
179  'uid' => 2,
180  ],
181  ],
182  ]);
183 
184  $expected = $input;
185  $expected['databaseRow']['aField'] = [
186  [
187  'table' => 'aForeignTable',
188  'uid' => 1,
189  'title' => '',
190  'row' => [
191  'uid' => 1,
192  ],
193  ],
194  [
195  'table' => 'aForeignTable',
196  'uid' => 2,
197  'title' => '',
198  'row' => [
199  'uid' => 2,
200  ],
201  ],
202  ];
203  $expected['processedTca']['columns']['aField']['config']['clipboardElements'] = [];
204 
205  self::assertSame($expected, (new ‪TcaGroup())->addData($input));
206  }
207 }
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaGroup
Definition: TcaGroup.php:32
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaGroupTest
Definition: TcaGroupTest.php:34
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaGroupTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: TcaGroupTest.php:38
‪TYPO3\CMS\Backend\Clipboard\Clipboard
Definition: Clipboard.php:49
‪TYPO3\CMS\Core\Database\RelationHandler
Definition: RelationHandler.php:37
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaGroupTest\addDataThrowsExceptionWithTypeGroupAndNoValidInternalType
‪addDataThrowsExceptionWithTypeGroupAndNoValidInternalType()
Definition: TcaGroupTest.php:66
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaGroupTest\addDataReturnsFieldUnchangedIfFieldIsNotTypeGroup
‪addDataReturnsFieldUnchangedIfFieldIsNotTypeGroup()
Definition: TcaGroupTest.php:43
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaGroupTest\addDataSetsFolderData
‪addDataSetsFolderData()
Definition: TcaGroupTest.php:89
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:37
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:41
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaGroupTest\addDataSetsDatabaseData
‪addDataSetsDatabaseData()
Definition: TcaGroupTest.php:129
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider
Definition: DatabaseDefaultLanguagePageRowTest.php:18