[BUGFIX] displayCond IN operator doesn't work like documented 37/43837/2
authorThomas Maroschik <tmaroschik@dfau.de>
Mon, 5 Oct 2015 20:49:12 +0000 (22:49 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 8 Oct 2015 15:57:52 +0000 (17:57 +0200)
The FormEngine refactoring changed the representation
of field values, so that select boxes are now arrays.
The condition evaluation cannot handle those values as
prior to the refactoring and following the documentation.

This patch changes the behavior to follow strictly the
documentation. The = operator now compares only the first
element in case of an array. The IN operator compares two
potential lists for any match.

Fixes: #70421
Releases: master
Change-Id: I17e610215dede4c1c06c27d4d25ec1672bfccf83
Reviewed-on: http://review.typo3.org/43837
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/backend/Classes/Form/FormDataProvider/EvaluateDisplayConditions.php
typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/EvaluateDisplayConditionsTest.php

index 4eabbcd..855ca31 100644 (file)
@@ -376,13 +376,23 @@ class EvaluateDisplayConditions implements FormDataProviderInterface {
                                        $result = !$result;
                                }
                                break;
-                       case 'IN':
-                       case '!IN':
                        case '=':
                        case '!=':
-                               $result = is_array($fieldValue)
-                                       ? in_array($operand, $fieldValue)
-                                       : GeneralUtility::inList($operand, $fieldValue);
+                               if (is_array($fieldValue) && count($fieldValue) === 1) {
+                                       $fieldValue = array_shift($fieldValue);
+                               }
+                               $result = $fieldValue == $operand;
+                               if ($operator[0] === '!') {
+                                       $result = !$result;
+                               }
+                               break;
+                       case 'IN':
+                       case '!IN':
+                               if (is_array($fieldValue)) {
+                                       $result = count(array_intersect($fieldValue, explode(',', $operand))) > 0;
+                               } else {
+                                       $result = GeneralUtility::inList($operand, $fieldValue);
+                               }
                                if ($operator[0] === '!') {
                                        $result = !$result;
                                }
index 9d5a717..f5624fe 100644 (file)
@@ -417,6 +417,11 @@ class EvaluateDisplayConditionsTest extends UnitTestCase {
                                ['foo' => 'bar'],
                                TRUE,
                        ],
+                       'Field value string comparison against list' => [
+                               'FIELD:foo:IN:bar,baz',
+                               ['foo' => 'baz'],
+                               TRUE,
+                       ],
                        'Field value comparison of 1 against multi-value field of 5 returns true' => [
                                'FIELD:content:BIT:1',
                                ['content' => '5'],
@@ -442,6 +447,11 @@ class EvaluateDisplayConditionsTest extends UnitTestCase {
                                ['foo' => 'bar'],
                                TRUE,
                        ],
+                       'Field value string not equal comparison against list' => [
+                               'FIELD:foo:!IN:bar,baz',
+                               ['foo' => 'foo'],
+                               TRUE,
+                       ],
                        'Field value in range' => [
                                'FIELD:uid:-:3-42',
                                ['uid' => '23'],