summaryrefslogtreecommitdiffstats
path: root/tests/lib/share
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-12-02 14:04:27 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2015-12-02 21:42:14 +0100
commitdcc7ff09ba4cfba6fe200f4f686cca7a1853390c (patch)
tree348352422c29c0bdbfbde3f05e8e041c5c0b03a6 /tests/lib/share
parenteebe2b9c239a7f9e7e127f52ab4b9e97763b0149 (diff)
downloadnextcloud-server-dcc7ff09ba4cfba6fe200f4f686cca7a1853390c.tar.gz
nextcloud-server-dcc7ff09ba4cfba6fe200f4f686cca7a1853390c.zip
Adding unit test for MailNotifications::sendInternalShareMail()
Diffstat (limited to 'tests/lib/share')
-rw-r--r--tests/lib/share/MailNotificationsTest.php101
1 files changed, 70 insertions, 31 deletions
diff --git a/tests/lib/share/MailNotificationsTest.php b/tests/lib/share/MailNotificationsTest.php
index e76550b127d..2124a8bf13b 100644
--- a/tests/lib/share/MailNotificationsTest.php
+++ b/tests/lib/share/MailNotificationsTest.php
@@ -171,37 +171,7 @@ class MailNotificationsTest extends \Test\TestCase {
}
public function testSendLinkShareMailException() {
- $message = $this->getMockBuilder('\OC\Mail\Message')
- ->disableOriginalConstructor()->getMock();
-
- $message
- ->expects($this->once())
- ->method('setSubject')
- ->with('TestUser shared »MyFile« with you');
- $message
- ->expects($this->once())
- ->method('setTo')
- ->with(['lukas@owncloud.com']);
- $message
- ->expects($this->once())
- ->method('setHtmlBody');
- $message
- ->expects($this->once())
- ->method('setPlainBody');
- $message
- ->expects($this->once())
- ->method('setFrom')
- ->with([\OCP\Util::getDefaultEmailAddress('sharing-noreply') => 'TestUser via UnitTestCloud']);
-
- $this->mailer
- ->expects($this->once())
- ->method('createMessage')
- ->will($this->returnValue($message));
- $this->mailer
- ->expects($this->once())
- ->method('send')
- ->with($message)
- ->will($this->throwException(new Exception('Some Exception Message')));
+ $this->setupMailerMock('TestUser shared »MyFile« with you', ['lukas@owncloud.com']);
$mailNotifications = new MailNotifications(
$this->user,
@@ -214,4 +184,73 @@ class MailNotificationsTest extends \Test\TestCase {
$this->assertSame(['lukas@owncloud.com'], $mailNotifications->sendLinkShareMail('lukas@owncloud.com', 'MyFile', 'https://owncloud.com/file/?foo=bar', 3600));
}
+ public function testSendInternalShareMail() {
+ $this->setupMailerMock('TestUser shared »welcome.txt« with you', ['recipient@owncloud.com' => 'Recipient'], false);
+
+ /** @var MailNotifications | PHPUnit_Framework_MockObject_MockObject $mailNotifications */
+ $mailNotifications = $this->getMock('OC\Share\MailNotifications',['getItemSharedWithUser'], [
+ $this->user,
+ $this->l10n,
+ $this->mailer,
+ $this->logger,
+ $this->defaults]);
+
+ $mailNotifications->method('getItemSharedWithUser')
+ ->withAnyParameters()
+ ->willReturn([
+ ['file_target' => '/welcome.txt']
+ ]);
+
+ $recipient = $this->getMockBuilder('\OCP\IUser')
+ ->disableOriginalConstructor()->getMock();
+ $recipient
+ ->expects($this->once())
+ ->method('getEMailAddress')
+ ->willReturn('recipient@owncloud.com');
+ $recipient
+ ->expects($this->once())
+ ->method('getDisplayName')
+ ->willReturn('Recipient');
+
+ $recipientList = [$recipient];
+ $result = $mailNotifications->sendInternalShareMail($recipientList, '3', 'file');
+ $this->assertSame([], $result);
+
+ }
+
+ protected function setupMailerMock($subject, $to, $exceptionOnSend = true) {
+ $message = $this->getMockBuilder('\OC\Mail\Message')
+ ->disableOriginalConstructor()->getMock();
+
+ $message
+ ->expects($this->once())
+ ->method('setSubject')
+ ->with($subject);
+ $message
+ ->expects($this->once())
+ ->method('setTo')
+ ->with($to);
+ $message
+ ->expects($this->once())
+ ->method('setHtmlBody');
+ $message
+ ->expects($this->once())
+ ->method('setPlainBody');
+ $message
+ ->expects($this->once())
+ ->method('setFrom')
+ ->with([\OCP\Util::getDefaultEmailAddress('sharing-noreply') => 'TestUser via UnitTestCloud']);
+
+ $this->mailer
+ ->expects($this->once())
+ ->method('createMessage')
+ ->will($this->returnValue($message));
+ if ($exceptionOnSend) {
+ $this->mailer
+ ->expects($this->once())
+ ->method('send')
+ ->with($message)
+ ->will($this->throwException(new Exception('Some Exception Message')));
+ }
+ }
}