[TASK] FormEngine result array cleanup for internal data 44/43944/5
authorAnja Leichsenring <aleichsenring@ab-softlab.de>
Fri, 9 Oct 2015 16:42:21 +0000 (18:42 +0200)
committerMorton Jonuschat <m.jonuschat@mojocode.de>
Fri, 9 Oct 2015 19:13:05 +0000 (21:13 +0200)
Some of the data created within the FormDataCompiler stuff by
the data providers is used only within the data creation
process internally and should not be used by the render
engine later.
An example is the "inline overrule" array that is merged
by one provider to the target TCA and render engine must
not access or handle this later on.
The patch introduces a list of keys in FormDataCompiler
that is unset from the result array before it is returned
to the calling controller.

Change-Id: Ic6abf7787d18a92753ae1415e91f50411ca149d4
Resolves: #70552
Releases: master
Reviewed-on: http://review.typo3.org/43944
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de>
typo3/sysext/backend/Classes/Form/FormDataCompiler.php
typo3/sysext/backend/Tests/Unit/Form/FormDataCompilerTest.php [new file with mode: 0644]
typo3/sysext/backend/Tests/Unit/Form/FormDataComplierTest.php [deleted file]

index d271bc1..c67ca9f 100644 (file)
@@ -28,6 +28,16 @@ class FormDataCompiler
     protected $formDataGroup;
 
     /**
+     * List of top level array elements to be unset from
+     * result array before final result is returned.
+     *
+     * @var array
+     */
+    protected $removeKeysFromFinalResultArray = [
+        'inlineOverruleTypesArray',
+    ];
+
+    /**
      * Get form data group injected
      *
      * @param FormDataGroupInterface $formDataGroup
@@ -96,6 +106,12 @@ class FormDataCompiler
             );
         }
 
+        // Remove some data elements form result that are data provider internal and should
+        // not be exposed to calling object.
+        foreach ($this->removeKeysFromFinalResultArray as $key) {
+            unset($result[$key]);
+        }
+
         return $result;
     }
 
diff --git a/typo3/sysext/backend/Tests/Unit/Form/FormDataCompilerTest.php b/typo3/sysext/backend/Tests/Unit/Form/FormDataCompilerTest.php
new file mode 100644 (file)
index 0000000..78150c8
--- /dev/null
@@ -0,0 +1,163 @@
+<?php
+namespace TYPO3\CMS\Backend\Tests\Unit\Form;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use Prophecy\Argument;
+use Prophecy\Prophecy\ObjectProphecy;
+use TYPO3\CMS\Core\Tests\UnitTestCase;
+use TYPO3\CMS\Backend\Form\FormDataCompiler;
+use TYPO3\CMS\Backend\Form\FormDataGroupInterface;
+
+/**
+ * Test case
+ */
+class FormDataComplierTest extends UnitTestCase
+{
+    /**
+     * @var FormDataCompiler
+     */
+    protected $subject;
+
+    /**
+     * @var FormDataGroupInterface | ObjectProphecy
+     */
+    protected $formDataGroupProphecy;
+
+    protected function setUp()
+    {
+        $this->formDataGroupProphecy = $this->prophesize(FormDataGroupInterface::class);
+        $this->subject = new FormDataCompiler($this->formDataGroupProphecy->reveal());
+    }
+
+    /**
+     * @test
+     */
+    public function compileThrowsExceptionIfInputContainsKeysNotValidInResult()
+    {
+        $input = [
+            'foo' => 'bar',
+        ];
+        $this->setExpectedException(\InvalidArgumentException::class, $this->anything(), 1440601540);
+        $this->subject->compile($input);
+    }
+
+    /**
+     * @test
+     */
+    public function compileThrowsExceptionAtUnknownCommand()
+    {
+        $input = [
+            'command' => 'unknownCommand',
+        ];
+        $this->setExpectedException(\InvalidArgumentException::class, $this->anything(), 1437653136);
+        $this->subject->compile($input);
+    }
+
+    /**
+     * @test
+     */
+    public function compileThrowsExceptionIfNoTableNameGiven()
+    {
+        $input = [
+            'tableName' => '',
+        ];
+        $this->setExpectedException(\InvalidArgumentException::class, $this->anything(), 1437654409);
+        $this->subject->compile($input);
+    }
+
+    /**
+     * @test
+     */
+    public function compileThrowsExceptionIfUidIsNotAnInteger()
+    {
+        $input = [
+            'vanillaUid' => 'foo123',
+        ];
+        $this->setExpectedException(\InvalidArgumentException::class, $this->anything(), 1437654247);
+        $this->subject->compile($input);
+    }
+
+    /**
+     * @test
+     */
+    public function compileThrowsExceptionIfCommandIsEditAndUidIsNegative()
+    {
+        $input = [
+            'command' => 'edit',
+            'vanillaUid' => -100,
+        ];
+        $this->setExpectedException(\InvalidArgumentException::class, $this->anything(), 1437654332);
+        $this->subject->compile($input);
+    }
+
+    /**
+     * @test
+     */
+    public function compileReturnsResultArrayWithInputDataSet()
+    {
+        $input = [
+            'tableName' => 'pages',
+            'vanillaUid' => 123,
+            'command' => 'edit',
+        ];
+        $this->formDataGroupProphecy->compile(Argument::cetera())->willReturnArgument(0);
+        $result = $this->subject->compile($input);
+        $this->assertEquals('pages', $result['tableName']);
+        $this->assertEquals(123, $result['vanillaUid']);
+        $this->assertEquals('edit', $result['command']);
+    }
+
+    /**
+     * @test
+     */
+    public function compileReturnsResultArrayWithAdditionalDataFormFormDataGroup()
+    {
+        $this->formDataGroupProphecy->compile(Argument::cetera())->will(function ($arguments) {
+            $result = $arguments[0];
+            $result['databaseRow'] = 'newData';
+            return $result;
+        });
+        $result = $this->subject->compile([]);
+        $this->assertEquals('newData', $result['databaseRow']);
+    }
+
+    /**
+     * @test
+     */
+    public function compileThrowsExceptionIfFormDataGroupRemovedKeysFromResultArray()
+    {
+        $this->formDataGroupProphecy->compile(Argument::cetera())->will(function ($arguments) {
+            $result = $arguments[0];
+            unset($result['tableName']);
+            return $result;
+        });
+        $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1438079402);
+        $this->subject->compile([]);
+    }
+
+    /**
+     * @test
+     */
+    public function compileThrowsExceptionIfFormDataGroupAddedKeysToResultArray()
+    {
+        $this->formDataGroupProphecy->compile(Argument::cetera())->will(function ($arguments) {
+            $result = $arguments[0];
+            $result['newKey'] = 'newData';
+            return $result;
+        });
+        $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1438079402);
+        $this->subject->compile([]);
+    }
+}
diff --git a/typo3/sysext/backend/Tests/Unit/Form/FormDataComplierTest.php b/typo3/sysext/backend/Tests/Unit/Form/FormDataComplierTest.php
deleted file mode 100644 (file)
index 78150c8..0000000
+++ /dev/null
@@ -1,163 +0,0 @@
-<?php
-namespace TYPO3\CMS\Backend\Tests\Unit\Form;
-
-/*
- * This file is part of the TYPO3 CMS project.
- *
- * It is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, either version 2
- * of the License, or any later version.
- *
- * For the full copyright and license information, please read the
- * LICENSE.txt file that was distributed with this source code.
- *
- * The TYPO3 project - inspiring people to share!
- */
-
-use Prophecy\Argument;
-use Prophecy\Prophecy\ObjectProphecy;
-use TYPO3\CMS\Core\Tests\UnitTestCase;
-use TYPO3\CMS\Backend\Form\FormDataCompiler;
-use TYPO3\CMS\Backend\Form\FormDataGroupInterface;
-
-/**
- * Test case
- */
-class FormDataComplierTest extends UnitTestCase
-{
-    /**
-     * @var FormDataCompiler
-     */
-    protected $subject;
-
-    /**
-     * @var FormDataGroupInterface | ObjectProphecy
-     */
-    protected $formDataGroupProphecy;
-
-    protected function setUp()
-    {
-        $this->formDataGroupProphecy = $this->prophesize(FormDataGroupInterface::class);
-        $this->subject = new FormDataCompiler($this->formDataGroupProphecy->reveal());
-    }
-
-    /**
-     * @test
-     */
-    public function compileThrowsExceptionIfInputContainsKeysNotValidInResult()
-    {
-        $input = [
-            'foo' => 'bar',
-        ];
-        $this->setExpectedException(\InvalidArgumentException::class, $this->anything(), 1440601540);
-        $this->subject->compile($input);
-    }
-
-    /**
-     * @test
-     */
-    public function compileThrowsExceptionAtUnknownCommand()
-    {
-        $input = [
-            'command' => 'unknownCommand',
-        ];
-        $this->setExpectedException(\InvalidArgumentException::class, $this->anything(), 1437653136);
-        $this->subject->compile($input);
-    }
-
-    /**
-     * @test
-     */
-    public function compileThrowsExceptionIfNoTableNameGiven()
-    {
-        $input = [
-            'tableName' => '',
-        ];
-        $this->setExpectedException(\InvalidArgumentException::class, $this->anything(), 1437654409);
-        $this->subject->compile($input);
-    }
-
-    /**
-     * @test
-     */
-    public function compileThrowsExceptionIfUidIsNotAnInteger()
-    {
-        $input = [
-            'vanillaUid' => 'foo123',
-        ];
-        $this->setExpectedException(\InvalidArgumentException::class, $this->anything(), 1437654247);
-        $this->subject->compile($input);
-    }
-
-    /**
-     * @test
-     */
-    public function compileThrowsExceptionIfCommandIsEditAndUidIsNegative()
-    {
-        $input = [
-            'command' => 'edit',
-            'vanillaUid' => -100,
-        ];
-        $this->setExpectedException(\InvalidArgumentException::class, $this->anything(), 1437654332);
-        $this->subject->compile($input);
-    }
-
-    /**
-     * @test
-     */
-    public function compileReturnsResultArrayWithInputDataSet()
-    {
-        $input = [
-            'tableName' => 'pages',
-            'vanillaUid' => 123,
-            'command' => 'edit',
-        ];
-        $this->formDataGroupProphecy->compile(Argument::cetera())->willReturnArgument(0);
-        $result = $this->subject->compile($input);
-        $this->assertEquals('pages', $result['tableName']);
-        $this->assertEquals(123, $result['vanillaUid']);
-        $this->assertEquals('edit', $result['command']);
-    }
-
-    /**
-     * @test
-     */
-    public function compileReturnsResultArrayWithAdditionalDataFormFormDataGroup()
-    {
-        $this->formDataGroupProphecy->compile(Argument::cetera())->will(function ($arguments) {
-            $result = $arguments[0];
-            $result['databaseRow'] = 'newData';
-            return $result;
-        });
-        $result = $this->subject->compile([]);
-        $this->assertEquals('newData', $result['databaseRow']);
-    }
-
-    /**
-     * @test
-     */
-    public function compileThrowsExceptionIfFormDataGroupRemovedKeysFromResultArray()
-    {
-        $this->formDataGroupProphecy->compile(Argument::cetera())->will(function ($arguments) {
-            $result = $arguments[0];
-            unset($result['tableName']);
-            return $result;
-        });
-        $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1438079402);
-        $this->subject->compile([]);
-    }
-
-    /**
-     * @test
-     */
-    public function compileThrowsExceptionIfFormDataGroupAddedKeysToResultArray()
-    {
-        $this->formDataGroupProphecy->compile(Argument::cetera())->will(function ($arguments) {
-            $result = $arguments[0];
-            $result['newKey'] = 'newData';
-            return $result;
-        });
-        $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1438079402);
-        $this->subject->compile([]);
-    }
-}