-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: SebastianKrupinski <[email protected]>
- Loading branch information
1 parent
19ba872
commit c3d0b64
Showing
25 changed files
with
2,420 additions
and
31 deletions.
There are no files selected for viewing
This file contains 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 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 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); | ||
|
||
$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 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 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.