[BUGFIX] Evaluate displayConditions based on array values 93/43693/3
authorAnja Leichsenring <aleichsenring@ab-softlab.de>
Thu, 1 Oct 2015 12:44:56 +0000 (14:44 +0200)
committerGeorg Ringer <georg.ringer@gmail.com>
Fri, 2 Oct 2015 06:11:17 +0000 (08:11 +0200)
With the rewrite of the FormEngine, all data defined as select
fields in TCA became arrays in the data provision. Therefore
displayConditions based on single values are not evaluated
correctly anymore.

A check was added, when the array contains only one value, this
one is used to perform the evaluation.

Change-Id: If43067eb5d19748afce02b41ce44a14ca4b7fa1f
Resolves: #70265
Releases: master
Reviewed-on: http://review.typo3.org/43693
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
typo3/sysext/backend/Classes/Form/FormDataProvider/EvaluateDisplayConditions.php
typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/EvaluateDisplayConditionsTest.php

index 5937c01..af0c25d 100644 (file)
@@ -332,6 +332,9 @@ class EvaluateDisplayConditions implements FormDataProviderInterface {
                $result = FALSE;
                switch ($operator) {
                        case 'REQ':
+                               if (is_array($fieldValue) && count($fieldValue) === 1) {
+                                       $fieldValue = array_shift($fieldValue);
+                               }
                                if (strtoupper($operand) === 'TRUE') {
                                        $result = (bool)$fieldValue;
                                } else {
@@ -339,19 +342,34 @@ class EvaluateDisplayConditions implements FormDataProviderInterface {
                                }
                                break;
                        case '>':
+                               if (is_array($fieldValue) && count($fieldValue) === 1) {
+                                       $fieldValue = array_shift($fieldValue);
+                               }
                                $result = $fieldValue > $operand;
                                break;
                        case '<':
+                               if (is_array($fieldValue) && count($fieldValue) === 1) {
+                                       $fieldValue = array_shift($fieldValue);
+                               }
                                $result = $fieldValue < $operand;
                                break;
                        case '>=':
+                               if (is_array($fieldValue) && count($fieldValue) === 1) {
+                                       $fieldValue = array_shift($fieldValue);
+                               }
                                $result = $fieldValue >= $operand;
                                break;
                        case '<=':
+                               if (is_array($fieldValue) && count($fieldValue) === 1) {
+                                       $fieldValue = array_shift($fieldValue);
+                               }
                                $result = $fieldValue <= $operand;
                                break;
                        case '-':
                        case '!-':
+                               if (is_array($fieldValue) && count($fieldValue) === 1) {
+                                       $fieldValue = array_shift($fieldValue);
+                               }
                                list($minimum, $maximum) = explode('-', $operand);
                                $result = $fieldValue >= $minimum && $fieldValue <= $maximum;
                                if ($operator[0] === '!') {
index 9201236..d9fe493 100644 (file)
@@ -602,6 +602,36 @@ class EvaluateDisplayConditionsTest extends UnitTestCase {
        }
 
        /**
+        * @param string $condition
+        * @param array $record
+        * @param string $expectedResult
+        *
+        * @dataProvider conditionStringDataProvider
+        * @test
+        */
+       public function matchConditionStringsWithRecordTestFieldBeingArray($condition, array $record, $expectedResult) {
+               $input = [
+                       'processedTca' => [
+                               'columns' => [
+                                       'testField' => [
+                                               'displayCond' => $condition,
+                                               'config' => [
+                                                       'type' => 'input',
+                                               ],
+                                       ],
+                               ],
+                       ],
+               ];
+               $input['databaseRow'] = $record ?: ['testField' => ['key' => $record['testField']]];
+
+               $expected = $input;
+               if (!$expectedResult) {
+                       unset($expected['processedTca']['columns']['testField']);
+               }
+               $this->assertSame($expected, $this->subject->addData($input));
+       }
+
+       /**
         * Returns data sets for the test matchConditionStrings
         * Each data set is an array with the following elements:
         * - the condition string