[BUGFIX] getLabelsFromItemsList() retuns no value when no item found 66/25866/6
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:37:58 +0000 (18:37 +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
typo3/sysext/backend/Classes/Utility/BackendUtility.php
typo3/sysext/backend/Tests/Unit/Utility/BackendUtilityTest.php

index 53eb885..34917e4 100644 (file)
@@ -1863,14 +1863,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 1e67812..2dfb35d 100644 (file)
@@ -458,6 +458,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
         */