[TASK] Avoid redundant condition blocking arrays as form object 37/44137/5
authorClaus Due <claus@namelesscoder.net>
Sun, 18 Oct 2015 00:08:23 +0000 (02:08 +0200)
committerAndreas Fernandez <typo3@scripting-base.de>
Sat, 14 Nov 2015 16:42:15 +0000 (17:42 +0100)
Values of arrays (if formObject) can now be accessed with
property paths e.g. "key1.vars.special"

Change-Id: I578d2ca2d0c5cc5a5ba965e9b7209e88f4af3a88
Resolves: #66533
Releases: master
Reviewed-on: https://review.typo3.org/44137
Reviewed-by: Oliver Eglseder <oliver.eglseder@in2code.de>
Tested-by: Oliver Eglseder <oliver.eglseder@in2code.de>
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
typo3/sysext/fluid/Classes/ViewHelpers/Form/AbstractFormFieldViewHelper.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Form/AbstractFormFieldViewHelperTest.php

index 8a30786..abfe5bb 100644 (file)
@@ -331,11 +331,7 @@ abstract class AbstractFormFieldViewHelper extends AbstractFormViewHelper
         $formObject = $this->viewHelperVariableContainer->get(
             \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'formObject'
         );
-        $propertyName = $this->arguments['property'];
-        if (is_array($formObject)) {
-            return isset($formObject[$propertyName]) ? $formObject[$propertyName] : null;
-        }
-        return ObjectAccess::getPropertyPath($formObject, $propertyName);
+        return ObjectAccess::getPropertyPath($formObject, $this->arguments['property']);
     }
 
     /**
index a4a26d9..1315f9b 100644 (file)
@@ -565,4 +565,31 @@ class AbstractFormFieldViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHe
         $actual = $formViewHelper->_call('renderHiddenFieldForEmptyValue');
         $this->assertEquals($expected, $actual);
     }
+
+    /**
+     * @test
+     */
+    public function getPropertyValueReturnsArrayValueByPropertyPath()
+    {
+        $formFieldViewHelper = $this->getAccessibleMock(
+            \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper::class,
+            ['renderHiddenIdentityField'],
+            [],
+            '',
+            false
+        );
+
+        $this->injectDependenciesIntoViewHelper($formFieldViewHelper);
+        $formFieldViewHelper->_set('arguments', ['property' => 'key1.key2']);
+
+        $this->viewHelperVariableContainer->expects($this->at(0))->method('exists')->with(
+            \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'formObject'
+        )->will($this->returnValue(true));
+        $this->viewHelperVariableContainer->expects($this->at(1))->method('get')->with(
+            \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'formObject'
+        )->will($this->returnValue(['key1' => ['key2' => 'valueX']]));
+
+        $actual = $formFieldViewHelper->_call('getPropertyValue');
+        $this->assertEquals('valueX', $actual);
+    }
 }