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; + } +}