Skip to content

Commit

Permalink
Generate a valid URL for link notification
Browse files Browse the repository at this point in the history
fixes #23197

* Updated unit test
  • Loading branch information
rullzer committed Mar 15, 2016
1 parent f818057 commit 1db8207
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
6 changes: 4 additions & 2 deletions core/ajax/share.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
\OC::$server->getL10N('lib'),
\OC::$server->getMailer(),
\OC::$server->getLogger(),
$defaults
$defaults,
\OC::$server->getURLGenerator()
);
$result = $mailNotification->sendInternalShareMail($recipientList, $itemSource, $itemType);

Expand Down Expand Up @@ -108,7 +109,8 @@
\OC::$server->getL10N('lib'),
\OC::$server->getMailer(),
\OC::$server->getLogger(),
$defaults
$defaults,
\OC::$server->getURLGenerator()
);

$expiration = null;
Expand Down
13 changes: 11 additions & 2 deletions lib/private/share/mailnotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

use DateTime;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\Mail\IMailer;
use OCP\ILogger;
Expand Down Expand Up @@ -57,24 +58,29 @@ class MailNotifications {
private $defaults;
/** @var ILogger */
private $logger;
/** @var IURLGenerator */
private $urlGenerator;

/**
* @param IUser $user
* @param IL10N $l10n
* @param IMailer $mailer
* @param ILogger $logger
* @param Defaults $defaults
* @param IURLGenerator $urlGenerator
*/
public function __construct(IUser $user,
IL10N $l10n,
IMailer $mailer,
ILogger $logger,
Defaults $defaults) {
Defaults $defaults,
IURLGenerator $urlGenerator) {
$this->l = $l10n;
$this->user = $user;
$this->mailer = $mailer;
$this->logger = $logger;
$this->defaults = $defaults;
$this->urlGenerator = $urlGenerator;

$this->replyTo = $this->user->getEMailAddress();
$this->senderDisplayName = $this->user->getDisplayName();
Expand Down Expand Up @@ -131,7 +137,10 @@ public function sendInternalShareMail($recipientList, $itemSource, $itemType) {
);
}

$link = Util::linkToAbsolute('files', 'index.php', $args);
$link = $this->urlGenerator->linkToRouteAbsolute(
'files.view.index',
$args
);

list($htmlBody, $textBody) = $this->createMailBody($filename, $link, $expiration, 'internal');

Expand Down
27 changes: 23 additions & 4 deletions tests/lib/share/MailNotificationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use OCP\Mail\IMailer;
use OCP\ILogger;
use OCP\Defaults;
use OCP\IURLGenerator;

/**
* Class MailNotificationsTest
Expand All @@ -40,6 +41,8 @@ class MailNotificationsTest extends \Test\TestCase {
private $defaults;
/** @var IUser | PHPUnit_Framework_MockObject_MockObject */
private $user;
/** @var IURLGenerator | PHPUnit_Framework_MockObject_MockObject */
private $urlGenerator;


public function setUp() {
Expand All @@ -55,6 +58,7 @@ public function setUp() {
->disableOriginalConstructor()->getMock();
$this->user = $this->getMockBuilder('\OCP\IUser')
->disableOriginalConstructor()->getMock();
$this->urlGenerator = $this->getMock('\OCP\IURLGenerator');

$this->l10n->expects($this->any())
->method('t')
Expand Down Expand Up @@ -116,7 +120,8 @@ public function testSendLinkShareMailWithoutReplyTo() {
$this->l10n,
$this->mailer,
$this->logger,
$this->defaults
$this->defaults,
$this->urlGenerator
);

$this->assertSame([], $mailNotifications->sendLinkShareMail('lukas@owncloud.com', 'MyFile', 'https://owncloud.com/file/?foo=bar', 3600));
Expand Down Expand Up @@ -180,7 +185,8 @@ public function testSendLinkShareMailWithReplyTo($to, array $expectedTo) {
$this->l10n,
$this->mailer,
$this->logger,
$this->defaults
$this->defaults,
$this->urlGenerator
);
$this->assertSame([], $mailNotifications->sendLinkShareMail($to, 'MyFile', 'https://owncloud.com/file/?foo=bar', 3600));
}
Expand All @@ -193,7 +199,8 @@ public function testSendLinkShareMailException() {
$this->l10n,
$this->mailer,
$this->logger,
$this->defaults
$this->defaults,
$this->urlGenerator
);

$this->assertSame(['lukas@owncloud.com'], $mailNotifications->sendLinkShareMail('lukas@owncloud.com', 'MyFile', 'https://owncloud.com/file/?foo=bar', 3600));
Expand All @@ -208,7 +215,9 @@ public function testSendInternalShareMail() {
$this->l10n,
$this->mailer,
$this->logger,
$this->defaults]);
$this->defaults,
$this->urlGenerator
]);

$mailNotifications->method('getItemSharedWithUser')
->withAnyParameters()
Expand All @@ -227,6 +236,16 @@ public function testSendInternalShareMail() {
->method('getDisplayName')
->willReturn('Recipient');

$this->urlGenerator->expects($this->once())
->method('linkToRouteAbsolute')
->with(
$this->equalTo('files.view.index'),
$this->equalTo([
'dir' => '/',
'scrollto' => 'welcome.txt'
])
);

$recipientList = [$recipient];
$result = $mailNotifications->sendInternalShareMail($recipientList, '3', 'file');
$this->assertSame([], $result);
Expand Down

0 comments on commit 1db8207

Please sign in to comment.