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 0000000000000000000000000000000000000000..5a2c17c10ef8fcffbaa788594d4f93c19900e9cf --- /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 0000000000000000000000000000000000000000..ac3da5212c55259316d4f90e991454d1726aa90d --- /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 5dfa2b4f0df3dc2f53aa7609d634f33e2a0f68b0..94201e8e17553bd15476cf86687386731e846191 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 4c1e704606d6473592fbe258d58a03112c354a60..7c308142a0058f7bb433f4c54ba02bbaa6e78c23 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