[BUGFIX] EXT:form - fix error on single database insert 82/53982/2
authorMathias Brodala <mbrodala@pagemachine.de>
Thu, 7 Sep 2017 18:37:13 +0000 (20:37 +0200)
committerSusanne Moog <susanne.moog@typo3.org>
Fri, 8 Sep 2017 08:34:50 +0000 (10:34 +0200)
Resolves: #81805
Releases: master, 8.7
Change-Id: I8ee3582170db9812d7be2b9710cb4d46335ec86a
Reviewed-on: https://review.typo3.org/53982
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Daniel Lorenz <daniel.lorenz@extco.de>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
typo3/sysext/form/Classes/Domain/Finishers/SaveToDatabaseFinisher.php
typo3/sysext/form/Tests/Unit/Domain/Finishers/SaveToDatabaseFinisherTest.php

index 7f53c91..89afdb5 100644 (file)
@@ -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;
index 7e12d3a..6533e79 100644 (file)
@@ -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());
+    }
 }