[BUGFIX] Use special treatment for language field in RelationHandler 85/49485/3
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:18:33 +0000 (17:18 +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/49485
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/Tests/Functional/DataHandling/DataHandler/SpecialLanguagesTest.php [new file with mode: 0644]

index b0ced4a..a1ec0b8 100644 (file)
@@ -407,7 +407,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 || isset($configuration['special']) && $configuration['special'] === '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/Tests/Functional/DataHandling/DataHandler/SpecialLanguagesTest.php b/typo3/sysext/core/Tests/Functional/DataHandling/DataHandler/SpecialLanguagesTest.php
new file mode 100644 (file)
index 0000000..a93c4e5
--- /dev/null
@@ -0,0 +1,65 @@
+<?php
+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,
+        ]);
+
+        $row = $this->getDatabaseConnection()
+            ->exec_SELECTgetSingleRow(
+                'allowed_languages',
+                'be_groups',
+                'uid=1'
+            );
+        $this->assertEquals($expected, $row['allowed_languages']);
+    }
+
+    /**
+     * @return array
+     */
+    public function allowedLanguagesAreAssignedToBackendUserGroupDataProvider()
+    {
+        return [
+            'valid languages' => ['1,2', '1,2'],
+            'default language' => ['0', '0'],
+            'empty value' => ['', ''],
+            'invalid integer' => ['not-an-integer', ''],
+        ];
+    }
+}