summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/files_sharing/tests/ApiTest.php22
-rw-r--r--apps/updatenotification/appinfo/app.php53
-rw-r--r--apps/updatenotification/appinfo/info.xml4
-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.php96
-rw-r--r--apps/updatenotification/lib/Controller/AdminController.php99
-rw-r--r--apps/updatenotification/lib/Notification/BackgroundJob.php56
-rw-r--r--apps/updatenotification/lib/Notification/Notifier.php18
-rw-r--r--apps/updatenotification/lib/ResetTokenBackgroundJob.php27
-rw-r--r--apps/updatenotification/lib/Settings/Admin.php117
-rw-r--r--apps/updatenotification/lib/UpdateChecker.php13
-rw-r--r--apps/updatenotification/templates/admin.php9
-rw-r--r--apps/updatenotification/tests/Controller/AdminControllerTest.php163
-rw-r--r--apps/updatenotification/tests/Notification/BackgroundJobTest.php41
-rw-r--r--apps/updatenotification/tests/Notification/NotifierTest.php7
-rw-r--r--apps/updatenotification/tests/ResetTokenBackgroundJobTest.php20
-rw-r--r--apps/updatenotification/tests/Settings/AdminTest.php127
-rw-r--r--apps/updatenotification/tests/UpdateCheckerTest.php8
19 files changed, 458 insertions, 424 deletions
diff --git a/apps/files_sharing/tests/ApiTest.php b/apps/files_sharing/tests/ApiTest.php
index 2279155e914..8e2b5942d14 100644
--- a/apps/files_sharing/tests/ApiTest.php
+++ b/apps/files_sharing/tests/ApiTest.php
@@ -62,8 +62,8 @@ class ApiTest extends TestCase {
protected function setUp() {
parent::setUp();
- \OC::$server->getAppConfig()->setValue('core', 'shareapi_exclude_groups', 'no');
- \OC::$server->getAppConfig()->setValue('core', 'shareapi_expire_after_n_days', '7');
+ \OC::$server->getConfig()->setAppValue('core', 'shareapi_exclude_groups', 'no');
+ \OC::$server->getConfig()->setAppValue('core', 'shareapi_expire_after_n_days', '7');
$this->folder = self::TEST_FOLDER_NAME;
$this->subfolder = '/subfolder_share_api_test';
@@ -239,8 +239,8 @@ class ApiTest extends TestCase {
function testEnfoceLinkPassword() {
$password = md5(time());
- $appConfig = \OC::$server->getAppConfig();
- $appConfig->setValue('core', 'shareapi_enforce_links_password', 'yes');
+ $config = \OC::$server->getConfig();
+ $config->setAppValue('core', 'shareapi_enforce_links_password', 'yes');
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
try {
@@ -287,7 +287,7 @@ class ApiTest extends TestCase {
$ocs->deleteShare($data['id']);
$ocs->cleanup();
- $appConfig->setValue('core', 'shareapi_enforce_links_password', 'no');
+ $config->setAppValue('core', 'shareapi_enforce_links_password', 'no');
}
/**
@@ -296,7 +296,7 @@ class ApiTest extends TestCase {
function testSharePermissions() {
// sharing file to a user should work if shareapi_exclude_groups is set
// to no
- \OC::$server->getAppConfig()->setValue('core', 'shareapi_exclude_groups', 'no');
+ \OC::$server->getConfig()->setAppValue('core', 'shareapi_exclude_groups', 'no');
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare($this->filename, \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
@@ -311,8 +311,8 @@ class ApiTest extends TestCase {
$ocs->cleanup();
// exclude groups, but not the group the user belongs to. Sharing should still work
- \OC::$server->getAppConfig()->setValue('core', 'shareapi_exclude_groups', 'yes');
- \OC::$server->getAppConfig()->setValue('core', 'shareapi_exclude_groups_list', 'admin,group1,group2');
+ \OC::$server->getConfig()->setAppValue('core', 'shareapi_exclude_groups', 'yes');
+ \OC::$server->getConfig()->setAppValue('core', 'shareapi_exclude_groups_list', 'admin,group1,group2');
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare($this->filename, \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
@@ -327,15 +327,15 @@ class ApiTest extends TestCase {
$ocs->cleanup();
// now we exclude the group the user belongs to ('group'), sharing should fail now
- \OC::$server->getAppConfig()->setValue('core', 'shareapi_exclude_groups_list', 'admin,group');
+ \OC::$server->getConfig()->setAppValue('core', 'shareapi_exclude_groups_list', 'admin,group');
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs->createShare($this->filename, \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
$ocs->cleanup();
// cleanup
- \OC::$server->getAppConfig()->setValue('core', 'shareapi_exclude_groups', 'no');
- \OC::$server->getAppConfig()->setValue('core', 'shareapi_exclude_groups_list', '');
+ \OC::$server->getConfig()->setAppValue('core', 'shareapi_exclude_groups', 'no');
+ \OC::$server->getConfig()->setAppValue('core', 'shareapi_exclude_groups_list', '');
}
diff --git a/apps/updatenotification/appinfo/app.php b/apps/updatenotification/appinfo/app.php
index fd1739bde55..5002fd7c837 100644
--- a/apps/updatenotification/appinfo/app.php
+++ b/apps/updatenotification/appinfo/app.php
@@ -1,56 +1,25 @@
<?php
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @copyright Copyright (c) 2018, Joas Schilling <coding@schilljs.com>
*
* @author Joas Schilling <coding@schilljs.com>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
*
- * @license AGPL-3.0
+ * @license GNU AGPL version 3 or any later version
*
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
-if(\OC::$server->getConfig()->getSystemValue('updatechecker', true) === true) {
- $updater = new \OC\Updater\VersionCheck(
- \OC::$server->getHTTPClientService(),
- \OC::$server->getConfig()
- );
- $updateChecker = new \OCA\UpdateNotification\UpdateChecker(
- $updater
- );
-
- $userObject = \OC::$server->getUserSession()->getUser();
- if($userObject !== null) {
- if(\OC::$server->getGroupManager()->isAdmin($userObject->getUID()) &&
- !\OC::$server->getAppManager()->isEnabledForUser('notifications')) {
- if($updateChecker->getUpdateState() !== []) {
- \OCP\Util::addScript('updatenotification', 'notification');
- OC_Hook::connect('\OCP\Config', 'js', $updateChecker, 'getJavaScript');
- }
- }
- }
-
- $manager = \OC::$server->getNotificationManager();
- $manager->registerNotifier(function() use ($manager) {
- return \OC::$server->query(\OCA\UpdateNotification\Notification\Notifier::class);
- }, function() {
- $l = \OC::$server->getL10N('updatenotification');
- return [
- 'id' => 'updatenotification',
- 'name' => $l->t('Update notifications'),
- ];
- });
-}
+$app = new \OCA\UpdateNotification\AppInfo\Application();
+$app->register();
diff --git a/apps/updatenotification/appinfo/info.xml b/apps/updatenotification/appinfo/info.xml
index 5dc0889bb9d..14ec98916ab 100644
--- a/apps/updatenotification/appinfo/info.xml
+++ b/apps/updatenotification/appinfo/info.xml
@@ -5,7 +5,7 @@
<description>Displays update notifications for Nextcloud and provides the SSO for the updater.</description>
<licence>AGPL</licence>
<author>Lukas Reschke</author>
- <version>1.4.0</version>
+ <version>1.4.1</version>
<namespace>UpdateNotification</namespace>
<default_enable/>
<dependencies>
@@ -17,6 +17,6 @@
</background-jobs>
<settings>
- <admin>OCA\UpdateNotification\Controller\AdminController</admin>
+ <admin>OCA\UpdateNotification\Settings\Admin</admin>
</settings>
</info>
diff --git a/apps/updatenotification/composer/composer/autoload_classmap.php b/apps/updatenotification/composer/composer/autoload_classmap.php
index e1833548bcf..55ad497a858 100644
--- a/apps/updatenotification/composer/composer/autoload_classmap.php
+++ b/apps/updatenotification/composer/composer/autoload_classmap.php
@@ -11,5 +11,6 @@ return array(
'OCA\\UpdateNotification\\Notification\\BackgroundJob' => $baseDir . '/../lib/Notification/BackgroundJob.php',
'OCA\\UpdateNotification\\Notification\\Notifier' => $baseDir . '/../lib/Notification/Notifier.php',
'OCA\\UpdateNotification\\ResetTokenBackgroundJob' => $baseDir . '/../lib/ResetTokenBackgroundJob.php',
+ 'OCA\\UpdateNotification\\Settings\\Admin' => $baseDir . '/../lib/Settings/Admin.php',
'OCA\\UpdateNotification\\UpdateChecker' => $baseDir . '/../lib/UpdateChecker.php',
);
diff --git a/apps/updatenotification/composer/composer/autoload_static.php b/apps/updatenotification/composer/composer/autoload_static.php
index 1c63a2d234b..4a50e180a8f 100644
--- a/apps/updatenotification/composer/composer/autoload_static.php
+++ b/apps/updatenotification/composer/composer/autoload_static.php
@@ -26,6 +26,7 @@ class ComposerStaticInitUpdateNotification
'OCA\\UpdateNotification\\Notification\\BackgroundJob' => __DIR__ . '/..' . '/../lib/Notification/BackgroundJob.php',
'OCA\\UpdateNotification\\Notification\\Notifier' => __DIR__ . '/..' . '/../lib/Notification/Notifier.php',
'OCA\\UpdateNotification\\ResetTokenBackgroundJob' => __DIR__ . '/..' . '/../lib/ResetTokenBackgroundJob.php',
+ 'OCA\\UpdateNotification\\Settings\\Admin' => __DIR__ . '/..' . '/../lib/Settings/Admin.php',
'OCA\\UpdateNotification\\UpdateChecker' => __DIR__ . '/..' . '/../lib/UpdateChecker.php',
);
diff --git a/apps/updatenotification/lib/AppInfo/Application.php b/apps/updatenotification/lib/AppInfo/Application.php
index 5eba176f312..d79f14764de 100644
--- a/apps/updatenotification/lib/AppInfo/Application.php
+++ b/apps/updatenotification/lib/AppInfo/Application.php
@@ -1,56 +1,84 @@
<?php
+declare(strict_types=1);
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @copyright Copyright (c) 2018, Joas Schilling <coding@schilljs.com>
*
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
+ * @author Joas Schilling <coding@schilljs.com>
*
- * @license AGPL-3.0
+ * @license GNU AGPL version 3 or any later version
*
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\UpdateNotification\AppInfo;
-use OC\AppFramework\Utility\TimeFactory;
-use OCA\UpdateNotification\Controller\AdminController;
+use OCA\UpdateNotification\Notification\Notifier;
use OCA\UpdateNotification\UpdateChecker;
use OCP\AppFramework\App;
-use OCP\AppFramework\IAppContainer;
+use OCP\AppFramework\QueryException;
+use OCP\IUser;
+use OCP\Util;
class Application extends App {
- public function __construct (array $urlParams = array()) {
- parent::__construct('updatenotification', $urlParams);
- $container = $this->getContainer();
-
- $container->registerService('AdminController', function(IAppContainer $c) {
- $updater = new \OC\Updater\VersionCheck(
- \OC::$server->getHTTPClientService(),
- \OC::$server->getConfig()
- );
- return new AdminController(
- $c->query('AppName'),
- $c->query('Request'),
- $c->getServer()->getJobList(),
- $c->getServer()->getSecureRandom(),
- $c->getServer()->getConfig(),
- new TimeFactory(),
- $c->getServer()->getL10N($c->query('AppName')),
- new UpdateChecker($updater),
- $c->getServer()->getDateTimeFormatter()
- );
- });
+ public function __construct() {
+ parent::__construct('updatenotification', []);
}
+ public function register() {
+ $server = $this->getContainer()->getServer();
+
+ if ($server->getConfig()->getSystemValue('updatechecker', true) !== true) {
+ // Updater check is disabled
+ return;
+ }
+
+ $user = $server->getUserSession()->getUser();
+ if (!$user instanceof IUser) {
+ // Nothing to do for guests
+ return;
+ }
+
+ if ($server->getAppManager()->isEnabledForUser('notifications')) {
+ // Notifications app is available, so we register.
+ // Since notifications also work for non-admins we don't check this here.
+ $this->registerNotifier();
+ } else if ($server->getGroupManager()->isAdmin($user->getUID())) {
+ try {
+ $updateChecker = $this->getContainer()->query(UpdateChecker::class);
+ } catch (QueryException $e) {
+ $server->getLogger()->logException($e);
+ return;
+ }
+
+ if ($updateChecker->getUpdateState() !== []) {
+ Util::addScript('updatenotification', 'notification');
+ \OC_Hook::connect('\OCP\Config', 'js', $updateChecker, 'populateJavaScriptVariables');
+ }
+ }
+ }
+
+ public function registerNotifier() {
+ $notificationsManager = $this->getContainer()->getServer()->getNotificationManager();
+ $notificationsManager->registerNotifier(function() {
+ return $this->getContainer()->query(Notifier::class);
+ }, function() {
+ $l = $this->getContainer()->getServer()->getL10N('updatenotification');
+ return [
+ 'id' => 'updatenotification',
+ 'name' => $l->t('Update notifications'),
+ ];
+ });
+ }
}
diff --git a/apps/updatenotification/lib/Controller/AdminController.php b/apps/updatenotification/lib/Controller/AdminController.php
index 9d2a5074a4a..57f89969db4 100644
--- a/apps/updatenotification/lib/Controller/AdminController.php
+++ b/apps/updatenotification/lib/Controller/AdminController.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -25,20 +26,18 @@
namespace OCA\UpdateNotification\Controller;
-use OCA\UpdateNotification\UpdateChecker;
+use OCA\UpdateNotification\ResetTokenBackgroundJob;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\DataResponse;
-use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList;
use OCP\IConfig;
-use OCP\IDateTimeFormatter;
use OCP\IL10N;
use OCP\IRequest;
use OCP\Security\ISecureRandom;
-use OCP\Settings\ISettings;
+use OCP\Util;
-class AdminController extends Controller implements ISettings {
+class AdminController extends Controller {
/** @var IJobList */
private $jobList;
/** @var ISecureRandom */
@@ -47,12 +46,8 @@ class AdminController extends Controller implements ISettings {
private $config;
/** @var ITimeFactory */
private $timeFactory;
- /** @var UpdateChecker */
- private $updateChecker;
/** @var IL10N */
private $l10n;
- /** @var IDateTimeFormatter */
- private $dateTimeFormatter;
/**
* @param string $appName
@@ -62,8 +57,6 @@ class AdminController extends Controller implements ISettings {
* @param IConfig $config
* @param ITimeFactory $timeFactory
* @param IL10N $l10n
- * @param UpdateChecker $updateChecker
- * @param IDateTimeFormatter $dateTimeFormatter
*/
public function __construct($appName,
IRequest $request,
@@ -71,70 +64,21 @@ class AdminController extends Controller implements ISettings {
ISecureRandom $secureRandom,
IConfig $config,
ITimeFactory $timeFactory,
- IL10N $l10n,
- UpdateChecker $updateChecker,
- IDateTimeFormatter $dateTimeFormatter) {
+ IL10N $l10n) {
parent::__construct($appName, $request);
$this->jobList = $jobList;
$this->secureRandom = $secureRandom;
$this->config = $config;
$this->timeFactory = $timeFactory;
$this->l10n = $l10n;
- $this->updateChecker = $updateChecker;
- $this->dateTimeFormatter = $dateTimeFormatter;
}
/**
- * @return TemplateResponse
- */
- public function displayPanel() {
- $lastUpdateCheckTimestamp = $this->config->getAppValue('core', 'lastupdatedat');
- $lastUpdateCheck = $this->dateTimeFormatter->formatDateTime($lastUpdateCheckTimestamp);
-
- $channels = [
- 'daily',
- 'beta',
- 'stable',
- 'production',
- ];
- $currentChannel = \OCP\Util::getChannel();
-
- // Remove the currently used channel from the channels list
- if(($key = array_search($currentChannel, $channels)) !== false) {
- unset($channels[$key]);
- }
- $updateState = $this->updateChecker->getUpdateState();
-
- $notifyGroups = json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'), true);
-
- $defaultUpdateServerURL = 'https://updates.nextcloud.com/server/';
- $updateServerURL = $this->config->getSystemValue('updater.server.url', $defaultUpdateServerURL);
-
- $params = [
- 'isNewVersionAvailable' => !empty($updateState['updateAvailable']),
- 'isUpdateChecked' => $lastUpdateCheckTimestamp > 0,
- 'lastChecked' => $lastUpdateCheck,
- 'currentChannel' => $currentChannel,
- 'channels' => $channels,
- 'newVersionString' => (empty($updateState['updateVersion'])) ? '' : $updateState['updateVersion'],
- 'downloadLink' => (empty($updateState['downloadLink'])) ? '' : $updateState['downloadLink'],
- 'updaterEnabled' => (empty($updateState['updaterEnabled'])) ? false : $updateState['updaterEnabled'],
- 'isDefaultUpdateServerURL' => $updateServerURL === $defaultUpdateServerURL,
- 'updateServerURL' => $updateServerURL,
- 'notify_groups' => implode('|', $notifyGroups),
- ];
-
- return new TemplateResponse($this->appName, 'admin', $params, '');
- }
-
- /**
- * @UseSession
- *
* @param string $channel
* @return DataResponse
*/
- public function setChannel($channel) {
- \OCP\Util::setChannel($channel);
+ public function setChannel(string $channel): DataResponse {
+ Util::setChannel($channel);
$this->config->setAppValue('core', 'lastupdatedat', 0);
return new DataResponse(['status' => 'success', 'data' => ['message' => $this->l10n->t('Channel updated')]]);
}
@@ -142,9 +86,9 @@ class AdminController extends Controller implements ISettings {
/**
* @return DataResponse
*/
- public function createCredentials() {
+ public function createCredentials(): DataResponse {
// Create a new job and store the creation date
- $this->jobList->add('OCA\UpdateNotification\ResetTokenBackgroundJob');
+ $this->jobList->add(ResetTokenBackgroundJob::class);
$this->config->setAppValue('core', 'updater.secret.created', $this->timeFactory->getTime());
// Create a new token
@@ -153,29 +97,4 @@ class AdminController extends Controller implements ISettings {
return new DataResponse($newToken);
}
-
- /**
- * @return TemplateResponse returns the instance with all parameters set, ready to be rendered
- */
- public function getForm() {
- return $this->displayPanel();
- }
-
- /**
- * @return string the section ID, e.g. 'sharing'
- */
- public function getSection() {
- return 'server';
- }
-
- /**
- * @return int whether the form should be rather on the top or bottom of
- * the admin section. The forms are arranged in ascending order of the
- * priority values. It is required to return a value between 0 and 100.
- *
- * E.g.: 70
- */
- public function getPriority() {
- return 1;
- }
}
diff --git a/apps/updatenotification/lib/Notification/BackgroundJob.php b/apps/updatenotification/lib/Notification/BackgroundJob.php
index 3c0cac60cde..c010ccc89e5 100644
--- a/apps/updatenotification/lib/Notification/BackgroundJob.php
+++ b/apps/updatenotification/lib/Notification/BackgroundJob.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -90,7 +91,7 @@ class BackgroundJob extends TimedJob {
* Check for ownCloud update
*/
protected function checkCoreUpdate() {
- if (in_array($this->getChannel(), ['daily', 'git'], true)) {
+ if (\in_array($this->getChannel(), ['daily', 'git'], true)) {
// "These aren't the update channels you're looking for." - Ben Obi-Wan Kenobi
return;
}
@@ -102,10 +103,10 @@ class BackgroundJob extends TimedJob {
$errors = 1 + (int) $this->config->getAppValue('updatenotification', 'update_check_errors', 0);
$this->config->setAppValue('updatenotification', 'update_check_errors', $errors);
- if (in_array($errors, $this->connectionNotifications, true)) {
+ if (\in_array($errors, $this->connectionNotifications, true)) {
$this->sendErrorNotifications($errors);
}
- } else if (is_array($status)) {
+ } else if (\is_array($status)) {
$this->config->setAppValue('updatenotification', 'update_check_errors', 0);
$this->clearErrorNotifications();
@@ -178,26 +179,31 @@ class BackgroundJob extends TimedJob {
if ($lastNotification === $version) {
// We already notified about this update
return;
- } else if ($lastNotification !== false) {
+ }
+
+ if ($lastNotification !== false) {
// Delete old updates
$this->deleteOutdatedNotifications($app, $lastNotification);
}
-
$notification = $this->notificationManager->createNotification();
- $notification->setApp('updatenotification')
- ->setDateTime(new \DateTime())
- ->setObject($app, $version);
-
- if ($visibleVersion !== '') {
- $notification->setSubject('update_available', ['version' => $visibleVersion]);
- } else {
- $notification->setSubject('update_available');
- }
+ try {
+ $notification->setApp('updatenotification')
+ ->setDateTime(new \DateTime())
+ ->setObject($app, $version);
- foreach ($this->getUsersToNotify() as $uid) {
- $notification->setUser($uid);
- $this->notificationManager->notify($notification);
+ if ($visibleVersion !== '') {
+ $notification->setSubject('update_available', ['version' => $visibleVersion]);
+ } else {
+ $notification->setSubject('update_available');
+ }
+
+ foreach ($this->getUsersToNotify() as $uid) {
+ $notification->setUser($uid);
+ $this->notificationManager->notify($notification);
+ }
+ } catch (\InvalidArgumentException $e) {
+ return;
}
$this->config->setAppValue('updatenotification', $app, $version);
@@ -206,12 +212,12 @@ class BackgroundJob extends TimedJob {
/**
* @return string[]
*/
- protected function getUsersToNotify() {
+ protected function getUsersToNotify(): array {
if ($this->users !== null) {
return $this->users;
}
- $notifyGroups = json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'), true);
+ $notifyGroups = (array) json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'), true);
$this->users = [];
foreach ($notifyGroups as $group) {
$groupToNotify = $this->groupManager->get($group);
@@ -235,15 +241,19 @@ class BackgroundJob extends TimedJob {
*/
protected function deleteOutdatedNotifications($app, $version) {
$notification = $this->notificationManager->createNotification();
- $notification->setApp('updatenotification')
- ->setObject($app, $version);
+ try {
+ $notification->setApp('updatenotification')
+ ->setObject($app, $version);
+ } catch (\InvalidArgumentException $e) {
+ return;
+ }
$this->notificationManager->markProcessed($notification);
}
/**
* @return VersionCheck
*/
- protected function createVersionCheck() {
+ protected function createVersionCheck(): VersionCheck {
return new VersionCheck(
$this->client,
$this->config
@@ -253,7 +263,7 @@ class BackgroundJob extends TimedJob {
/**
* @return string
*/
- protected function getChannel() {
+ protected function getChannel(): string {
return \OC_Util::getChannel();
}
diff --git a/apps/updatenotification/lib/Notification/Notifier.php b/apps/updatenotification/lib/Notification/Notifier.php
index d18a2663702..c88937f0dff 100644
--- a/apps/updatenotification/lib/Notification/Notifier.php
+++ b/apps/updatenotification/lib/Notification/Notifier.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -33,6 +34,7 @@ use OCP\L10N\IFactory;
use OCP\Notification\IManager;
use OCP\Notification\INotification;
use OCP\Notification\INotifier;
+use OCP\Util;
class Notifier implements INotifier {
@@ -84,9 +86,9 @@ class Notifier implements INotifier {
* @throws \InvalidArgumentException When the notification was not prepared by a notifier
* @since 9.0.0
*/
- public function prepare(INotification $notification, $languageCode) {
+ public function prepare(INotification $notification, $languageCode): INotification {
if ($notification->getApp() !== 'updatenotification') {
- throw new \InvalidArgumentException();
+ throw new \InvalidArgumentException('Unknown app id');
}
$l = $this->l10NFactory->get('updatenotification', $languageCode);
@@ -94,7 +96,7 @@ class Notifier implements INotifier {
$errors = (int) $this->config->getAppValue('updatenotification', 'update_check_errors', 0);
if ($errors === 0) {
$this->notificationManager->markProcessed($notification);
- throw new \InvalidArgumentException();
+ throw new \InvalidArgumentException('Update checked worked again');
}
$notification->setParsedSubject($l->t('The update server could not be reached since %d days to check for new updates.', [$errors]))
@@ -145,14 +147,14 @@ class Notifier implements INotifier {
protected function updateAlreadyInstalledCheck(INotification $notification, $installedVersion) {
if (version_compare($notification->getObjectId(), $installedVersion, '<=')) {
$this->notificationManager->markProcessed($notification);
- throw new \InvalidArgumentException();
+ throw new \InvalidArgumentException('Update already installed');
}
}
/**
* @return bool
*/
- protected function isAdmin() {
+ protected function isAdmin(): bool {
$user = $this->userSession->getUser();
if ($user instanceof IUser) {
@@ -162,11 +164,11 @@ class Notifier implements INotifier {
return false;
}
- protected function getCoreVersions() {
- return implode('.', \OCP\Util::getVersion());
+ protected function getCoreVersions(): string {
+ return implode('.', Util::getVersion());
}
- protected function getAppVersions() {
+ protected function getAppVersions(): array {
return \OC_App::getAppVersions();
}
diff --git a/apps/updatenotification/lib/ResetTokenBackgroundJob.php b/apps/updatenotification/lib/ResetTokenBackgroundJob.php
index 93b5a750789..87cca466ec7 100644
--- a/apps/updatenotification/lib/ResetTokenBackgroundJob.php
+++ b/apps/updatenotification/lib/ResetTokenBackgroundJob.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -22,7 +23,6 @@
namespace OCA\UpdateNotification;
-use OC\AppFramework\Utility\TimeFactory;
use OC\BackgroundJob\TimedJob;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IConfig;
@@ -40,28 +40,15 @@ class ResetTokenBackgroundJob extends TimedJob {
private $timeFactory;
/**
- * @param IConfig|null $config
- * @param ITimeFactory|null $timeFactory
+ * @param IConfig $config
+ * @param ITimeFactory $timeFactory
*/
- public function __construct(IConfig $config = null,
- ITimeFactory $timeFactory = null) {
+ public function __construct(IConfig $config,
+ ITimeFactory $timeFactory) {
// Run all 10 minutes
$this->setInterval(60 * 10);
-
- if ($config instanceof IConfig && $timeFactory instanceof ITimeFactory) {
- $this->config = $config;
- $this->timeFactory = $timeFactory;
- } else {
- $this->fixDIForJobs();
- }
- }
-
- /**
- * DI for jobs
- */
- private function fixDIForJobs() {
- $this->config = \OC::$server->getConfig();
- $this->timeFactory = new TimeFactory();
+ $this->config = $config;
+ $this->timeFactory = $timeFactory;
}
/**
diff --git a/apps/updatenotification/lib/Settings/Admin.php b/apps/updatenotification/lib/Settings/Admin.php
new file mode 100644
index 00000000000..7fb6cc99dea
--- /dev/null
+++ b/apps/updatenotification/lib/Settings/Admin.php
@@ -0,0 +1,117 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ *
+ * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
+ * @author Joas Schilling <coding@schilljs.com>
+ * @author Lukas Reschke <lukas@statuscode.ch>
+ * @author Morris Jobke <hey@morrisjobke.de>
+ *
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\UpdateNotification\Settings;
+
+use OCA\UpdateNotification\UpdateChecker;
+use OCP\AppFramework\Http\TemplateResponse;
+use OCP\IConfig;
+use OCP\IDateTimeFormatter;
+use OCP\Settings\ISettings;
+use OCP\Util;
+
+class Admin implements ISettings {
+ /** @var IConfig */
+ private $config;
+ /** @var UpdateChecker */
+ private $updateChecker;
+ /** @var IDateTimeFormatter */
+ private $dateTimeFormatter;
+
+ /**
+ * @param IConfig $config
+ * @param UpdateChecker $updateChecker
+ * @param IDateTimeFormatter $dateTimeFormatter
+ */
+ public function __construct(IConfig $config,
+ UpdateChecker $updateChecker,
+ IDateTimeFormatter $dateTimeFormatter) {
+ $this->config = $config;
+ $this->updateChecker = $updateChecker;
+ $this->dateTimeFormatter = $dateTimeFormatter;
+ }
+
+ /**
+ * @return TemplateResponse
+ */
+ public function getForm(): TemplateResponse {
+ $lastUpdateCheckTimestamp = $this->config->getAppValue('core', 'lastupdatedat');
+ $lastUpdateCheck = $this->dateTimeFormatter->formatDateTime($lastUpdateCheckTimestamp);
+
+ $channels = [
+ 'daily',
+ 'beta',
+ 'stable',
+ 'production',
+ ];
+ $currentChannel = Util::getChannel();
+
+ // Remove the currently used channel from the channels list
+ if(($key = array_search($currentChannel, $channels, true)) !== false) {
+ unset($channels[$key]);
+ }
+ $updateState = $this->updateChecker->getUpdateState();
+
+ $notifyGroups = json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'), true);
+
+ $defaultUpdateServerURL = 'https://updates.nextcloud.com/server/';
+ $updateServerURL = $this->config->getSystemValue('updater.server.url', $defaultUpdateServerURL);
+
+ $params = [
+ 'isNewVersionAvailable' => !empty($updateState['updateAvailable']),
+ 'isUpdateChecked' => $lastUpdateCheckTimestamp > 0,
+ 'lastChecked' => $lastUpdateCheck,
+ 'currentChannel' => $currentChannel,
+ 'channels' => $channels,
+ 'newVersionString' => empty($updateState['updateVersion']) ? '' : $updateState['updateVersion'],
+ 'downloadLink' => empty($updateState['downloadLink']) ? '' : $updateState['downloadLink'],
+ 'updaterEnabled' => empty($updateState['updaterEnabled']) ? false : $updateState['updaterEnabled'],
+ 'isDefaultUpdateServerURL' => $updateServerURL === $defaultUpdateServerURL,
+ 'updateServerURL' => $updateServerURL,
+ 'notify_groups' => implode('|', $notifyGroups),
+ ];
+
+ return new TemplateResponse('updatenotification', 'admin', $params, '');
+ }
+
+ /**
+ * @return string the section ID, e.g. 'sharing'
+ */
+ public function getSection(): string {
+ return 'server';
+ }
+
+ /**
+ * @return int whether the form should be rather on the top or bottom of
+ * the admin section. The forms are arranged in ascending order of the
+ * priority values. It is required to return a value between 0 and 100.
+ *
+ * E.g.: 70
+ */
+ public function getPriority(): int {
+ return 1;
+ }
+}
diff --git a/apps/updatenotification/lib/UpdateChecker.php b/apps/updatenotification/lib/UpdateChecker.php
index ad76de56953..5f2712423d2 100644
--- a/apps/updatenotification/lib/UpdateChecker.php
+++ b/apps/updatenotification/lib/UpdateChecker.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -40,18 +41,18 @@ class UpdateChecker {
/**
* @return array
*/
- public function getUpdateState() {
+ public function getUpdateState(): array {
$data = $this->updater->check();
$result = [];
- if(isset($data['version']) && $data['version'] !== '' && $data['version'] !== []) {
+ if (isset($data['version']) && $data['version'] !== '' && $data['version'] !== []) {
$result['updateAvailable'] = true;
$result['updateVersion'] = $data['versionstring'];
$result['updaterEnabled'] = $data['autoupdater'] === '1';
- if(substr($data['web'], 0, 8) === 'https://') {
+ if (strpos($data['web'], 'https://') === 0) {
$result['updateLink'] = $data['web'];
}
- if(substr($data['url'], 0, 8) === 'https://') {
+ if (strpos($data['url'], 'https://') === 0) {
$result['downloadLink'] = $data['url'];
}
@@ -64,11 +65,11 @@ class UpdateChecker {
/**
* @param array $data
*/
- public function getJavaScript(array $data) {
+ public function populateJavaScriptVariables(array $data) {
$data['array']['oc_updateState'] = json_encode([
'updateAvailable' => true,
'updateVersion' => $this->getUpdateState()['updateVersion'],
- 'updateLink' => isset($this->getUpdateState()['updateLink']) ? $this->getUpdateState()['updateLink'] : '',
+ 'updateLink' => $this->getUpdateState()['updateLink'] ?? '',
]);
}
}
diff --git a/apps/updatenotification/templates/admin.php b/apps/updatenotification/templates/admin.php
index e09d19848e7..19bbec769d0 100644
--- a/apps/updatenotification/templates/admin.php
+++ b/apps/updatenotification/templates/admin.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
script('updatenotification', 'admin');
style('updatenotification', 'admin');
@@ -40,7 +41,7 @@
<?php if (!$isDefaultUpdateServerURL) { ?>
<br />
<em>
- <?php p($l->t("A non-default update server is in use to be checked for updates:")); ?>
+ <?php p($l->t('A non-default update server is in use to be checked for updates:')); ?>
<code><?php p($updateServerURL); ?></code>
</em>
<?php } ?>
@@ -65,10 +66,10 @@
<p id="oca_updatenotification_groups">
<?php p($l->t('Notify members of the following groups about available updates:')); ?>
<input name="oca_updatenotification_groups_list" type="hidden" id="oca_updatenotification_groups_list" value="<?php p($_['notify_groups']) ?>" style="width: 400px"><br />
- <em class="<?php if (!in_array($currentChannel, ['daily', 'git'])) p('hidden'); ?>">
+ <em class="<?php if (!\in_array($currentChannel, ['daily', 'git'], true)) { p('hidden'); } ?>">
<?php p($l->t('Only notification for app updates are available.')); ?>
- <?php if ($currentChannel === 'daily') p($l->t('The selected update channel makes dedicated notifications for the server obsolete.')); ?>
- <?php if ($currentChannel === 'git') p($l->t('The selected update channel does not support updates of the server.')); ?>
+ <?php if ($currentChannel === 'daily') { p($l->t('The selected update channel makes dedicated notifications for the server obsolete.')); } ?>
+ <?php if ($currentChannel === 'git') { p($l->t('The selected update channel does not support updates of the server.')); } ?>
</em>
</p>
</form>
diff --git a/apps/updatenotification/tests/Controller/AdminControllerTest.php b/apps/updatenotification/tests/Controller/AdminControllerTest.php
index 75588a1aec5..98b08e633bb 100644
--- a/apps/updatenotification/tests/Controller/AdminControllerTest.php
+++ b/apps/updatenotification/tests/Controller/AdminControllerTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -25,50 +26,41 @@
namespace OCA\UpdateNotification\Tests\Controller;
use OCA\UpdateNotification\Controller\AdminController;
-use OCA\UpdateNotification\UpdateChecker;
+use OCA\UpdateNotification\ResetTokenBackgroundJob;
use OCP\AppFramework\Http\DataResponse;
-use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList;
use OCP\IConfig;
-use OCP\IDateTimeFormatter;
use OCP\IL10N;
use OCP\IRequest;
use OCP\Security\ISecureRandom;
use Test\TestCase;
class AdminControllerTest extends TestCase {
- /** @var IRequest */
+ /** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */
private $request;
- /** @var IJobList */
+ /** @var IJobList|\PHPUnit_Framework_MockObject_MockObject */
private $jobList;
- /** @var ISecureRandom */
+ /** @var ISecureRandom|\PHPUnit_Framework_MockObject_MockObject */
private $secureRandom;
- /** @var IConfig */
+ /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
private $config;
/** @var AdminController */
private $adminController;
- /** @var ITimeFactory */
+ /** @var ITimeFactory|\PHPUnit_Framework_MockObject_MockObject */
private $timeFactory;
- /** @var IL10N */
+ /** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
private $l10n;
- /** @var UpdateChecker */
- private $updateChecker;
- /** @var IDateTimeFormatter */
- private $dateTimeFormatter;
public function setUp() {
parent::setUp();
- $this->request = $this->getMockBuilder('\\OCP\\IRequest')->getMock();
- $this->jobList = $this->getMockBuilder('\\OCP\\BackgroundJob\\IJobList')->getMock();
- $this->secureRandom = $this->getMockBuilder('\\OCP\\Security\\ISecureRandom')->getMock();
- $this->config = $this->getMockBuilder('\\OCP\\IConfig')->getMock();
- $this->timeFactory = $this->getMockBuilder('\\OCP\\AppFramework\\Utility\\ITimeFactory')->getMock();
- $this->l10n = $this->getMockBuilder('\\OCP\\IL10N')->getMock();
- $this->updateChecker = $this->getMockBuilder('\\OCA\\UpdateNotification\\UpdateChecker')
- ->disableOriginalConstructor()->getMock();
- $this->dateTimeFormatter = $this->getMockBuilder('\\OCP\\IDateTimeFormatter')->getMock();
+ $this->request = $this->createMock(IRequest::class);
+ $this->jobList = $this->createMock(IJobList::class);
+ $this->secureRandom = $this->createMock(ISecureRandom::class);
+ $this->config = $this->createMock(IConfig::class);
+ $this->timeFactory = $this->createMock(ITimeFactory::class);
+ $this->l10n = $this->createMock(IL10N::class);
$this->adminController = new AdminController(
'updatenotification',
@@ -77,131 +69,15 @@ class AdminControllerTest extends TestCase {
$this->secureRandom,
$this->config,
$this->timeFactory,
- $this->l10n,
- $this->updateChecker,
- $this->dateTimeFormatter
+ $this->l10n
);
}
- public function testDisplayPanelWithUpdate() {
- $channels = [
- 'daily',
- 'beta',
- 'stable',
- 'production',
- ];
- $currentChannel = \OCP\Util::getChannel();
-
- // Remove the currently used channel from the channels list
- if(($key = array_search($currentChannel, $channels)) !== false) {
- unset($channels[$key]);
- }
-
- $this->config
- ->expects($this->exactly(2))
- ->method('getAppValue')
- ->willReturnMap([
- ['core', 'lastupdatedat', '', '12345'],
- ['updatenotification', 'notify_groups', '["admin"]', '["admin"]'],
- ]);
- $this->config
- ->expects($this->once())
- ->method('getSystemValue')
- ->with('updater.server.url', 'https://updates.nextcloud.com/server/')
- ->willReturn('https://updates.nextcloud.com/server/');
- $this->dateTimeFormatter
- ->expects($this->once())
- ->method('formatDateTime')
- ->with('12345')
- ->willReturn('LastCheckedReturnValue');
- $this->updateChecker
- ->expects($this->once())
- ->method('getUpdateState')
- ->willReturn([
- 'updateAvailable' => true,
- 'updateVersion' => '8.1.2',
- 'downloadLink' => 'https://downloads.nextcloud.org/server',
- 'updaterEnabled' => true,
- ]);
-
- $params = [
- 'isNewVersionAvailable' => true,
- 'isUpdateChecked' => true,
- 'lastChecked' => 'LastCheckedReturnValue',
- 'currentChannel' => \OCP\Util::getChannel(),
- 'channels' => $channels,
- 'newVersionString' => '8.1.2',
- 'downloadLink' => 'https://downloads.nextcloud.org/server',
- 'updaterEnabled' => true,
- 'isDefaultUpdateServerURL' => true,
- 'updateServerURL' => 'https://updates.nextcloud.com/server/',
- 'notify_groups' => 'admin',
- ];
-
- $expected = new TemplateResponse('updatenotification', 'admin', $params, '');
- $this->assertEquals($expected, $this->adminController->displayPanel());
- }
-
- public function testDisplayPanelWithoutUpdate() {
- $channels = [
- 'daily',
- 'beta',
- 'stable',
- 'production',
- ];
- $currentChannel = \OCP\Util::getChannel();
-
- // Remove the currently used channel from the channels list
- if(($key = array_search($currentChannel, $channels)) !== false) {
- unset($channels[$key]);
- }
-
- $this->config
- ->expects($this->exactly(2))
- ->method('getAppValue')
- ->willReturnMap([
- ['core', 'lastupdatedat', '', '12345'],
- ['updatenotification', 'notify_groups', '["admin"]', '["admin"]'],
- ]);
- $this->config
- ->expects($this->once())
- ->method('getSystemValue')
- ->with('updater.server.url', 'https://updates.nextcloud.com/server/')
- ->willReturn('https://updates.nextcloud.com/server/');
- $this->dateTimeFormatter
- ->expects($this->once())
- ->method('formatDateTime')
- ->with('12345')
- ->willReturn('LastCheckedReturnValue');
- $this->updateChecker
- ->expects($this->once())
- ->method('getUpdateState')
- ->willReturn([]);
-
- $params = [
- 'isNewVersionAvailable' => false,
- 'isUpdateChecked' => true,
- 'lastChecked' => 'LastCheckedReturnValue',
- 'currentChannel' => \OCP\Util::getChannel(),
- 'channels' => $channels,
- 'newVersionString' => '',
- 'downloadLink' => '',
- 'updaterEnabled' => 0,
- 'isDefaultUpdateServerURL' => true,
- 'updateServerURL' => 'https://updates.nextcloud.com/server/',
- 'notify_groups' => 'admin',
- ];
-
- $expected = new TemplateResponse('updatenotification', 'admin', $params, '');
- $this->assertEquals($expected, $this->adminController->displayPanel());
- }
-
-
public function testCreateCredentials() {
$this->jobList
->expects($this->once())
->method('add')
- ->with('OCA\UpdateNotification\ResetTokenBackgroundJob');
+ ->with(ResetTokenBackgroundJob::class);
$this->secureRandom
->expects($this->once())
->method('generate')
@@ -224,11 +100,4 @@ class AdminControllerTest extends TestCase {
$this->assertEquals($expected, $this->adminController->createCredentials());
}
- public function testGetSection() {
- $this->assertSame('server', $this->adminController->getSection());
- }
-
- public function testGetPriority() {
- $this->assertSame(1, $this->adminController->getPriority());
- }
}
diff --git a/apps/updatenotification/tests/Notification/BackgroundJobTest.php b/apps/updatenotification/tests/Notification/BackgroundJobTest.php
index 0355b10a09c..4ed1c350674 100644
--- a/apps/updatenotification/tests/Notification/BackgroundJobTest.php
+++ b/apps/updatenotification/tests/Notification/BackgroundJobTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -105,7 +106,7 @@ class BackgroundJobTest extends TestCase {
self::invokePrivate($job, 'run', [null]);
}
- public function dataCheckCoreUpdate() {
+ public function dataCheckCoreUpdate(): array {
return [
['daily', null, null, null, null],
['git', null, null, null, null],
@@ -142,7 +143,7 @@ class BackgroundJobTest extends TestCase {
* @param null|string $readableVersion
* @param null|int $errorDays
*/
- public function testCheckCoreUpdate($channel, $versionCheck, $version, $readableVersion, $errorDays) {
+ public function testCheckCoreUpdate(string $channel, $versionCheck, $version, $readableVersion, $errorDays) {
$job = $this->getJob([
'getChannel',
'createVersionCheck',
@@ -197,13 +198,13 @@ class BackgroundJobTest extends TestCase {
->method('clearErrorNotifications');
$job->expects($this->once())
->method('createNotifications')
- ->willReturn('core', $version, $readableVersion);
+ ->with('core', $version, $readableVersion);
}
self::invokePrivate($job, 'checkCoreUpdate');
}
- public function dataCheckAppUpdates() {
+ public function dataCheckAppUpdates(): array {
return [
[
['app1', 'app2'],
@@ -235,18 +236,18 @@ class BackgroundJobTest extends TestCase {
->method('getInstalledApps')
->willReturn($apps);
- $job->expects($this->exactly(count($apps)))
+ $job->expects($this->exactly(\count($apps)))
->method('isUpdateAvailable')
->willReturnMap($isUpdateAvailable);
- $mockedMethod = $job->expects($this->exactly(count($notifications)))
+ $mockedMethod = $job->expects($this->exactly(\count($notifications)))
->method('createNotifications');
- call_user_func_array([$mockedMethod, 'withConsecutive'], $notifications);
+ \call_user_func_array([$mockedMethod, 'withConsecutive'], $notifications);
self::invokePrivate($job, 'checkAppUpdates');
}
- public function dataCreateNotifications() {
+ public 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']]],
@@ -265,7 +266,7 @@ class BackgroundJobTest extends TestCase {
* @param string[]|null $users
* @param array|null $userNotifications
*/
- public function testCreateNotifications($app, $version, $lastNotification, $callDelete, $createNotification, $users, $userNotifications) {
+ public function testCreateNotifications(string $app, string $version, $lastNotification, $callDelete, $createNotification, $users, $userNotifications) {
$job = $this->getJob([
'deleteOutdatedNotifications',
'getUsersToNotify',
@@ -319,12 +320,12 @@ class BackgroundJobTest extends TestCase {
->willReturnSelf();
if ($userNotifications !== null) {
- $mockedMethod = $notification->expects($this->exactly(count($userNotifications)))
+ $mockedMethod = $notification->expects($this->exactly(\count($userNotifications)))
->method('setUser')
->willReturnSelf();
- call_user_func_array([$mockedMethod, 'withConsecutive'], $userNotifications);
+ \call_user_func_array([$mockedMethod, 'withConsecutive'], $userNotifications);
- $this->notificationManager->expects($this->exactly(count($userNotifications)))
+ $this->notificationManager->expects($this->exactly(\count($userNotifications)))
->method('notify')
->willReturn($notification);
}
@@ -340,7 +341,7 @@ class BackgroundJobTest extends TestCase {
self::invokePrivate($job, 'createNotifications', [$app, $version]);
}
- public function dataGetUsersToNotify() {
+ public function dataGetUsersToNotify(): array {
return [
[['g1', 'g2'], ['g1' => null, 'g2' => ['u1', 'u2']], ['u1', 'u2']],
[['g3', 'g4'], ['g3' => ['u1', 'u2'], 'g4' => ['u2', 'u3']], ['u1', 'u2', 'u3']],
@@ -353,7 +354,7 @@ class BackgroundJobTest extends TestCase {
* @param array $groupUsers
* @param string[] $expected
*/
- public function testGetUsersToNotify($groups, array $groupUsers, array $expected) {
+ public function testGetUsersToNotify(array $groups, array $groupUsers, array $expected) {
$job = $this->getJob();
$this->config->expects($this->once())
@@ -373,7 +374,7 @@ class BackgroundJobTest extends TestCase {
}
$groupMap[] = [$gid, $group];
}
- $this->groupManager->expects($this->exactly(count($groups)))
+ $this->groupManager->expects($this->exactly(\count($groups)))
->method('get')
->willReturnMap($groupMap);
@@ -385,7 +386,7 @@ class BackgroundJobTest extends TestCase {
$this->assertEquals($expected, $result);
}
- public function dataDeleteOutdatedNotifications() {
+ public function dataDeleteOutdatedNotifications(): array {
return [
['app1', '1.1.0'],
['app2', '1.2.0'],
@@ -397,7 +398,7 @@ class BackgroundJobTest extends TestCase {
* @param string $app
* @param string $version
*/
- public function testDeleteOutdatedNotifications($app, $version) {
+ public function testDeleteOutdatedNotifications(string $app, string $version) {
$notification = $this->createMock(INotification::class);
$notification->expects($this->once())
->method('setApp')
@@ -423,7 +424,7 @@ class BackgroundJobTest extends TestCase {
* @param string[] $userIds
* @return IUser[]|\PHPUnit_Framework_MockObject_MockObject[]
*/
- protected function getUsers(array $userIds) {
+ protected function getUsers(array $userIds): array {
$users = [];
foreach ($userIds as $uid) {
$user = $this->createMock(IUser::class);
@@ -436,10 +437,10 @@ class BackgroundJobTest extends TestCase {
}
/**
- * @param $gid
+ * @param string $gid
* @return \OCP\IGroup|\PHPUnit_Framework_MockObject_MockObject
*/
- protected function getGroup($gid) {
+ protected function getGroup(string $gid) {
$group = $this->createMock(IGroup::class);
$group->expects($this->any())
->method('getGID')
diff --git a/apps/updatenotification/tests/Notification/NotifierTest.php b/apps/updatenotification/tests/Notification/NotifierTest.php
index 34486bf5ba5..b1ddf7b478d 100644
--- a/apps/updatenotification/tests/Notification/NotifierTest.php
+++ b/apps/updatenotification/tests/Notification/NotifierTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -88,7 +89,7 @@ class NotifierTest extends TestCase {
}
}
- public function dataUpdateAlreadyInstalledCheck() {
+ public function dataUpdateAlreadyInstalledCheck(): array {
return [
['1.1.0', '1.0.0', false],
['1.1.0', '1.1.0', true],
@@ -103,7 +104,7 @@ class NotifierTest extends TestCase {
* @param string $versionInstalled
* @param bool $exception
*/
- public function testUpdateAlreadyInstalledCheck($versionNotification, $versionInstalled, $exception) {
+ public function testUpdateAlreadyInstalledCheck(string $versionNotification, string $versionInstalled, bool $exception) {
$notifier = $this->getNotifier();
$notification = $this->createMock(INotification::class);
@@ -121,7 +122,7 @@ class NotifierTest extends TestCase {
}
try {
- $this->invokePrivate($notifier, 'updateAlreadyInstalledCheck', [$notification, $versionInstalled]);
+ self::invokePrivate($notifier, 'updateAlreadyInstalledCheck', [$notification, $versionInstalled]);
$this->assertFalse($exception);
} catch (\Exception $e) {
$this->assertTrue($exception);
diff --git a/apps/updatenotification/tests/ResetTokenBackgroundJobTest.php b/apps/updatenotification/tests/ResetTokenBackgroundJobTest.php
index 4309aed84bf..d78a5ed94cc 100644
--- a/apps/updatenotification/tests/ResetTokenBackgroundJobTest.php
+++ b/apps/updatenotification/tests/ResetTokenBackgroundJobTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -29,23 +30,23 @@ use OCP\IConfig;
use Test\TestCase;
class ResetTokenBackgroundJobTest extends TestCase {
- /** @var IConfig */
+ /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
private $config;
+ /** @var ITimeFactory|\PHPUnit_Framework_MockObject_MockObject */
+ private $timeFactory;
/** @var ResetTokenBackgroundJob */
private $resetTokenBackgroundJob;
- /** @var ITimeFactory */
- private $timeFactory;
public function setUp() {
parent::setUp();
- $this->config = $this->getMockBuilder('\\OCP\\IConfig')->getMock();
- $this->timeFactory = $this->getMockBuilder('\\OCP\\AppFramework\\Utility\\ITimeFactory')->getMock();
+ $this->config = $this->createMock(IConfig::class);
+ $this->timeFactory = $this->createMock(ITimeFactory::class);
$this->resetTokenBackgroundJob = new ResetTokenBackgroundJob($this->config, $this->timeFactory);
}
public function testRunWithNotExpiredToken() {
$this->timeFactory
- ->expects($this->any())
+ ->expects($this->atLeastOnce())
->method('getTime')
->willReturn(123);
$this->config
@@ -54,10 +55,9 @@ class ResetTokenBackgroundJobTest extends TestCase {
->with('core', 'updater.secret.created', 123);
$this->config
->expects($this->never())
- ->method('deleteSystemValue')
- ->with('updater.secret');
+ ->method('deleteSystemValue');
- $this->invokePrivate($this->resetTokenBackgroundJob, 'run', ['']);
+ static::invokePrivate($this->resetTokenBackgroundJob, 'run', [null]);
}
public function testRunWithExpiredToken() {
@@ -78,6 +78,6 @@ class ResetTokenBackgroundJobTest extends TestCase {
->method('deleteSystemValue')
->with('updater.secret');
- $this->invokePrivate($this->resetTokenBackgroundJob, 'run', ['']);
+ static::invokePrivate($this->resetTokenBackgroundJob, 'run', [null]);
}
}
diff --git a/apps/updatenotification/tests/Settings/AdminTest.php b/apps/updatenotification/tests/Settings/AdminTest.php
new file mode 100644
index 00000000000..12734b808c0
--- /dev/null
+++ b/apps/updatenotification/tests/Settings/AdminTest.php
@@ -0,0 +1,127 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ *
+ * @author Joas Schilling <coding@schilljs.com>
+ * @author Lukas Reschke <lukas@statuscode.ch>
+ * @author Morris Jobke <hey@morrisjobke.de>
+ *
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\UpdateNotification\Tests\Settings;
+
+use OCA\UpdateNotification\Settings\Admin;
+use OCA\UpdateNotification\UpdateChecker;
+use OCP\AppFramework\Http\TemplateResponse;
+use OCP\IConfig;
+use OCP\IDateTimeFormatter;
+use OCP\Util;
+use Test\TestCase;
+
+class AdminTest extends TestCase {
+ /** @var Admin */
+ private $admin;
+ /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
+ private $config;
+ /** @var UpdateChecker|\PHPUnit_Framework_MockObject_MockObject */
+ private $updateChecker;
+ /** @var IDateTimeFormatter|\PHPUnit_Framework_MockObject_MockObject */
+ private $dateTimeFormatter;
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->config = $this->createMock(IConfig::class);
+ $this->updateChecker = $this->createMock(UpdateChecker::class);
+ $this->dateTimeFormatter = $this->createMock(IDateTimeFormatter::class);
+
+ $this->admin = new Admin(
+ $this->config,
+ $this->updateChecker,
+ $this->dateTimeFormatter
+ );
+ }
+
+ public function testGetFormWithUpdate() {
+ $channels = [
+ 'daily',
+ 'beta',
+ 'stable',
+ 'production',
+ ];
+ $currentChannel = Util::getChannel();
+
+ // Remove the currently used channel from the channels list
+ if(($key = array_search($currentChannel, $channels, true)) !== false) {
+ unset($channels[$key]);
+ }
+
+ $this->config
+ ->expects($this->exactly(2))
+ ->method('getAppValue')
+ ->willReturnMap([
+ ['core', 'lastupdatedat', '', '12345'],
+ ['updatenotification', 'notify_groups', '["admin"]', '["admin"]'],
+ ]);
+ $this->config
+ ->expects($this->once())
+ ->method('getSystemValue')
+ ->with('updater.server.url', 'https://updates.nextcloud.com/server/')
+ ->willReturn('https://updates.nextcloud.com/server/');
+ $this->dateTimeFormatter
+ ->expects($this->once())
+ ->method('formatDateTime')
+ ->with('12345')
+ ->willReturn('LastCheckedReturnValue');
+ $this->updateChecker
+ ->expects($this->once())
+ ->method('getUpdateState')
+ ->willReturn([
+ 'updateAvailable' => true,
+ 'updateVersion' => '8.1.2',
+ 'downloadLink' => 'https://downloads.nextcloud.org/server',
+ 'updaterEnabled' => true,
+ ]);
+
+ $params = [
+ 'isNewVersionAvailable' => true,
+ 'isUpdateChecked' => true,
+ 'lastChecked' => 'LastCheckedReturnValue',
+ 'currentChannel' => Util::getChannel(),
+ 'channels' => $channels,
+ 'newVersionString' => '8.1.2',
+ 'downloadLink' => 'https://downloads.nextcloud.org/server',
+ 'updaterEnabled' => true,
+ 'isDefaultUpdateServerURL' => true,
+ 'updateServerURL' => 'https://updates.nextcloud.com/server/',
+ 'notify_groups' => 'admin',
+ ];
+
+ $expected = new TemplateResponse('updatenotification', 'admin', $params, '');
+ $this->assertEquals($expected, $this->admin->getForm());
+ }
+
+
+ public function testGetSection() {
+ $this->assertSame('server', $this->admin->getSection());
+ }
+
+ public function testGetPriority() {
+ $this->assertSame(1, $this->admin->getPriority());
+ }
+}
diff --git a/apps/updatenotification/tests/UpdateCheckerTest.php b/apps/updatenotification/tests/UpdateCheckerTest.php
index f7ed83047a6..5502e1ce8ac 100644
--- a/apps/updatenotification/tests/UpdateCheckerTest.php
+++ b/apps/updatenotification/tests/UpdateCheckerTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -24,12 +25,12 @@
namespace OCA\UpdateNotification\Tests;
-use OC\Updater;
+use OC\Updater\VersionCheck;
use OCA\UpdateNotification\UpdateChecker;
use Test\TestCase;
class UpdateCheckerTest extends TestCase {
- /** @var Updater */
+ /** @var VersionCheck|\PHPUnit_Framework_MockObject_MockObject */
private $updater;
/** @var UpdateChecker */
private $updateChecker;
@@ -37,8 +38,7 @@ class UpdateCheckerTest extends TestCase {
public function setUp() {
parent::setUp();
- $this->updater = $this->getMockBuilder('\OC\Updater\VersionCheck')
- ->disableOriginalConstructor()->getMock();
+ $this->updater = $this->createMock(VersionCheck::class);
$this->updateChecker = new UpdateChecker($this->updater);
}