-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feature: mail provider backend #45383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,10 @@ | |
| use OCP\Mail\IEMailTemplate; | ||
| use OCP\Mail\IMailer; | ||
| use OCP\Mail\IMessage; | ||
| use OCP\Mail\Provider\IManager as IMailManager; | ||
| use OCP\Mail\Provider\IMessage as IMailMessageNew; | ||
| use OCP\Mail\Provider\IMessageSend as IMailMessageSend; | ||
| use OCP\Mail\Provider\IService as IMailService; | ||
| use PHPUnit\Framework\MockObject\MockObject; | ||
| use Psr\Log\LoggerInterface; | ||
| use Sabre\VObject\Component\VCalendar; | ||
|
|
@@ -26,6 +30,11 @@ | |
| use Test\TestCase; | ||
| use function array_merge; | ||
|
|
||
| interface IMailServiceMock extends IMailService, IMailMessageSend { | ||
| // workaround for creating mock class with multiple interfaces | ||
| // TODO: remove after phpUnit 10 is supported. | ||
| } | ||
|
|
||
| class IMipPluginTest extends TestCase { | ||
|
|
||
| /** @var IMessage|MockObject */ | ||
|
|
@@ -67,6 +76,15 @@ class IMipPluginTest extends TestCase { | |
| /** @var EventComparisonService|MockObject */ | ||
| private $eventComparisonService; | ||
|
|
||
| /** @var IMailManager|MockObject */ | ||
| private $mailManager; | ||
|
|
||
| /** @var IMailService|IMailMessageSend|MockObject */ | ||
| private $mailService; | ||
|
|
||
| /** @var IMailMessageNew|MockObject */ | ||
| private $mailMessageNew; | ||
|
|
||
| protected function setUp(): void { | ||
| $this->mailMessage = $this->createMock(IMessage::class); | ||
| $this->mailMessage->method('setFrom')->willReturn($this->mailMessage); | ||
|
|
@@ -90,10 +108,6 @@ protected function setUp(): void { | |
| $this->config = $this->createMock(IConfig::class); | ||
|
|
||
| $this->user = $this->createMock(IUser::class); | ||
| /* | ||
| $this->user->method('getUID'); | ||
| $this->user->method('getDisplayName'); | ||
| */ | ||
|
|
||
| $this->userSession = $this->createMock(IUserSession::class); | ||
| $this->userSession->method('getUser') | ||
|
|
@@ -107,6 +121,12 @@ protected function setUp(): void { | |
|
|
||
| $this->eventComparisonService = $this->createMock(EventComparisonService::class); | ||
|
|
||
| $this->mailManager = $this->createMock(IMailManager::class); | ||
SebastianKrupinski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| $this->mailService = $this->createMock(IMailServiceMock::class); | ||
|
|
||
| $this->mailMessageNew = $this->createMock(IMailMessageNew::class); | ||
|
|
||
| $this->plugin = new IMipPlugin( | ||
| $this->config, | ||
| $this->mailer, | ||
|
|
@@ -115,7 +135,8 @@ protected function setUp(): void { | |
| $this->defaults, | ||
| $this->userSession, | ||
| $this->service, | ||
| $this->eventComparisonService | ||
| $this->eventComparisonService, | ||
| $this->mailManager, | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -582,6 +603,111 @@ public function testFailedDelivery(): void { | |
| $this->assertEquals('5.0', $message->getScheduleStatus()); | ||
| } | ||
|
|
||
| public function testMailProviderSend(): void { | ||
| // construct iTip message with event and attendees | ||
| $message = new Message(); | ||
| $message->method = 'REQUEST'; | ||
| $calendar = new VCalendar(); | ||
| $event = new VEvent($calendar, 'one', array_merge([ | ||
| 'UID' => 'uid-1234', | ||
| 'SEQUENCE' => 1, | ||
| 'SUMMARY' => 'Fellowship meeting without (!) Boromir', | ||
| 'DTSTART' => new \DateTime('2016-01-01 00:00:00') | ||
| ], [])); | ||
| $event->add('ORGANIZER', 'mailto:[email protected]'); | ||
| $event->add('ATTENDEE', 'mailto:' . '[email protected]', ['RSVP' => 'TRUE', 'CN' => 'Frodo']); | ||
| $message->message = $calendar; | ||
| $message->sender = 'mailto:[email protected]'; | ||
| $message->senderName = 'Mr. Wizard'; | ||
| $message->recipient = 'mailto:' . '[email protected]'; | ||
| // construct | ||
| foreach ($event->select('ATTENDEE') as $entry) { | ||
| if (strcasecmp($entry->getValue(), $message->recipient) === 0) { | ||
| $attendee = $entry; | ||
| } | ||
| } | ||
| // construct body data return | ||
| $data = ['invitee_name' => 'Mr. Wizard', | ||
| 'meeting_title' => 'Fellowship meeting without (!) Boromir', | ||
| 'attendee_name' => '[email protected]' | ||
| ]; | ||
| // construct system config mock returns | ||
| $this->config->expects(self::once()) | ||
| ->method('getAppValue') | ||
| ->with('dav', 'invitation_link_recipients', 'yes') | ||
| ->willReturn('yes'); | ||
| // construct user mock returns | ||
| $this->user->expects(self::any()) | ||
| ->method('getUID') | ||
| ->willReturn('user1'); | ||
| $this->user->expects(self::any()) | ||
| ->method('getDisplayName') | ||
| ->willReturn('Mr. Wizard'); | ||
| // construct user session mock returns | ||
| $this->userSession->expects(self::any()) | ||
| ->method('getUser') | ||
| ->willReturn($this->user); | ||
| // construct service mock returns | ||
| $this->service->expects(self::once()) | ||
| ->method('getLastOccurrence') | ||
| ->willReturn('1496912700'); | ||
| $this->service->expects(self::once()) | ||
| ->method('getCurrentAttendee') | ||
| ->with($message) | ||
| ->willReturn($attendee); | ||
| $this->service->expects(self::once()) | ||
| ->method('isRoomOrResource') | ||
| ->with($attendee) | ||
| ->willReturn(false); | ||
| $this->service->expects(self::once()) | ||
| ->method('buildBodyData') | ||
| ->with($event, null) | ||
| ->willReturn($data); | ||
| $this->service->expects(self::once()) | ||
| ->method('getFrom'); | ||
| $this->service->expects(self::once()) | ||
| ->method('addSubjectAndHeading') | ||
| ->with($this->emailTemplate, 'request', 'Mr. Wizard', 'Fellowship meeting without (!) Boromir', false); | ||
| $this->service->expects(self::once()) | ||
| ->method('addBulletList') | ||
| ->with($this->emailTemplate, $event, $data); | ||
| $this->service->expects(self::once()) | ||
| ->method('getAttendeeRsvpOrReqForParticipant') | ||
| ->willReturn(true); | ||
| $this->service->expects(self::once()) | ||
| ->method('createInvitationToken') | ||
| ->with($message, $event, '1496912700') | ||
| ->willReturn('token'); | ||
| $this->service->expects(self::once()) | ||
| ->method('addResponseButtons') | ||
| ->with($this->emailTemplate, 'token'); | ||
| $this->service->expects(self::once()) | ||
| ->method('addMoreOptionsButton') | ||
| ->with($this->emailTemplate, 'token'); | ||
| $this->eventComparisonService->expects(self::once()) | ||
| ->method('findModified') | ||
| ->willReturn(['old' => [] ,'new' => [$event]]); | ||
| // construct mail mock returns | ||
| $this->mailer->expects(self::once()) | ||
| ->method('validateMailAddress') | ||
| ->with('[email protected]') | ||
| ->willReturn(true); | ||
| // construct mail provider mock returns | ||
| $this->mailService | ||
| ->method('initiateMessage') | ||
| ->willReturn($this->mailMessageNew); | ||
| $this->mailService | ||
| ->method('sendMessage') | ||
| ->with($this->mailMessageNew); | ||
| $this->mailManager | ||
| ->method('findServiceByAddress') | ||
| ->with('user1', '[email protected]') | ||
| ->willReturn($this->mailService); | ||
|
|
||
| $this->plugin->schedule($message); | ||
| $this->assertEquals('1.1', $message->getScheduleStatus()); | ||
| } | ||
|
|
||
| public function testNoOldEvent(): void { | ||
| $message = new Message(); | ||
| $message->method = 'REQUEST'; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.