[BUGFIX] respectSubmittedDataValue false has to load property value with Form ViewHelpers 97/44397/6
authorAndreas Allacher <andreas@allacher.com>
Fri, 30 Oct 2015 13:11:30 +0000 (14:11 +0100)
committerOliver Hader <oliver.hader@typo3.org>
Tue, 10 Nov 2015 12:21:37 +0000 (13:21 +0100)
Form related ViewHelpers have to load property values
even if RespectSubmittedDataValue is false.
The corresponding change  https://review.typo3.org/#/c/42298/
ensures that Form related ViewHelpers respect submitted form data.
However, if a form related ViewHelper does not respect submitted data
it still needs to load the property value.

Change-Id: I04d285345f7512f7f3567e54c3dc20d99f935e0f
Relates: #66588
Resolves: #71166
Releases: master
Reviewed-on: https://review.typo3.org/44397
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
Reviewed-by: Sebastian Fischer <typo3@evoweb.de>
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
Tested-by: Oliver Hader <oliver.hader@typo3.org>
typo3/sysext/fluid/Classes/ViewHelpers/Form/AbstractFormFieldViewHelper.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Form/AbstractFormFieldViewHelperTest.php

index d1862eb..8a30786 100644 (file)
@@ -190,6 +190,8 @@ abstract class AbstractFormFieldViewHelper extends AbstractFormViewHelper
             $value = $this->getValueFromSubmittedFormData($value);
         } elseif ($this->hasArgument('value')) {
             $value = $this->arguments['value'];
+        } elseif ($this->isObjectAccessorMode()) {
+            $value = $this->getPropertyValue();
         }
 
         $value = $this->convertToPlainValue($value);
index 33e0c43..a4a26d9 100644 (file)
@@ -48,6 +48,35 @@ class AbstractFormFieldViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHe
     /**
      * @test
      */
+    public function getValueAttributeBuildsValueFromPropertyAndFormObjectIfInObjectAccessorModeAndRespectSubmittedDataValueSetFalse()
+    {
+        $formViewHelper = $this->getAccessibleMock(
+            \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper::class,
+            ['isObjectAccessorMode', 'addAdditionalIdentityPropertiesIfNeeded'], [], '', false
+        );
+        $this->injectDependenciesIntoViewHelper($formViewHelper);
+        $formViewHelper->_set('respectSubmittedDataValue', false);
+
+        $mockObject = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\ClassWithTwoGetters();
+
+        $formViewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(true));
+        $this->viewHelperVariableContainer->expects($this->atLeastOnce())->method('get')->with(
+            \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'formObject'
+        )->will($this->returnValue($mockObject));
+        $this->viewHelperVariableContainer->expects($this->atLeastOnce())->method('exists')->with(
+            \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'formObject'
+        )->will($this->returnValue(true));
+
+        $arguments = ['name' => null, 'value' => null, 'property' => 'value.something'];
+        $formViewHelper->_set('arguments', $arguments);
+        $expected = 'MyString';
+        $actual = $formViewHelper->_call('getValueAttribute');
+        $this->assertSame($expected, $actual);
+    }
+
+    /**
+     * @test
+     */
     public function ifAnAttributeValueIsAnObjectMaintainedByThePersistenceManagerItIsConvertedToAUID()
     {
         $mockPersistenceManager = $this->getMock(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface::class);