[BUGFIX] getLabelsFromItemsList() retuns no value when no item found 12/27212/2
authorFrans Saris <franssaris@gmail.com>
Mon, 2 Dec 2013 09:43:30 +0000 (10:43 +0100)
committerAndreas Wolf <andreas.wolf@typo3.org>
Fri, 31 Jan 2014 17:38:23 +0000 (18:38 +0100)
BackendUtility::getLabelsFromItemsList() does not take
itemsProcFunc into account. This means no value is
returned when there is no matching item found.

With this change the plain db value is returned
when no matching item is found.

Resolves: #54131
Releases: 6.2, 6.1
Change-Id: Ieb04394fa104627b765f6bc05d0d5886f29099c9
Reviewed-on: https://review.typo3.org/25866
Reviewed-by: Andreas Wolf
Tested-by: Andreas Wolf
(cherry picked from commit 3d240dda104fa96b019a4b395c76500e74a1248b)
Reviewed-on: https://review.typo3.org/27212

typo3/sysext/backend/Classes/Utility/BackendUtility.php
typo3/sysext/backend/Tests/Unit/Utility/BackendUtilityTest.php

index 7543e4e..60e101f 100644 (file)
@@ -1838,14 +1838,20 @@ class BackendUtility {
                        if (is_array($GLOBALS['TCA'][$table]) && is_array($GLOBALS['TCA'][$table]['columns'][$column]) && is_array($GLOBALS['TCA'][$table]['columns'][$column]['config']['items'])) {
                                // Loop on all selected values
                                foreach ($values as $aValue) {
+                                       $valueFound = FALSE;
                                        foreach ($GLOBALS['TCA'][$table]['columns'][$column]['config']['items'] as $itemConfiguration) {
                                                // Loop on all available items
                                                // Keep matches and move on to next value
                                                if ($aValue == $itemConfiguration[1]) {
                                                        $labels[] = $GLOBALS['LANG']->sL($itemConfiguration[0]);
+                                                       $valueFound = TRUE;
                                                        break;
                                                }
                                        }
+                                       // no item label found then we use the plain db value
+                                       if (!$valueFound) {
+                                               $labels[] = $aValue;
+                                       }
                                }
                        }
                }
index d659053..8a4db2e 100644 (file)
@@ -457,6 +457,65 @@ class BackendUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        }
 
        /**
+        * Tests concerning getLabelsFromItemsList
+        */
+
+       /**
+        * @test
+        */
+       public function getLabelsFromItemsListReturnsValueIfItemIsFound() {
+               $table = 'foobar';
+               $col = 'someColumn';
+               $tca = array(
+                       'columns' => array(
+                               'someColumn' => array(
+                                       'config' => array(
+                                               'items' => array(
+                                                       '0' => array('aFooLabel', 'foo'),
+                                                       '1' => array('aBarLabel', 'bar')
+                                               )
+                                       )
+                               )
+                       )
+               );
+
+               $tcaBackup = $GLOBALS['TCA'][$table];
+               unset($GLOBALS['TCA'][$table]);
+               $GLOBALS['TCA'][$table] = $tca;
+               $label = $this->fixture->getLabelsFromItemsList($table, $col, 'foo,bar');
+               unset($GLOBALS['TCA'][$table]);
+               $GLOBALS['TCA'][$table] = $tcaBackup;
+               $this->assertEquals('aFooLabel, aBarLabel', $label);
+       }
+
+       /**
+        * @test
+        */
+       public function getLabelsFromItemsListReturnsPlainValueIfItemIsNotFound() {
+               $table = 'foobar';
+               $col = 'someColumn';
+               $tca = array(
+                       'columns' => array(
+                               'someColumn' => array(
+                                       'config' => array(
+                                               'items' => array(
+                                                       '0' => array('aFooLabel', 'foo')
+                                               )
+                                       )
+                               )
+                       )
+               );
+
+               $tcaBackup = $GLOBALS['TCA'][$table];
+               unset($GLOBALS['TCA'][$table]);
+               $GLOBALS['TCA'][$table] = $tca;
+               $label = $this->fixture->getLabelsFromItemsList($table, $col, 'foo,something,missing');
+               unset($GLOBALS['TCA'][$table]);
+               $GLOBALS['TCA'][$table] = $tcaBackup;
+               $this->assertEquals('aFooLabel, something, missing', $label);
+       }
+
+       /**
         * Tests concerning getExcludeFields
         */