[+BUGFIX] MVC: Make forwarding of objects work
authorMarc Bastian Heinrichs <heinrichs@mbh-web.de>
Mon, 21 Mar 2011 08:19:27 +0000 (09:19 +0100)
committerMarc Bastian Heinrichs <heinrichs@mbh-web.de>
Mon, 21 Mar 2011 08:19:27 +0000 (09:19 +0100)
When setValue() on Controller_Argument is used with an already mapped
object with the correct datatype, don't try to transform the value.

Fixes: #9687

Change-Id: I95310d85be36dc39bde815fddde042052033a3f4

typo3/sysext/extbase/Classes/MVC/Controller/Argument.php
typo3/sysext/extbase/Tests/Unit/MVC/Controller/ArgumentTest.php

index 542114c..a91e8aa 100644 (file)
@@ -324,7 +324,7 @@ class Tx_Extbase_MVC_Controller_Argument {
         * @api
         */
        public function getValidator() {
-               return $this->validator;
+               return $this->validator;
        }
 
        /**
@@ -345,8 +345,11 @@ class Tx_Extbase_MVC_Controller_Argument {
         * @throws Tx_Extbase_MVC_Exception_InvalidArgumentValue if the argument is not a valid object of type $dataType
         */
        public function setValue($value) {
-               $this->value = $this->transformValue($value);
-
+               if ($value === NULL || (is_object($value) && $value instanceof $this->dataType)) {
+                       $this->value = $value;
+               } else {
+                       $this->value = $this->transformValue($value);
+               }
                return $this;
        }
 
@@ -361,9 +364,6 @@ class Tx_Extbase_MVC_Controller_Argument {
         * @return mixed
         */
        protected function transformValue($value) {
-               if ($value === NULL) {
-                       return NULL;
-               }
                if (!class_exists($this->dataType)) {
                        return $value;
                }
index 37aa0c3..b8e65b5 100644 (file)
@@ -71,6 +71,26 @@ class Tx_Extbase_Tests_Unit_MVC_Controller_ArgumentTest extends Tx_Extbase_Tests
 
        /**
         * @test
+        * @author Karsten Dambekalns <karsten@typo3.org>
+        */
+       public function setValueUsesNullAsIs() {
+               $argument = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('transformValue'), array('dummy', 'ArrayObject'));
+               $argument->expects($this->never())->method('transformValue');
+               $argument->setValue(NULL);
+       }
+
+       /**
+        * @test
+        * @author Karsten Dambekalns <karsten@typo3.org>
+       */
+       public function setValueUsesMatchingInstanceAsIs() {
+               $argument = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('transformValue'), array('dummy', 'ArrayObject'));
+               $argument->expects($this->never())->method('transformValue');
+               $argument->setValue(new ArrayObject());
+       }
+
+       /**
+        * @test
         */
        public function setValueTriesToConvertAnUidIntoTheRealObjectIfTheDataTypeClassSchemaIsSet() {
                $object = new StdClass();