From 342fe7df5650321aaeb5ed7f8ec86c57031638be Mon Sep 17 00:00:00 2001 From: Git'Fellow <12234510+solracsf@users.noreply.github.com> Date: Thu, 5 Mar 2026 15:09:12 +0100 Subject: [PATCH 1/2] fix(cards): correctly copy label and description when cloning cards Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com> --- lib/Service/CardService.php | 6 +++-- lib/Service/LabelService.php | 35 ++++++++------------------ tests/unit/Service/CardServiceTest.php | 7 ++++-- 3 files changed, 20 insertions(+), 28 deletions(-) diff --git a/lib/Service/CardService.php b/lib/Service/CardService.php index 3b9f97d42..8f0406700 100644 --- a/lib/Service/CardService.php +++ b/lib/Service/CardService.php @@ -374,8 +374,10 @@ public function cloneCard(int $id, ?int $targetStackId = null):Card { } $this->assignmentService->assignUser($newCard->getId(), $assignement->getParticipant()); } - $newCard->setDescription($originCard->getDescription()); - $card = $this->enrichCards([$this->cardMapper->update($newCard)]); + $freshCard = $this->cardMapper->find($newCard->getId()); + $freshCard->setDescription($originCard->getDescription()); + $card = $this->enrichCards([$this->cardMapper->update($freshCard)]); + return $card[0]; } diff --git a/lib/Service/LabelService.php b/lib/Service/LabelService.php index bec844f9f..309100c74 100644 --- a/lib/Service/LabelService.php +++ b/lib/Service/LabelService.php @@ -17,29 +17,13 @@ class LabelService { - /** @var LabelMapper */ - private $labelMapper; - /** @var PermissionService */ - private $permissionService; - /** @var BoardService */ - private $boardService; - /** @var ChangeHelper */ - private $changeHelper; - /** @var LabelServiceValidator */ - private LabelServiceValidator $labelServiceValidator; - public function __construct( - LabelMapper $labelMapper, - PermissionService $permissionService, - BoardService $boardService, - ChangeHelper $changeHelper, - LabelServiceValidator $labelServiceValidator, + private LabelMapper $labelMapper, + private PermissionService $permissionService, + private BoardService $boardService, + private ChangeHelper $changeHelper, + private LabelServiceValidator $labelServiceValidator, ) { - $this->labelMapper = $labelMapper; - $this->permissionService = $permissionService; - $this->boardService = $boardService; - $this->changeHelper = $changeHelper; - $this->labelServiceValidator = $labelServiceValidator; } /** @@ -81,6 +65,7 @@ public function create(string $title, string $color, int $boardId): Label { $label->setColor($color); $label->setBoardId($boardId); $this->changeHelper->boardChanged($boardId); + return $this->labelMapper->insert($label); } @@ -90,10 +75,10 @@ public function cloneLabelIfNotExists(int $labelId, int $targetBoardId): Label { $originLabel = $this->find($labelId); $filteredValues = array_values(array_filter($boardLabels, fn ($item) => $item->getTitle() === $originLabel->getTitle())); if (empty($filteredValues)) { - $label = $this->create($originLabel->getTitle(), $originLabel->getColor(), $targetBoardId); - return $label; + return $this->create($originLabel->getTitle(), $originLabel->getColor(), $targetBoardId); } - return $originLabel; + + return $filteredValues[0]; } /** @@ -112,6 +97,7 @@ public function delete(int $id): Label { } $label = $this->labelMapper->delete($this->find($id)); $this->changeHelper->boardChanged($label->getBoardId()); + return $label; } @@ -147,6 +133,7 @@ public function update(int $id, string $title, string $color): Label { $label->setTitle($title); $label->setColor($color); $this->changeHelper->boardChanged($label->getBoardId()); + return $this->labelMapper->update($label); } } diff --git a/tests/unit/Service/CardServiceTest.php b/tests/unit/Service/CardServiceTest.php index 041c012ff..adf04f8c4 100644 --- a/tests/unit/Service/CardServiceTest.php +++ b/tests/unit/Service/CardServiceTest.php @@ -253,15 +253,17 @@ public function testClone() { $clonedCard = clone $card; $clonedCard->setId(2); $clonedCard->setStackId(1234); + $this->cardMapper->expects($this->exactly(2)) ->method('insert') ->willReturn($card, $clonedCard); $this->cardMapper->expects($this->once()) ->method('update')->willReturn($clonedCard); - $this->cardMapper->expects($this->exactly(2)) + + $this->cardMapper->expects($this->exactly(3)) ->method('find') - ->willReturn($card, $clonedCard); + ->willReturn($card, $clonedCard, $clonedCard); $this->cardMapper->expects($this->any()) ->method('findBoardId') @@ -302,6 +304,7 @@ public function testClone() { $this->stackMapper->expects($this->any()) ->method('find') ->willReturn($stackMock); + $b = $this->cardService->create('Card title', 123, 'text', 999, 'admin'); $c = $this->cardService->cloneCard($b->getId(), 1234); $this->assertEquals($b->getTitle(), $c->getTitle()); From 3514bbf742a9d45c51cd2191111880a54ea63601 Mon Sep 17 00:00:00 2001 From: Git'Fellow <12234510+solracsf@users.noreply.github.com> Date: Wed, 11 Mar 2026 19:09:54 +0100 Subject: [PATCH 2/2] chore: Add tests for label and description clone Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com> --- tests/unit/Service/CardServiceTest.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/unit/Service/CardServiceTest.php b/tests/unit/Service/CardServiceTest.php index adf04f8c4..b3f124323 100644 --- a/tests/unit/Service/CardServiceTest.php +++ b/tests/unit/Service/CardServiceTest.php @@ -250,6 +250,8 @@ public function testClone() { $card->setOrder(0); $card->setOwner('admin'); $card->setStackId(12345); + $card->setDescription('A test description'); + $clonedCard = clone $card; $clonedCard->setId(2); $clonedCard->setStackId(1234); @@ -289,6 +291,10 @@ public function testClone() { ->with(1) ->willReturn([$a1]); + $this->assignedUsersMapper->expects($this->any()) + ->method('findIn') + ->willReturn([]); + // check if labels get cloned $label = new Label(); $label->setId(1); @@ -299,6 +305,15 @@ public function testClone() { ->method('assignLabel') ->with($clonedCard->getId(), $label->getId()); + $labelForClone = Label::fromRow([ + 'id' => 1, + 'boardId' => 1234, + 'cardId' => 2, + ]); + $this->labelMapper->expects($this->any()) + ->method('findAssignedLabelsForCards') + ->willReturn([$labelForClone]); + $stackMock = new Stack(); $stackMock->setBoardId(1234); $this->stackMapper->expects($this->any()) @@ -307,9 +322,15 @@ public function testClone() { $b = $this->cardService->create('Card title', 123, 'text', 999, 'admin'); $c = $this->cardService->cloneCard($b->getId(), 1234); + $this->assertEquals($b->getTitle(), $c->getTitle()); $this->assertEquals($b->getOwner(), $c->getOwner()); $this->assertNotEquals($b->getStackId(), $c->getStackId()); + + $this->assertEquals('A test description', $c->getDescription()); + + $this->assertCount(1, $c->getLabels()); + $this->assertEquals($label->getId(), $c->getLabels()[0]->getId()); } public function testDelete() {