summaryrefslogtreecommitdiffstats
path: root/apps/dav
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav')
-rw-r--r--apps/dav/appinfo/v1/caldav.php3
-rw-r--r--apps/dav/l10n/nl.js3
-rw-r--r--apps/dav/l10n/nl.json3
-rw-r--r--apps/dav/lib/CalDAV/Schedule/IMipPlugin.php321
-rw-r--r--apps/dav/lib/Server.php3
-rw-r--r--apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php96
6 files changed, 379 insertions, 50 deletions
diff --git a/apps/dav/appinfo/v1/caldav.php b/apps/dav/appinfo/v1/caldav.php
index a103f82a420..53f167bea36 100644
--- a/apps/dav/appinfo/v1/caldav.php
+++ b/apps/dav/appinfo/v1/caldav.php
@@ -87,9 +87,8 @@ $server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
$server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin());
if ($sendInvitations) {
- $server->addPlugin(new \OCA\DAV\CalDAV\Schedule\IMipPlugin( \OC::$server->getMailer(), \OC::$server->getLogger(), new \OC\AppFramework\Utility\TimeFactory()));
+ $server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class));
}
-
$server->addPlugin(new ExceptionLoggerPlugin('caldav', \OC::$server->getLogger()));
// And off we go!
diff --git a/apps/dav/l10n/nl.js b/apps/dav/l10n/nl.js
index 094e621c926..26908ebb3fc 100644
--- a/apps/dav/l10n/nl.js
+++ b/apps/dav/l10n/nl.js
@@ -46,6 +46,7 @@ OC.L10N.register(
"Remote Address: %s" : "Extern adres: %s",
"Request ID: %s" : "Aanvraag-ID: %s",
"CalDAV server" : "CalDAV server",
- "Send invitations to attendees" : "Verzend uitnodigingen naar deelnemers"
+ "Send invitations to attendees" : "Verzend uitnodigingen naar deelnemers",
+ "Please make sure to properly set up the email settings above." : "Zorg ervoor dat je de bovenstaande e-mailinstellingen correct instelt."
},
"nplurals=2; plural=(n != 1);");
diff --git a/apps/dav/l10n/nl.json b/apps/dav/l10n/nl.json
index f38a938cd2d..7b55c63d626 100644
--- a/apps/dav/l10n/nl.json
+++ b/apps/dav/l10n/nl.json
@@ -44,6 +44,7 @@
"Remote Address: %s" : "Extern adres: %s",
"Request ID: %s" : "Aanvraag-ID: %s",
"CalDAV server" : "CalDAV server",
- "Send invitations to attendees" : "Verzend uitnodigingen naar deelnemers"
+ "Send invitations to attendees" : "Verzend uitnodigingen naar deelnemers",
+ "Please make sure to properly set up the email settings above." : "Zorg ervoor dat je de bovenstaande e-mailinstellingen correct instelt."
},"pluralForm" :"nplurals=2; plural=(n != 1);"
} \ No newline at end of file
diff --git a/apps/dav/lib/CalDAV/Schedule/IMipPlugin.php b/apps/dav/lib/CalDAV/Schedule/IMipPlugin.php
index 8e1d7e2563d..889b0851336 100644
--- a/apps/dav/lib/CalDAV/Schedule/IMipPlugin.php
+++ b/apps/dav/lib/CalDAV/Schedule/IMipPlugin.php
@@ -24,14 +24,22 @@
namespace OCA\DAV\CalDAV\Schedule;
use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\IConfig;
+use OCP\IL10N;
use OCP\ILogger;
+use OCP\IURLGenerator;
+use OCP\L10N\IFactory as L10NFactory;
+use OCP\Mail\IEMailTemplate;
use OCP\Mail\IMailer;
+use Sabre\CalDAV\Schedule\IMipPlugin as SabreIMipPlugin;
+use Sabre\DAV\Xml\Element\Prop;
use Sabre\VObject\Component\VCalendar;
+use Sabre\VObject\Component\VEvent;
use Sabre\VObject\DateTimeParser;
-use Sabre\VObject\ITip;
-use Sabre\CalDAV\Schedule\IMipPlugin as SabreIMipPlugin;
+use Sabre\VObject\ITip\Message;
+use Sabre\VObject\Parameter;
+use Sabre\VObject\Property;
use Sabre\VObject\Recur\EventIterator;
-
/**
* iMIP handler.
*
@@ -48,6 +56,12 @@ use Sabre\VObject\Recur\EventIterator;
*/
class IMipPlugin extends SabreIMipPlugin {
+ /** @var string */
+ private $userId;
+
+ /** @var IConfig */
+ private $config;
+
/** @var IMailer */
private $mailer;
@@ -57,29 +71,45 @@ class IMipPlugin extends SabreIMipPlugin {
/** @var ITimeFactory */
private $timeFactory;
+ /** @var L10NFactory */
+ private $l10nFactory;
+
+ /** @var IURLGenerator */
+ private $urlGenerator;
+
const MAX_DATE = '2038-01-01';
+ const METHOD_REQUEST = 'request';
+ const METHOD_REPLY = 'reply';
+ const METHOD_CANCEL = 'cancel';
+
/**
- * Creates the email handler.
- *
+ * @param IConfig $config
* @param IMailer $mailer
* @param ILogger $logger
* @param ITimeFactory $timeFactory
+ * @param L10NFactory $l10nFactory
+ * @param IUrlGenerator $urlGenerator
+ * @param string $userId
*/
- function __construct(IMailer $mailer, ILogger $logger, ITimeFactory $timeFactory) {
+ public function __construct(IConfig $config, IMailer $mailer, ILogger $logger, ITimeFactory $timeFactory, L10NFactory $l10nFactory, IURLGenerator $urlGenerator, $userId) {
parent::__construct('');
+ $this->userId = $userId;
+ $this->config = $config;
$this->mailer = $mailer;
$this->logger = $logger;
$this->timeFactory = $timeFactory;
+ $this->l10nFactory = $l10nFactory;
+ $this->urlGenerator = $urlGenerator;
}
/**
* Event handler for the 'schedule' event.
*
- * @param ITip\Message $iTipMessage
+ * @param Message $iTipMessage
* @return void
*/
- function schedule(ITip\Message $iTipMessage) {
+ public function schedule(Message $iTipMessage) {
// Not sending any emails if the system considers the update
// insignificant.
@@ -105,40 +135,100 @@ class IMipPlugin extends SabreIMipPlugin {
return;
}
+ // Strip off mailto:
$sender = substr($iTipMessage->sender, 7);
$recipient = substr($iTipMessage->recipient, 7);
- $senderName = ($iTipMessage->senderName) ? $iTipMessage->senderName : null;
- $recipientName = ($iTipMessage->recipientName) ? $iTipMessage->recipientName : null;
+ $senderName = $iTipMessage->senderName ?: null;
+ $recipientName = $iTipMessage->recipientName ?: null;
- $subject = 'SabreDAV iTIP message';
- switch (strtoupper($iTipMessage->method)) {
- case 'REPLY' :
- $subject = 'Re: ' . $summary;
- break;
- case 'REQUEST' :
- $subject = $summary;
+ /** @var VEvent $vevent */
+ $vevent = $iTipMessage->message->VEVENT;
+
+ $attendee = $this->getCurrentAttendee($iTipMessage);
+ $defaultLang = $this->config->getUserValue($this->userId, 'core', 'lang', $this->l10nFactory->findLanguage());
+ $lang = $this->getAttendeeLangOrDefault($defaultLang, $attendee);
+ $l10n = $this->l10nFactory->get('dav', $lang);
+
+ $meetingAttendeeName = $recipientName ?: $recipient;
+ $meetingInviteeName = $senderName ?: $sender;
+
+ $meetingTitle = $vevent->SUMMARY;
+ $meetingDescription = $vevent->DESCRIPTION;
+
+ $start = $vevent->DTSTART;
+ if (isset($vevent->DTEND)) {
+ $end = $vevent->DTEND;
+ } elseif (isset($vevent->DURATION)) {
+ $isFloating = $vevent->DTSTART->isFloating();
+ $end = clone $vevent->DTSTART;
+ $endDateTime = $end->getDateTime();
+ $endDateTime = $endDateTime->add(DateTimeParser::parse($vevent->DURATION->getValue()));
+ $end->setDateTime($endDateTime, $isFloating);
+ } elseif (!$vevent->DTSTART->hasTime()) {
+ $isFloating = $vevent->DTSTART->isFloating();
+ $end = clone $vevent->DTSTART;
+ $endDateTime = $end->getDateTime();
+ $endDateTime = $endDateTime->modify('+1 day');
+ $end->setDateTime($endDateTime, $isFloating);
+ } else {
+ $end = clone $vevent->DTSTART;
+ }
+
+ $meetingWhen = $this->generateWhenString($l10n, $start, $end);
+
+ $meetingUrl = $vevent->URL;
+ $meetingLocation = $vevent->LOCATION;
+
+ $defaultVal = '--';
+
+ $method = self::METHOD_REQUEST;
+ switch (strtolower($iTipMessage->method)) {
+ case self::METHOD_REPLY:
+ $method = self::METHOD_REPLY;
break;
- case 'CANCEL' :
- $subject = 'Cancelled: ' . $summary;
+ case self::METHOD_CANCEL:
+ $method = self::METHOD_CANCEL;
break;
}
- $contentType = 'text/calendar; charset=UTF-8; method=' . $iTipMessage->method;
+ $data = array(
+ 'attendee_name' => (string)$meetingAttendeeName ?: $defaultVal,
+ 'invitee_name' => (string)$meetingInviteeName ?: $defaultVal,
+ 'meeting_title' => (string)$meetingTitle ?: $defaultVal,
+ 'meeting_description' => (string)$meetingDescription ?: $defaultVal,
+ 'meeting_url' => (string)$meetingUrl ?: $defaultVal,
+ );
+
+ $message = $this->mailer->createMessage()
+ ->setReplyTo([$sender => $senderName])
+ ->setTo([$recipient => $recipientName]);
+
+ $template = $this->mailer->createEMailTemplate('dav.calendarInvite.' . $method, $data);
+ $template->addHeader();
- $message = $this->mailer->createMessage();
+ $this->addSubjectAndHeading($template, $l10n, $method, $summary,
+ $meetingAttendeeName, $meetingInviteeName);
+ $this->addBulletList($template, $l10n, $meetingWhen, $meetingLocation,
+ $meetingDescription, $meetingUrl);
+
+ $template->addFooter();
+ $message->useTemplate($template);
+
+ $attachment = $this->mailer->createAttachment(
+ $iTipMessage->message->serialize(),
+ 'event.ics',// TODO(leon): Make file name unique, e.g. add event id
+ 'text/calendar; method=' . $iTipMessage->method
+ );
+ $message->attach($attachment);
- $message->setReplyTo([$sender => $senderName])
- ->setTo([$recipient => $recipientName])
- ->setSubject($subject)
- ->setBody($iTipMessage->message->serialize(), $contentType);
try {
$failed = $this->mailer->send($message);
+ $iTipMessage->scheduleStatus = '1.1; Scheduling message is sent via iMip';
if ($failed) {
$this->logger->error('Unable to deliver message to {failed}', ['app' => 'dav', 'failed' => implode(', ', $failed)]);
$iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
}
- $iTipMessage->scheduleStatus = '1.1; Scheduling message is sent via iMip';
} catch(\Exception $ex) {
$this->logger->logException($ex, ['app' => 'dav']);
$iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
@@ -151,6 +241,7 @@ class IMipPlugin extends SabreIMipPlugin {
* @return bool
*/
private function isEventInThePast(VCalendar $vObject) {
+ /** @var VEvent $component */
$component = $vObject->VEVENT;
$firstOccurrence = $component->DTSTART->getDateTime()->getTimeStamp();
@@ -159,15 +250,17 @@ class IMipPlugin extends SabreIMipPlugin {
if (isset($component->DTEND)) {
$lastOccurrence = $component->DTEND->getDateTime()->getTimeStamp();
} elseif (isset($component->DURATION)) {
+ /** @var \DateTime $endDate */
$endDate = clone $component->DTSTART->getDateTime();
// $component->DTEND->getDateTime() returns DateTimeImmutable
$endDate = $endDate->add(DateTimeParser::parse($component->DURATION->getValue()));
- $lastOccurrence = $endDate->getTimeStamp();
+ $lastOccurrence = $endDate->getTimestamp();
} elseif (!$component->DTSTART->hasTime()) {
+ /** @var \DateTime $endDate */
$endDate = clone $component->DTSTART->getDateTime();
// $component->DTSTART->getDateTime() returns DateTimeImmutable
$endDate = $endDate->modify('+1 day');
- $lastOccurrence = $endDate->getTimeStamp();
+ $lastOccurrence = $endDate->getTimestamp();
} else {
$lastOccurrence = $firstOccurrence;
}
@@ -190,4 +283,176 @@ class IMipPlugin extends SabreIMipPlugin {
$currentTime = $this->timeFactory->getTime();
return $lastOccurrence < $currentTime;
}
+
+
+ /**
+ * @param Message $iTipMessage
+ * @return null|Property
+ */
+ private function getCurrentAttendee(Message $iTipMessage) {
+ /** @var VEvent $vevent */
+ $vevent = $iTipMessage->message->VEVENT;
+ $attendees = $vevent->select('ATTENDEE');
+ foreach ($attendees as $attendee) {
+ /** @var Property $attendee */
+ if (strcasecmp($attendee->getValue(), $iTipMessage->recipient) === 0) {
+ return $attendee;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @param string $default
+ * @param Property|null $attendee
+ * @return string
+ */
+ private function getAttendeeLangOrDefault($default, Property $attendee = null) {
+ if ($attendee !== null) {
+ $lang = $attendee->offsetGet('LANGUAGE');
+ if ($lang instanceof Parameter) {
+ return $lang->getValue();
+ }
+ }
+ return $default;
+ }
+
+ /**
+ * @param IL10N $l10n
+ * @param Property $dtstart
+ * @param Property $dtend
+ */
+ private function generateWhenString(IL10N $l10n, Property $dtstart, Property $dtend) {
+ $isAllDay = $dtstart instanceof Property\ICalendar\Date;
+
+ /** @var Property\ICalendar\Date | Property\ICalendar\DateTime $dtstart */
+ /** @var Property\ICalendar\Date | Property\ICalendar\DateTime $dtend */
+ /** @var \DateTimeImmutable $dtstartDt */
+ $dtstartDt = $dtstart->getDateTime();
+ /** @var \DateTimeImmutable $dtendDt */
+ $dtendDt = $dtend->getDateTime();
+
+ $diff = $dtstartDt->diff($dtendDt);
+
+ $dtstartDt = new \DateTime($dtstartDt->format(\DateTime::ATOM));
+ $dtendDt = new \DateTime($dtendDt->format(\DateTime::ATOM));
+
+ if ($isAllDay) {
+ // One day event
+ if ($diff->days === 1) {
+ return $l10n->l('date', $dtstartDt, ['width' => 'medium']);
+ }
+
+ //event that spans over multiple days
+ $localeStart = $l10n->l('date', $dtstartDt, ['width' => 'medium']);
+ $localeEnd = $l10n->l('date', $dtendDt, ['width' => 'medium']);
+
+ return $localeStart . ' - ' . $localeEnd;
+ }
+
+ /** @var Property\ICalendar\DateTime $dtstart */
+ /** @var Property\ICalendar\DateTime $dtend */
+ $isFloating = $dtstart->isFloating();
+ $startTimezone = $endTimezone = null;
+ if (!$isFloating) {
+ $prop = $dtstart->offsetGet('TZID');
+ if ($prop instanceof Parameter) {
+ $startTimezone = $prop->getValue();
+ }
+
+ $prop = $dtend->offsetGet('TZID');
+ if ($prop instanceof Parameter) {
+ $endTimezone = $prop->getValue();
+ }
+ }
+
+ $localeStart = $l10n->l('datetime', $dtstartDt, ['width' => 'medium']);
+
+ // always show full date with timezone if timezones are different
+ if ($startTimezone !== $endTimezone) {
+ $localeEnd = $l10n->l('datetime', $dtendDt, ['width' => 'medium']);
+
+ return $localeStart . ' (' . $startTimezone . ') - ' .
+ $localeEnd . ' (' . $endTimezone . ')';
+ }
+
+ // show only end time if date is the same
+ if ($this->isDayEqual($dtstartDt, $dtendDt)) {
+ $localeEnd = $l10n->l('time', $dtendDt, ['width' => 'medium']);
+ } else {
+ $localeEnd = $l10n->l('datetime', $dtendDt, ['width' => 'medium']);
+ }
+
+ return $localeStart . ' - ' . $localeEnd . ' (' . $startTimezone . ')';
+ }
+
+ /**
+ * @param \DateTime $dtStart
+ * @param \DateTime $dtEnd
+ * @return bool
+ */
+ private function isDayEqual(\DateTime $dtStart, \DateTime $dtEnd) {
+ return $dtStart->format('Y-m-d') === $dtEnd->format('Y-m-d');
+ }
+
+ /**
+ * @param IEMailTemplate $template
+ * @param IL10N $l10n
+ * @param string $method
+ * @param string $summary
+ * @param string $attendeeName
+ * @param string $inviteeName
+ */
+ private function addSubjectAndHeading(IEMailTemplate $template, IL10N $l10n,
+ $method, $summary, $attendeeName, $inviteeName) {
+ if ($method === self::METHOD_CANCEL) {
+ $template->setSubject('Cancelled: ' . $summary);
+ $template->addHeading($l10n->t('Invitation canceled'), $l10n->t('Hello %s,', [$attendeeName]));
+ $template->addBodyText($l10n->t('The meeting »%s« with %s was canceled.', [$summary, $inviteeName]));
+ } else if ($method === self::METHOD_REPLY) {
+ $template->setSubject('Re: ' . $summary);
+ $template->addHeading($l10n->t('Invitation updated'), $l10n->t('Hello %s,', [$attendeeName]));
+ $template->addBodyText($l10n->t('The meeting »%s« with %s was updated.', [$summary, $inviteeName]));
+ } else {
+ $template->setSubject('Invitation: ' . $summary);
+ $template->addHeading($l10n->t('%s invited you to »%s«', [$inviteeName, $summary]), $l10n->t('Hello %s,', [$attendeeName]));
+ }
+
+ }
+
+ /**
+ * @param IEMailTemplate $template
+ * @param IL10N $l10n
+ * @param string $time
+ * @param string $location
+ * @param string $description
+ * @param string $url
+ */
+ private function addBulletList(IEMailTemplate $template, IL10N $l10n, $time, $location, $description, $url) {
+ $template->addBodyListItem($time, $l10n->t('When:'),
+ $this->getAbsoluteImagePath('filetypes/text-calendar.svg'));
+
+ if ($location) {
+ $template->addBodyListItem($location, $l10n->t('Where:'),
+ $this->getAbsoluteImagePath('filetypes/location.svg'));
+ }
+ if ($description) {
+ $template->addBodyListItem((string)$description, $l10n->t('Description:'),
+ $this->getAbsoluteImagePath('filetypes/text.svg'));
+ }
+ if ($url) {
+ $template->addBodyListItem((string)$url, $l10n->t('Link:'),
+ $this->getAbsoluteImagePath('filetypes/link.svg'));
+ }
+ }
+
+ /**
+ * @param string $path
+ * @return string
+ */
+ private function getAbsoluteImagePath($path) {
+ return $this->urlGenerator->getAbsoluteURL(
+ $this->urlGenerator->imagePath('core', $path)
+ );
+ }
}
diff --git a/apps/dav/lib/Server.php b/apps/dav/lib/Server.php
index 719e4974755..dfe55959a90 100644
--- a/apps/dav/lib/Server.php
+++ b/apps/dav/lib/Server.php
@@ -77,6 +77,7 @@ class Server {
$dispatcher = \OC::$server->getEventDispatcher();
$timezone = new TimeFactory();
$sendInvitations = \OC::$server->getConfig()->getAppValue('dav', 'sendInvitations', 'yes') === 'yes';
+ $l10nFactory = \OC::$server->getL10NFactory();
$root = new RootCollection();
$this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root));
@@ -139,7 +140,7 @@ class Server {
$this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
$this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin());
if ($sendInvitations) {
- $this->server->addPlugin(new IMipPlugin($mailer, $logger, $timezone));
+ $this->server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class));
}
$this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin());
$this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin());
diff --git a/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php b/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php
index 894617781b5..664e33dfd08 100644
--- a/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php
+++ b/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php
@@ -28,7 +28,15 @@ namespace OCA\DAV\Tests\unit\CalDAV\Schedule;
use OC\Mail\Mailer;
use OCA\DAV\CalDAV\Schedule\IMipPlugin;
use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\IConfig;
+use OCP\IL10N;
use OCP\ILogger;
+use OCP\IURLGenerator;
+use OCP\L10N\IFactory;
+use OCP\Mail\IAttachment;
+use OCP\Mail\IEMailTemplate;
+use OCP\Mail\IMailer;
+use OCP\Mail\IMessage;
use Sabre\VObject\Component\VCalendar;
use Sabre\VObject\ITip\Message;
use Test\TestCase;
@@ -36,17 +44,31 @@ use Test\TestCase;
class IMipPluginTest extends TestCase {
public function testDelivery() {
- $mailMessage = new \OC\Mail\Message(new \Swift_Message());
+ $mailMessage = $this->createMock(IMessage::class);
+ $mailMessage->method('setReplyTo')->willReturn($mailMessage);
+ $mailMessage->method('setTo')->willReturn($mailMessage);
/** @var Mailer | \PHPUnit_Framework_MockObject_MockObject $mailer */
- $mailer = $this->getMockBuilder(Mailer::class)->disableOriginalConstructor()->getMock();
+ $mailer = $this->getMockBuilder(IMailer::class)->disableOriginalConstructor()->getMock();
+ $emailTemplate = $this->createMock(IEMailTemplate::class);
+ $emailAttachment = $this->createMock(IAttachment::class);
+ $mailer->method('createEMailTemplate')->willReturn($emailTemplate);
$mailer->method('createMessage')->willReturn($mailMessage);
+ $mailer->method('createAttachment')->willReturn($emailAttachment);
$mailer->expects($this->once())->method('send');
/** @var ILogger | \PHPUnit_Framework_MockObject_MockObject $logger */
$logger = $this->getMockBuilder(ILogger::class)->disableOriginalConstructor()->getMock();
$timeFactory = $this->getMockBuilder(ITimeFactory::class)->disableOriginalConstructor()->getMock();
$timeFactory->method('getTime')->willReturn(1);
+ /** @var IConfig | \PHPUnit_Framework_MockObject_MockObject $config */
+ $config = $this->createMock(IConfig::class);
+ $l10n = $this->createMock(IL10N::class);
+ /** @var IFactory | \PHPUnit_Framework_MockObject_MockObject $l10nFactory */
+ $l10nFactory = $this->createMock(IFactory::class);
+ $l10nFactory->method('get')->willReturn($l10n);
+ /** @var IURLGenerator | \PHPUnit_Framework_MockObject_MockObject $urlGenerator */
+ $urlGenerator = $this->createMock(IURLGenerator::class);
- $plugin = new IMipPlugin($mailer, $logger, $timeFactory);
+ $plugin = new IMipPlugin($config, $mailer, $logger, $timeFactory, $l10nFactory, $urlGenerator, 'user123');
$message = new Message();
$message->method = 'REQUEST';
$message->message = new VCalendar();
@@ -59,26 +81,46 @@ class IMipPluginTest extends TestCase {
$message->sender = 'mailto:gandalf@wiz.ard';
$message->recipient = 'mailto:frodo@hobb.it';
+ $emailTemplate->expects($this->once())
+ ->method('setSubject')
+ ->with('Invitation: Fellowship meeting');
+ $mailMessage->expects($this->once())
+ ->method('setTo')
+ ->with(['frodo@hobb.it' => null]);
+ $mailMessage->expects($this->once())
+ ->method('setReplyTo')
+ ->with(['gandalf@wiz.ard' => null]);
+
$plugin->schedule($message);
$this->assertEquals('1.1', $message->getScheduleStatus());
- $this->assertEquals('Fellowship meeting', $mailMessage->getSubject());
- $this->assertEquals(['frodo@hobb.it' => null], $mailMessage->getTo());
- $this->assertEquals(['gandalf@wiz.ard' => null], $mailMessage->getReplyTo());
- $this->assertEquals('text/calendar; charset=UTF-8; method=REQUEST', $mailMessage->getSwiftMessage()->getContentType());
}
public function testFailedDelivery() {
- $mailMessage = new \OC\Mail\Message(new \Swift_Message());
+ $mailMessage = $this->createMock(IMessage::class);
+ $mailMessage->method('setReplyTo')->willReturn($mailMessage);
+ $mailMessage->method('setTo')->willReturn($mailMessage);
/** @var Mailer | \PHPUnit_Framework_MockObject_MockObject $mailer */
- $mailer = $this->getMockBuilder(Mailer::class)->disableOriginalConstructor()->getMock();
+ $mailer = $this->getMockBuilder(IMailer::class)->disableOriginalConstructor()->getMock();
+ $emailTemplate = $this->createMock(IEMailTemplate::class);
+ $emailAttachment = $this->createMock(IAttachment::class);
+ $mailer->method('createEMailTemplate')->willReturn($emailTemplate);
$mailer->method('createMessage')->willReturn($mailMessage);
+ $mailer->method('createAttachment')->willReturn($emailAttachment);
$mailer->method('send')->willThrowException(new \Exception());
/** @var ILogger | \PHPUnit_Framework_MockObject_MockObject $logger */
$logger = $this->getMockBuilder(ILogger::class)->disableOriginalConstructor()->getMock();
$timeFactory = $this->getMockBuilder(ITimeFactory::class)->disableOriginalConstructor()->getMock();
$timeFactory->method('getTime')->willReturn(1);
+ /** @var IConfig | \PHPUnit_Framework_MockObject_MockObject $config */
+ $config = $this->createMock(IConfig::class);
+ $l10n = $this->createMock(IL10N::class);
+ /** @var IFactory | \PHPUnit_Framework_MockObject_MockObject $l10nFactory */
+ $l10nFactory = $this->createMock(IFactory::class);
+ $l10nFactory->method('get')->willReturn($l10n);
+ /** @var IURLGenerator | \PHPUnit_Framework_MockObject_MockObject $urlGenerator */
+ $urlGenerator = $this->createMock(IURLGenerator::class);
- $plugin = new IMipPlugin($mailer, $logger, $timeFactory);
+ $plugin = new IMipPlugin($config, $mailer, $logger, $timeFactory, $l10nFactory, $urlGenerator, 'user123');
$message = new Message();
$message->method = 'REQUEST';
$message->message = new VCalendar();
@@ -91,22 +133,34 @@ class IMipPluginTest extends TestCase {
$message->sender = 'mailto:gandalf@wiz.ard';
$message->recipient = 'mailto:frodo@hobb.it';
+ $emailTemplate->expects($this->once())
+ ->method('setSubject')
+ ->with('Invitation: Fellowship meeting');
+ $mailMessage->expects($this->once())
+ ->method('setTo')
+ ->with(['frodo@hobb.it' => null]);
+ $mailMessage->expects($this->once())
+ ->method('setReplyTo')
+ ->with(['gandalf@wiz.ard' => null]);
+
$plugin->schedule($message);
$this->assertEquals('5.0', $message->getScheduleStatus());
- $this->assertEquals('Fellowship meeting', $mailMessage->getSubject());
- $this->assertEquals(['frodo@hobb.it' => null], $mailMessage->getTo());
- $this->assertEquals(['gandalf@wiz.ard' => null], $mailMessage->getReplyTo());
- $this->assertEquals('text/calendar; charset=UTF-8; method=REQUEST', $mailMessage->getSwiftMessage()->getContentType());
}
/**
* @dataProvider dataNoMessageSendForPastEvents
*/
public function testNoMessageSendForPastEvents($veventParams, $expectsMail) {
- $mailMessage = new \OC\Mail\Message(new \Swift_Message());
+ $mailMessage = $this->createMock(IMessage::class);
+ $mailMessage->method('setReplyTo')->willReturn($mailMessage);
+ $mailMessage->method('setTo')->willReturn($mailMessage);
/** @var Mailer | \PHPUnit_Framework_MockObject_MockObject $mailer */
- $mailer = $this->getMockBuilder(Mailer::class)->disableOriginalConstructor()->getMock();
+ $mailer = $this->getMockBuilder(IMailer::class)->disableOriginalConstructor()->getMock();
+ $emailTemplate = $this->createMock(IEMailTemplate::class);
+ $emailAttachment = $this->createMock(IAttachment::class);
+ $mailer->method('createEMailTemplate')->willReturn($emailTemplate);
$mailer->method('createMessage')->willReturn($mailMessage);
+ $mailer->method('createAttachment')->willReturn($emailAttachment);
if ($expectsMail) {
$mailer->expects($this->once())->method('send');
} else {
@@ -116,8 +170,16 @@ class IMipPluginTest extends TestCase {
$logger = $this->getMockBuilder(ILogger::class)->disableOriginalConstructor()->getMock();
$timeFactory = $this->getMockBuilder(ITimeFactory::class)->disableOriginalConstructor()->getMock();
$timeFactory->method('getTime')->willReturn(1496912528);
+ /** @var IConfig | \PHPUnit_Framework_MockObject_MockObject $config */
+ $config = $this->createMock(IConfig::class);
+ $l10n = $this->createMock(IL10N::class);
+ /** @var IFactory | \PHPUnit_Framework_MockObject_MockObject $l10nFactory */
+ $l10nFactory = $this->createMock(IFactory::class);
+ $l10nFactory->method('get')->willReturn($l10n);
+ /** @var IURLGenerator | \PHPUnit_Framework_MockObject_MockObject $urlGenerator */
+ $urlGenerator = $this->createMock(IURLGenerator::class);
- $plugin = new IMipPlugin($mailer, $logger, $timeFactory);
+ $plugin = new IMipPlugin($config, $mailer, $logger, $timeFactory, $l10nFactory, $urlGenerator, 'user123');
$message = new Message();
$message->method = 'REQUEST';
$message->message = new VCalendar();