From 9c8a45aee42626871be0843bcefdc47c0a950d81 Mon Sep 17 00:00:00 2001 From: Mathias Brodala <mbrodala@pagemachine.de> Date: Thu, 7 Sep 2017 20:37:13 +0200 Subject: [PATCH] [BUGFIX] EXT:form - fix error on single database insert Resolves: #81805 Releases: master, 8.7 Change-Id: I8ee3582170db9812d7be2b9710cb4d46335ec86a Reviewed-on: https://review.typo3.org/53969 Tested-by: TYPO3com <no-reply@typo3.com> Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de> Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de> Reviewed-by: Carlos Meyer <cm@davitec.de> Tested-by: Carlos Meyer <cm@davitec.de> Reviewed-by: Daniel Lorenz <daniel.lorenz@extco.de> Reviewed-by: Susanne Moog <susanne.moog@typo3.org> Tested-by: Susanne Moog <susanne.moog@typo3.org> --- .../Finishers/SaveToDatabaseFinisher.php | 2 +- .../Finishers/SaveToDatabaseFinisherTest.php | 51 ++++++++++++++++++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/typo3/sysext/form/Classes/Domain/Finishers/SaveToDatabaseFinisher.php b/typo3/sysext/form/Classes/Domain/Finishers/SaveToDatabaseFinisher.php index 7f53c91ca007..89afdb5dc5a5 100644 --- a/typo3/sysext/form/Classes/Domain/Finishers/SaveToDatabaseFinisher.php +++ b/typo3/sysext/form/Classes/Domain/Finishers/SaveToDatabaseFinisher.php @@ -196,7 +196,7 @@ class SaveToDatabaseFinisher extends AbstractFinisher */ protected function executeInternal() { - if (!is_array($this->options)) { + if (isset($this->options['table'])) { $options[] = $this->options; } else { $options = $this->options; diff --git a/typo3/sysext/form/Tests/Unit/Domain/Finishers/SaveToDatabaseFinisherTest.php b/typo3/sysext/form/Tests/Unit/Domain/Finishers/SaveToDatabaseFinisherTest.php index 7e12d3a95f06..6533e792bd61 100644 --- a/typo3/sysext/form/Tests/Unit/Domain/Finishers/SaveToDatabaseFinisherTest.php +++ b/typo3/sysext/form/Tests/Unit/Domain/Finishers/SaveToDatabaseFinisherTest.php @@ -15,6 +15,7 @@ namespace TYPO3\CMS\Form\Tests\Unit\Domain\Finishers; */ use TYPO3\CMS\Form\Domain\Finishers\Exception\FinisherException; +use TYPO3\CMS\Form\Domain\Finishers\FinisherContext; use TYPO3\CMS\Form\Domain\Finishers\SaveToDatabaseFinisher; use TYPO3\CMS\Form\Domain\Model\FormElements\FormElementInterface; @@ -27,7 +28,7 @@ class SaveToDatabaseFinisherTest extends \TYPO3\TestingFramework\Core\Unit\UnitT /** * @test */ - public function throwExceptionOnInconsistentConfigurationThrowExceptionOnInconsistentConfiguration() + public function throwExceptionOnInconsistentConfigurationThrowsExceptionOnInconsistentConfiguration() { $this->expectException(FinisherException::class); $this->expectExceptionCode(1480469086); @@ -67,4 +68,52 @@ class SaveToDatabaseFinisherTest extends \TYPO3\TestingFramework\Core\Unit\UnitT self::assertSame('one,two', $databaseData['bar']); } + + /** + * @test + */ + public function executeInternalProcessesSingleTable() + { + $saveToDatabaseFinisher = $this->getMockBuilder(SaveToDatabaseFinisher::class) + ->setMethods(['process']) + ->getMock(); + $this->inject($saveToDatabaseFinisher, 'options', [ + 'table' => 'tx_foo', + 'databaseColumnMappings' => [ + 'foo' => 1, + ], + ]); + + $saveToDatabaseFinisher->expects($this->once())->method('process')->with(0); + + $saveToDatabaseFinisher->execute($this->prophesize(FinisherContext::class)->reveal()); + } + + /** + * @test + */ + public function executeInternalProcessesMultipleTables() + { + $saveToDatabaseFinisher = $this->getMockBuilder(SaveToDatabaseFinisher::class) + ->setMethods(['process']) + ->getMock(); + $this->inject($saveToDatabaseFinisher, 'options', [ + [ + 'table' => 'tx_foo', + 'databaseColumnMappings' => [ + 'foo' => 1, + ], + ], + [ + 'table' => 'tx_bar', + 'databaseColumnMappings' => [ + 'bar' => 1, + ], + ], + ]); + + $saveToDatabaseFinisher->expects($this->exactly(2))->method('process')->withConsecutive([0], [1]); + + $saveToDatabaseFinisher->execute($this->prophesize(FinisherContext::class)->reveal()); + } } -- GitLab