Skip to content

Commit

Permalink
fix(DuplicationService): postTitle and postName are now correctly suf…
Browse files Browse the repository at this point in the history
…fixed
  • Loading branch information
williarin committed Jul 14, 2022
1 parent 8886776 commit 6533c7e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Persistence/DuplicationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function duplicate(
$properties = $this->getClassPropertyAttributes($clone, BaseEntity::class, $suffix);

foreach ($properties as $property => $attributes) {
$entity->{$property} .= \in_array(Slug::class, $attributes, true)
$clone->{$property} .= \in_array(Slug::class, $attributes, true)
? '-' . $this->slugger->slug($suffix)
->lower()
->toString()
Expand Down
28 changes: 28 additions & 0 deletions test/Test/Manipulation/DuplicationServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,32 @@ public function testDuplicateByEntity(): void
self::assertSame(array_column($originalTerms, 'name'), array_column($newTerms, 'name'));
self::assertEquals($originalTerms, $newTerms);
}

public function testDuplicateWithCustomSuffix(): void
{
$newEntity = $this->duplicationService->duplicate(
23,
Product::class,
DuplicationService::POST_STATUS_DRAFT,
' Custom Suffix',
);

self::assertNotSame(23, $newEntity->id);
self::assertIsNumeric($newEntity->id);
self::assertSame($newEntity->postTitle, 'Hoodie with Zipper Custom Suffix');
self::assertSame($newEntity->sku, 'woo-hoodie-with-zipper-custom-suffix');
}

public function testDuplicateWithPublishPostStatus(): void
{
$newEntity = $this->duplicationService->duplicate(
23,
Product::class,
DuplicationService::POST_STATUS_PUBLISH,
);

self::assertNotSame(23, $newEntity->id);
self::assertIsNumeric($newEntity->id);
self::assertSame($newEntity->postStatus, 'publish');
}
}

0 comments on commit 6533c7e

Please sign in to comment.