Dont concat if one of the strings is empty during part merge

This commit is contained in:
Jan Böhmer 2023-11-24 23:16:26 +01:00
parent 36879dd7da
commit b9956e38b8
2 changed files with 29 additions and 0 deletions

View file

@ -319,6 +319,14 @@ trait EntityMergerHelperTrait
return $t;
}
//Skip empty strings
if (trim($t) === '') {
return trim($o);
}
if (trim($o) === '') {
return trim($t);
}
return trim($t) . $separator . trim($o);
},
$target,
@ -344,6 +352,14 @@ trait EntityMergerHelperTrait
return $t;
}
//Skip empty strings
if (trim($t) === '') {
return trim($o);
}
if (trim($o) === '') {
return trim($t);
}
return sprintf("%s\n\n<b>%s:</b>\n%s",
trim($t),
$other->getName(),

View file

@ -207,6 +207,13 @@ class EntityMergerHelperTraitTest extends KernelTestCase
$obj2->string_property = 'Test1';
$this->assertSame($obj1, $this->mergeTextWithSeparator($obj1, $obj2, 'string_property', ' # '));
$this->assertSame('Test1', $obj1->string_property);
//Test what happens if the second text is empty
$obj1->string_property = 'Test1';
$obj2->string_property = '';
$this->assertSame($obj1, $this->mergeTextWithSeparator($obj1, $obj2, 'string_property', ' # '));
$this->assertSame('Test1', $obj1->string_property);
}
public function testMergeComment(): void
@ -227,5 +234,11 @@ class EntityMergerHelperTraitTest extends KernelTestCase
$obj2->setComment('Comment1');
$this->assertSame($obj1, $this->mergeComment($obj1, $obj2));
$this->assertSame('Comment1', $obj1->getComment());
//Test what happens if the second comment is empty
$obj1->setComment('Comment1');
$obj2->setComment('');
$this->assertSame($obj1, $this->mergeComment($obj1, $obj2));
$this->assertSame('Comment1', $obj1->getComment());
}
}