summaryrefslogtreecommitdiffstats
path: root/apps/updatenotification/lib/Notification
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2016-05-09 12:04:32 +0200
committerJoas Schilling <nickvergessen@owncloud.com>2016-05-24 11:26:53 +0200
commit96691138df3ce6b1fda98f2c1b9a42ced6e614c0 (patch)
treefb1d9de5bf9f801f86c6c9a0e19f8af74dc96b91 /apps/updatenotification/lib/Notification
parentc34788918d83ff3f10c44d2c8cb7dfde09b326a5 (diff)
downloadnextcloud-server-96691138df3ce6b1fda98f2c1b9a42ced6e614c0.tar.gz
nextcloud-server-96691138df3ce6b1fda98f2c1b9a42ced6e614c0.zip
Add tests for the background job
Diffstat (limited to 'apps/updatenotification/lib/Notification')
-rw-r--r--apps/updatenotification/lib/Notification/BackgroundJob.php49
1 files changed, 38 insertions, 11 deletions
diff --git a/apps/updatenotification/lib/Notification/BackgroundJob.php b/apps/updatenotification/lib/Notification/BackgroundJob.php
index f2cf7e1cd85..3a89f3813e6 100644
--- a/apps/updatenotification/lib/Notification/BackgroundJob.php
+++ b/apps/updatenotification/lib/Notification/BackgroundJob.php
@@ -82,15 +82,12 @@ class BackgroundJob extends TimedJob {
* Check for ownCloud update
*/
protected function checkCoreUpdate() {
- if (in_array(\OC_Util::getChannel(), ['daily', 'git'])) {
+ if (in_array($this->getChannel(), ['daily', 'git'])) {
// "These aren't the update channels you're looking for." - Ben Obi-Wan Kenobi
return;
}
- $updater = new VersionCheck(
- $this->client,
- $this->config
- );
+ $updater = $this->createVersionCheck();
$status = $updater->check();
if (isset($status['version'])) {
@@ -104,7 +101,7 @@ class BackgroundJob extends TimedJob {
protected function checkAppUpdates() {
$apps = $this->appManager->getInstalledApps();
foreach ($apps as $app) {
- $update = Installer::isUpdateAvailable($app);
+ $update = $this->isUpdateAvailable($app);
if ($update !== false) {
$this->createNotifications($app, $update);
}
@@ -134,8 +131,8 @@ class BackgroundJob extends TimedJob {
->setObject($app, $version)
->setSubject('update_available');
- foreach ($this->getUsersToNotify() as $user) {
- $notification->setUser($user->getUID());
+ foreach ($this->getUsersToNotify() as $uid) {
+ $notification->setUser($uid);
$this->notificationManager->notify($notification);
}
@@ -143,21 +140,26 @@ class BackgroundJob extends TimedJob {
}
/**
- * @return \OCP\IUser[]
+ * @return string[]
*/
protected function getUsersToNotify() {
if ($this->users !== null) {
return $this->users;
}
- $notifyGroups = json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'));
+ $notifyGroups = json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'), true);
+ $this->users = [];
foreach ($notifyGroups as $group) {
$groupToNotify = $this->groupManager->get($group);
if ($groupToNotify instanceof IGroup) {
- $this->users = array_merge($this->users, $groupToNotify->getUsers());
+ foreach ($groupToNotify->getUsers() as $user) {
+ $this->users[$user->getUID()] = true;
+ }
}
}
+ $this->users = array_keys($this->users);
+
return $this->users;
}
@@ -173,4 +175,29 @@ class BackgroundJob extends TimedJob {
->setObject($app, $version);
$this->notificationManager->markProcessed($notification);
}
+
+ /**
+ * @return VersionCheck
+ */
+ protected function createVersionCheck() {
+ return new VersionCheck(
+ $this->client,
+ $this->config
+ );
+ }
+
+ /**
+ * @return string
+ */
+ protected function getChannel() {
+ return \OC_Util::getChannel();
+ }
+
+ /**
+ * @param string $app
+ * @return string|false
+ */
+ protected function isUpdateAvailable($app) {
+ return Installer::isUpdateAvailable($app);
+ }
}