‪TYPO3CMS  ‪main
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 PHPUnit\Framework\Attributes\Test;
26 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
27 
28 final class ‪TcaGroupTest extends UnitTestCase
29 {
30  protected bool ‪$resetSingletonInstances = true;
31 
32  #[Test]
34  {
35  $input = [
36  'databaseRow' => [
37  'aField' => 'aValue',
38  ],
39  'processedTca' => [
40  'columns' => [
41  'aField' => [
42  'config' => [
43  'type' => 'foo',
44  ],
45  ],
46  ],
47  ],
48  ];
49  $expected = $input;
50  self::assertSame($expected, (new ‪TcaGroup())->addData($input));
51  }
52 
53  #[Test]
54  public function ‪addDataSetsDatabaseData(): void
55  {
56  $aFieldConfig = [
57  'type' => 'group',
58  'MM' => 'mmTableName',
59  'allowed' => 'aForeignTable',
60  'maxitems' => 99999,
61  ];
62  $input = [
63  'tableName' => 'aTable',
64  'databaseRow' => [
65  'uid' => 42,
66  'aField' => '1,2',
67  ],
68  'processedTca' => [
69  'columns' => [
70  'aField' => [
71  'config' => $aFieldConfig,
72  ],
73  ],
74  ],
75  ];
76 
77  ‪$GLOBALS['BE_USER'] = $this->createMock(BackendUserAuthentication::class);
78 
79  $clipboardMock = $this->createMock(Clipboard::class);
80  GeneralUtility::addInstance(Clipboard::class, $clipboardMock);
81  $clipboardMock->expects(self::atLeastOnce())->method('initializeClipboard');
82  $clipboardMock->expects(self::atLeastOnce())->method('elFromTable')->with('aForeignTable')->willReturn([]);
83 
84  $relationHandlerMock = $this->createMock(RelationHandler::class);
85  GeneralUtility::addInstance(RelationHandler::class, $relationHandlerMock);
86  $relationHandlerMock->expects(self::atLeastOnce())->method('start')
87  ->with('1,2', 'aForeignTable', 'mmTableName', 42, 'aTable', $aFieldConfig);
88  $relationHandlerMock->expects(self::atLeastOnce())->method('getFromDB');
89  $relationHandlerMock->expects(self::atLeastOnce())->method('processDeletePlaceholder');
90  $relationHandlerMock->expects(self::atLeastOnce())->method('getResolvedItemArray')->willReturn([
91  [
92  'table' => 'aForeignTable',
93  'uid' => 1,
94  'record' => [
95  'uid' => 1,
96  ],
97  ],
98  [
99  'table' => 'aForeignTable',
100  'uid' => 2,
101  'record' => [
102  'uid' => 2,
103  ],
104  ],
105  ]);
106 
107  $expected = $input;
108  $expected['databaseRow']['aField'] = [
109  [
110  'table' => 'aForeignTable',
111  'uid' => 1,
112  'title' => '',
113  'row' => [
114  'uid' => 1,
115  ],
116  ],
117  [
118  'table' => 'aForeignTable',
119  'uid' => 2,
120  'title' => '',
121  'row' => [
122  'uid' => 2,
123  ],
124  ],
125  ];
126  $expected['processedTca']['columns']['aField']['config']['clipboardElements'] = [];
127 
128  self::assertSame($expected, (new ‪TcaGroup())->addData($input));
129  }
130 }
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaGroup
Definition: TcaGroup.php:29
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaGroupTest
Definition: TcaGroupTest.php:29
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaGroupTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: TcaGroupTest.php:30
‪TYPO3\CMS\Backend\Clipboard\Clipboard
Definition: Clipboard.php:48
‪TYPO3\CMS\Core\Database\RelationHandler
Definition: RelationHandler.php:36
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaGroupTest\addDataReturnsFieldUnchangedIfFieldIsNotTypeGroup
‪addDataReturnsFieldUnchangedIfFieldIsNotTypeGroup()
Definition: TcaGroupTest.php:33
‪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:52
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaGroupTest\addDataSetsDatabaseData
‪addDataSetsDatabaseData()
Definition: TcaGroupTest.php:54
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider
Definition: DatabaseDefaultLanguagePageRowTest.php:18