[BUGFIX] Use special treatment for language field in RelationHandler 95/49295/9
authorEsteban Marín <esteban.marin@bithost.ch>
Tue, 2 Aug 2016 09:21:52 +0000 (11:21 +0200)
committerOliver Hader <oliver.hader@typo3.org>
Mon, 15 Aug 2016 15:17:25 +0000 (17:17 +0200)
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>
typo3/sysext/core/Classes/Database/RelationHandler.php
typo3/sysext/core/Classes/Tests/FunctionalTestCase.php
typo3/sysext/core/Tests/Functional/DataHandling/DataHandler/SpecialLanguagesTest.php [new file with mode: 0644]

index f3a713b..8eac1fb 100644 (file)
@@ -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:
index bd04e12..8030cfd 100644 (file)
@@ -270,6 +270,14 @@ abstract class FunctionalTestCase extends BaseTestCase
     }
 
     /**
+     * @return ConnectionPool
+     */
+    protected function getConnectionPool()
+    {
+        return GeneralUtility::makeInstance(ConnectionPool::class);
+    }
+
+    /**
      * Initialize backend user
      *
      * @param int $userUid uid of the user we want to initialize. This user must exist in the fixture file
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 (file)
index 0000000..bdafec0
--- /dev/null
@@ -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', ''],
+        ];
+    }
+}