aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/tests/unit
diff options
context:
space:
mode:
authorGeorg Ehrke <developer@georgehrke.com>2017-11-02 16:38:16 +0100
committerGeorg Ehrke <developer@georgehrke.com>2017-11-03 11:20:03 +0100
commit43147aeadaa73ada7421b7a9a226bd925dd7e54b (patch)
tree768a6acf13a64d75fcf58d05d1076d5be64fbb61 /apps/dav/tests/unit
parent1bb048d11f247c744ece1a6804c3482264b600e7 (diff)
downloadnextcloud-server-43147aeadaa73ada7421b7a9a226bd925dd7e54b.tar.gz
nextcloud-server-43147aeadaa73ada7421b7a9a226bd925dd7e54b.zip
fancify invitation emails
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
Diffstat (limited to 'apps/dav/tests/unit')
-rw-r--r--apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php96
1 files changed, 79 insertions, 17 deletions
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();