aboutsummaryrefslogtreecommitdiffstats
path: root/apps/updatenotification/tests
diff options
context:
space:
mode:
Diffstat (limited to 'apps/updatenotification/tests')
-rw-r--r--apps/updatenotification/tests/BackgroundJob/ResetTokenTest.php12
-rw-r--r--apps/updatenotification/tests/BackgroundJob/UpdateAvailableNotificationsTest.php138
-rw-r--r--apps/updatenotification/tests/Controller/APIControllerTest.php160
-rw-r--r--apps/updatenotification/tests/Controller/AdminControllerTest.php16
-rw-r--r--apps/updatenotification/tests/Notification/NotifierTest.php56
-rw-r--r--apps/updatenotification/tests/Settings/AdminTest.php262
-rw-r--r--apps/updatenotification/tests/UpdateCheckerTest.php50
7 files changed, 392 insertions, 302 deletions
diff --git a/apps/updatenotification/tests/BackgroundJob/ResetTokenTest.php b/apps/updatenotification/tests/BackgroundJob/ResetTokenTest.php
index b93efd3a275..c03d4c48827 100644
--- a/apps/updatenotification/tests/BackgroundJob/ResetTokenTest.php
+++ b/apps/updatenotification/tests/BackgroundJob/ResetTokenTest.php
@@ -16,9 +16,9 @@ use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class ResetTokenTest extends TestCase {
- private IConfig|MockObject $config;
- private IAppConfig|MockObject $appConfig;
- private ITimeFactory|MockObject $timeFactory;
+ private IConfig&MockObject $config;
+ private IAppConfig&MockObject $appConfig;
+ private ITimeFactory&MockObject $timeFactory;
private BackgroundJobResetToken $resetTokenBackgroundJob;
protected function setUp(): void {
@@ -33,7 +33,7 @@ class ResetTokenTest extends TestCase {
);
}
- public function testRunWithNotExpiredToken() {
+ public function testRunWithNotExpiredToken(): void {
$this->timeFactory
->expects($this->atLeastOnce())
->method('getTime')
@@ -54,7 +54,7 @@ class ResetTokenTest extends TestCase {
static::invokePrivate($this->resetTokenBackgroundJob, 'run', [null]);
}
- public function testRunWithExpiredToken() {
+ public function testRunWithExpiredToken(): void {
$this->timeFactory
->expects($this->once())
->method('getTime')
@@ -72,7 +72,7 @@ class ResetTokenTest extends TestCase {
static::invokePrivate($this->resetTokenBackgroundJob, 'run', [null]);
}
- public function testRunWithExpiredTokenAndReadOnlyConfigFile() {
+ public function testRunWithExpiredTokenAndReadOnlyConfigFile(): void {
$this->timeFactory
->expects($this->never())
->method('getTime');
diff --git a/apps/updatenotification/tests/BackgroundJob/UpdateAvailableNotificationsTest.php b/apps/updatenotification/tests/BackgroundJob/UpdateAvailableNotificationsTest.php
index ca058cedff7..26a5ecde052 100644
--- a/apps/updatenotification/tests/BackgroundJob/UpdateAvailableNotificationsTest.php
+++ b/apps/updatenotification/tests/BackgroundJob/UpdateAvailableNotificationsTest.php
@@ -20,22 +20,25 @@ use OCP\IGroupManager;
use OCP\IUser;
use OCP\Notification\IManager;
use OCP\Notification\INotification;
+use OCP\ServerVersion;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class UpdateAvailableNotificationsTest extends TestCase {
- private IConfig|MockObject $config;
- private IManager|MockObject $notificationManager;
- private IGroupManager|MockObject $groupManager;
- private IAppManager|MockObject $appManager;
- private IAppConfig|MockObject $appConfig;
- private ITimeFactory|MockObject $timeFactory;
- private Installer|MockObject $installer;
- private VersionCheck|MockObject $versionCheck;
+ private ServerVersion&MockObject $serverVersion;
+ private IConfig&MockObject $config;
+ private IManager&MockObject $notificationManager;
+ private IGroupManager&MockObject $groupManager;
+ private IAppManager&MockObject $appManager;
+ private IAppConfig&MockObject $appConfig;
+ private ITimeFactory&MockObject $timeFactory;
+ private Installer&MockObject $installer;
+ private VersionCheck&MockObject $versionCheck;
protected function setUp(): void {
parent::setUp();
+ $this->serverVersion = $this->createMock(ServerVersion::class);
$this->config = $this->createMock(IConfig::class);
$this->appConfig = $this->createMock(IAppConfig::class);
$this->notificationManager = $this->createMock(IManager::class);
@@ -47,13 +50,13 @@ class UpdateAvailableNotificationsTest extends TestCase {
}
/**
- * @param array $methods
* @return UpdateAvailableNotifications|MockObject
*/
- protected function getJob(array $methods = []) {
+ protected function getJob(array $methods = []): UpdateAvailableNotifications {
if (empty($methods)) {
return new UpdateAvailableNotifications(
$this->timeFactory,
+ $this->serverVersion,
$this->config,
$this->appConfig,
$this->notificationManager,
@@ -67,6 +70,7 @@ class UpdateAvailableNotificationsTest extends TestCase {
return $this->getMockBuilder(UpdateAvailableNotifications::class)
->setConstructorArgs([
$this->timeFactory,
+ $this->serverVersion,
$this->config,
$this->appConfig,
$this->notificationManager,
@@ -80,7 +84,7 @@ class UpdateAvailableNotificationsTest extends TestCase {
}
}
- public function testRun() {
+ public function testRun(): void {
$job = $this->getJob([
'checkCoreUpdate',
'checkAppUpdates',
@@ -91,21 +95,16 @@ class UpdateAvailableNotificationsTest extends TestCase {
$job->expects($this->once())
->method('checkAppUpdates');
- $this->config->expects($this->exactly(2))
+ $this->config->expects(self::exactly(2))
->method('getSystemValueBool')
- ->withConsecutive(
- ['has_internet_connection', true],
- ['debug', false],
- )
- ->willReturnOnConsecutiveCalls(
- true,
- true,
- );
-
+ ->willReturnMap([
+ ['debug', false, true],
+ ['has_internet_connection', true, true],
+ ]);
self::invokePrivate($job, 'run', [null]);
}
- public function testRunNoInternet() {
+ public function testRunNoInternet(): void {
$job = $this->getJob([
'checkCoreUpdate',
'checkAppUpdates',
@@ -116,14 +115,16 @@ class UpdateAvailableNotificationsTest extends TestCase {
$job->expects($this->never())
->method('checkAppUpdates');
- $this->config->method('getSystemValueBool')
+ $this->config
+ ->expects(self::once())
+ ->method('getSystemValueBool')
->with('has_internet_connection', true)
->willReturn(false);
self::invokePrivate($job, 'run', [null]);
}
- public function dataCheckCoreUpdate(): array {
+ public static function dataCheckCoreUpdate(): array {
return [
['daily', null, null, null, null],
['git', null, null, null, null],
@@ -151,24 +152,15 @@ class UpdateAvailableNotificationsTest extends TestCase {
];
}
- /**
- * @dataProvider dataCheckCoreUpdate
- *
- * @param string $channel
- * @param mixed $versionCheck
- * @param null|string $version
- * @param null|string $readableVersion
- * @param null|int $errorDays
- */
- public function testCheckCoreUpdate(string $channel, $versionCheck, $version, $readableVersion, $errorDays) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataCheckCoreUpdate')]
+ public function testCheckCoreUpdate(string $channel, mixed $versionCheck, mixed $version, ?string $readableVersion, ?int $errorDays): void {
$job = $this->getJob([
- 'getChannel',
'createNotifications',
'clearErrorNotifications',
'sendErrorNotifications',
]);
- $job->expects($this->once())
+ $this->serverVersion->expects($this->once())
->method('getChannel')
->willReturn($channel);
@@ -212,10 +204,17 @@ class UpdateAvailableNotificationsTest extends TestCase {
->with('core', $version, $readableVersion);
}
+ $this->config->expects(self::any())
+ ->method('getSystemValueBool')
+ ->willReturnMap([
+ ['updatechecker', true, true],
+ ['has_internet_connection', true, true],
+ ]);
+
self::invokePrivate($job, 'checkCoreUpdate');
}
- public function dataCheckAppUpdates(): array {
+ public static function dataCheckAppUpdates(): array {
return [
[
['app1', 'app2'],
@@ -224,41 +223,40 @@ class UpdateAvailableNotificationsTest extends TestCase {
['app2', '1.9.2'],
],
[
- ['app2', '1.9.2'],
+ ['app2', '1.9.2', ''],
],
],
];
}
- /**
- * @dataProvider dataCheckAppUpdates
- *
- * @param string[] $apps
- * @param array $isUpdateAvailable
- * @param array $notifications
- */
- public function testCheckAppUpdates(array $apps, array $isUpdateAvailable, array $notifications) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataCheckAppUpdates')]
+ public function testCheckAppUpdates(array $apps, array $isUpdateAvailable, array $notifications): void {
$job = $this->getJob([
'isUpdateAvailable',
'createNotifications',
]);
$this->appManager->expects($this->once())
- ->method('getInstalledApps')
+ ->method('getEnabledApps')
->willReturn($apps);
$job->expects($this->exactly(\count($apps)))
->method('isUpdateAvailable')
->willReturnMap($isUpdateAvailable);
- $mockedMethod = $job->expects($this->exactly(\count($notifications)))
- ->method('createNotifications');
- \call_user_func_array([$mockedMethod, 'withConsecutive'], $notifications);
+ $i = 0;
+ $job->expects($this->exactly(\count($notifications)))
+ ->method('createNotifications')
+ ->willReturnCallback(function () use ($notifications, &$i): void {
+ $this->assertEquals($notifications[$i], func_get_args());
+ $i++;
+ });
+
self::invokePrivate($job, 'checkAppUpdates');
}
- public function dataCreateNotifications(): array {
+ public static function dataCreateNotifications(): array {
return [
['app1', '1.0.0', '1.0.0', false, false, null, null],
['app2', '1.0.1', '1.0.0', '1.0.0', true, ['user1'], [['user1']]],
@@ -266,18 +264,8 @@ class UpdateAvailableNotificationsTest extends TestCase {
];
}
- /**
- * @dataProvider dataCreateNotifications
- *
- * @param string $app
- * @param string $version
- * @param string|false $lastNotification
- * @param string|false $callDelete
- * @param bool $createNotification
- * @param string[]|null $users
- * @param array|null $userNotifications
- */
- public function testCreateNotifications(string $app, string $version, $lastNotification, $callDelete, $createNotification, $users, $userNotifications) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataCreateNotifications')]
+ public function testCreateNotifications(string $app, string $version, string|false $lastNotification, string|false $callDelete, bool $createNotification, ?array $users, ?array $userNotifications): void {
$job = $this->getJob([
'deleteOutdatedNotifications',
'getUsersToNotify',
@@ -286,7 +274,7 @@ class UpdateAvailableNotificationsTest extends TestCase {
$this->appConfig->expects($this->once())
->method('getAppValueString')
->with($app, '')
- ->willReturn($lastNotification ? $lastNotification : '');
+ ->willReturn($lastNotification ?: '');
if ($lastNotification !== $version) {
$this->appConfig->expects($this->once())
@@ -331,10 +319,9 @@ class UpdateAvailableNotificationsTest extends TestCase {
->willReturnSelf();
if ($userNotifications !== null) {
- $mockedMethod = $notification->expects($this->exactly(\count($userNotifications)))
+ $notification->expects($this->exactly(\count($userNotifications)))
->method('setUser')
->willReturnSelf();
- \call_user_func_array([$mockedMethod, 'withConsecutive'], $userNotifications);
$this->notificationManager->expects($this->exactly(\count($userNotifications)))
->method('notify');
@@ -351,20 +338,15 @@ class UpdateAvailableNotificationsTest extends TestCase {
self::invokePrivate($job, 'createNotifications', [$app, $version]);
}
- public function dataGetUsersToNotify(): array {
+ public static function dataGetUsersToNotify(): array {
return [
[['g1', 'g2'], ['g1' => null, 'g2' => ['u1', 'u2']], ['u1', 'u2']],
[['g3', 'g4'], ['g3' => ['u1', 'u2'], 'g4' => ['u2', 'u3']], ['u1', 'u2', 'u3']],
];
}
- /**
- * @dataProvider dataGetUsersToNotify
- * @param string[] $groups
- * @param array $groupUsers
- * @param string[] $expected
- */
- public function testGetUsersToNotify(array $groups, array $groupUsers, array $expected) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetUsersToNotify')]
+ public function testGetUsersToNotify(array $groups, array $groupUsers, array $expected): void {
$job = $this->getJob();
$this->appConfig->expects($this->once())
@@ -396,7 +378,7 @@ class UpdateAvailableNotificationsTest extends TestCase {
$this->assertEquals($expected, $result);
}
- public function dataDeleteOutdatedNotifications(): array {
+ public static function dataDeleteOutdatedNotifications(): array {
return [
['app1', '1.1.0'],
['app2', '1.2.0'],
@@ -404,11 +386,11 @@ class UpdateAvailableNotificationsTest extends TestCase {
}
/**
- * @dataProvider dataDeleteOutdatedNotifications
* @param string $app
* @param string $version
*/
- public function testDeleteOutdatedNotifications(string $app, string $version) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataDeleteOutdatedNotifications')]
+ public function testDeleteOutdatedNotifications(string $app, string $version): void {
$notification = $this->createMock(INotification::class);
$notification->expects($this->once())
->method('setApp')
@@ -448,7 +430,7 @@ class UpdateAvailableNotificationsTest extends TestCase {
/**
* @param string $gid
- * @return \OCP\IGroup|MockObject
+ * @return IGroup|MockObject
*/
protected function getGroup(string $gid) {
$group = $this->createMock(IGroup::class);
diff --git a/apps/updatenotification/tests/Controller/APIControllerTest.php b/apps/updatenotification/tests/Controller/APIControllerTest.php
new file mode 100644
index 00000000000..84973e64c22
--- /dev/null
+++ b/apps/updatenotification/tests/Controller/APIControllerTest.php
@@ -0,0 +1,160 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\UpdateNotification\Tests\Controller;
+
+use OC\App\AppStore\Fetcher\AppFetcher;
+use OCA\UpdateNotification\AppInfo\Application;
+use OCA\UpdateNotification\Controller\APIController;
+use OCA\UpdateNotification\Manager;
+use OCP\App\IAppManager;
+use OCP\AppFramework\Http;
+use OCP\IConfig;
+use OCP\IRequest;
+use OCP\IUserSession;
+use OCP\L10N\IFactory;
+use PHPUnit\Framework\MockObject\MockObject;
+use Test\TestCase;
+
+class APIControllerTest extends TestCase {
+ private IRequest&MockObject $request;
+ private IConfig&MockObject $config;
+ private IAppManager&MockObject $appManager;
+ private AppFetcher&MockObject $appFetcher;
+ private IFactory&MockObject $l10nFactory;
+ private IUserSession&MockObject $userSession;
+ private Manager&MockObject $manager;
+
+ private APIController $apiController;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->request = $this->createMock(IRequest::class);
+ $this->config = $this->createMock(IConfig::class);
+ $this->appManager = $this->createMock(IAppManager::class);
+ $this->appFetcher = $this->createMock(AppFetcher::class);
+ $this->l10nFactory = $this->createMock(IFactory::class);
+ $this->userSession = $this->createMock(IUserSession::class);
+ $this->manager = $this->createMock(Manager::class);
+
+ $this->apiController = new APIController(
+ Application::APP_NAME,
+ $this->request,
+ $this->config,
+ $this->appManager,
+ $this->appFetcher,
+ $this->l10nFactory,
+ $this->userSession,
+ $this->manager,
+ );
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetAppChangelog')]
+ public function testGetAppChangelogEntry(
+ array $params,
+ bool $hasChanges,
+ array $appInfo,
+ array $expected,
+ ): void {
+ $this->appManager->method('getAppInfo')
+ ->with('the-app')
+ ->willReturn($appInfo);
+ $this->appManager->method('getAppVersion')
+ ->with('the-app')
+ ->willReturn($appInfo['version']);
+ $this->manager->method('getChangelog')
+ ->with('the-app', self::anything())
+ ->willReturnCallback(fn ($app, $version) => $hasChanges ? "$app v$version" : null);
+
+ $result = $this->apiController->getAppChangelogEntry(...$params);
+ $this->assertEquals($result->getStatus(), $expected['status']);
+ $this->assertEquals($result->getData(), $expected['data']);
+ }
+
+ public static function dataGetAppChangelog(): array {
+ return [
+ 'no changes found' => [
+ ['the-app', null],
+ false,
+ [
+ 'name' => 'Localized name',
+ 'version' => '1.0.0',
+ ],
+ [
+ 'status' => Http::STATUS_NOT_FOUND,
+ 'data' => [],
+ ]
+ ],
+ 'changes with version parameter' => [
+ ['the-app', '1.0.0'],
+ true,
+ [
+ 'name' => 'Localized name',
+ 'version' => '1.2.0', // installed version
+ ],
+ [
+ 'status' => Http::STATUS_OK,
+ 'data' => [
+ 'appName' => 'Localized name',
+ 'content' => 'the-app v1.0.0',
+ 'version' => '1.0.0',
+ ],
+ ]
+ ],
+ 'changes without version parameter' => [
+ ['the-app', null],
+ true,
+ [
+ 'name' => 'Localized name',
+ 'version' => '1.2.0',
+ ],
+ [
+ 'status' => Http::STATUS_OK,
+ 'data' => [
+ 'appName' => 'Localized name',
+ 'content' => 'the-app v1.2.0',
+ 'version' => '1.2.0',
+ ],
+ ]
+ ],
+ 'changes of pre-release version' => [
+ ['the-app', null],
+ true,
+ [
+ 'name' => 'Localized name',
+ 'version' => '1.2.0-alpha.1',
+ ],
+ [
+ 'status' => Http::STATUS_OK,
+ 'data' => [
+ 'appName' => 'Localized name',
+ 'content' => 'the-app v1.2.0',
+ 'version' => '1.2.0-alpha.1',
+ ],
+ ]
+ ],
+ 'changes of pre-release version as parameter' => [
+ ['the-app', '1.2.0-alpha.2'],
+ true,
+ [
+ 'name' => 'Localized name',
+ 'version' => '1.2.0-beta.3',
+ ],
+ [
+ 'status' => Http::STATUS_OK,
+ 'data' => [
+ 'appName' => 'Localized name',
+ 'content' => 'the-app v1.2.0',
+ 'version' => '1.2.0-alpha.2',
+ ],
+ ]
+ ],
+ ];
+ }
+}
diff --git a/apps/updatenotification/tests/Controller/AdminControllerTest.php b/apps/updatenotification/tests/Controller/AdminControllerTest.php
index 74fcb4f8773..2263495fc14 100644
--- a/apps/updatenotification/tests/Controller/AdminControllerTest.php
+++ b/apps/updatenotification/tests/Controller/AdminControllerTest.php
@@ -22,13 +22,13 @@ use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class AdminControllerTest extends TestCase {
- private IRequest|MockObject $request;
- private IJobList|MockObject $jobList;
- private ISecureRandom|MockObject $secureRandom;
- private IConfig|MockObject $config;
- private ITimeFactory|MockObject $timeFactory;
- private IL10N|MockObject $l10n;
- private IAppConfig|MockObject $appConfig;
+ private IRequest&MockObject $request;
+ private IJobList&MockObject $jobList;
+ private ISecureRandom&MockObject $secureRandom;
+ private IConfig&MockObject $config;
+ private ITimeFactory&MockObject $timeFactory;
+ private IL10N&MockObject $l10n;
+ private IAppConfig&MockObject $appConfig;
private AdminController $adminController;
@@ -55,7 +55,7 @@ class AdminControllerTest extends TestCase {
);
}
- public function testCreateCredentials() {
+ public function testCreateCredentials(): void {
$this->jobList
->expects($this->once())
->method('add')
diff --git a/apps/updatenotification/tests/Notification/NotifierTest.php b/apps/updatenotification/tests/Notification/NotifierTest.php
index 7455966975a..aab5a84d6f3 100644
--- a/apps/updatenotification/tests/Notification/NotifierTest.php
+++ b/apps/updatenotification/tests/Notification/NotifierTest.php
@@ -4,12 +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\IConfig;
+use OCP\App\IAppManager;
+use OCP\AppFramework\Services\IAppConfig;
use OCP\IGroupManager;
use OCP\IURLGenerator;
use OCP\IUserSession;
@@ -17,65 +19,69 @@ use OCP\L10N\IFactory;
use OCP\Notification\AlreadyProcessedException;
use OCP\Notification\IManager;
use OCP\Notification\INotification;
+use OCP\ServerVersion;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class NotifierTest extends TestCase {
- /** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
- protected $urlGenerator;
- /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
- protected $config;
- /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
- protected $notificationManager;
- /** @var IFactory|\PHPUnit\Framework\MockObject\MockObject */
- protected $l10nFactory;
- /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
- protected $userSession;
- /** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */
- protected $groupManager;
+ protected IURLGenerator&MockObject $urlGenerator;
+ protected IAppConfig&MockObject $appConfig;
+ protected IManager&MockObject $notificationManager;
+ protected IFactory&MockObject $l10nFactory;
+ protected IUserSession&MockObject $userSession;
+ protected IGroupManager&MockObject $groupManager;
+ protected IAppManager&MockObject $appManager;
+ protected ServerVersion&MockObject $serverVersion;
protected function setUp(): void {
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);
$this->groupManager = $this->createMock(IGroupManager::class);
+ $this->appManager = $this->createMock(IAppManager::class);
+ $this->serverVersion = $this->createMock(ServerVersion::class);
}
/**
* @param array $methods
- * @return Notifier|\PHPUnit\Framework\MockObject\MockObject
+ * @return Notifier|MockObject
*/
- protected function getNotifier(array $methods = []) {
+ protected function getNotifier(array $methods = []): Notifier {
if (empty($methods)) {
return new Notifier(
$this->urlGenerator,
- $this->config,
+ $this->appConfig,
$this->notificationManager,
$this->l10nFactory,
$this->userSession,
- $this->groupManager
+ $this->groupManager,
+ $this->appManager,
+ $this->serverVersion,
);
}
{
return $this->getMockBuilder(Notifier::class)
->setConstructorArgs([
$this->urlGenerator,
- $this->config,
+ $this->appConfig,
$this->notificationManager,
$this->l10nFactory,
$this->userSession,
$this->groupManager,
+ $this->appManager,
+ $this->serverVersion,
])
->onlyMethods($methods)
->getMock();
}
}
- public function dataUpdateAlreadyInstalledCheck(): array {
+ public static function dataUpdateAlreadyInstalledCheck(): array {
return [
['1.1.0', '1.0.0', false],
['1.1.0', '1.1.0', true],
@@ -83,14 +89,8 @@ class NotifierTest extends TestCase {
];
}
- /**
- * @dataProvider dataUpdateAlreadyInstalledCheck
- *
- * @param string $versionNotification
- * @param string $versionInstalled
- * @param bool $exception
- */
- public function testUpdateAlreadyInstalledCheck(string $versionNotification, string $versionInstalled, bool $exception) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataUpdateAlreadyInstalledCheck')]
+ public function testUpdateAlreadyInstalledCheck(string $versionNotification, string $versionInstalled, bool $exception): void {
$notifier = $this->getNotifier();
$notification = $this->createMock(INotification::class);
diff --git a/apps/updatenotification/tests/Settings/AdminTest.php b/apps/updatenotification/tests/Settings/AdminTest.php
index 80ad2ec7587..0429c628049 100644
--- a/apps/updatenotification/tests/Settings/AdminTest.php
+++ b/apps/updatenotification/tests/Settings/AdminTest.php
@@ -4,11 +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 OC\User\Backend;
+use OCA\UpdateNotification\AppInfo\Application;
use OCA\UpdateNotification\Settings\Admin;
use OCA\UpdateNotification\UpdateChecker;
use OCP\AppFramework\Http\TemplateResponse;
@@ -21,36 +22,25 @@ use OCP\IGroupManager;
use OCP\IUserManager;
use OCP\L10N\IFactory;
use OCP\L10N\ILanguageIterator;
+use OCP\ServerVersion;
use OCP\Support\Subscription\IRegistry;
-use OCP\User\Backend\ICountUsersBackend;
-use OCP\UserInterface;
-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 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;
+ private Admin $admin;
protected function setUp(): void {
parent::setUp();
@@ -65,6 +55,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,
@@ -76,73 +67,46 @@ class AdminTest extends TestCase {
$this->subscriptionRegistry,
$this->userManager,
$this->logger,
- $this->initialState
+ $this->initialState,
+ $this->serverVersion,
);
}
- public function testGetFormWithUpdate() {
- $backend1 = $this->createMock(CountUsersBackend::class);
- $backend2 = $this->createMock(CountUsersBackend::class);
- $backend3 = $this->createMock(CountUsersBackend::class);
- $backend1
- ->expects($this->once())
- ->method('implementsActions')
- ->with(Backend::COUNT_USERS)
- ->willReturn(false);
- $backend2
- ->expects($this->once())
- ->method('implementsActions')
- ->with(Backend::COUNT_USERS)
- ->willReturn(true);
- $backend3
- ->expects($this->once())
- ->method('implementsActions')
- ->with(Backend::COUNT_USERS)
- ->willReturn(true);
- $backend1
- ->expects($this->never())
- ->method('countUsers');
- $backend2
- ->expects($this->once())
- ->method('countUsers')
- ->with()
- ->willReturn(false);
- $backend3
- ->expects($this->once())
- ->method('countUsers')
- ->with()
- ->willReturn(5);
+ public function testGetFormWithUpdate(): void {
+ $this->serverVersion->expects(self::atLeastOnce())
+ ->method('getChannel')
+ ->willReturn('daily');
$this->userManager
->expects($this->once())
- ->method('getBackends')
- ->with()
- ->willReturn([$backend1, $backend2, $backend3]);
+ ->method('countUsersTotal')
+ ->willReturn(5);
$channels = [
'daily',
'beta',
'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([
['updater.server.url', 'https://updates.nextcloud.com/updater_server/', 'https://updates.nextcloud.com/updater_server/'],
['upgrade.disable-web', false, false],
]);
+ $this->config
+ ->expects(self::any())
+ ->method('getSystemValueBool')
+ ->with('updatechecker', true)
+ ->willReturn(true);
$this->dateTimeFormatter
->expects($this->once())
->method('formatDateTime')
@@ -184,7 +148,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',
@@ -202,57 +166,24 @@ 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() {
- $backend1 = $this->createMock(CountUsersBackend::class);
- $backend2 = $this->createMock(CountUsersBackend::class);
- $backend3 = $this->createMock(CountUsersBackend::class);
- $backend1
- ->expects($this->once())
- ->method('implementsActions')
- ->with(Backend::COUNT_USERS)
- ->willReturn(false);
- $backend2
- ->expects($this->once())
- ->method('implementsActions')
- ->with(Backend::COUNT_USERS)
- ->willReturn(true);
- $backend3
- ->expects($this->once())
- ->method('implementsActions')
- ->with(Backend::COUNT_USERS)
- ->willReturn(true);
- $backend1
- ->expects($this->never())
- ->method('countUsers');
- $backend2
- ->expects($this->once())
- ->method('countUsers')
- ->with()
- ->willReturn(false);
- $backend3
- ->expects($this->once())
- ->method('countUsers')
- ->with()
- ->willReturn(5);
+ public function testGetFormWithUpdateAndChangedUpdateServer(): void {
+ $this->serverVersion->expects(self::atLeastOnce())
+ ->method('getChannel')
+ ->willReturn('beta');
$this->userManager
->expects($this->once())
- ->method('getBackends')
- ->with()
- ->willReturn([$backend1, $backend2, $backend3]);
+ ->method('countUsersTotal')
+ ->willReturn(5);
$channels = [
'daily',
'beta',
'stable',
'production',
];
- $currentChannel = Util::getChannel();
- if ($currentChannel === 'git') {
- $channels[] = 'git';
- }
$this->appConfig
->expects($this->once())
@@ -260,10 +191,15 @@ class AdminTest extends TestCase {
->with('core', 'lastupdatedat', 0)
->willReturn(12345);
$this->config
+ ->expects(self::any())
+ ->method('getSystemValueBool')
+ ->with('updatechecker', true)
+ ->willReturn(true);
+ $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([
@@ -311,7 +247,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',
@@ -329,57 +265,24 @@ 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() {
- $backend1 = $this->createMock(CountUsersBackend::class);
- $backend2 = $this->createMock(CountUsersBackend::class);
- $backend3 = $this->createMock(CountUsersBackend::class);
- $backend1
- ->expects($this->once())
- ->method('implementsActions')
- ->with(Backend::COUNT_USERS)
- ->willReturn(false);
- $backend2
- ->expects($this->once())
- ->method('implementsActions')
- ->with(Backend::COUNT_USERS)
- ->willReturn(true);
- $backend3
- ->expects($this->once())
- ->method('implementsActions')
- ->with(Backend::COUNT_USERS)
- ->willReturn(true);
- $backend1
- ->expects($this->never())
- ->method('countUsers');
- $backend2
- ->expects($this->once())
- ->method('countUsers')
- ->with()
- ->willReturn(false);
- $backend3
- ->expects($this->once())
- ->method('countUsers')
- ->with()
- ->willReturn(5);
+ public function testGetFormWithUpdateAndCustomersUpdateServer(): void {
+ $this->serverVersion->expects(self::atLeastOnce())
+ ->method('getChannel')
+ ->willReturn('production');
$this->userManager
->expects($this->once())
- ->method('getBackends')
- ->with()
- ->willReturn([$backend1, $backend2, $backend3]);
+ ->method('countUsersTotal')
+ ->willReturn(5);
$channels = [
'daily',
'beta',
'stable',
'production',
];
- $currentChannel = Util::getChannel();
- if ($currentChannel === 'git') {
- $channels[] = 'git';
- }
$this->appConfig
->expects($this->once())
@@ -387,10 +290,15 @@ class AdminTest extends TestCase {
->with('core', 'lastupdatedat', 0)
->willReturn(12345);
$this->config
- ->expects($this->once())
- ->method('getAppValue')
- ->with('updatenotification', 'notify_groups', '["admin"]')
- ->willReturn('["admin"]');
+ ->expects(self::any())
+ ->method('getSystemValueBool')
+ ->with('updatechecker', true)
+ ->willReturn(true);
+ $this->appConfig
+ ->expects(self::once())
+ ->method('getValueArray')
+ ->with(Application::APP_NAME, 'notify_groups', ['admin'])
+ ->willReturn(['admin']);
$this->config
->method('getSystemValue')
->willReturnMap([
@@ -438,7 +346,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',
@@ -456,20 +364,36 @@ 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 testGetSection() {
+ public function testGetSection(): void {
+ $this->config
+ ->expects(self::atLeastOnce())
+ ->method('getSystemValueBool')
+ ->with('updatechecker', true)
+ ->willReturn(true);
+
$this->assertSame('overview', $this->admin->getSection());
}
- public function testGetPriority() {
+ public function testGetSectionDisabled(): void {
+ $this->config
+ ->expects(self::atLeastOnce())
+ ->method('getSystemValueBool')
+ ->with('updatechecker', true)
+ ->willReturn(false);
+
+ $this->assertNull($this->admin->getSection());
+ }
+
+ public function testGetPriority(): void {
$this->assertSame(11, $this->admin->getPriority());
}
- public function changesProvider() {
+ public static function changesProvider(): array {
return [
[ #0, all info, en
[
@@ -524,10 +448,8 @@ class AdminTest extends TestCase {
];
}
- /**
- * @dataProvider changesProvider
- */
- public function testFilterChanges($changes, $userLang, $expectation) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('changesProvider')]
+ public function testFilterChanges($changes, $userLang, $expectation): void {
$iterator = $this->createMock(ILanguageIterator::class);
$iterator->expects($this->any())
->method('current')
@@ -543,7 +465,3 @@ class AdminTest extends TestCase {
$this->assertSame($expectation, $result);
}
}
-
-abstract class CountUsersBackend implements UserInterface, ICountUsersBackend {
-
-}
diff --git a/apps/updatenotification/tests/UpdateCheckerTest.php b/apps/updatenotification/tests/UpdateCheckerTest.php
index 54d756ddcb7..cffdc25d3e4 100644
--- a/apps/updatenotification/tests/UpdateCheckerTest.php
+++ b/apps/updatenotification/tests/UpdateCheckerTest.php
@@ -11,25 +11,31 @@ namespace OCA\UpdateNotification\Tests;
use OC\Updater\ChangesCheck;
use OC\Updater\VersionCheck;
use OCA\UpdateNotification\UpdateChecker;
+use OCP\AppFramework\Services\IInitialState;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class UpdateCheckerTest extends TestCase {
- /** @var ChangesCheck|\PHPUnit\Framework\MockObject\MockObject */
- protected $changesChecker;
- /** @var VersionCheck|\PHPUnit\Framework\MockObject\MockObject */
- private $updater;
- /** @var UpdateChecker */
- private $updateChecker;
+
+ private ChangesCheck&MockObject $changesChecker;
+ private VersionCheck&MockObject $updater;
+ private IInitialState&MockObject $initialState;
+ private UpdateChecker $updateChecker;
protected function setUp(): void {
parent::setUp();
$this->updater = $this->createMock(VersionCheck::class);
$this->changesChecker = $this->createMock(ChangesCheck::class);
- $this->updateChecker = new UpdateChecker($this->updater, $this->changesChecker);
+ $this->initialState = $this->createMock(IInitialState::class);
+ $this->updateChecker = new UpdateChecker(
+ $this->updater,
+ $this->changesChecker,
+ $this->initialState,
+ );
}
- public function testGetUpdateStateWithUpdateAndInvalidLink() {
+ public function testGetUpdateStateWithUpdateAndInvalidLink(): void {
$this->updater
->expects($this->once())
->method('check')
@@ -53,7 +59,7 @@ class UpdateCheckerTest extends TestCase {
$this->assertSame($expected, $this->updateChecker->getUpdateState());
}
- public function testGetUpdateStateWithUpdateAndValidLink() {
+ public function testGetUpdateStateWithUpdateAndValidLink(): void {
$changes = [
'changelog' => 'https://nextcloud.com/changelog/#123-0-0',
'whatsNew' => [
@@ -101,7 +107,7 @@ class UpdateCheckerTest extends TestCase {
$this->assertSame($expected, $this->updateChecker->getUpdateState());
}
- public function testGetUpdateStateWithoutUpdate() {
+ public function testGetUpdateStateWithoutUpdate(): void {
$this->updater
->expects($this->once())
->method('check')
@@ -110,4 +116,28 @@ class UpdateCheckerTest extends TestCase {
$expected = [];
$this->assertSame($expected, $this->updateChecker->getUpdateState());
}
+
+ public function testSetInitialState(): void {
+ $this->updater
+ ->expects($this->once())
+ ->method('check')
+ ->willReturn([
+ 'version' => '1.2.3',
+ 'versionstring' => 'Nextcloud 1.2.3',
+ 'web' => 'https://docs.nextcloud.com/myUrl',
+ 'url' => 'https://downloads.nextcloud.org/server',
+ 'changes' => 'https://updates.nextcloud.com/changelog_server/?version=123.0.0',
+ 'autoupdater' => '1',
+ 'eol' => '0',
+ ]);
+
+ $this->initialState->expects(self::once())
+ ->method('provideInitialState')
+ ->with('updateState', [
+ 'updateVersion' => 'Nextcloud 1.2.3',
+ 'updateLink' => 'https://docs.nextcloud.com/myUrl',
+ ]);
+
+ $this->updateChecker->setInitialState();
+ }
}