summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/twofactor_backupcodes/lib/Notifications/Notifier.php9
-rw-r--r--apps/twofactor_backupcodes/tests/Unit/Notification/NotifierTest.php21
2 files changed, 26 insertions, 4 deletions
diff --git a/apps/twofactor_backupcodes/lib/Notifications/Notifier.php b/apps/twofactor_backupcodes/lib/Notifications/Notifier.php
index 3d5fedd93ea..df92c7a9e01 100644
--- a/apps/twofactor_backupcodes/lib/Notifications/Notifier.php
+++ b/apps/twofactor_backupcodes/lib/Notifications/Notifier.php
@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace OCA\TwoFactorBackupCodes\Notifications;
+use OCP\IURLGenerator;
use OCP\L10N\IFactory;
use OCP\Notification\INotification;
use OCP\Notification\INotifier;
@@ -33,8 +34,12 @@ class Notifier implements INotifier {
/** @var IFactory */
private $factory;
- public function __construct(IFactory $factory) {
+ /** @var IURLGenerator */
+ private $url;
+
+ public function __construct(IFactory $factory, IURLGenerator $url) {
$this->factory = $factory;
+ $this->url = $url;
}
public function prepare(INotification $notification, $languageCode) {
@@ -53,6 +58,8 @@ class Notifier implements INotifier {
)->setParsedMessage(
$l->t('You have enabled two-factor authentication but have not yet generated backup codes. Be sure to do this in case you lose access to your second factor.')
);
+
+ $notification->setLink($this->url->linkToRouteAbsolute('settings.PersonalSettings.index', ['section' => 'security']));
return $notification;
default:
diff --git a/apps/twofactor_backupcodes/tests/Unit/Notification/NotifierTest.php b/apps/twofactor_backupcodes/tests/Unit/Notification/NotifierTest.php
index 508fa453e16..9a641eb9f85 100644
--- a/apps/twofactor_backupcodes/tests/Unit/Notification/NotifierTest.php
+++ b/apps/twofactor_backupcodes/tests/Unit/Notification/NotifierTest.php
@@ -26,17 +26,21 @@ namespace OCA\TwoFactorBackupCodes\Tests\Unit\Notification;
use OCA\TwoFactorBackupCodes\Notifications\Notifier;
use OCP\IL10N;
+use OCP\IURLGenerator;
use OCP\L10N\IFactory;
use OCP\Notification\INotification;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class NotifierTest extends TestCase {
/** @var Notifier */
protected $notifier;
- /** @var IFactory|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IFactory|MockObject */
protected $factory;
- /** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IURLGenerator|MockObject */
+ protected $url;
+ /** @var IL10N|MockObject */
protected $l;
protected function setUp() {
@@ -49,12 +53,14 @@ class NotifierTest extends TestCase {
return vsprintf($string, $args);
});
$this->factory = $this->createMock(IFactory::class);
+ $this->url = $this->createMock(IURLGenerator::class);
$this->factory->expects($this->any())
->method('get')
->willReturn($this->l);
$this->notifier = new Notifier(
- $this->factory
+ $this->factory,
+ $this->url
);
}
@@ -114,6 +120,15 @@ class NotifierTest extends TestCase {
->with('You have enabled two-factor authentication but have not yet generated backup codes. Be sure to do this in case you lose access to your second factor.')
->willReturnSelf();
+ $this->url->expects($this->once())
+ ->method('linkToRouteAbsolute')
+ ->with('settings.PersonalSettings.index', ['section' => 'security'])
+ ->willReturn('linkToRouteAbsolute');
+ $notification->expects($this->once())
+ ->method('setLink')
+ ->with('linkToRouteAbsolute')
+ ->willReturnSelf();
+
$return = $this->notifier->prepare($notification, 'nl');
$this->assertEquals($notification, $return);
}