summaryrefslogtreecommitdiffstats
path: root/tests/lib/share/MailNotificationsTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/share/MailNotificationsTest.php')
-rw-r--r--tests/lib/share/MailNotificationsTest.php173
1 files changed, 96 insertions, 77 deletions
diff --git a/tests/lib/share/MailNotificationsTest.php b/tests/lib/share/MailNotificationsTest.php
index c74fe406db1..2124a8bf13b 100644
--- a/tests/lib/share/MailNotificationsTest.php
+++ b/tests/lib/share/MailNotificationsTest.php
@@ -22,6 +22,7 @@
use OC\Share\MailNotifications;
use OCP\IConfig;
use OCP\IL10N;
+use OCP\IUser;
use OCP\Mail\IMailer;
use OCP\ILogger;
use OCP\Defaults;
@@ -30,23 +31,21 @@ use OCP\Defaults;
* Class MailNotificationsTest
*/
class MailNotificationsTest extends \Test\TestCase {
- /** @var IConfig */
- private $config;
/** @var IL10N */
private $l10n;
- /** @var IMailer */
+ /** @var IMailer | PHPUnit_Framework_MockObject_MockObject */
private $mailer;
/** @var ILogger */
private $logger;
- /** @var Defaults */
+ /** @var Defaults | PHPUnit_Framework_MockObject_MockObject */
private $defaults;
+ /** @var IUser | PHPUnit_Framework_MockObject_MockObject */
+ private $user;
public function setUp() {
parent::setUp();
- $this->config = $this->getMockBuilder('\OCP\IConfig')
- ->disableOriginalConstructor()->getMock();
$this->l10n = $this->getMockBuilder('\OCP\IL10N')
->disableOriginalConstructor()->getMock();
$this->mailer = $this->getMockBuilder('\OCP\Mail\IMailer')
@@ -54,13 +53,30 @@ class MailNotificationsTest extends \Test\TestCase {
$this->logger = $this->getMockBuilder('\OCP\ILogger')
->disableOriginalConstructor()->getMock();
$this->defaults = $this->getMockBuilder('\OCP\Defaults')
- ->disableOriginalConstructor()->getMock();
+ ->disableOriginalConstructor()->getMock();
+ $this->user = $this->getMockBuilder('\OCP\IUser')
+ ->disableOriginalConstructor()->getMock();
$this->l10n->expects($this->any())
->method('t')
->will($this->returnCallback(function($text, $parameters = array()) {
return vsprintf($text, $parameters);
}));
+
+ $this->defaults
+ ->expects($this->once())
+ ->method('getName')
+ ->will($this->returnValue('UnitTestCloud'));
+
+ $this->user
+ ->expects($this->once())
+ ->method('getEMailAddress')
+ ->willReturn('sharer@owncloud.com');
+ $this->user
+ ->expects($this->once())
+ ->method('getDisplayName')
+ ->willReturn('TestUser');
+
}
public function testSendLinkShareMailWithoutReplyTo() {
@@ -96,20 +112,8 @@ class MailNotificationsTest extends \Test\TestCase {
->with($message)
->will($this->returnValue([]));
- $this->defaults
- ->expects($this->once())
- ->method('getName')
- ->will($this->returnValue('UnitTestCloud'));
-
- $this->config
- ->expects($this->at(0))
- ->method('getUserValue')
- ->with('TestUser', 'settings', 'email', null)
- ->will($this->returnValue('sharer@owncloud.com'));
-
$mailNotifications = new MailNotifications(
- 'TestUser',
- $this->config,
+ $this->user,
$this->l10n,
$this->mailer,
$this->logger,
@@ -156,20 +160,8 @@ class MailNotificationsTest extends \Test\TestCase {
->with($message)
->will($this->returnValue([]));
- $this->defaults
- ->expects($this->once())
- ->method('getName')
- ->will($this->returnValue('UnitTestCloud'));
-
- $this->config
- ->expects($this->at(0))
- ->method('getUserValue')
- ->with('TestUser', 'settings', 'email', null)
- ->will($this->returnValue('sharer@owncloud.com'));
-
$mailNotifications = new MailNotifications(
- 'TestUser',
- $this->config,
+ $this->user,
$this->l10n,
$this->mailer,
$this->logger,
@@ -179,52 +171,10 @@ 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->defaults
- ->expects($this->once())
- ->method('getName')
- ->will($this->returnValue('UnitTestCloud'));
-
- $this->config
- ->expects($this->at(0))
- ->method('getUserValue')
- ->with('TestUser', 'settings', 'email', null)
- ->will($this->returnValue('sharer@owncloud.com'));
+ $this->setupMailerMock('TestUser shared »MyFile« with you', ['lukas@owncloud.com']);
$mailNotifications = new MailNotifications(
- 'TestUser',
- $this->config,
+ $this->user,
$this->l10n,
$this->mailer,
$this->logger,
@@ -234,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')));
+ }
+ }
}