diff --git a/typo3/sysext/form/Classes/Domain/Factory/ArrayFormFactory.php b/typo3/sysext/form/Classes/Domain/Factory/ArrayFormFactory.php index 9baf7f2f3cd4e4f8da54770c27323a5c48ca548a..bfbbd24d143f8b82bb6003e58c8a78cf25581c95 100644 --- a/typo3/sysext/form/Classes/Domain/Factory/ArrayFormFactory.php +++ b/typo3/sysext/form/Classes/Domain/Factory/ArrayFormFactory.php @@ -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 index 0000000000000000000000000000000000000000..27d87677cc350d7089490d210507c2b6e16f6c8f --- /dev/null +++ b/typo3/sysext/form/Tests/Unit/Domain/Factory/ArrayFormFactoryTest.php @@ -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); + } +}