From db78e2d08776eb94a4c06430f94c2de58b9cd0c4 Mon Sep 17 00:00:00 2001 From: Susanne Moog <look@susi.dev> Date: Wed, 25 Mar 2020 17:35:54 +0100 Subject: [PATCH] [TASK] Add test for checkValueForSelect According to a report, items added by itemsProcFunc cannot be saved via datahandler. Adding a test case to test the behaviour. Resolves: #76509 Releases: master Change-Id: I2d5e34c6a9eff7a8fa0129106c9676307c5e3151 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/63917 Tested-by: TYPO3com <noreply@typo3.com> Tested-by: Susanne Moog <look@susi.dev> Reviewed-by: Susanne Moog <look@susi.dev> --- .../Regular/CheckValueTestForSelect.php | 70 +++++++++++++++++++ .../Classes/Tca/SelectElementItems.php | 16 +++++ .../test_datahandler/ext_tables.php | 16 +++++ .../test_datahandler/ext_tables.sql | 1 + 4 files changed, 103 insertions(+) create mode 100644 typo3/sysext/core/Tests/Functional/DataHandling/Regular/CheckValueTestForSelect.php create mode 100644 typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_datahandler/Classes/Tca/SelectElementItems.php diff --git a/typo3/sysext/core/Tests/Functional/DataHandling/Regular/CheckValueTestForSelect.php b/typo3/sysext/core/Tests/Functional/DataHandling/Regular/CheckValueTestForSelect.php new file mode 100644 index 000000000000..5a2c17c10ef8 --- /dev/null +++ b/typo3/sysext/core/Tests/Functional/DataHandling/Regular/CheckValueTestForSelect.php @@ -0,0 +1,70 @@ +<?php +declare(strict_types = 1); +namespace TYPO3\CMS\Core\Tests\Functional\DataHandling\Regular; + +/* + * This file is part of the TYPO3 CMS project. + * + * It is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, either version 2 + * of the License, or any later version. + * + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + * + * The TYPO3 project - inspiring people to share! + */ +use TYPO3\CMS\Backend\Utility\BackendUtility; +use TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase; + +/** + * Functional Test for DataHandler::checkValue() concerning checkboxes + */ +class CheckValueTestForSelect extends AbstractDataHandlerActionTestCase +{ + + /** + * @var string + */ + protected $scenarioDataSetDirectory = 'typo3/sysext/core/Tests/Functional/DataHandling/Regular/DataSet/'; + + protected function setUp(): void + { + $this->testExtensionsToLoad[] = 'typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_datahandler'; + + parent::setUp(); + $this->importScenarioDataSet('LiveDefaultPages'); + } + + /** + * @test + */ + public function selectValueMustBeDefinedInTcaItems() + { + // pid 88 comes from LiveDefaultPages + $result = $this->actionService->createNewRecord('tt_content', 88, [ + 'tx_testdatahandler_select_dynamic' => 'predefined value' + ]); + $recordUid = $result['tt_content'][0]; + + $record = BackendUtility::getRecord('tt_content', $recordUid); + + self::assertEquals('predefined value', $record['tx_testdatahandler_select_dynamic']); + } + + /** + * @test + */ + public function selectValueMustComeFromItemsProcFuncIfNotDefinedInTcaItems() + { + // pid 88 comes from LiveDefaultPages + $result = $this->actionService->createNewRecord('tt_content', 88, [ + 'tx_testdatahandler_select_dynamic' => 'processed value' + ]); + $recordUid = $result['tt_content'][0]; + + $record = BackendUtility::getRecord('tt_content', $recordUid); + + self::assertEquals('processed value', $record['tx_testdatahandler_select_dynamic']); + } +} diff --git a/typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_datahandler/Classes/Tca/SelectElementItems.php b/typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_datahandler/Classes/Tca/SelectElementItems.php new file mode 100644 index 000000000000..ac3da5212c55 --- /dev/null +++ b/typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_datahandler/Classes/Tca/SelectElementItems.php @@ -0,0 +1,16 @@ +<?php +namespace TYPO3\TestDatahandler\Classes\Tca; + +/** + * Items processor for radio buttons for the functional tests of DataHandler::checkValue() + */ +class SelectElementItems +{ + /** + * @return array + */ + public function getItems($params) + { + $params['items'][] = ['processed label', 'processed value']; + } +} diff --git a/typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_datahandler/ext_tables.php b/typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_datahandler/ext_tables.php index 5dfa2b4f0df3..94201e8e1755 100644 --- a/typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_datahandler/ext_tables.php +++ b/typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_datahandler/ext_tables.php @@ -18,6 +18,22 @@ defined('TYPO3_MODE') or die(); 'autoSizeMax' => 10, 'default' => '', ], + ], + 'tx_testdatahandler_select_dynamic' => [ + 'exclude' => true, + 'label' => 'DataHandler Test Select', + 'config' => [ + 'type' => 'select', + 'renderType' => 'selectMultipleSideBySide', + 'items' => [ + ['predefined label', 'predefined value'] + ], + 'itemsProcFunc' => 'TYPO3\TestDatahandler\Classes\Tca\SelectElementItems->getItems', + 'minitems' => 1, + 'maxitems' => 10, + 'autoSizeMax' => 10, + 'default' => '', + ], ], 'tx_testdatahandler_group' => [ 'exclude' => true, diff --git a/typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_datahandler/ext_tables.sql b/typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_datahandler/ext_tables.sql index 4c1e704606d6..7c308142a005 100644 --- a/typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_datahandler/ext_tables.sql +++ b/typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_datahandler/ext_tables.sql @@ -3,6 +3,7 @@ # CREATE TABLE tt_content ( tx_testdatahandler_select text, + tx_testdatahandler_select_dynamic text, tx_testdatahandler_group text, tx_testdatahandler_radio text, tx_testdatahandler_checkbox text -- GitLab