Skip to content
Snippets Groups Projects
Commit 7b179396 authored by Andreas Fernandez's avatar Andreas Fernandez Committed by Susanne Moog
Browse files

[BUGFIX] EXT:form - Cover empty strings for "skipIfValueIsEmpty"

This ensures that e.g. unchecked checkboxes are not tried to be
stored in the database as empty strings causing an error on int
fields.

Resolves: #82938
Releases: master, 8.7
Change-Id: I6f1811b8fdf17de4c0dd1fac4dec8076600924c6
Reviewed-on: https://review.typo3.org/54577


Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: default avatarDaniel Lorenz <daniel.lorenz@extco.de>
Tested-by: default avatarDaniel Lorenz <daniel.lorenz@extco.de>
Reviewed-by: default avatarSusanne Moog <susanne.moog@typo3.org>
Tested-by: default avatarSusanne Moog <susanne.moog@typo3.org>
parent bc4efde7
No related merge requests found
......@@ -219,7 +219,7 @@ class SaveToDatabaseFinisher extends AbstractFinisher
{
foreach ($this->getFormValues() as $elementIdentifier => $elementValue) {
if (
$elementValue === null
($elementValue === null || $elementValue === '')
&& isset($elementsConfiguration[$elementIdentifier])
&& isset($elementsConfiguration[$elementIdentifier]['skipIfValueIsEmpty'])
&& $elementsConfiguration[$elementIdentifier]['skipIfValueIsEmpty'] === true
......
......@@ -89,6 +89,64 @@ class SaveToDatabaseFinisherTest extends \TYPO3\TestingFramework\Core\Unit\UnitT
$saveToDatabaseFinisher->execute($this->prophesize(FinisherContext::class)->reveal());
}
/**
* @return array
*/
public function skipIfValueIsEmptyDataProvider()
{
return [
'null value' => [
'value' => null,
'expectedEmpty' => true,
],
'empty string' => [
'value' => '',
'expectedEmpty' => true,
],
'false value' => [
'value' => false,
'expectedEmpty' => false,
],
'space character' => [
'value' => ' ',
'expectedEmpty' => false,
],
'zero' => [
'value' => 0,
'expectedEmpty' => false,
],
'zero float' => [
'value' => 0.0,
'expectedEmpty' => false,
],
];
}
/**
* @test
* @dataProvider skipIfValueIsEmptyDataProvider
* @param mixed $value
* @param bool $expectedEmpty
*/
public function skipIfValueIsEmptyDetectsEmptyValues($value, bool $expectedEmpty)
{
$elementsConfiguration = [
'foo' => [
'mapOnDatabaseColumn' => 'bar',
'skipIfValueIsEmpty' => true,
]
];
$saveToDatabaseFinisher = $this->getAccessibleMock(SaveToDatabaseFinisher::class, ['getFormValues', 'getElementByIdentifier']);
$saveToDatabaseFinisher->method('getFormValues')->willReturn([
'foo' => $value
]);
$saveToDatabaseFinisher->method('getElementByIdentifier')->willReturn($this->prophesize(FormElementInterface::class)->reveal());
$databaseData = $saveToDatabaseFinisher->_call('prepareData', $elementsConfiguration, []);
self:self::assertSame($expectedEmpty, empty($databaseData));
}
/**
* @test
*/
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment