diff --git a/typo3/sysext/backend/Tests/Functional/Form/FormDataProvider/Fixtures/DataSet/TestTcaGroup.xml b/typo3/sysext/backend/Tests/Functional/Form/FormDataProvider/Fixtures/DataSet/TestTcaGroup.xml new file mode 100644 index 0000000000..b778d4abf2 --- /dev/null +++ b/typo3/sysext/backend/Tests/Functional/Form/FormDataProvider/Fixtures/DataSet/TestTcaGroup.xml @@ -0,0 +1,36 @@ + + + + 1 + 1 + visible + 0 + + + 2 + 1 + deleted + 1 + + + 3 + 1 + hidden + 1 + + + 4 + 1 + expired + 1262300400 + + + 5 + -1 + deletedInWorkspace + 1 + 1 + 1 + 2 + + diff --git a/typo3/sysext/backend/Tests/Functional/Form/FormDataProvider/TcaGroupTest.php b/typo3/sysext/backend/Tests/Functional/Form/FormDataProvider/TcaGroupTest.php new file mode 100644 index 0000000000..077da3d035 --- /dev/null +++ b/typo3/sysext/backend/Tests/Functional/Form/FormDataProvider/TcaGroupTest.php @@ -0,0 +1,122 @@ +importDataSet(__DIR__ . '/Fixtures/DataSet/TestTcaGroup.xml'); + + $aFieldConfig = [ + 'type' => 'group', + 'internal_type' => 'db', + 'allowed' => 'pages', + 'maxitems' => 99999, + ]; + $input = [ + 'tableName' => 'aTable', + 'databaseRow' => [ + 'uid' => 42, + 'aField' => '1,2,3,4', + ], + 'processedTca' => [ + 'columns' => [ + 'aField' => [ + 'config' => $aFieldConfig, + ], + ], + ], + ]; + + $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class); + $GLOBALS['BE_USER'] = $backendUserProphecy->reveal(); + + $clipboardProphecy = $this->prophesize(Clipboard::class); + GeneralUtility::addInstance(Clipboard::class, $clipboardProphecy->reveal()); + $clipboardProphecy->initializeClipboard()->shouldBeCalled(); + $clipboardProphecy->elFromTable('pages')->shouldBeCalled()->willReturn([]); + + $result = (new TcaGroup)->addData($input); + static::assertIsArray($result['databaseRow']['aField'], 'TcaGroup did not load items'); + + $loadedUids = array_column($result['databaseRow']['aField'], 'uid'); + static::assertEquals($loadedUids, [1, 3, 4], 'TcaGroup did not load the correct items'); + } + + /** + * This test checks if TcaGroup respects deleted elements in a workspace + * + * @test + */ + public function respectsDeletedElementsInWorkspace() + { + $this->importDataSet(__DIR__ . '/Fixtures/DataSet/TestTcaGroup.xml'); + + $aFieldConfig = [ + 'type' => 'group', + 'internal_type' => 'db', + 'allowed' => 'pages', + 'maxitems' => 99999, + ]; + $input = [ + 'tableName' => 'aTable', + 'databaseRow' => [ + 'uid' => 42, + 'aField' => '1,2,3,4', + ], + 'processedTca' => [ + 'columns' => [ + 'aField' => [ + 'config' => $aFieldConfig, + ], + ], + ], + ]; + + $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class); + $backendUserProphecy->workspace = 1; + $GLOBALS['BE_USER'] = $backendUserProphecy->reveal(); + + $clipboardProphecy = $this->prophesize(Clipboard::class); + GeneralUtility::addInstance(Clipboard::class, $clipboardProphecy->reveal()); + $clipboardProphecy->initializeClipboard()->shouldBeCalled(); + $clipboardProphecy->elFromTable('pages')->shouldBeCalled()->willReturn([]); + + $result = (new TcaGroup)->addData($input); + static::assertIsArray($result['databaseRow']['aField'], 'TcaGroup did not load items in a workspace'); + + $loadedUids = array_column($result['databaseRow']['aField'], 'uid'); + static::assertEquals($loadedUids, [3, 4], 'TcaGroup did not load the correct items in a workspace'); + } +}