‪TYPO3CMS  10.4
TcaGroupTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Prophecy\Prophecy\ObjectProphecy;
26 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
27 
31 class ‪TcaGroupTest extends UnitTestCase
32 {
36  protected ‪$resetSingletonInstances = true;
37 
42  {
43  $input = [
44  'databaseRow' => [
45  'aField' => 'aValue',
46  ],
47  'processedTca' => [
48  'columns' => [
49  'aField' => [
50  'config' => [
51  'type' => 'foo',
52  ],
53  ],
54  ],
55  ],
56  ];
57  $expected = $input;
58  self::assertSame($expected, (new ‪TcaGroup())->addData($input));
59  }
60 
65  {
66  $input = [
67  'tableName' => 'aTable',
68  'processedTca' => [
69  'columns' => [
70  'aField' => [
71  'config' => [
72  'type' => 'group',
73  'internal_type' => 'foo',
74  ],
75  ],
76  ],
77  ],
78  ];
79  $this->expectException(\UnexpectedValueException::class);
80  $this->expectExceptionCode(1438780511);
81  (new ‪TcaGroup())->addData($input);
82  }
83 
87  public function ‪addDataSetsFolderData()
88  {
89  $input = [
90  'databaseRow' => [
91  'aField' => '1:/aFolder/anotherFolder/',
92  ],
93  'processedTca' => [
94  'columns' => [
95  'aField' => [
96  'config' => [
97  'type' => 'group',
98  'internal_type' => 'folder',
99  'maxitems' => 99999,
100  ],
101  ],
102  ],
103  ],
104  ];
105 
107  $folderProphecy = $this->prophesize(Folder::class);
108 
110  $resourceFactoryProphecy = $this->prophesize(ResourceFactory::class);
111  GeneralUtility::setSingletonInstance(ResourceFactory::class, $resourceFactoryProphecy->reveal());
112  $resourceFactoryProphecy->retrieveFileOrFolderObject('1:/aFolder/anotherFolder/')
113  ->shouldBeCalled()
114  ->willReturn($folderProphecy->reveal());
115 
116  $expected = $input;
117  $expected['databaseRow']['aField'] = [
118  [
119  'folder' => '1:/aFolder/anotherFolder/',
120  ]
121  ];
122  $expected['processedTca']['columns']['aField']['config']['clipboardElements'] = [];
123  self::assertSame($expected, (new ‪TcaGroup())->addData($input));
124  }
125 
129  public function ‪addDataSetsDatabaseData()
130  {
131  $aFieldConfig = [
132  'type' => 'group',
133  'internal_type' => 'db',
134  'MM' => 'mmTableName',
135  'allowed' => 'aForeignTable',
136  'maxitems' => 99999,
137  ];
138  $input = [
139  'tableName' => 'aTable',
140  'databaseRow' => [
141  'uid' => 42,
142  'aField' => '1,2',
143  ],
144  'processedTca' => [
145  'columns' => [
146  'aField' => [
147  'config' => $aFieldConfig,
148  ],
149  ],
150  ],
151  ];
152 
153  $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
154  ‪$GLOBALS['BE_USER'] = $backendUserProphecy->reveal();
155 
156  $clipboardProphecy = $this->prophesize(Clipboard::class);
157  GeneralUtility::addInstance(Clipboard::class, $clipboardProphecy->reveal());
158  $clipboardProphecy->initializeClipboard()->shouldBeCalled();
159  $clipboardProphecy->elFromTable('aForeignTable')->shouldBeCalled()->willReturn([]);
160 
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  ],
172  [
173  'table' => 'aForeignTable',
174  'uid' => 2,
175  ],
176  ]);
177 
178  $expected = $input;
179  $expected['databaseRow']['aField'] = [
180  [
181  'table' => 'aForeignTable',
182  'uid' => null,
183  'title' => '',
184  'row' => null,
185  ],
186  [
187  'table' => 'aForeignTable',
188  'uid' => null,
189  'title' => '',
190  'row' => null,
191  ]
192  ];
193  $expected['processedTca']['columns']['aField']['config']['clipboardElements'] = [];
194 
195  self::assertSame($expected, (new ‪TcaGroup())->addData($input));
196  }
197 }
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaGroup
Definition: TcaGroup.php:32
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaGroupTest
Definition: TcaGroupTest.php:32
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaGroupTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: TcaGroupTest.php:35
‪TYPO3\CMS\Backend\Clipboard\Clipboard
Definition: Clipboard.php:43
‪TYPO3\CMS\Core\Database\RelationHandler
Definition: RelationHandler.php:35
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaGroupTest\addDataThrowsExceptionWithTypeGroupAndNoValidInternalType
‪addDataThrowsExceptionWithTypeGroupAndNoValidInternalType()
Definition: TcaGroupTest.php:63
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaGroupTest\addDataReturnsFieldUnchangedIfFieldIsNotTypeGroup
‪addDataReturnsFieldUnchangedIfFieldIsNotTypeGroup()
Definition: TcaGroupTest.php:40
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaGroupTest\addDataSetsFolderData
‪addDataSetsFolderData()
Definition: TcaGroupTest.php:86
‪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:5
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaGroupTest\addDataSetsDatabaseData
‪addDataSetsDatabaseData()
Definition: TcaGroupTest.php:128
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider
Definition: DatabaseDefaultLanguagePageRowTest.php:18