timeFactory = $this->createMock(ITimeFactory::class); $this->timeFactory->method('getTime') ->willReturn($today->getTimestamp()); $this->timeFactory->method('getDateTime') ->willReturn($today); // IMipService $this->urlGenerator = $this->createMock(URLGenerator::class); $this->config = $this->createMock(IConfig::class); $this->db = $this->createMock(IDBConnection::class); $this->random = $this->createMock(ISecureRandom::class); $l10n = $this->createMock(L10N::class); $this->l10nFactory = $this->createMock(IFactory::class); $this->l10nFactory->method('findGenericLanguage') ->willReturn('en'); $this->l10nFactory->method('findLocale') ->willReturn('en_US'); $this->l10nFactory->method('get') ->willReturn($l10n); $this->imipService = new IMipService( $this->urlGenerator, $this->config, $this->db, $this->random, $this->l10nFactory, $this->timeFactory, ); // EventComparisonService $this->eventComparisonService = new EventComparisonService(); // IMipPlugin $this->appConfig = $this->createMock(IAppConfig::class); $message = new \OC\Mail\Message(new Email(), false); $this->mailer = $this->createMock(IMailer::class); $this->mailer->method('createMessage') ->willReturn($message); $this->mailer->method('validateMailAddress') ->willReturn(true); $this->logger = new NullLogger(); $this->defaults = $this->createMock(Defaults::class); $this->defaults->method('getName') ->willReturn('Instance Name 123'); $user = $this->createMock(IUser::class); $user->method('getUID') ->willReturn('luigi'); $this->userSession = $this->createMock(IUserSession::class); $this->userSession->method('getUser') ->willReturn($user); $this->mailManager = $this->createMock(IManager::class); $this->imipPlugin = new IMipPlugin( $this->appConfig, $this->mailer, $this->logger, $this->timeFactory, $this->defaults, $this->userSession, $this->imipService, $this->eventComparisonService, $this->mailManager, ); // ITipMessage $calendar = new VCalendar(); $event = new VEvent($calendar, 'VEVENT'); $event->UID = 'uid-1234'; $event->SEQUENCE = 1; $event->SUMMARY = 'Lunch'; $event->DTSTART = new \DateTime('2025-06-20 12:30:00'); $organizer = new CalAddress($calendar, 'ORGANIZER', 'mailto:luigi@example.org'); $event->add($organizer); $attendee = new CalAddress($calendar, 'ATTENDEE', 'mailto:jose@example.org', ['RSVP' => 'TRUE', 'CN' => 'José']); $event->add($attendee); $calendar->add($event); $this->itipMessage = new Message(); $this->itipMessage->method = 'REQUEST'; $this->itipMessage->message = $calendar; $this->itipMessage->sender = 'mailto:luigi@example.org'; $this->itipMessage->senderName = 'Luigi'; $this->itipMessage->recipient = 'mailto:' . 'jose@example.org'; } public function testCharsetMailer(): void { // Arrange $symfonyEmail = null; $this->mailer->expects(self::once()) ->method('send') ->willReturnCallback(function (IMessage $message) use (&$symfonyEmail): array { if ($message instanceof \OC\Mail\Message) { $symfonyEmail = $message->getSymfonyEmail(); } return []; }); // Act $this->imipPlugin->schedule($this->itipMessage); // Assert $this->assertNotNull($symfonyEmail); $body = $symfonyEmail->getBody()->toString(); $this->assertStringContainsString('Content-Type: text/calendar; method=REQUEST; charset="utf-8"; name=event.ics', $body); } public function testCharsetMailProvider(): void { // Arrange $this->appConfig->method('getValueBool') ->with('core', 'mail_providers_enabled', true) ->willReturn(true); $mailMessage = new MailProviderMessage(); $mailService = $this->createStubForIntersectionOfInterfaces([IService::class, IMessageSend::class]); $mailService->method('initiateMessage') ->willReturn($mailMessage); $mailService->expects(self::once()) ->method('sendMessage'); $this->mailManager->method('findServiceByAddress') ->willReturn($mailService); // Act $this->imipPlugin->schedule($this->itipMessage); // Assert $attachments = $mailMessage->getAttachments(); $this->assertCount(1, $attachments); $this->assertStringContainsString('text/calendar; method=REQUEST; charset="utf-8"; name=event.ics', $attachments[0]->getType()); } }