diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index 379b05950..0c999a57d 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -125,7 +125,7 @@ public function prepare(INotification $notification, string $languageCode): INot ] ] ); - $notification->setLink($this->getCardUrl($boardId, $cardId)); + $notification->setLink($this->getCardRedirectUrl($cardId)); break; case 'card-overdue': $cardId = (int)$notification->getObjectId(); @@ -157,7 +157,7 @@ public function prepare(INotification $notification, string $languageCode): INot ], ] ); - $notification->setLink($this->getCardUrl($boardId, $cardId)); + $notification->setLink($this->getCardRedirectUrl($cardId)); break; case 'card-comment-mentioned': $cardId = (int)$notification->getObjectId(); @@ -197,7 +197,7 @@ public function prepare(INotification $notification, string $languageCode): INot if ($notification->getMessage() === '{message}') { $notification->setParsedMessage($notification->getMessageParameters()['message']); } - $notification->setLink($this->getCardUrl($boardId, $cardId)); + $notification->setLink($this->getCardRedirectUrl($cardId)); break; case 'board-shared': $boardId = (int)$notification->getObjectId(); @@ -253,4 +253,8 @@ private function getBoardUrl(int $boardId): string { private function getCardUrl(int $boardId, int $cardId): string { return $this->url->linkToRouteAbsolute('deck.page.indexCard', ['boardId' => $boardId, 'cardId' => $cardId]); } + + private function getCardRedirectUrl(int $cardId): string { + return $this->url->linkToRouteAbsolute('deck.page.redirectToCard', ['cardId' => $cardId]); + } } diff --git a/tests/unit/Notification/NotifierTest.php b/tests/unit/Notification/NotifierTest.php index 491f78d6e..6a42876cb 100644 --- a/tests/unit/Notification/NotifierTest.php +++ b/tests/unit/Notification/NotifierTest.php @@ -83,6 +83,7 @@ public function setUp(): void { return match ($route) { 'deck.page.indexBoard' => '/board/123', 'deck.page.indexCard' => '/board/123/card/234', + 'deck.page.redirectToCard' => '/card/234', }; }); } @@ -135,6 +136,9 @@ public function testPrepareCardOverdue() { $notification->expects($this->once()) ->method('setIcon') ->with('/absolute/deck-dark.svg'); + $notification->expects($this->once()) + ->method('setLink') + ->with('/card/123'); $actualNotification = $this->notifier->prepare($notification, 'en_US'); @@ -351,6 +355,47 @@ public function testPrepareBoardShared($withUserFound = true) { $this->assertEquals($notification, $actualNotification); } + public function testPrepareCardAssignedUsesRedirectUrl() { + /** @var INotification|MockObject $notification */ + $notification = $this->createMock(INotification::class); + $notification->expects($this->once()) + ->method('getApp') + ->willReturn('deck'); + + $notification->expects($this->once()) + ->method('getSubjectParameters') + ->willReturn(['Card title','Board title', 'admin']); + + $notification->expects($this->once()) + ->method('getSubject') + ->willReturn('card-assigned'); + $notification->expects($this->once()) + ->method('getObjectId') + ->willReturn('123'); + $this->stackMapper->expects($this->once()) + ->method('findStackFromCardId') + ->willReturn($this->buildMockStack()); + + $this->url->expects($this->once()) + ->method('imagePath') + ->with('deck', 'deck-dark.svg') + ->willReturn('deck-dark.svg'); + $this->url->expects($this->once()) + ->method('getAbsoluteURL') + ->with('deck-dark.svg') + ->willReturn('/absolute/deck-dark.svg'); + $notification->expects($this->once()) + ->method('setIcon') + ->with('/absolute/deck-dark.svg'); + $notification->expects($this->once()) + ->method('setLink') + ->with('/card/123'); + + $actualNotification = $this->notifier->prepare($notification, 'en_US'); + + $this->assertEquals($notification, $actualNotification); + } + /** * @param int $boardId * @return Stack|MockObject