From c220019b262ec2fffe5788e60940443e47e9343f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20Mar=C3=ADn?= <esteban.marin@bithost.ch> Date: Tue, 2 Aug 2016 11:21:52 +0200 Subject: [PATCH] [BUGFIX] Use special treatment for language field in RelationHandler This fixes saving the default language in BE user group permissions. Fixes: #75998 Releases: master,7.6 Change-Id: Iace9a0e04b57a7306a529402c7a44b777f494290 Reviewed-on: https://review.typo3.org/49295 Tested-by: Bamboo TYPO3com <info@typo3.com> Reviewed-by: Markus Klein <markus.klein@typo3.org> Reviewed-by: Oliver Hader <oliver.hader@typo3.org> Tested-by: Oliver Hader <oliver.hader@typo3.org> --- .../core/Classes/Database/RelationHandler.php | 7 +- .../core/Classes/Tests/FunctionalTestCase.php | 8 +++ .../DataHandler/SpecialLanguagesTest.php | 66 +++++++++++++++++++ 3 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 typo3/sysext/core/Tests/Functional/DataHandling/DataHandler/SpecialLanguagesTest.php diff --git a/typo3/sysext/core/Classes/Database/RelationHandler.php b/typo3/sysext/core/Classes/Database/RelationHandler.php index f3a713bf8acc..8eac1fb70eff 100644 --- a/typo3/sysext/core/Classes/Database/RelationHandler.php +++ b/typo3/sysext/core/Classes/Database/RelationHandler.php @@ -409,7 +409,12 @@ class RelationHandler ? strrev(trim($parts[1])) : ($this->secondTable && $theID < 0 ? $this->secondTable : $this->firstTable); // If the ID is not blank and the table name is among the names in the inputted tableList - if (((string)$theID != '' && $theID) && $theTable && isset($this->tableArray[$theTable])) { + if ( + (string)$theID != '' + // allow the default language '0' for the special languages configuration + && ($theID || ($configuration['special'] ?? null) === 'languages') + && $theTable && isset($this->tableArray[$theTable]) + ) { // Get ID as the right value: $theID = $this->secondTable ? abs((int)$theID) : (int)$theID; // Register ID/table name in internal arrays: diff --git a/typo3/sysext/core/Classes/Tests/FunctionalTestCase.php b/typo3/sysext/core/Classes/Tests/FunctionalTestCase.php index bd04e12315de..8030cfd06c55 100644 --- a/typo3/sysext/core/Classes/Tests/FunctionalTestCase.php +++ b/typo3/sysext/core/Classes/Tests/FunctionalTestCase.php @@ -269,6 +269,14 @@ abstract class FunctionalTestCase extends BaseTestCase return $GLOBALS['TYPO3_DB']; } + /** + * @return ConnectionPool + */ + protected function getConnectionPool() + { + return GeneralUtility::makeInstance(ConnectionPool::class); + } + /** * Initialize backend user * diff --git a/typo3/sysext/core/Tests/Functional/DataHandling/DataHandler/SpecialLanguagesTest.php b/typo3/sysext/core/Tests/Functional/DataHandling/DataHandler/SpecialLanguagesTest.php new file mode 100644 index 000000000000..bdafec0c039d --- /dev/null +++ b/typo3/sysext/core/Tests/Functional/DataHandling/DataHandler/SpecialLanguagesTest.php @@ -0,0 +1,66 @@ +<?php +declare (strict_types = 1); +namespace TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler; + +/* + * 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\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase; + +/** + * Testing behavior of TCA field configuration 'special' => 'languages' + */ +class SpecialLanguagesTest extends AbstractDataHandlerActionTestCase +{ + protected function setUp() + { + parent::setUp(); + $this->backendUser->workspace = 0; + } + + /** + * @param string $value + * @param string $expected + * + * @test + * @dataProvider allowedLanguagesAreAssignedToBackendUserGroupDataProvider + */ + public function allowedLanguagesAreAssignedToBackendUserGroup($value, $expected) + { + $this->actionService->createNewRecord('be_groups', 0, [ + 'title' => 'Testing Group', + 'allowed_languages' => $value, + ]); + + $statement = $this->getConnectionPool() + ->getQueryBuilderForTable('be_groups') + ->select('allowed_languages') + ->from('be_groups') + ->where('uid=1') + ->execute(); + $this->assertEquals($expected, $statement->fetchColumn(0)); + } + + /** + * @return array + */ + public function allowedLanguagesAreAssignedToBackendUserGroupDataProvider() + { + return [ + 'valid languages' => ['1,2', '1,2'], + 'default language' => ['0', '0'], + 'empty value' => ['', ''], + 'invalid integer' => ['not-an-integer', ''], + ]; + } +} -- GitLab