diff --git a/lib/Service/Appointments/MailService.php b/lib/Service/Appointments/MailService.php index 42a0ca16f4..f69d68c7b6 100644 --- a/lib/Service/Appointments/MailService.php +++ b/lib/Service/Appointments/MailService.php @@ -31,6 +31,7 @@ use OCA\Calendar\Db\Booking; use OCA\Calendar\Exception\ServiceException; use OCP\Defaults; +use OCP\IConfig; use OCP\IDateTimeFormatter; use OCP\IL10N; use OCP\IURLGenerator; @@ -72,7 +73,8 @@ public function __construct(IMailer $mailer, IURLGenerator $urlGenerator, IDateTimeFormatter $dateFormatter, IFactory $lFactory, - IManager $notificationManager) { + IManager $notificationManager, + private IConfig $userConfig) { $this->userManager = $userManager; $this->mailer = $mailer; $this->l10n = $l10n; @@ -230,7 +232,7 @@ public function sendBookingInformationEmail(Booking $booking, AppointmentConfig private function addBulletList(IEMailTemplate $template, IL10N $l10n, Booking $booking, - AppointmentConfig $config):void { + AppointmentConfig $config): void { $template->addBodyListItem($booking->getDisplayName(), $l10n->t('Appointment for:')); $l = $this->lFactory->findGenericLanguage(); @@ -272,10 +274,9 @@ private function getSysEmail(): string { return \OCP\Util::getDefaultEmailAddress('appointments-noreply'); } - public function sendOrganizerBookingInformationEmail(Booking $booking, AppointmentConfig $config, string $calendar) { + public function sendOrganizerBookingInformationEmail(Booking $booking, AppointmentConfig $config, string $calendar): void { /** @var IUser $user */ $user = $this->userManager->get($config->getUserId()); - if ($user === null) { throw new ServiceException('Could not find organizer'); } @@ -295,12 +296,14 @@ public function sendOrganizerBookingInformationEmail(Booking $booking, Appointme $template = $this->mailer->createEMailTemplate('calendar.confirmOrganizer'); $template->addHeader(); + $lang = $this->userConfig->getUserValue($user->getUID(), 'core', 'lang', null); + $l10n = $this->lFactory->get('calendar', $lang); // Subject - $subject = $this->l10n->t('You have a new appointment booking "%s" from %s', [$config->getName(), $booking->getDisplayName()]); + $subject = $l10n->t('You have a new appointment booking "%s" from %s', [$config->getName(), $booking->getDisplayName()]); $template->setSubject($subject); // Heading - $summary = $this->l10n->t('Dear %s, %s (%s) booked an appointment with you.', [$user->getDisplayName(), $booking->getDisplayName(), $booking->getEmail()]); + $summary = $l10n->t('Dear %s, %s (%s) booked an appointment with you.', [$user->getDisplayName(), $booking->getDisplayName(), $booking->getEmail()]); $template->addHeading($summary); $template->addBodyListItem($booking->getDisplayName() . ' (' . $booking->getEmail() . ')', 'Appointment with:'); diff --git a/tests/php/unit/Service/Appointments/MailServiceTest.php b/tests/php/unit/Service/Appointments/MailServiceTest.php index 0f698d6841..8e4aa82d78 100644 --- a/tests/php/unit/Service/Appointments/MailServiceTest.php +++ b/tests/php/unit/Service/Appointments/MailServiceTest.php @@ -34,6 +34,7 @@ use OCA\Calendar\Service\Appointments\MailService; use OCP\Calendar\ICalendarQuery; use OCP\Defaults; +use OCP\IConfig; use OCP\IDateTimeFormatter; use OCP\IL10N; use OCP\IUser; @@ -77,6 +78,7 @@ class MailServiceTest extends TestCase { /** @var MailService */ private $mailService; + private IConfig|MockObject $userConfig; protected function setUp(): void { parent::setUp(); @@ -94,6 +96,7 @@ protected function setUp(): void { $this->dateFormatter = $this->createMock(IDateTimeFormatter::class); $this->lFactory = $this->createMock(IFactory::class); $this->notificationManager = $this->createMock(IManager::class); + $this->userConfig = $this->createMock(IConfig::class); $this->mailService = new MailService( $this->mailer, $this->userManager, @@ -104,6 +107,7 @@ protected function setUp(): void { $this->dateFormatter, $this->lFactory, $this->notificationManager, + $this->userConfig ); } @@ -528,6 +532,9 @@ public function testSendOrganizerBookingInformationEmail(): void { $this->mailer->expects(self::once()) ->method('createEmailTemplate') ->willReturn($emailTemplate); + $this->userConfig->expects(self::once()) + ->method('getUserValue') + ->willReturn('en'); $emailTemplate->expects(self::once()) ->method('addHeader'); $emailTemplate->expects(self::once()) @@ -547,8 +554,9 @@ public function testSendOrganizerBookingInformationEmail(): void { $this->lFactory->expects(self::once()) ->method('findGenericLanguage') ->willReturn('en'); - $this->lFactory->expects(self::once()) - ->method('get'); + $this->lFactory->expects(self::exactly(2)) + ->method('get') + ->willReturn($this->l10n); $this->dateFormatter->expects(self::once()) ->method('formatDateTimeRelativeDay') ->willReturn('Test'); @@ -583,6 +591,9 @@ public function testSendOrganizerBookingInformationEmailFailed(): void { $this->mailer->expects(self::once()) ->method('createMessage') ->willReturn($mailMessage); + $this->userConfig->expects(self::once()) + ->method('getUserValue') + ->willReturn('en'); $mailMessage->expects(self::once()) ->method('setFrom') ->willReturn($mailMessage); @@ -615,8 +626,9 @@ public function testSendOrganizerBookingInformationEmailFailed(): void { $this->lFactory->expects(self::once()) ->method('findGenericLanguage') ->willReturn('en'); - $this->lFactory->expects(self::once()) - ->method('get'); + $this->lFactory->expects(self::exactly(2)) + ->method('get') + ->willReturn($this->l10n); $this->dateFormatter->expects(self::once()) ->method('formatDateTimeRelativeDay') ->willReturn('Test');