mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 01:25:55 +02:00
Dont concat if one of the strings is empty during part merge
This commit is contained in:
parent
36879dd7da
commit
b9956e38b8
2 changed files with 29 additions and 0 deletions
|
@ -319,6 +319,14 @@ trait EntityMergerHelperTrait
|
||||||
return $t;
|
return $t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Skip empty strings
|
||||||
|
if (trim($t) === '') {
|
||||||
|
return trim($o);
|
||||||
|
}
|
||||||
|
if (trim($o) === '') {
|
||||||
|
return trim($t);
|
||||||
|
}
|
||||||
|
|
||||||
return trim($t) . $separator . trim($o);
|
return trim($t) . $separator . trim($o);
|
||||||
},
|
},
|
||||||
$target,
|
$target,
|
||||||
|
@ -344,6 +352,14 @@ trait EntityMergerHelperTrait
|
||||||
return $t;
|
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",
|
return sprintf("%s\n\n<b>%s:</b>\n%s",
|
||||||
trim($t),
|
trim($t),
|
||||||
$other->getName(),
|
$other->getName(),
|
||||||
|
|
|
@ -207,6 +207,13 @@ class EntityMergerHelperTraitTest extends KernelTestCase
|
||||||
$obj2->string_property = 'Test1';
|
$obj2->string_property = 'Test1';
|
||||||
$this->assertSame($obj1, $this->mergeTextWithSeparator($obj1, $obj2, 'string_property', ' # '));
|
$this->assertSame($obj1, $this->mergeTextWithSeparator($obj1, $obj2, 'string_property', ' # '));
|
||||||
$this->assertSame('Test1', $obj1->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
|
public function testMergeComment(): void
|
||||||
|
@ -227,5 +234,11 @@ class EntityMergerHelperTraitTest extends KernelTestCase
|
||||||
$obj2->setComment('Comment1');
|
$obj2->setComment('Comment1');
|
||||||
$this->assertSame($obj1, $this->mergeComment($obj1, $obj2));
|
$this->assertSame($obj1, $this->mergeComment($obj1, $obj2));
|
||||||
$this->assertSame('Comment1', $obj1->getComment());
|
$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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue