Skip to content

Commit

Permalink
Add expiration date to share email
Browse files Browse the repository at this point in the history
Signed-off-by: Olivier Lechevalier <olivier.lechevalier@gmail.com>
  • Loading branch information
RageZBla committed Oct 3, 2019
1 parent e105d19 commit 2a6ab0d
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
4 changes: 4 additions & 0 deletions apps/sharebymail/lib/ShareByMailProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,10 @@ protected function sendMailNotification($filename,
$emailTemplate->addHeader();
$emailTemplate->addHeading($this->l->t('%1$s shared »%2$s« with you', [$initiatorDisplayName, $filename]), false);
$text = $this->l->t('%1$s shared »%2$s« with you.', [$initiatorDisplayName, $filename]);
if ($expiration) {
$relativeDate = (string)$expiration->diff(new \DateTime('now'))->format("%a");
$text .= ' ' . $this->l->t('It will expire in %1$s days.', [$relativeDate]);
}

$emailTemplate->addBodyText(
htmlspecialchars($text . ' ' . $this->l->t('Click the button below to open it.')),
Expand Down
90 changes: 90 additions & 0 deletions apps/sharebymail/tests/ShareByMailProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1112,4 +1112,94 @@ public function testSendMailNotificationWithDifferentUserAndNoUserEmail() {
null,
]);
}

public function testSendMailNotificationWithExpiration() {
$provider = $this->getInstance();
$initiatorUser = $this->createMock(IUser::class);
$this->userManager
->expects($this->once())
->method('get')
->with('InitiatorUser')
->willReturn($initiatorUser);
$initiatorUser
->expects($this->once())
->method('getDisplayName')
->willReturn('Mr. Initiator User');
$message = $this->createMock(Message::class);
$this->mailer
->expects($this->once())
->method('createMessage')
->willReturn($message);
$template = $this->createMock(IEMailTemplate::class);
$this->mailer
->expects($this->once())
->method('createEMailTemplate')
->willReturn($template);
$template
->expects($this->once())
->method('addHeader');
$template
->expects($this->once())
->method('addHeading')
->with('Mr. Initiator User shared »file.txt« with you');
$template
->expects($this->once())
->method('addBodyText')
->with(
'Mr. Initiator User shared »file.txt« with you. It will expire in 7 days. Click the button below to open it.',
'Mr. Initiator User shared »file.txt« with you. It will expire in 7 days.'
);
$template
->expects($this->once())
->method('addBodyButton')
->with(
'Open »file.txt«',
'https://example.com/file.txt'
);
$message
->expects($this->once())
->method('setTo')
->with(['john@doe.com']);
$this->defaults
->expects($this->once())
->method('getName')
->willReturn('UnitTestCloud');
$message
->expects($this->once())
->method('setFrom')
->with([
\OCP\Util::getDefaultEmailAddress('UnitTestCloud') => 'Mr. Initiator User via UnitTestCloud'
]);
$message
->expects($this->never())
->method('setReplyTo');
$template
->expects($this->once())
->method('addFooter')
->with('');
$template
->expects($this->once())
->method('setSubject')
->with('Mr. Initiator User shared »file.txt« with you');
$message
->expects($this->once())
->method('useTemplate')
->with($template);
$this->mailer
->expects($this->once())
->method('send')
->with($message);

$inOneWeek = (new \DateTime('now'))->add(new \DateInterval('P7D'));
self::invokePrivate(
$provider,
'sendMailNotification',
[
'file.txt',
'https://example.com/file.txt',
'InitiatorUser',
'john@doe.com',
$inOneWeek,
]);
}
}
Empty file added phpunit.xml
Empty file.

0 comments on commit 2a6ab0d

Please sign in to comment.