summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2020-03-25 08:10:04 +0100
committerGitHub <noreply@github.com>2020-03-25 08:10:04 +0100
commitb93e1e300e70bca18f7ba822f6d8dfa09bc86803 (patch)
tree0088ff767b61915b8116692e46a6def2d6fe98db /tests
parent52957d99d8c4d971d2ad68b87311fde759d784d7 (diff)
parenta16aa995866d3319d9f848e0d5811786fad2f223 (diff)
downloadnextcloud-server-b93e1e300e70bca18f7ba822f6d8dfa09bc86803.tar.gz
nextcloud-server-b93e1e300e70bca18f7ba822f6d8dfa09bc86803.zip
Merge pull request #14722 from tacruc/GpgMailerHooks
Add Mailer events
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Mail/MailerTest.php31
-rw-r--r--tests/lib/Mail/MessageTest.php52
2 files changed, 69 insertions, 14 deletions
diff --git a/tests/lib/Mail/MailerTest.php b/tests/lib/Mail/MailerTest.php
index 3a08cd9acf2..1d19929fe00 100644
--- a/tests/lib/Mail/MailerTest.php
+++ b/tests/lib/Mail/MailerTest.php
@@ -1,6 +1,9 @@
<?php
/**
* Copyright (c) 2014-2015 Lukas Reschke <lukas@owncloud.com>
+ *
+ * @author Arne Hamann <github@arne.email>
+ *
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
@@ -8,14 +11,20 @@
namespace Test\Mail;
+
use OC\Mail\EMailTemplate;
use OC\Mail\Mailer;
+use OC\Mail\Message;
use OCP\Defaults;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IL10N;
use OCP\ILogger;
use OCP\IURLGenerator;
+use OCP\Mail\Events\BeforeMessageSent;
+use OCP\Mail\IMessage;
use Test\TestCase;
+use Swift_SwiftException;
class MailerTest extends TestCase {
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
@@ -30,6 +39,9 @@ class MailerTest extends TestCase {
private $l10n;
/** @var Mailer */
private $mailer;
+ /** @var IEventDispatcher */
+ private $dispatcher;
+
protected function setUp(): void {
parent::setUp();
@@ -39,12 +51,14 @@ class MailerTest extends TestCase {
$this->logger = $this->createMock(ILogger::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->l10n = $this->createMock(IL10N::class);
+ $this->dispatcher = $this->createMock(IEventDispatcher::class);
$this->mailer = new Mailer(
$this->config,
$this->logger,
$this->defaults,
$this->urlGenerator,
- $this->l10n
+ $this->l10n,
+ $this->dispatcher
);
}
@@ -117,6 +131,21 @@ class MailerTest extends TestCase {
$this->assertInstanceOf(\Swift_SendmailTransport::class, $mailer->getTransport());
}
+ public function testEvents() {
+ $message = $this->createMock(Message::class);
+
+ $event = new BeforeMessageSent($message);
+ $this->dispatcher->expects($this->at(0))
+ ->method('dispatchTyped')
+ ->with($this->equalTo($event));
+
+ # We do not care at this point about errors in Swiftmailer
+ try {
+ $this->mailer->send($message);
+ } catch (Swift_SwiftException $e) {
+ }
+ }
+
public function testCreateMessage() {
$this->config
->expects($this->any())
diff --git a/tests/lib/Mail/MessageTest.php b/tests/lib/Mail/MessageTest.php
index e0a0f468a50..ab62cfcfdcb 100644
--- a/tests/lib/Mail/MessageTest.php
+++ b/tests/lib/Mail/MessageTest.php
@@ -27,7 +27,17 @@ class MessageTest extends TestCase {
array(array('lukas@owncloud.com' => 'Lukas Reschke'), array('lukas@owncloud.com' => 'Lukas Reschke')),
array(array('lukas@owncloud.com' => 'Lukas Reschke', 'lukas@öwnclöüd.com', 'lukäs@owncloud.örg' => 'Lükäs Réschke'),
array('lukas@owncloud.com' => 'Lukas Reschke', 'lukas@xn--wncld-iuae2c.com', 'lukäs@owncloud.xn--rg-eka' => 'Lükäs Réschke')),
- array(array('lukas@öwnclöüd.com'), array('lukas@xn--wncld-iuae2c.com'))
+ array(array('lukas@öwnclöüd.com'), array('lukas@xn--wncld-iuae2c.com')),
+ );
+ }
+
+ /**
+ * @return array
+ */
+ public function getMailAddressProvider() {
+ return array(
+ array(NULL, array()),
+ array(array('lukas@owncloud.com' => 'Lukas Reschke'), array('lukas@owncloud.com' => 'Lukas Reschke')),
);
}
@@ -59,13 +69,20 @@ class MessageTest extends TestCase {
$this->message->setFrom(array('lukas@owncloud.com'));
}
- public function testGetFrom() {
+
+ /**
+ * @dataProvider getMailAddressProvider
+ *
+ * @param $swiftresult
+ * @param $return
+ */
+ public function testGetFrom($swiftresult, $return) {
$this->swiftMessage
->expects($this->once())
->method('getFrom')
- ->will($this->returnValue(array('lukas@owncloud.com')));
+ ->will($this->returnValue($swiftresult));
- $this->assertSame(array('lukas@owncloud.com'), $this->message->getFrom());
+ $this->assertSame($return, $this->message->getFrom());
}
public function testSetReplyTo() {
@@ -93,13 +110,16 @@ class MessageTest extends TestCase {
$this->message->setTo(array('lukas@owncloud.com'));
}
- public function testGetTo() {
+ /**
+ * @dataProvider getMailAddressProvider
+ */
+ public function testGetTo($swiftresult,$return) {
$this->swiftMessage
->expects($this->once())
->method('getTo')
- ->will($this->returnValue(array('lukas@owncloud.com')));
+ ->will($this->returnValue($swiftresult));
- $this->assertSame(array('lukas@owncloud.com'), $this->message->getTo());
+ $this->assertSame($return, $this->message->getTo());
}
public function testSetCc() {
@@ -110,13 +130,16 @@ class MessageTest extends TestCase {
$this->message->setCc(array('lukas@owncloud.com'));
}
- public function testGetCc() {
+ /**
+ * @dataProvider getMailAddressProvider
+ */
+ public function testGetCc($swiftresult,$return) {
$this->swiftMessage
->expects($this->once())
->method('getCc')
- ->will($this->returnValue(array('lukas@owncloud.com')));
+ ->will($this->returnValue($swiftresult));
- $this->assertSame(array('lukas@owncloud.com'), $this->message->getCc());
+ $this->assertSame($return, $this->message->getCc());
}
public function testSetBcc() {
@@ -127,13 +150,16 @@ class MessageTest extends TestCase {
$this->message->setBcc(array('lukas@owncloud.com'));
}
- public function testGetBcc() {
+ /**
+ * @dataProvider getMailAddressProvider
+ */
+ public function testGetBcc($swiftresult,$return) {
$this->swiftMessage
->expects($this->once())
->method('getBcc')
- ->will($this->returnValue(array('lukas@owncloud.com')));
+ ->will($this->returnValue($swiftresult));
- $this->assertSame(array('lukas@owncloud.com'), $this->message->getBcc());
+ $this->assertSame($return, $this->message->getBcc());
}
public function testSetSubject() {