aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKate <26026535+provokateurin@users.noreply.github.com>2025-05-15 00:07:31 +0200
committerGitHub <noreply@github.com>2025-05-15 00:07:31 +0200
commitc3ddd1da46c9f75071f61d3cf7381570297a74d6 (patch)
tree16030cf003d2f8255289c149ab3379a878ad6517
parentbaae99eaad84587bc1e8b3520af65d1e7f0ce3e2 (diff)
parent76696be7628ed2f0bdd4fb399cfa9254cd38da75 (diff)
downloadnextcloud-server-c3ddd1da46c9f75071f61d3cf7381570297a74d6.tar.gz
nextcloud-server-c3ddd1da46c9f75071f61d3cf7381570297a74d6.zip
Merge pull request #52669 from nextcloud/chore/refactor-update-notification+
-rw-r--r--apps/updatenotification/composer/autoload.php5
-rw-r--r--apps/updatenotification/composer/composer/autoload_classmap.php1
-rw-r--r--apps/updatenotification/composer/composer/autoload_static.php1
-rw-r--r--apps/updatenotification/lib/AppInfo/Application.php2
-rw-r--r--apps/updatenotification/lib/BackgroundJob/UpdateAvailableNotifications.php40
-rw-r--r--apps/updatenotification/lib/Command/Check.php16
-rw-r--r--apps/updatenotification/lib/Controller/APIController.php19
-rw-r--r--apps/updatenotification/lib/Controller/AdminController.php5
-rw-r--r--apps/updatenotification/lib/Manager.php2
-rw-r--r--apps/updatenotification/lib/Migration/Version011901Date20240305120000.php58
-rw-r--r--apps/updatenotification/lib/Notification/Notifier.php24
-rw-r--r--apps/updatenotification/lib/Settings/Admin.php10
-rw-r--r--apps/updatenotification/lib/UpdateChecker.php1
-rw-r--r--apps/updatenotification/tests/Notification/NotifierTest.php11
-rw-r--r--apps/updatenotification/tests/Settings/AdminTest.php104
15 files changed, 113 insertions, 186 deletions
diff --git a/apps/updatenotification/composer/autoload.php b/apps/updatenotification/composer/autoload.php
index 36afdad067f..a1e9eceb11c 100644
--- a/apps/updatenotification/composer/autoload.php
+++ b/apps/updatenotification/composer/autoload.php
@@ -14,10 +14,7 @@ if (PHP_VERSION_ID < 50600) {
echo $err;
}
}
- trigger_error(
- $err,
- E_USER_ERROR
- );
+ throw new RuntimeException($err);
}
require_once __DIR__ . '/composer/autoload_real.php';
diff --git a/apps/updatenotification/composer/composer/autoload_classmap.php b/apps/updatenotification/composer/composer/autoload_classmap.php
index 4aa401f661e..a03003ef3b2 100644
--- a/apps/updatenotification/composer/composer/autoload_classmap.php
+++ b/apps/updatenotification/composer/composer/autoload_classmap.php
@@ -18,7 +18,6 @@ return array(
'OCA\\UpdateNotification\\Listener\\AppUpdateEventListener' => $baseDir . '/../lib/Listener/AppUpdateEventListener.php',
'OCA\\UpdateNotification\\Listener\\BeforeTemplateRenderedEventListener' => $baseDir . '/../lib/Listener/BeforeTemplateRenderedEventListener.php',
'OCA\\UpdateNotification\\Manager' => $baseDir . '/../lib/Manager.php',
- 'OCA\\UpdateNotification\\Migration\\Version011901Date20240305120000' => $baseDir . '/../lib/Migration/Version011901Date20240305120000.php',
'OCA\\UpdateNotification\\Notification\\AppUpdateNotifier' => $baseDir . '/../lib/Notification/AppUpdateNotifier.php',
'OCA\\UpdateNotification\\Notification\\Notifier' => $baseDir . '/../lib/Notification/Notifier.php',
'OCA\\UpdateNotification\\ResponseDefinitions' => $baseDir . '/../lib/ResponseDefinitions.php',
diff --git a/apps/updatenotification/composer/composer/autoload_static.php b/apps/updatenotification/composer/composer/autoload_static.php
index 9e1fdd09def..57eedf5e075 100644
--- a/apps/updatenotification/composer/composer/autoload_static.php
+++ b/apps/updatenotification/composer/composer/autoload_static.php
@@ -33,7 +33,6 @@ class ComposerStaticInitUpdateNotification
'OCA\\UpdateNotification\\Listener\\AppUpdateEventListener' => __DIR__ . '/..' . '/../lib/Listener/AppUpdateEventListener.php',
'OCA\\UpdateNotification\\Listener\\BeforeTemplateRenderedEventListener' => __DIR__ . '/..' . '/../lib/Listener/BeforeTemplateRenderedEventListener.php',
'OCA\\UpdateNotification\\Manager' => __DIR__ . '/..' . '/../lib/Manager.php',
- 'OCA\\UpdateNotification\\Migration\\Version011901Date20240305120000' => __DIR__ . '/..' . '/../lib/Migration/Version011901Date20240305120000.php',
'OCA\\UpdateNotification\\Notification\\AppUpdateNotifier' => __DIR__ . '/..' . '/../lib/Notification/AppUpdateNotifier.php',
'OCA\\UpdateNotification\\Notification\\Notifier' => __DIR__ . '/..' . '/../lib/Notification/Notifier.php',
'OCA\\UpdateNotification\\ResponseDefinitions' => __DIR__ . '/..' . '/../lib/ResponseDefinitions.php',
diff --git a/apps/updatenotification/lib/AppInfo/Application.php b/apps/updatenotification/lib/AppInfo/Application.php
index d34429e9e73..56012667bb4 100644
--- a/apps/updatenotification/lib/AppInfo/Application.php
+++ b/apps/updatenotification/lib/AppInfo/Application.php
@@ -73,7 +73,7 @@ class Application extends App implements IBootstrap {
}
if ($updateChecker->getUpdateState() !== []) {
- Util::addScript('updatenotification', 'update-notification-legacy');
+ Util::addScript(self::APP_NAME, 'update-notification-legacy');
$updateChecker->setInitialState();
}
}
diff --git a/apps/updatenotification/lib/BackgroundJob/UpdateAvailableNotifications.php b/apps/updatenotification/lib/BackgroundJob/UpdateAvailableNotifications.php
index 29bd5cb1426..8879bb0c223 100644
--- a/apps/updatenotification/lib/BackgroundJob/UpdateAvailableNotifications.php
+++ b/apps/updatenotification/lib/BackgroundJob/UpdateAvailableNotifications.php
@@ -10,6 +10,7 @@ namespace OCA\UpdateNotification\BackgroundJob;
use OC\Installer;
use OC\Updater\VersionCheck;
+use OCA\UpdateNotification\AppInfo\Application;
use OCP\App\IAppManager;
use OCP\AppFramework\Services\IAppConfig;
use OCP\AppFramework\Utility\ITimeFactory;
@@ -21,10 +22,15 @@ use OCP\Notification\IManager;
use OCP\ServerVersion;
class UpdateAvailableNotifications extends TimedJob {
- protected $connectionNotifications = [3, 7, 14, 30];
- /** @var string[] */
- protected $users;
+ /**
+ * Numbers of failed updater connection to report error as notification.
+ * @var list<int>
+ */
+ protected const CONNECTION_NOTIFICATIONS = [3, 7, 14, 30];
+
+ /** @var ?string[] */
+ protected $users = null;
public function __construct(
ITimeFactory $timeFactory,
@@ -66,7 +72,7 @@ class UpdateAvailableNotifications extends TimedJob {
/**
* Check for Nextcloud server update
*/
- protected function checkCoreUpdate() {
+ protected function checkCoreUpdate(): void {
if (!$this->config->getSystemValueBool('updatechecker', true)) {
// update checker is disabled so no core update check!
return;
@@ -82,7 +88,7 @@ class UpdateAvailableNotifications extends TimedJob {
$errors = 1 + $this->appConfig->getAppValueInt('update_check_errors', 0);
$this->appConfig->setAppValueInt('update_check_errors', $errors);
- if (\in_array($errors, $this->connectionNotifications, true)) {
+ if (\in_array($errors, self::CONNECTION_NOTIFICATIONS, true)) {
$this->sendErrorNotifications($errors);
}
} elseif (\is_array($status)) {
@@ -99,14 +105,14 @@ class UpdateAvailableNotifications extends TimedJob {
* Send a message to the admin when the update server could not be reached
* @param int $numDays
*/
- protected function sendErrorNotifications($numDays) {
+ protected function sendErrorNotifications($numDays): void {
$this->clearErrorNotifications();
$notification = $this->notificationManager->createNotification();
try {
- $notification->setApp('updatenotification')
+ $notification->setApp(Application::APP_NAME)
->setDateTime(new \DateTime())
- ->setObject('updatenotification', 'error')
+ ->setObject(Application::APP_NAME, 'error')
->setSubject('connection_error', ['days' => $numDays]);
foreach ($this->getUsersToNotify() as $uid) {
@@ -121,12 +127,12 @@ class UpdateAvailableNotifications extends TimedJob {
/**
* Remove error notifications again
*/
- protected function clearErrorNotifications() {
+ protected function clearErrorNotifications(): void {
$notification = $this->notificationManager->createNotification();
try {
- $notification->setApp('updatenotification')
+ $notification->setApp(Application::APP_NAME)
->setSubject('connection_error')
- ->setObject('updatenotification', 'error');
+ ->setObject(Application::APP_NAME, 'error');
} catch (\InvalidArgumentException $e) {
return;
}
@@ -136,7 +142,7 @@ class UpdateAvailableNotifications extends TimedJob {
/**
* Check all installed apps for updates
*/
- protected function checkAppUpdates() {
+ protected function checkAppUpdates(): void {
$apps = $this->appManager->getEnabledApps();
foreach ($apps as $app) {
$update = $this->isUpdateAvailable($app);
@@ -153,7 +159,7 @@ class UpdateAvailableNotifications extends TimedJob {
* @param string $version
* @param string $visibleVersion
*/
- protected function createNotifications($app, $version, $visibleVersion = '') {
+ protected function createNotifications($app, $version, $visibleVersion = ''): void {
$lastNotification = $this->appConfig->getAppValueString($app, '');
if ($lastNotification === $version) {
// We already notified about this update
@@ -167,7 +173,7 @@ class UpdateAvailableNotifications extends TimedJob {
$notification = $this->notificationManager->createNotification();
try {
- $notification->setApp('updatenotification')
+ $notification->setApp(Application::APP_NAME)
->setDateTime(new \DateTime())
->setObject($app, $version);
@@ -217,12 +223,12 @@ class UpdateAvailableNotifications extends TimedJob {
* @param string $app
* @param string $version
*/
- protected function deleteOutdatedNotifications($app, $version) {
+ protected function deleteOutdatedNotifications($app, $version): void {
$notification = $this->notificationManager->createNotification();
try {
- $notification->setApp('updatenotification')
+ $notification->setApp(Application::APP_NAME)
->setObject($app, $version);
- } catch (\InvalidArgumentException $e) {
+ } catch (\InvalidArgumentException) {
return;
}
$this->notificationManager->markProcessed($notification);
diff --git a/apps/updatenotification/lib/Command/Check.php b/apps/updatenotification/lib/Command/Check.php
index c7de570cd2c..d93e4935012 100644
--- a/apps/updatenotification/lib/Command/Check.php
+++ b/apps/updatenotification/lib/Command/Check.php
@@ -17,24 +17,12 @@ use Symfony\Component\Console\Output\OutputInterface;
class Check extends Command {
- /**
- * @var Installer $installer
- */
- private $installer;
-
- /**
- * @var AppManager $appManager
- */
- private $appManager;
-
public function __construct(
- AppManager $appManager,
+ private AppManager $appManager,
private UpdateChecker $updateChecker,
- Installer $installer,
+ private Installer $installer,
) {
parent::__construct();
- $this->installer = $installer;
- $this->appManager = $appManager;
}
protected function configure(): void {
diff --git a/apps/updatenotification/lib/Controller/APIController.php b/apps/updatenotification/lib/Controller/APIController.php
index c96a5101e0f..4360d814dd2 100644
--- a/apps/updatenotification/lib/Controller/APIController.php
+++ b/apps/updatenotification/lib/Controller/APIController.php
@@ -26,8 +26,7 @@ use OCP\L10N\IFactory;
*/
class APIController extends OCSController {
- /** @var string */
- protected $language;
+ protected ?string $language = null;
/**
* List of apps that were in the appstore but are now shipped and don't have
@@ -95,7 +94,7 @@ class APIController extends OCSController {
$this->appFetcher->setVersion($newVersion, 'future-apps.json', false);
// Apps available on the app store for that version
- $availableApps = array_map(static function (array $app) {
+ $availableApps = array_map(static function (array $app): string {
return $app['id'];
}, $this->appFetcher->get());
@@ -106,8 +105,6 @@ class APIController extends OCSController {
], Http::STATUS_NOT_FOUND);
}
- $this->language = $this->l10nFactory->getUserLanguage($this->userSession->getUser());
-
// Ignore apps that are deployed from git
$installedApps = array_filter($installedApps, function (string $appId) {
try {
@@ -139,14 +136,20 @@ class APIController extends OCSController {
*/
protected function getAppDetails(string $appId): array {
$app = $this->appManager->getAppInfo($appId, false, $this->language);
- /** @var ?string $name */
- $name = $app['name'];
+ $name = $app['name'] ?? $appId;
return [
'appId' => $appId,
- 'appName' => $name ?? $appId,
+ 'appName' => $name,
];
}
+ protected function getLanguage(): string {
+ if ($this->language === null) {
+ $this->language = $this->l10nFactory->getUserLanguage($this->userSession->getUser());
+ }
+ return $this->language;
+ }
+
/**
* Get changelog entry for an app
*
diff --git a/apps/updatenotification/lib/Controller/AdminController.php b/apps/updatenotification/lib/Controller/AdminController.php
index 6e7f9935d93..26745948890 100644
--- a/apps/updatenotification/lib/Controller/AdminController.php
+++ b/apps/updatenotification/lib/Controller/AdminController.php
@@ -4,6 +4,7 @@ declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\UpdateNotification\Controller;
@@ -36,8 +37,8 @@ class AdminController extends Controller {
parent::__construct($appName, $request);
}
- private function isUpdaterEnabled() {
- return !$this->config->getSystemValue('upgrade.disable-web', false);
+ private function isUpdaterEnabled(): bool {
+ return !$this->config->getSystemValueBool('upgrade.disable-web');
}
/**
diff --git a/apps/updatenotification/lib/Manager.php b/apps/updatenotification/lib/Manager.php
index b6f455f93fe..ebc1c83a9b4 100644
--- a/apps/updatenotification/lib/Manager.php
+++ b/apps/updatenotification/lib/Manager.php
@@ -73,7 +73,7 @@ class Manager {
/**
* Retrieve a log entry from the changelog
- * @param string $path The path to the changlog file
+ * @param string $path The path to the changelog file
* @param string $version The version to query (make sure to only pass in "{major}.{minor}(.{patch}" format)
*/
protected function retrieveChangelogEntry(string $path, string $version): ?string {
diff --git a/apps/updatenotification/lib/Migration/Version011901Date20240305120000.php b/apps/updatenotification/lib/Migration/Version011901Date20240305120000.php
deleted file mode 100644
index 6c608df313d..00000000000
--- a/apps/updatenotification/lib/Migration/Version011901Date20240305120000.php
+++ /dev/null
@@ -1,58 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-/**
- * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
- * SPDX-License-Identifier: AGPL-3.0-or-later
- */
-
-namespace OCA\UpdateNotification\Migration;
-
-use OCA\UpdateNotification\BackgroundJob\ResetToken;
-use OCA\UpdateNotification\Notification\BackgroundJob;
-use OCA\UpdateNotification\ResetTokenBackgroundJob;
-use OCP\BackgroundJob\IJobList;
-use OCP\Migration\IOutput;
-use OCP\Migration\SimpleMigrationStep;
-
-/**
- * Drop this with Nextcloud 30
- */
-class Version011901Date20240305120000 extends SimpleMigrationStep {
-
- public function __construct(
- private IJobList $joblist,
- ) {
- }
-
- public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options): void {
- /**
- * Remove and replace the reset-updater-token background job
- * This class was renamed so it is now unknow but we still need to remove it
- * @psalm-suppress UndefinedClass, InvalidArgument
- */
- $hasOldResetToken = $this->joblist->has(ResetTokenBackgroundJob::class, null);
- $hasNewResetToken = $this->joblist->has(ResetToken::class, null);
- if ($hasOldResetToken) {
- /**
- * @psalm-suppress UndefinedClass, InvalidArgument
- */
- $this->joblist->remove(ResetTokenBackgroundJob::class);
- if (!$hasNewResetToken) {
- $this->joblist->add(ResetToken::class);
- }
- }
-
- /**
- * Remove the "has updates" background job, the new one is automatically started from the info.xml
- * @psalm-suppress UndefinedClass, InvalidArgument
- */
- if ($this->joblist->has(BackgroundJob::class, null)) {
- /**
- * @psalm-suppress UndefinedClass, InvalidArgument
- */
- $this->joblist->remove(BackgroundJob::class);
- }
- }
-}
diff --git a/apps/updatenotification/lib/Notification/Notifier.php b/apps/updatenotification/lib/Notification/Notifier.php
index 8ce6bfc2d3d..787675bd98d 100644
--- a/apps/updatenotification/lib/Notification/Notifier.php
+++ b/apps/updatenotification/lib/Notification/Notifier.php
@@ -8,8 +8,9 @@ declare(strict_types=1);
*/
namespace OCA\UpdateNotification\Notification;
+use OCA\UpdateNotification\AppInfo\Application;
use OCP\App\IAppManager;
-use OCP\IConfig;
+use OCP\AppFramework\Services\IAppConfig;
use OCP\IGroupManager;
use OCP\IURLGenerator;
use OCP\IUser;
@@ -28,17 +29,10 @@ class Notifier implements INotifier {
/**
* Notifier constructor.
- *
- * @param IURLGenerator $url
- * @param IConfig $config
- * @param IManager $notificationManager
- * @param IFactory $l10NFactory
- * @param IUserSession $userSession
- * @param IGroupManager $groupManager
*/
public function __construct(
protected IURLGenerator $url,
- protected IConfig $config,
+ protected IAppConfig $appConfig,
protected IManager $notificationManager,
protected IFactory $l10NFactory,
protected IUserSession $userSession,
@@ -56,7 +50,7 @@ class Notifier implements INotifier {
* @since 17.0.0
*/
public function getID(): string {
- return 'updatenotification';
+ return Application::APP_NAME;
}
/**
@@ -66,7 +60,7 @@ class Notifier implements INotifier {
* @since 17.0.0
*/
public function getName(): string {
- return $this->l10NFactory->get('updatenotification')->t('Update notifications');
+ return $this->l10NFactory->get(Application::APP_NAME)->t('Update notifications');
}
/**
@@ -78,7 +72,7 @@ class Notifier implements INotifier {
* @since 9.0.0
*/
public function prepare(INotification $notification, string $languageCode): INotification {
- if ($notification->getApp() !== 'updatenotification') {
+ if ($notification->getApp() !== Application::APP_NAME) {
throw new UnknownNotificationException('Unknown app id');
}
@@ -86,9 +80,9 @@ class Notifier implements INotifier {
throw new UnknownNotificationException('Unknown subject');
}
- $l = $this->l10NFactory->get('updatenotification', $languageCode);
+ $l = $this->l10NFactory->get(Application::APP_NAME, $languageCode);
if ($notification->getSubject() === 'connection_error') {
- $errors = (int)$this->config->getAppValue('updatenotification', 'update_check_errors', '0');
+ $errors = $this->appConfig->getAppValueInt('update_check_errors', 0);
if ($errors === 0) {
throw new AlreadyProcessedException();
}
@@ -133,7 +127,7 @@ class Notifier implements INotifier {
}
}
- $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('updatenotification', 'notification.svg')));
+ $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath(Application::APP_NAME, 'notification.svg')));
return $notification;
}
diff --git a/apps/updatenotification/lib/Settings/Admin.php b/apps/updatenotification/lib/Settings/Admin.php
index dfd4de4180f..22228f1bccc 100644
--- a/apps/updatenotification/lib/Settings/Admin.php
+++ b/apps/updatenotification/lib/Settings/Admin.php
@@ -8,6 +8,7 @@ declare(strict_types=1);
*/
namespace OCA\UpdateNotification\Settings;
+use OCA\UpdateNotification\AppInfo\Application;
use OCA\UpdateNotification\UpdateChecker;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
@@ -17,9 +18,9 @@ use OCP\IDateTimeFormatter;
use OCP\IGroupManager;
use OCP\IUserManager;
use OCP\L10N\IFactory;
+use OCP\ServerVersion;
use OCP\Settings\ISettings;
use OCP\Support\Subscription\IRegistry;
-use OCP\Util;
use Psr\Log\LoggerInterface;
class Admin implements ISettings {
@@ -34,6 +35,7 @@ class Admin implements ISettings {
private IUserManager $userManager,
private LoggerInterface $logger,
private IInitialState $initialState,
+ private ServerVersion $serverVersion,
) {
}
@@ -47,14 +49,14 @@ class Admin implements ISettings {
'stable',
'production',
];
- $currentChannel = Util::getChannel();
+ $currentChannel = $this->serverVersion->getChannel();
if ($currentChannel === 'git') {
$channels[] = 'git';
}
$updateState = $this->updateChecker->getUpdateState();
- $notifyGroups = json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'), true);
+ $notifyGroups = $this->appConfig->getValueArray(Application::APP_NAME, 'notify_groups', ['admin']);
$defaultUpdateServerURL = 'https://updates.nextcloud.com/updater_server/';
$updateServerURL = $this->config->getSystemValue('updater.server.url', $defaultUpdateServerURL);
@@ -112,7 +114,7 @@ class Admin implements ISettings {
}
/**
- * @param list<string> $groupIds
+ * @param string[] $groupIds
* @return list<array{id: string, displayname: string}>
*/
protected function getSelectedGroups(array $groupIds): array {
diff --git a/apps/updatenotification/lib/UpdateChecker.php b/apps/updatenotification/lib/UpdateChecker.php
index 76afc8f6a54..b206ba4a3e4 100644
--- a/apps/updatenotification/lib/UpdateChecker.php
+++ b/apps/updatenotification/lib/UpdateChecker.php
@@ -4,6 +4,7 @@ declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\UpdateNotification;
diff --git a/apps/updatenotification/tests/Notification/NotifierTest.php b/apps/updatenotification/tests/Notification/NotifierTest.php
index 45c4fc9960f..4102fdcb773 100644
--- a/apps/updatenotification/tests/Notification/NotifierTest.php
+++ b/apps/updatenotification/tests/Notification/NotifierTest.php
@@ -4,13 +4,14 @@ declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\UpdateNotification\Tests\Notification;
use OCA\UpdateNotification\Notification\Notifier;
use OCP\App\IAppManager;
-use OCP\IConfig;
+use OCP\AppFramework\Services\IAppConfig;
use OCP\IGroupManager;
use OCP\IURLGenerator;
use OCP\IUserSession;
@@ -25,7 +26,7 @@ use Test\TestCase;
class NotifierTest extends TestCase {
protected IURLGenerator&MockObject $urlGenerator;
- protected IConfig&MockObject $config;
+ protected IAppConfig&MockObject $appConfig;
protected IManager&MockObject $notificationManager;
protected IFactory&MockObject $l10nFactory;
protected IUserSession&MockObject $userSession;
@@ -37,7 +38,7 @@ class NotifierTest extends TestCase {
parent::setUp();
$this->urlGenerator = $this->createMock(IURLGenerator::class);
- $this->config = $this->createMock(IConfig::class);
+ $this->appConfig = $this->createMock(IAppConfig::class);
$this->notificationManager = $this->createMock(IManager::class);
$this->l10nFactory = $this->createMock(IFactory::class);
$this->userSession = $this->createMock(IUserSession::class);
@@ -54,7 +55,7 @@ class NotifierTest extends TestCase {
if (empty($methods)) {
return new Notifier(
$this->urlGenerator,
- $this->config,
+ $this->appConfig,
$this->notificationManager,
$this->l10nFactory,
$this->userSession,
@@ -67,7 +68,7 @@ class NotifierTest extends TestCase {
return $this->getMockBuilder(Notifier::class)
->setConstructorArgs([
$this->urlGenerator,
- $this->config,
+ $this->appConfig,
$this->notificationManager,
$this->l10nFactory,
$this->userSession,
diff --git a/apps/updatenotification/tests/Settings/AdminTest.php b/apps/updatenotification/tests/Settings/AdminTest.php
index 3652c8f9081..d228c29f119 100644
--- a/apps/updatenotification/tests/Settings/AdminTest.php
+++ b/apps/updatenotification/tests/Settings/AdminTest.php
@@ -4,10 +4,12 @@ declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\UpdateNotification\Tests\Settings;
+use OCA\UpdateNotification\AppInfo\Application;
use OCA\UpdateNotification\Settings\Admin;
use OCA\UpdateNotification\UpdateChecker;
use OCP\AppFramework\Http\TemplateResponse;
@@ -20,34 +22,27 @@ use OCP\IGroupManager;
use OCP\IUserManager;
use OCP\L10N\IFactory;
use OCP\L10N\ILanguageIterator;
+use OCP\ServerVersion;
use OCP\Support\Subscription\IRegistry;
-use OCP\Util;
+use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\TestCase;
class AdminTest extends TestCase {
- /** @var IFactory|\PHPUnit\Framework\MockObject\MockObject */
- protected $l10nFactory;
- /** @var Admin */
- 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 */
- private $groupManager;
- /** @var IDateTimeFormatter|\PHPUnit\Framework\MockObject\MockObject */
- private $dateTimeFormatter;
- /** @var IRegistry|\PHPUnit\Framework\MockObject\MockObject */
- private $subscriptionRegistry;
- /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
- private $userManager;
- /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
- private $logger;
- /** IInitialState|\PHPUnit\Framework\MockObject\MockObject */
- private $initialState;
+
+ private Admin $admin;
+
+ private IFactory&MockObject $l10nFactory;
+ private IConfig&MockObject $config;
+ private IAppConfig&MockObject $appConfig;
+ private UpdateChecker&MockObject $updateChecker;
+ private IGroupManager&MockObject $groupManager;
+ private IDateTimeFormatter&MockObject $dateTimeFormatter;
+ private IRegistry&MockObject $subscriptionRegistry;
+ private IUserManager&MockObject $userManager;
+ private LoggerInterface&MockObject $logger;
+ private IInitialState&MockObject $initialState;
+ private ServerVersion&MockObject $serverVersion;
protected function setUp(): void {
parent::setUp();
@@ -62,6 +57,7 @@ class AdminTest extends TestCase {
$this->userManager = $this->createMock(IUserManager::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->initialState = $this->createMock(IInitialState::class);
+ $this->serverVersion = $this->createMock(ServerVersion::class);
$this->admin = new Admin(
$this->config,
@@ -73,11 +69,15 @@ class AdminTest extends TestCase {
$this->subscriptionRegistry,
$this->userManager,
$this->logger,
- $this->initialState
+ $this->initialState,
+ $this->serverVersion,
);
}
public function testGetFormWithUpdate(): void {
+ $this->serverVersion->expects(self::atLeastOnce())
+ ->method('getChannel')
+ ->willReturn('daily');
$this->userManager
->expects($this->once())
->method('countUsersTotal')
@@ -88,20 +88,16 @@ class AdminTest extends TestCase {
'stable',
'production',
];
- $currentChannel = Util::getChannel();
- if ($currentChannel === 'git') {
- $channels[] = 'git';
- }
$this->appConfig
->expects($this->once())
->method('getValueInt')
->with('core', 'lastupdatedat', 0)
->willReturn(12345);
- $this->config
+ $this->appConfig
->expects($this->once())
- ->method('getAppValue')
- ->with('updatenotification', 'notify_groups', '["admin"]')
- ->willReturn('["admin"]');
+ ->method('getValueArray')
+ ->with(Application::APP_NAME, 'notify_groups', ['admin'])
+ ->willReturn(['admin']);
$this->config
->method('getSystemValue')
->willReturnMap([
@@ -154,7 +150,7 @@ class AdminTest extends TestCase {
'isNewVersionAvailable' => true,
'isUpdateChecked' => true,
'lastChecked' => 'LastCheckedReturnValue',
- 'currentChannel' => Util::getChannel(),
+ 'currentChannel' => 'daily',
'channels' => $channels,
'newVersion' => '8.1.2',
'newVersionString' => 'Nextcloud 8.1.2',
@@ -172,11 +168,14 @@ class AdminTest extends TestCase {
'hasValidSubscription' => true,
]);
- $expected = new TemplateResponse('updatenotification', 'admin', [], '');
+ $expected = new TemplateResponse(Application::APP_NAME, 'admin', [], '');
$this->assertEquals($expected, $this->admin->getForm());
}
public function testGetFormWithUpdateAndChangedUpdateServer(): void {
+ $this->serverVersion->expects(self::atLeastOnce())
+ ->method('getChannel')
+ ->willReturn('beta');
$this->userManager
->expects($this->once())
->method('countUsersTotal')
@@ -187,10 +186,6 @@ class AdminTest extends TestCase {
'stable',
'production',
];
- $currentChannel = Util::getChannel();
- if ($currentChannel === 'git') {
- $channels[] = 'git';
- }
$this->appConfig
->expects($this->once())
@@ -202,11 +197,11 @@ class AdminTest extends TestCase {
->method('getSystemValueBool')
->with('updatechecker', true)
->willReturn(true);
- $this->config
+ $this->appConfig
->expects($this->once())
- ->method('getAppValue')
- ->with('updatenotification', 'notify_groups', '["admin"]')
- ->willReturn('["admin"]');
+ ->method('getValueArray')
+ ->with(Application::APP_NAME, 'notify_groups', ['admin'])
+ ->willReturn(['admin']);
$this->config
->method('getSystemValue')
->willReturnMap([
@@ -254,7 +249,7 @@ class AdminTest extends TestCase {
'isNewVersionAvailable' => true,
'isUpdateChecked' => true,
'lastChecked' => 'LastCheckedReturnValue',
- 'currentChannel' => Util::getChannel(),
+ 'currentChannel' => 'beta',
'channels' => $channels,
'newVersion' => '8.1.2',
'newVersionString' => 'Nextcloud 8.1.2',
@@ -272,11 +267,14 @@ class AdminTest extends TestCase {
'hasValidSubscription' => true,
]);
- $expected = new TemplateResponse('updatenotification', 'admin', [], '');
+ $expected = new TemplateResponse(Application::APP_NAME, 'admin', [], '');
$this->assertEquals($expected, $this->admin->getForm());
}
public function testGetFormWithUpdateAndCustomersUpdateServer(): void {
+ $this->serverVersion->expects(self::atLeastOnce())
+ ->method('getChannel')
+ ->willReturn('production');
$this->userManager
->expects($this->once())
->method('countUsersTotal')
@@ -287,10 +285,6 @@ class AdminTest extends TestCase {
'stable',
'production',
];
- $currentChannel = Util::getChannel();
- if ($currentChannel === 'git') {
- $channels[] = 'git';
- }
$this->appConfig
->expects($this->once())
@@ -302,11 +296,11 @@ class AdminTest extends TestCase {
->method('getSystemValueBool')
->with('updatechecker', true)
->willReturn(true);
- $this->config
- ->expects($this->once())
- ->method('getAppValue')
- ->with('updatenotification', 'notify_groups', '["admin"]')
- ->willReturn('["admin"]');
+ $this->appConfig
+ ->expects(self::once())
+ ->method('getValueArray')
+ ->with(Application::APP_NAME, 'notify_groups', ['admin'])
+ ->willReturn(['admin']);
$this->config
->method('getSystemValue')
->willReturnMap([
@@ -354,7 +348,7 @@ class AdminTest extends TestCase {
'isNewVersionAvailable' => true,
'isUpdateChecked' => true,
'lastChecked' => 'LastCheckedReturnValue',
- 'currentChannel' => Util::getChannel(),
+ 'currentChannel' => 'production',
'channels' => $channels,
'newVersion' => '8.1.2',
'newVersionString' => 'Nextcloud 8.1.2',
@@ -372,7 +366,7 @@ class AdminTest extends TestCase {
'hasValidSubscription' => true,
]);
- $expected = new TemplateResponse('updatenotification', 'admin', [], '');
+ $expected = new TemplateResponse(Application::APP_NAME, 'admin', [], '');
$this->assertEquals($expected, $this->admin->getForm());
}