Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/firstrunwizard.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2017-01-10 14:39:51 +0300
committerGitHub <noreply@github.com>2017-01-10 14:39:51 +0300
commit0fe37f9dad58bf169b5f29a728d8a78b74cee6ee (patch)
tree5e933d0d4d7836576288ea1814937e1a3491a916
parentc2a46593aaca1de7cc1925b4e0d438040c01ac42 (diff)
parent9f676a08f3c1f4df2a889c9fdbbf818768b44d90 (diff)
Merge pull request #31 from nextcloud/backport-30-better-notification-linksv11.0.3RC2v11.0.3RC1v11.0.3v11.0.2RC1v11.0.2v11.0.1
[stable11] Set the link of the notification on render instead of creation
-rw-r--r--lib/Notification/BackgroundJob.php11
-rw-r--r--lib/Notification/Notifier.php13
-rw-r--r--tests/Notification/BackgroundJobTest.php17
-rw-r--r--tests/Notification/NotifierTest.php25
4 files changed, 34 insertions, 32 deletions
diff --git a/lib/Notification/BackgroundJob.php b/lib/Notification/BackgroundJob.php
index bf94b7c8..e5d52c39 100644
--- a/lib/Notification/BackgroundJob.php
+++ b/lib/Notification/BackgroundJob.php
@@ -22,7 +22,6 @@
namespace OCA\FirstRunWizard\Notification;
use OC\BackgroundJob\QueuedJob;
-use OCP\IURLGenerator;
use OCP\Notification\IManager as INotificationManager;
class BackgroundJob extends QueuedJob {
@@ -30,18 +29,13 @@ class BackgroundJob extends QueuedJob {
/** @var INotificationManager */
protected $notificationManager;
- /** @var IURLGenerator */
- protected $urlGenerator;
-
/**
* BackgroundJob constructor.
*
* @param INotificationManager $notificationManager
- * @param IURLGenerator $urlGenerator
*/
- public function __construct(INotificationManager $notificationManager, IURLGenerator $urlGenerator) {
+ public function __construct(INotificationManager $notificationManager) {
$this->notificationManager = $notificationManager;
- $this->urlGenerator = $urlGenerator;
}
/**
@@ -55,8 +49,7 @@ class BackgroundJob extends QueuedJob {
->setUser($argument['uid']);
if ($this->notificationManager->getCount($notification) === 0) {
- $notification->setDateTime(new \DateTime())
- ->setLink($this->urlGenerator->getAbsoluteURL('index.php/settings/personal'));
+ $notification->setDateTime(new \DateTime());
$this->notificationManager->notify($notification);
}
}
diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php
index 103d48d6..508d4a9e 100644
--- a/lib/Notification/Notifier.php
+++ b/lib/Notification/Notifier.php
@@ -22,6 +22,7 @@
namespace OCA\FirstRunWizard\Notification;
+use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\L10N\IFactory;
use OCP\Notification\IManager as INotificationManager;
@@ -39,15 +40,20 @@ class Notifier implements INotifier {
/** @var INotificationManager */
protected $notificationManager;
+ /** @var IURLGenerator */
+ protected $url;
+
/**
* @param IFactory $factory
* @param IUserManager $userManager
* @param INotificationManager $notificationManager
+ * @param IURLGenerator $urlGenerator
*/
- public function __construct(IFactory $factory, IUserManager $userManager, INotificationManager $notificationManager) {
+ public function __construct(IFactory $factory, IUserManager $userManager, INotificationManager $notificationManager, IURLGenerator $urlGenerator) {
$this->factory = $factory;
$this->userManager = $userManager;
$this->notificationManager = $notificationManager;
+ $this->url = $urlGenerator;
}
/**
@@ -80,8 +86,9 @@ class Notifier implements INotifier {
$l = $this->factory->get('firstrunwizard', $languageCode);
$notification->setParsedSubject(
- $l->t('Add your profile information! For example your email is needed to reset your password.')
- );
+ $l->t('Add your profile information! For example your email is needed to reset your password.')
+ )
+ ->setLink($this->url->getAbsoluteURL('index.php/settings/personal'));
return $notification;
default:
diff --git a/tests/Notification/BackgroundJobTest.php b/tests/Notification/BackgroundJobTest.php
index 4663a6d2..a6a44984 100644
--- a/tests/Notification/BackgroundJobTest.php
+++ b/tests/Notification/BackgroundJobTest.php
@@ -24,12 +24,7 @@
namespace OCA\FirstRunWizard\Tests\Notification;
-use OCA\FirstRunWizard\Controller\WizardController;
use OCA\FirstRunWizard\Notification\BackgroundJob;
-use OCP\AppFramework\Http;
-use OCP\AppFramework\Http\DataResponse;
-use OCP\IRequest;
-use OCP\IURLGenerator;
use OCP\Notification\IManager;
use OCP\Notification\INotification;
use Test\TestCase;
@@ -44,19 +39,14 @@ class BackgroundJobTest extends TestCase {
/** @var IManager|\PHPUnit_Framework_MockObject_MockObject */
protected $notificationManager;
- /** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
- protected $urlGenerator;
-
/** @var BackgroundJob */
protected $job;
protected function setUp() {
parent::setUp();
$this->notificationManager = $this->createMock(IManager::class);
- $this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->job = new BackgroundJob(
- $this->notificationManager,
- $this->urlGenerator
+ $this->notificationManager
);
}
@@ -97,14 +87,9 @@ class BackgroundJobTest extends TestCase {
$notification->expects($this->once())
->method('setDateTime')
->willReturnSelf();
- $notification->expects($this->once())
- ->method('setLink')
- ->willReturnSelf();
} else {
$notification->expects($this->never())
->method('setDateTime');
- $notification->expects($this->never())
- ->method('setLink');
}
$this->notificationManager->expects($this->once())
diff --git a/tests/Notification/NotifierTest.php b/tests/Notification/NotifierTest.php
index 860584c0..7b8807ba 100644
--- a/tests/Notification/NotifierTest.php
+++ b/tests/Notification/NotifierTest.php
@@ -26,6 +26,7 @@ namespace OCA\FirstRunWizard\Tests\Notification;
use OCA\FirstRunWizard\Notification\Notifier;
use OCP\IImage;
use OCP\IL10N;
+use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
use OCP\L10N\IFactory;
@@ -43,6 +44,8 @@ class NotifierTest extends TestCase {
protected $userManager;
/** @var IFactory|\PHPUnit_Framework_MockObject_MockObject */
protected $factory;
+ /** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
+ protected $urlGenerator;
/** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
protected $l;
@@ -51,6 +54,7 @@ class NotifierTest extends TestCase {
$this->manager = $this->createMock(IManager::class);
$this->userManager = $this->createMock(IUserManager::class);
+ $this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->l = $this->createMock(IL10N::class);
$this->l->expects($this->any())
->method('t')
@@ -65,7 +69,8 @@ class NotifierTest extends TestCase {
$this->notifier = new Notifier(
$this->factory,
$this->userManager,
- $this->manager
+ $this->manager,
+ $this->urlGenerator
);
}
@@ -149,9 +154,7 @@ class NotifierTest extends TestCase {
*/
public function testPrepare($language, $user, $changeName, $changeAvatar, $name, $email, $avatar, $dismissNotification) {
/** @var \OCP\Notification\INotification|\PHPUnit_Framework_MockObject_MockObject $notification */
- $notification = $this->getMockBuilder('OCP\Notification\INotification')
- ->disableOriginalConstructor()
- ->getMock();
+ $notification = $this->createMock(INotification::class);
$notification->expects($this->once())
->method('getApp')
@@ -172,8 +175,13 @@ class NotifierTest extends TestCase {
->method('markProcessed')
->with($notification);
+ $this->urlGenerator->expects($this->never())
+ ->method('getAbsoluteURL');
+
$notification->expects($this->never())
->method('setParsedSubject');
+ $notification->expects($this->never())
+ ->method('setLink');
$this->setExpectedException(\InvalidArgumentException::class);
} else {
@@ -185,10 +193,19 @@ class NotifierTest extends TestCase {
->with('firstrunwizard', $language)
->willReturn($this->l);
+ $this->urlGenerator->expects($this->once())
+ ->method('getAbsoluteURL')
+ ->with('index.php/settings/personal')
+ ->willReturnArgument(0);
+
$notification->expects($this->once())
->method('setParsedSubject')
->with('Add your profile information! For example your email is needed to reset your password.')
->willReturnSelf();
+ $notification->expects($this->once())
+ ->method('setLink')
+ ->with($this->stringEndsWith('/settings/personal'))
+ ->willReturnSelf();
}
$return = $this->notifier->prepare($notification, $language);