aboutsummaryrefslogtreecommitdiffstats
path: root/apps/updatenotification
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2024-03-13 01:21:40 -0100
committerMaxence Lange <maxence@artificial-owl.com>2024-03-13 02:22:11 -0100
commit519e4345739876d2ae7e064e347d19524905b090 (patch)
tree0b997f8d18f54efcb97e9278503ae42e119fd9b6 /apps/updatenotification
parent5723c13dc0c7f4025c4d976c1f792f9bb3513fe2 (diff)
downloadnextcloud-server-519e4345739876d2ae7e064e347d19524905b090.tar.gz
nextcloud-server-519e4345739876d2ae7e064e347d19524905b090.zip
fix(updatenotification): spread the use of new appconfig
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'apps/updatenotification')
-rw-r--r--apps/updatenotification/lib/Settings/Admin.php41
-rw-r--r--apps/updatenotification/tests/Settings/AdminTest.php47
2 files changed, 42 insertions, 46 deletions
diff --git a/apps/updatenotification/lib/Settings/Admin.php b/apps/updatenotification/lib/Settings/Admin.php
index 730be5601a2..b95f3dec196 100644
--- a/apps/updatenotification/lib/Settings/Admin.php
+++ b/apps/updatenotification/lib/Settings/Admin.php
@@ -33,6 +33,7 @@ use OC\User\Backend;
use OCA\UpdateNotification\UpdateChecker;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
+use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IDateTimeFormatter;
use OCP\IGroupManager;
@@ -45,40 +46,22 @@ use OCP\Util;
use Psr\Log\LoggerInterface;
class Admin implements ISettings {
- private IConfig $config;
- private UpdateChecker $updateChecker;
- private IGroupManager $groupManager;
- private IDateTimeFormatter $dateTimeFormatter;
- private IFactory $l10nFactory;
- private IRegistry $subscriptionRegistry;
- private IUserManager $userManager;
- private LoggerInterface $logger;
- private IInitialState $initialState;
-
public function __construct(
- IConfig $config,
- UpdateChecker $updateChecker,
- IGroupManager $groupManager,
- IDateTimeFormatter $dateTimeFormatter,
- IFactory $l10nFactory,
- IRegistry $subscriptionRegistry,
- IUserManager $userManager,
- LoggerInterface $logger,
- IInitialState $initialState
+ private IConfig $config,
+ private IAppConfig $appConfig,
+ private UpdateChecker $updateChecker,
+ private IGroupManager $groupManager,
+ private IDateTimeFormatter $dateTimeFormatter,
+ private IFactory $l10nFactory,
+ private IRegistry $subscriptionRegistry,
+ private IUserManager $userManager,
+ private LoggerInterface $logger,
+ private IInitialState $initialState
) {
- $this->config = $config;
- $this->updateChecker = $updateChecker;
- $this->groupManager = $groupManager;
- $this->dateTimeFormatter = $dateTimeFormatter;
- $this->l10nFactory = $l10nFactory;
- $this->subscriptionRegistry = $subscriptionRegistry;
- $this->userManager = $userManager;
- $this->logger = $logger;
- $this->initialState = $initialState;
}
public function getForm(): TemplateResponse {
- $lastUpdateCheckTimestamp = (int)$this->config->getAppValue('core', 'lastupdatedat');
+ $lastUpdateCheckTimestamp = $this->appConfig->getValueInt('core', 'lastupdatedat');
$lastUpdateCheck = $this->dateTimeFormatter->formatDateTime($lastUpdateCheckTimestamp);
$channels = [
diff --git a/apps/updatenotification/tests/Settings/AdminTest.php b/apps/updatenotification/tests/Settings/AdminTest.php
index bdde25aceca..7776fa692cd 100644
--- a/apps/updatenotification/tests/Settings/AdminTest.php
+++ b/apps/updatenotification/tests/Settings/AdminTest.php
@@ -34,6 +34,7 @@ use OCA\UpdateNotification\Settings\Admin;
use OCA\UpdateNotification\UpdateChecker;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
+use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IDateTimeFormatter;
use OCP\IGroup;
@@ -55,6 +56,8 @@ class AdminTest extends TestCase {
private $admin;
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
private $config;
+ /** @var IAppConfig|\PHPUnit\Framework\MockObject\MockObject */
+ private $appConfig;
/** @var UpdateChecker|\PHPUnit\Framework\MockObject\MockObject */
private $updateChecker;
/** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */
@@ -74,6 +77,7 @@ class AdminTest extends TestCase {
parent::setUp();
$this->config = $this->createMock(IConfig::class);
+ $this->appConfig = $this->createMock(IAppConfig::class);
$this->updateChecker = $this->createMock(UpdateChecker::class);
$this->groupManager = $this->createMock(IGroupManager::class);
$this->dateTimeFormatter = $this->createMock(IDateTimeFormatter::class);
@@ -85,6 +89,7 @@ class AdminTest extends TestCase {
$this->admin = new Admin(
$this->config,
+ $this->appConfig,
$this->updateChecker,
$this->groupManager,
$this->dateTimeFormatter,
@@ -143,14 +148,16 @@ class AdminTest extends TestCase {
if ($currentChannel === 'git') {
$channels[] = 'git';
}
-
+ $this->appConfig
+ ->expects($this->once())
+ ->method('getValueInt')
+ ->with('core', 'lastupdatedat', 0)
+ ->willReturn(12345);
$this->config
- ->expects($this->exactly(2))
+ ->expects($this->once())
->method('getAppValue')
- ->willReturnMap([
- ['core', 'lastupdatedat', '', '12345'],
- ['updatenotification', 'notify_groups', '["admin"]', '["admin"]'],
- ]);
+ ->with('updatenotification', 'notify_groups', '["admin"]')
+ ->willReturn('["admin"]');
$this->config
->method('getSystemValue')
->willReturnMap([
@@ -160,7 +167,7 @@ class AdminTest extends TestCase {
$this->dateTimeFormatter
->expects($this->once())
->method('formatDateTime')
- ->with('12345')
+ ->with(12345)
->willReturn('LastCheckedReturnValue');
$this->updateChecker
->expects($this->once())
@@ -268,13 +275,16 @@ class AdminTest extends TestCase {
$channels[] = 'git';
}
+ $this->appConfig
+ ->expects($this->once())
+ ->method('getValueInt')
+ ->with('core', 'lastupdatedat', 0)
+ ->willReturn(12345);
$this->config
- ->expects($this->exactly(2))
+ ->expects($this->once())
->method('getAppValue')
- ->willReturnMap([
- ['core', 'lastupdatedat', '', '12345'],
- ['updatenotification', 'notify_groups', '["admin"]', '["admin"]'],
- ]);
+ ->with('updatenotification', 'notify_groups', '["admin"]')
+ ->willReturn('["admin"]');
$this->config
->method('getSystemValue')
->willReturnMap([
@@ -392,13 +402,16 @@ class AdminTest extends TestCase {
$channels[] = 'git';
}
+ $this->appConfig
+ ->expects($this->once())
+ ->method('getValueInt')
+ ->with('core', 'lastupdatedat', 0)
+ ->willReturn(12345);
$this->config
- ->expects($this->exactly(2))
+ ->expects($this->once())
->method('getAppValue')
- ->willReturnMap([
- ['core', 'lastupdatedat', '', '12345'],
- ['updatenotification', 'notify_groups', '["admin"]', '["admin"]'],
- ]);
+ ->with('updatenotification', 'notify_groups', '["admin"]')
+ ->willReturn('["admin"]');
$this->config
->method('getSystemValue')
->willReturnMap([