From 00b52d8f78bbb92712654c1bb35dd8171bc1b8b4 Mon Sep 17 00:00:00 2001 From: Git'Fellow <12234510+solracsf@users.noreply.github.com> Date: Thu, 6 Aug 2026 19:40:51 +0100 Subject: [PATCH] fix(notifications): Use the target id in guest conversion notifications The rich object describing the converted-to account fell back to the guest id when the target account could not be resolved, so a failed conversion reported the guest twice instead of naming the account it was supposed to become. Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com> --- lib/Notifications/Notifier.php | 2 +- tests/unit/Notifications/NotifierTest.php | 87 +++++++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 tests/unit/Notifications/NotifierTest.php diff --git a/lib/Notifications/Notifier.php b/lib/Notifications/Notifier.php index 0d943cca8..fb972b16e 100644 --- a/lib/Notifications/Notifier.php +++ b/lib/Notifications/Notifier.php @@ -49,7 +49,7 @@ private function getRichMessageParams(string $source, string $target): array { ], 'user' => [ 'type' => $targetUser ? 'user' : 'highlight', - 'id' => $targetUser?->getUID() ?? $source, + 'id' => $targetUser?->getUID() ?? $target, 'name' => $targetUser?->getDisplayName() ?? $target, ], ]; diff --git a/tests/unit/Notifications/NotifierTest.php b/tests/unit/Notifications/NotifierTest.php new file mode 100644 index 000000000..3347ed765 --- /dev/null +++ b/tests/unit/Notifications/NotifierTest.php @@ -0,0 +1,87 @@ +createMock(IL10N::class); + $l10n->method('t') + ->willReturnArgument(0); + $l10nFactory = $this->createMock(IFactory::class); + $l10nFactory->method('get') + ->willReturn($l10n); + + // Both accounts are gone by the time the notification is rendered. + $userManager = $this->createMock(IUserManager::class); + $userManager->method('get') + ->willReturn(null); + + $this->notifier = new Notifier( + $l10nFactory, + $this->createMock(IURLGenerator::class), + $userManager + ); + } + + public function testTransferDoneFallsBackToTheNotifiedIds(): void { + $parameters = $this->prepareTransferNotification('guest-transfer-done'); + + $this->assertSame('guest@example.tld', $parameters['guest']['id']); + $this->assertSame('new_account', $parameters['user']['id']); + } + + public function testTransferFailFallsBackToTheNotifiedIds(): void { + $parameters = $this->prepareTransferNotification('guest-transfer-fail'); + + $this->assertSame('guest@example.tld', $parameters['guest']['id']); + $this->assertSame('new_account', $parameters['user']['id']); + } + + /** + * @return array> + */ + private function prepareTransferNotification(string $subject): array { + $notification = $this->createMock(INotification::class); + $notification->method('getApp') + ->willReturn('guests'); + $notification->method('getSubject') + ->willReturn($subject); + $notification->method('getSubjectParameters') + ->willReturn([ + 'source' => 'guest@example.tld', + 'target' => 'new_account', + ]); + $notification->method('setRichSubject') + ->willReturnSelf(); + + $parameters = []; + $notification->expects($this->once()) + ->method('setRichMessage') + ->willReturnCallback(function (string $message, array $messageParameters) use (&$parameters, $notification): INotification { + $parameters = $messageParameters; + return $notification; + }); + + $this->notifier->prepare($notification, 'en'); + + return $parameters; + } +}