Skip to content

Commit

Permalink
[Bug]: "0" is interpreted as "--EMPTY--" in transformation pipeline (#…
Browse files Browse the repository at this point in the history
…213)

* fix 0 in str_replace-Operator

* Update src/Processing/ImportProcessingService.php

Co-authored-by: mcop1 <[email protected]>

* Apply php-cs-fixer changes

Co-authored-by: mcop1 <[email protected]>
Co-authored-by: robertSt7 <[email protected]>
  • Loading branch information
3 people authored Jun 7, 2022
1 parent e620b64 commit 765af38
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Processing/ImportProcessingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,10 @@ public function generateTransformationResultPreview(array $importDataRow, Mappin
$data = $operator->generateResultPreview($data);
}

if (empty($data)) {
return '-- EMPTY --';
} elseif (is_string($data)) {
if (is_string($data) && $data !== '') {
return $data;
} elseif (empty($data)) {
return '-- EMPTY --';
} elseif (is_array($data)) {
$dataStrings = [];
foreach ($data as $key => $dataEntry) {
Expand Down
36 changes: 36 additions & 0 deletions tests/unit/SimpleOperatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,40 @@ public function testStringReplaceEvaluateReturnTypeFunctionWithWrongInputType()
$service->setSettings(['search' => 'Test', 'replace' => 'Result']);
$service->evaluateReturnType("boolean");
}

public function testStringReplaceProcessFunctionWithZero() {
$service = $this->tester->grabService(StringReplace::class);
$service->setSettings(['search' => 'ObjectKey ', 'replace' => '']);
$data = $service->process("ObjectKey 0");

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

public function testStringReplaceProcessFunctionWithZeroInArray() {
$service = $this->tester->grabService(StringReplace::class);
$service->setSettings(['search' => 'Test', 'replace' => 'Result']);
$data = $service->process(["Test", "Test 0", "0"]);

$this->assertEquals($data[0], "Result");
$this->assertEquals($data[1], "Result 0");
$this->assertEquals($data[2], "0");
}

public function testStringReplaceProcessFunctionWithEmpty() {
$service = $this->tester->grabService(StringReplace::class);
$service->setSettings(['search' => 'ObjectKey', 'replace' => '']);
$data = $service->process("ObjectKey");

$this->assertEquals($data, '');
}

public function testStringReplaceProcessFunctionWithEmptyInArray() {
$service = $this->tester->grabService(StringReplace::class);
$service->setSettings(['search' => 'Test', 'replace' => '']);
$data = $service->process(["Hello Test", "", "Test"]);

$this->assertEquals($data[0], "Hello ");
$this->assertEquals($data[1], "");
$this->assertEquals($data[2], "");
}
}

0 comments on commit 765af38

Please sign in to comment.