[BUGFIX] Skip adding child elements if a nested form element is unknown 73/56773/8
authorRalf Zimmermann <ralf.zimmermann@tritum.de>
Sat, 21 Apr 2018 08:06:37 +0000 (10:06 +0200)
committerMathias Brodala <mbrodala@pagemachine.de>
Fri, 18 May 2018 10:03:11 +0000 (12:03 +0200)
Skip adding child elements within the form factory if a nested form
element is unknown.

Resolves: #84833
Releases: master, 8.7
Change-Id: I1cbb87b4c460bd45b58aa6bcca27a88c61a7e92f
Reviewed-on: https://review.typo3.org/56773
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Björn Jacob <bjoern.jacob@tritum.de>
Tested-by: Björn Jacob <bjoern.jacob@tritum.de>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
Reviewed-by: Mathias Brodala <mbrodala@pagemachine.de>
Tested-by: Mathias Brodala <mbrodala@pagemachine.de>
typo3/sysext/form/Classes/Domain/Factory/ArrayFormFactory.php
typo3/sysext/form/Tests/Unit/Domain/Factory/ArrayFormFactoryTest.php [new file with mode: 0644]

index 9baf7f2..bfbbd24 100644 (file)
@@ -112,8 +112,10 @@ class ArrayFormFactory extends AbstractFormFactory
 
         $renderable->setOptions($nestedRenderableConfiguration);
 
-        foreach ($childRenderables as $elementConfiguration) {
-            $this->addNestedRenderable($elementConfiguration, $renderable);
+        if ($renderable instanceof CompositeRenderableInterface) {
+            foreach ($childRenderables as $elementConfiguration) {
+                $this->addNestedRenderable($elementConfiguration, $renderable);
+            }
         }
 
         return $renderable;
diff --git a/typo3/sysext/form/Tests/Unit/Domain/Factory/ArrayFormFactoryTest.php b/typo3/sysext/form/Tests/Unit/Domain/Factory/ArrayFormFactoryTest.php
new file mode 100644 (file)
index 0000000..27d8767
--- /dev/null
@@ -0,0 +1,75 @@
+<?php
+declare(strict_types = 1);
+namespace TYPO3\CMS\Form\Tests\Unit\Domain\Factory;
+
+/*
+ * 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 TYPO3\CMS\Form\Domain\Exception\IdentifierNotValidException;
+use TYPO3\CMS\Form\Domain\Factory\ArrayFormFactory;
+use TYPO3\CMS\Form\Domain\Model\FormElements\Section;
+use TYPO3\CMS\Form\Domain\Model\FormElements\UnknownFormElement;
+
+/**
+ * Test case
+ */
+class ArrayFormFactoryTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
+{
+
+    /**
+     * @test
+     */
+    public function addNestedRenderableThrowsExceptionIfIdentifierIsMissing()
+    {
+        $this->expectException(IdentifierNotValidException::class);
+        $this->expectExceptionCode(1329289436);
+
+        $section = new Section('test', 'page');
+        $arrayFormFactory = $this->getAccessibleMock(ArrayFormFactory::class, ['dummy']);
+
+        $arrayFormFactory->_call('addNestedRenderable', [], $section);
+    }
+
+    /**
+     * @test
+     */
+    public function addNestedRenderableSkipChildElementRenderingIfCompositElementIsUnknown()
+    {
+        $unknownElement = new UnknownFormElement('test-2', 'test');
+
+        $section = $this->prophesize(Section::class);
+        $section->willBeConstructedWith(['test-1', 'Section']);
+        $section->createElement(Argument::cetera())->willReturn($unknownElement);
+
+        $arrayFormFactory = $this->getAccessibleMock(ArrayFormFactory::class, ['dummy']);
+
+        $configuration = [
+            'identifier' => 'test-3',
+            'type' => 'Foo',
+            'renderables' => [
+                0 => [
+                    'identifier' => 'test-4',
+                ],
+            ],
+        ];
+
+        $typeErrorExists = false;
+        try {
+            $arrayFormFactory->_call('addNestedRenderable', $configuration, $section->reveal());
+        } catch (\TypeError $error) {
+            $typeErrorExists = true;
+        }
+        $this->assertFalse($typeErrorExists);
+    }
+}