[BUGFIX] Display correct original state when invertStateDisplay is true 38/58238/4
authorJigal van Hemert <jigal.van.hemert@typo3.org>
Sun, 9 Sep 2018 11:01:24 +0000 (13:01 +0200)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Sun, 30 Sep 2018 15:10:28 +0000 (17:10 +0200)
In the fieldWizard defaultLanguageDifferences the opposite value must be
displayed if invertStateDisplay is active in fields of type "check".

Resolves: #86205
Releases: master
Change-Id: Iac8fa73406b076b3d26a6ed3aed7e21b79220750
Reviewed-on: https://review.typo3.org/58238
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Frans Saris <franssaris@gmail.com>
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
typo3/sysext/backend/Classes/Utility/BackendUtility.php
typo3/sysext/backend/Tests/Unit/Utility/BackendUtilityTest.php

index 29d713d..bc8af0d 100644 (file)
@@ -2202,7 +2202,14 @@ class BackendUtility
                 }
                 break;
             case 'check':
-                if (!is_array($theColConf['items']) || count($theColConf['items']) === 1) {
+                if (!is_array($theColConf['items'])) {
+                    $l = $value ? $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:yes') : $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:no');
+                } elseif (count($theColConf['items']) === 1) {
+                    reset($theColConf['items']);
+                    $invertStateDisplay = current($theColConf['items'])['invertStateDisplay'] ?? false;
+                    if ($invertStateDisplay) {
+                        $value = !$value;
+                    }
                     $l = $value ? $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:yes') : $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:no');
                 } else {
                     $lA = [];
index 1f54603..2344ece 100644 (file)
@@ -439,6 +439,65 @@ class BackendUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
     }
 
     /**
+     * @test
+     */
+    public function getProcessedValueForCheckWithSingleItem()
+    {
+        $GLOBALS['TCA'] = [
+            'tt_content' => [
+                'columns' => [
+                    'hide' => [
+                        'config' => [
+                            'type' => 'check',
+                            'items' => [
+                                [
+                                    0 => '',
+                                    1 => '',
+                                ]
+                            ]
+                        ]
+                    ]
+                ]
+            ]
+        ];
+        $languageServiceProphecy = $this->prophesize(\TYPO3\CMS\Core\Localization\LanguageService::class);
+        $languageServiceProphecy->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:yes')->willReturn('Yes');
+        $languageServiceProphecy->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:no')->willReturn('No');
+        $GLOBALS['LANG'] = $languageServiceProphecy->reveal();
+        $this->assertSame('Yes', BackendUtility::getProcessedValue('tt_content', 'hide', 1));
+    }
+
+    /**
+     * @test
+     */
+    public function getProcessedValueForCheckWithSingleItemInvertStateDisplay()
+    {
+        $GLOBALS['TCA'] = [
+            'tt_content' => [
+                'columns' => [
+                    'hide' => [
+                        'config' => [
+                            'type' => 'check',
+                            'items' => [
+                                [
+                                    0 => '',
+                                    1 => '',
+                                    'invertStateDisplay' => true,
+                                ]
+                            ]
+                        ]
+                    ]
+                ]
+            ]
+        ];
+        $languageServiceProphecy = $this->prophesize(\TYPO3\CMS\Core\Localization\LanguageService::class);
+        $languageServiceProphecy->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:yes')->willReturn('Yes');
+        $languageServiceProphecy->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:no')->willReturn('No');
+        $GLOBALS['LANG'] = $languageServiceProphecy->reveal();
+        $this->assertSame('No', BackendUtility::getProcessedValue('tt_content', 'hide', 1));
+    }
+
+    /**
      * Tests concerning getCommonSelectFields
      */