Skip to content

Commit

Permalink
Fix: Check text against '' to allow zero (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertSt7 authored Aug 2, 2022
1 parent dc6b946 commit 92da89b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Mapping/Operator/Simple/StaticText.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function process($inputData, bool $dryRun = false)
$inputData = [$inputData];
}

if ($this->text) {
if ($this->text !== '') {
foreach ($inputData as &$data) {
if (!empty($data) || $this->alwaysAdd) {
switch ($this->mode) {
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/SimpleOperatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Pimcore\Bundle\DataImporterBundle\Tests;

use Pimcore\Bundle\DataImporterBundle\Exception\InvalidConfigurationException;
use Pimcore\Bundle\DataImporterBundle\Mapping\Operator\Simple\StaticText;
use Pimcore\Bundle\DataImporterBundle\Mapping\Operator\Simple\StringReplace;
use Pimcore\Tests\Util\TestHelper;

Expand Down Expand Up @@ -82,4 +83,19 @@ public function testStringReplaceProcessFunctionWithEmptyInArray() {
$this->assertEquals($data[1], "");
$this->assertEquals($data[2], "");
}

public function testStaticTextProcessFunctionWithZero() {
$service = $this->tester->grabService(StaticText::class);
$service->setSettings(['mode' => StaticText::MODE_APPEND, 'text' => '0', 'alwaysAdd' => false]);
$data = $service->process("Test");

$this->assertEquals("Test0", $data);
}
public function testStaticTextProcessFunctionWithZeroAndAlwaysAdd() {
$service = $this->tester->grabService(StaticText::class);
$service->setSettings(['mode' => StaticText::MODE_APPEND, 'text' => '0', 'alwaysAdd' => true]);
$data = $service->process("");

$this->assertEquals("0", $data);
}
}

0 comments on commit 92da89b

Please sign in to comment.