2015-12-18 10:56:25 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 14:49:16 +00:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
2017-06-08 09:50:17 +00:00
|
|
|
* @copyright Copyright (c) 2017, Georg Ehrke
|
2016-07-21 14:49:16 +00:00
|
|
|
*
|
2017-11-06 19:15:27 +00:00
|
|
|
* @author Georg Ehrke <oc.list@georgehrke.com>
|
2016-07-21 14:49:16 +00:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2017-11-06 14:56:42 +00:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2015-12-18 10:56:25 +00:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-05-25 14:04:15 +00:00
|
|
|
namespace OCA\DAV\Tests\unit\CalDAV\Schedule;
|
2015-12-18 10:56:25 +00:00
|
|
|
|
|
|
|
use OC\Mail\Mailer;
|
|
|
|
use OCA\DAV\CalDAV\Schedule\IMipPlugin;
|
2017-06-08 09:50:17 +00:00
|
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
2017-11-14 14:01:53 +00:00
|
|
|
use OCP\Defaults;
|
2017-11-02 15:38:16 +00:00
|
|
|
use OCP\IConfig;
|
|
|
|
use OCP\IL10N;
|
2015-12-18 10:56:25 +00:00
|
|
|
use OCP\ILogger;
|
2017-11-02 15:38:16 +00:00
|
|
|
use OCP\IURLGenerator;
|
|
|
|
use OCP\L10N\IFactory;
|
|
|
|
use OCP\Mail\IAttachment;
|
|
|
|
use OCP\Mail\IEMailTemplate;
|
|
|
|
use OCP\Mail\IMailer;
|
|
|
|
use OCP\Mail\IMessage;
|
2015-12-18 10:56:25 +00:00
|
|
|
use Sabre\VObject\Component\VCalendar;
|
|
|
|
use Sabre\VObject\ITip\Message;
|
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
class IMipPluginTest extends TestCase {
|
|
|
|
|
|
|
|
public function testDelivery() {
|
2017-11-02 15:38:16 +00:00
|
|
|
$mailMessage = $this->createMock(IMessage::class);
|
2017-11-14 14:01:53 +00:00
|
|
|
$mailMessage->method('setFrom')->willReturn($mailMessage);
|
2017-11-02 15:38:16 +00:00
|
|
|
$mailMessage->method('setReplyTo')->willReturn($mailMessage);
|
|
|
|
$mailMessage->method('setTo')->willReturn($mailMessage);
|
2015-12-18 10:56:25 +00:00
|
|
|
/** @var Mailer | \PHPUnit_Framework_MockObject_MockObject $mailer */
|
2017-11-02 15:38:16 +00:00
|
|
|
$mailer = $this->getMockBuilder(IMailer::class)->disableOriginalConstructor()->getMock();
|
|
|
|
$emailTemplate = $this->createMock(IEMailTemplate::class);
|
|
|
|
$emailAttachment = $this->createMock(IAttachment::class);
|
|
|
|
$mailer->method('createEMailTemplate')->willReturn($emailTemplate);
|
2015-12-18 10:56:25 +00:00
|
|
|
$mailer->method('createMessage')->willReturn($mailMessage);
|
2017-11-02 15:38:16 +00:00
|
|
|
$mailer->method('createAttachment')->willReturn($emailAttachment);
|
2015-12-18 10:56:25 +00:00
|
|
|
$mailer->expects($this->once())->method('send');
|
|
|
|
/** @var ILogger | \PHPUnit_Framework_MockObject_MockObject $logger */
|
2017-10-24 13:26:53 +00:00
|
|
|
$logger = $this->getMockBuilder(ILogger::class)->disableOriginalConstructor()->getMock();
|
2017-06-08 09:50:17 +00:00
|
|
|
$timeFactory = $this->getMockBuilder(ITimeFactory::class)->disableOriginalConstructor()->getMock();
|
|
|
|
$timeFactory->method('getTime')->willReturn(1);
|
2017-11-02 15:38:16 +00:00
|
|
|
/** @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);
|
2017-11-14 14:01:53 +00:00
|
|
|
/** @var Defaults | \PHPUnit_Framework_MockObject_MockObject $defaults */
|
|
|
|
$defaults = $this->createMock(Defaults::class);
|
|
|
|
$defaults->expects($this->once())
|
|
|
|
->method('getName')
|
|
|
|
->will($this->returnValue('Instance Name 123'));
|
2015-12-18 10:56:25 +00:00
|
|
|
|
2017-11-14 14:01:53 +00:00
|
|
|
$plugin = new IMipPlugin($config, $mailer, $logger, $timeFactory, $l10nFactory, $urlGenerator, $defaults, 'user123');
|
2015-12-18 10:56:25 +00:00
|
|
|
$message = new Message();
|
|
|
|
$message->method = 'REQUEST';
|
|
|
|
$message->message = new VCalendar();
|
|
|
|
$message->message->add('VEVENT', [
|
|
|
|
'UID' => $message->uid,
|
|
|
|
'SEQUENCE' => $message->sequence,
|
|
|
|
'SUMMARY' => 'Fellowship meeting',
|
2017-06-08 09:50:17 +00:00
|
|
|
'DTSTART' => new \DateTime('2017-01-01 00:00:00') // 1483228800
|
2015-12-18 10:56:25 +00:00
|
|
|
]);
|
|
|
|
$message->sender = 'mailto:gandalf@wiz.ard';
|
|
|
|
$message->recipient = 'mailto:frodo@hobb.it';
|
|
|
|
|
2017-11-02 15:38:16 +00:00
|
|
|
$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]);
|
|
|
|
|
2015-12-18 10:56:25 +00:00
|
|
|
$plugin->schedule($message);
|
|
|
|
$this->assertEquals('1.1', $message->getScheduleStatus());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFailedDelivery() {
|
2017-11-02 15:38:16 +00:00
|
|
|
$mailMessage = $this->createMock(IMessage::class);
|
2017-11-14 14:01:53 +00:00
|
|
|
$mailMessage->method('setFrom')->willReturn($mailMessage);
|
2017-11-02 15:38:16 +00:00
|
|
|
$mailMessage->method('setReplyTo')->willReturn($mailMessage);
|
|
|
|
$mailMessage->method('setTo')->willReturn($mailMessage);
|
2015-12-18 10:56:25 +00:00
|
|
|
/** @var Mailer | \PHPUnit_Framework_MockObject_MockObject $mailer */
|
2017-11-02 15:38:16 +00:00
|
|
|
$mailer = $this->getMockBuilder(IMailer::class)->disableOriginalConstructor()->getMock();
|
|
|
|
$emailTemplate = $this->createMock(IEMailTemplate::class);
|
|
|
|
$emailAttachment = $this->createMock(IAttachment::class);
|
|
|
|
$mailer->method('createEMailTemplate')->willReturn($emailTemplate);
|
2015-12-18 10:56:25 +00:00
|
|
|
$mailer->method('createMessage')->willReturn($mailMessage);
|
2017-11-02 15:38:16 +00:00
|
|
|
$mailer->method('createAttachment')->willReturn($emailAttachment);
|
2015-12-18 10:56:25 +00:00
|
|
|
$mailer->method('send')->willThrowException(new \Exception());
|
|
|
|
/** @var ILogger | \PHPUnit_Framework_MockObject_MockObject $logger */
|
2017-10-24 13:26:53 +00:00
|
|
|
$logger = $this->getMockBuilder(ILogger::class)->disableOriginalConstructor()->getMock();
|
2017-06-08 09:50:17 +00:00
|
|
|
$timeFactory = $this->getMockBuilder(ITimeFactory::class)->disableOriginalConstructor()->getMock();
|
|
|
|
$timeFactory->method('getTime')->willReturn(1);
|
2017-11-02 15:38:16 +00:00
|
|
|
/** @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);
|
2017-11-14 14:01:53 +00:00
|
|
|
/** @var Defaults | \PHPUnit_Framework_MockObject_MockObject $defaults */
|
|
|
|
$defaults = $this->createMock(Defaults::class);
|
2015-12-18 10:56:25 +00:00
|
|
|
|
2017-11-14 14:01:53 +00:00
|
|
|
$plugin = new IMipPlugin($config, $mailer, $logger, $timeFactory, $l10nFactory, $urlGenerator, $defaults, 'user123');
|
2015-12-18 10:56:25 +00:00
|
|
|
$message = new Message();
|
|
|
|
$message->method = 'REQUEST';
|
|
|
|
$message->message = new VCalendar();
|
|
|
|
$message->message->add('VEVENT', [
|
|
|
|
'UID' => $message->uid,
|
|
|
|
'SEQUENCE' => $message->sequence,
|
|
|
|
'SUMMARY' => 'Fellowship meeting',
|
2017-06-08 09:50:17 +00:00
|
|
|
'DTSTART' => new \DateTime('2017-01-01 00:00:00') // 1483228800
|
2015-12-18 10:56:25 +00:00
|
|
|
]);
|
|
|
|
$message->sender = 'mailto:gandalf@wiz.ard';
|
|
|
|
$message->recipient = 'mailto:frodo@hobb.it';
|
|
|
|
|
2017-11-02 15:38:16 +00:00
|
|
|
$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]);
|
|
|
|
|
2015-12-18 10:56:25 +00:00
|
|
|
$plugin->schedule($message);
|
|
|
|
$this->assertEquals('5.0', $message->getScheduleStatus());
|
|
|
|
}
|
|
|
|
|
2017-06-08 09:50:17 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider dataNoMessageSendForPastEvents
|
|
|
|
*/
|
|
|
|
public function testNoMessageSendForPastEvents($veventParams, $expectsMail) {
|
2017-11-02 15:38:16 +00:00
|
|
|
$mailMessage = $this->createMock(IMessage::class);
|
2017-11-14 14:01:53 +00:00
|
|
|
$mailMessage->method('setFrom')->willReturn($mailMessage);
|
2017-11-02 15:38:16 +00:00
|
|
|
$mailMessage->method('setReplyTo')->willReturn($mailMessage);
|
|
|
|
$mailMessage->method('setTo')->willReturn($mailMessage);
|
2017-06-08 09:50:17 +00:00
|
|
|
/** @var Mailer | \PHPUnit_Framework_MockObject_MockObject $mailer */
|
2017-11-02 15:38:16 +00:00
|
|
|
$mailer = $this->getMockBuilder(IMailer::class)->disableOriginalConstructor()->getMock();
|
|
|
|
$emailTemplate = $this->createMock(IEMailTemplate::class);
|
|
|
|
$emailAttachment = $this->createMock(IAttachment::class);
|
|
|
|
$mailer->method('createEMailTemplate')->willReturn($emailTemplate);
|
2017-06-08 09:50:17 +00:00
|
|
|
$mailer->method('createMessage')->willReturn($mailMessage);
|
2017-11-02 15:38:16 +00:00
|
|
|
$mailer->method('createAttachment')->willReturn($emailAttachment);
|
2017-06-09 10:13:02 +00:00
|
|
|
if ($expectsMail) {
|
|
|
|
$mailer->expects($this->once())->method('send');
|
|
|
|
} else {
|
|
|
|
$mailer->expects($this->never())->method('send');
|
|
|
|
}
|
2017-06-08 09:50:17 +00:00
|
|
|
/** @var ILogger | \PHPUnit_Framework_MockObject_MockObject $logger */
|
2017-10-24 13:26:53 +00:00
|
|
|
$logger = $this->getMockBuilder(ILogger::class)->disableOriginalConstructor()->getMock();
|
2017-06-08 09:50:17 +00:00
|
|
|
$timeFactory = $this->getMockBuilder(ITimeFactory::class)->disableOriginalConstructor()->getMock();
|
|
|
|
$timeFactory->method('getTime')->willReturn(1496912528);
|
2017-11-02 15:38:16 +00:00
|
|
|
/** @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);
|
2017-11-14 14:01:53 +00:00
|
|
|
/** @var Defaults | \PHPUnit_Framework_MockObject_MockObject $defaults */
|
|
|
|
$defaults = $this->createMock(Defaults::class);
|
2017-06-08 09:50:17 +00:00
|
|
|
|
2017-11-14 14:01:53 +00:00
|
|
|
$plugin = new IMipPlugin($config, $mailer, $logger, $timeFactory, $l10nFactory, $urlGenerator, $defaults, 'user123');
|
2017-06-08 09:50:17 +00:00
|
|
|
$message = new Message();
|
|
|
|
$message->method = 'REQUEST';
|
|
|
|
$message->message = new VCalendar();
|
|
|
|
$message->message->add('VEVENT', array_merge([
|
2017-06-09 10:13:02 +00:00
|
|
|
'UID' => 'uid1337',
|
|
|
|
'SEQUENCE' => 42,
|
2017-06-08 09:50:17 +00:00
|
|
|
'SUMMARY' => 'Fellowship meeting',
|
|
|
|
], $veventParams));
|
|
|
|
$message->sender = 'mailto:gandalf@wiz.ard';
|
|
|
|
$message->recipient = 'mailto:frodo@hobb.it';
|
|
|
|
|
|
|
|
$plugin->schedule($message);
|
|
|
|
|
|
|
|
if ($expectsMail) {
|
|
|
|
$this->assertEquals('1.1', $message->getScheduleStatus());
|
|
|
|
} else {
|
|
|
|
$this->assertEquals(false, $message->getScheduleStatus());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function dataNoMessageSendForPastEvents() {
|
|
|
|
return [
|
|
|
|
[['DTSTART' => new \DateTime('2017-01-01 00:00:00')], false],
|
|
|
|
[['DTSTART' => new \DateTime('2017-01-01 00:00:00'), 'DTEND' => new \DateTime('2017-01-01 00:00:00')], false],
|
|
|
|
[['DTSTART' => new \DateTime('2017-01-01 00:00:00'), 'DTEND' => new \DateTime('2017-12-31 00:00:00')], true],
|
2017-06-09 10:13:02 +00:00
|
|
|
[['DTSTART' => new \DateTime('2017-01-01 00:00:00'), 'DURATION' => 'P1D'], false],
|
|
|
|
[['DTSTART' => new \DateTime('2017-01-01 00:00:00'), 'DURATION' => 'P52W'], true],
|
2017-06-08 09:50:17 +00:00
|
|
|
[['DTSTART' => new \DateTime('2017-01-01 00:00:00'), 'DTEND' => new \DateTime('2017-01-01 00:00:00'), 'RRULE' => 'FREQ=WEEKLY'], true],
|
|
|
|
[['DTSTART' => new \DateTime('2017-01-01 00:00:00'), 'DTEND' => new \DateTime('2017-01-01 00:00:00'), 'RRULE' => 'FREQ=WEEKLY;COUNT=3'], false],
|
|
|
|
[['DTSTART' => new \DateTime('2017-01-01 00:00:00'), 'DTEND' => new \DateTime('2017-01-01 00:00:00'), 'RRULE' => 'FREQ=WEEKLY;UNTIL=20170301T000000Z'], false],
|
|
|
|
[['DTSTART' => new \DateTime('2017-01-01 00:00:00'), 'DTEND' => new \DateTime('2017-01-01 00:00:00'), 'RRULE' => 'FREQ=WEEKLY;COUNT=33'], true],
|
|
|
|
[['DTSTART' => new \DateTime('2017-01-01 00:00:00'), 'DTEND' => new \DateTime('2017-01-01 00:00:00'), 'RRULE' => 'FREQ=WEEKLY;UNTIL=20171001T000000Z'], true],
|
|
|
|
];
|
|
|
|
}
|
2015-12-18 10:56:25 +00:00
|
|
|
}
|