aboutsummaryrefslogtreecommitdiffstats
path: root/apps/updatenotification/tests
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2017-03-17 12:47:26 +0100
committerRoeland Jago Douma <roeland@famdouma.nl>2017-03-26 10:59:58 +0200
commit3668673d7b3f64a5aaa80f569856b88460d9a522 (patch)
tree1767767ac8889e6001b9fca4f7670c237c28b158 /apps/updatenotification/tests
parentf3917cfea148d09832a727953c74ece952a47f84 (diff)
downloadnextcloud-server-3668673d7b3f64a5aaa80f569856b88460d9a522.tar.gz
nextcloud-server-3668673d7b3f64a5aaa80f569856b88460d9a522.zip
Create a notification when the update server couldn't be reached for some days
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/updatenotification/tests')
-rw-r--r--apps/updatenotification/tests/Notification/BackgroundJobTest.php107
-rw-r--r--apps/updatenotification/tests/Notification/NotifierTest.php6
2 files changed, 75 insertions, 38 deletions
diff --git a/apps/updatenotification/tests/Notification/BackgroundJobTest.php b/apps/updatenotification/tests/Notification/BackgroundJobTest.php
index 57771ec0ae9..468f4cf9594 100644
--- a/apps/updatenotification/tests/Notification/BackgroundJobTest.php
+++ b/apps/updatenotification/tests/Notification/BackgroundJobTest.php
@@ -28,10 +28,12 @@ use OCP\App\IAppManager;
use OCP\Http\Client\IClientService;
use OCP\IConfig;
use OCP\IGroupManager;
-use OCP\IURLGenerator;
use OCP\IUser;
use OCP\Notification\IManager;
use Test\TestCase;
+use OC\Updater\VersionCheck;
+use OCP\Notification\INotification;
+use OCP\IGroup;
class BackgroundJobTest extends TestCase {
@@ -49,11 +51,11 @@ class BackgroundJobTest extends TestCase {
public function setUp() {
parent::setUp();
- $this->config = $this->createMock(\OCP\IConfig::class);
- $this->notificationManager = $this->createMock(\OCP\Notification\IManager::class);
- $this->groupManager = $this->createMock(\OCP\IGroupManager::class);
- $this->appManager = $this->createMock(\OCP\App\IAppManager::class);
- $this->client = $this->createMock(\OCP\Http\Client\IClientService::class);
+ $this->config = $this->createMock(IConfig::class);
+ $this->notificationManager = $this->createMock(IManager::class);
+ $this->groupManager = $this->createMock(IGroupManager::class);
+ $this->appManager = $this->createMock(IAppManager::class);
+ $this->client = $this->createMock(IClientService::class);
}
/**
@@ -70,7 +72,7 @@ class BackgroundJobTest extends TestCase {
$this->client
);
} {
- return $this->getMockBuilder('OCA\UpdateNotification\Notification\BackgroundJob')
+ return $this->getMockBuilder(BackgroundJob::class)
->setConstructorArgs([
$this->config,
$this->notificationManager,
@@ -94,28 +96,34 @@ class BackgroundJobTest extends TestCase {
$job->expects($this->once())
->method('checkAppUpdates');
- $this->invokePrivate($job, 'run', [null]);
+ self::invokePrivate($job, 'run', [null]);
}
public function dataCheckCoreUpdate() {
return [
- ['daily', null, null, null],
- ['git', null, null, null],
- ['beta', false, null, null],
+ ['daily', null, null, null, null],
+ ['git', null, null, null, null],
+ ['beta', [], null, null, null],
+ ['beta', false, false, null, null],
+ ['beta', false, false, null, 13],
['beta', [
'version' => '9.2.0',
'versionstring' => 'Nextcloud 11.0.0',
- ], '9.2.0', 'Nextcloud 11.0.0'],
- ['stable', false, null, null],
+ ], '9.2.0', 'Nextcloud 11.0.0', null],
+ ['stable', [], null, null, null],
+ ['stable', false, false, null, null],
+ ['stable', false, false, null, 6],
['stable', [
'version' => '9.2.0',
'versionstring' => 'Nextcloud 11.0.0',
- ], '9.2.0', 'Nextcloud 11.0.0'],
- ['production', false, null, null],
+ ], '9.2.0', 'Nextcloud 11.0.0', null],
+ ['production', [], null, null, null],
+ ['production', false, false, null, null],
+ ['production', false, false, null, 2],
['production', [
'version' => '9.2.0',
'versionstring' => 'Nextcloud 11.0.0',
- ], '9.2.0', 'Nextcloud 11.0.0'],
+ ], '9.2.0', 'Nextcloud 11.0.0', null],
];
}
@@ -124,14 +132,17 @@ class BackgroundJobTest extends TestCase {
*
* @param string $channel
* @param mixed $versionCheck
- * @param null|string $notification
+ * @param null|string $version
* @param null|string $readableVersion
+ * @param null|int $errorDays
*/
- public function testCheckCoreUpdate($channel, $versionCheck, $notification, $readableVersion) {
+ public function testCheckCoreUpdate($channel, $versionCheck, $version, $readableVersion, $errorDays) {
$job = $this->getJob([
'getChannel',
'createVersionCheck',
'createNotifications',
+ 'clearErrorNotifications',
+ 'sendErrorNotifications',
]);
$job->expects($this->once())
@@ -142,9 +153,7 @@ class BackgroundJobTest extends TestCase {
$job->expects($this->never())
->method('createVersionCheck');
} else {
- $check = $this->getMockBuilder('OC\Updater\VersionCheck')
- ->disableOriginalConstructor()
- ->getMock();
+ $check = $this->createMock(VersionCheck::class);
$check->expects($this->once())
->method('check')
->willReturn($versionCheck);
@@ -154,16 +163,38 @@ class BackgroundJobTest extends TestCase {
->willReturn($check);
}
- if ($notification === null) {
+ if ($version === null) {
+ $job->expects($this->never())
+ ->method('createNotifications');
+ $job->expects($this->never())
+ ->method('clearErrorNotifications');
+ } else if ($version === false) {
$job->expects($this->never())
->method('createNotifications');
+ $job->expects($this->never())
+ ->method('clearErrorNotifications');
+
+ $this->config->expects($this->once())
+ ->method('getAppValue')
+ ->willReturn($errorDays);
+ $this->config->expects($this->once())
+ ->method('setAppValue')
+ ->with('updatenotification', 'update_check_errors', $errorDays + 1);
+ $job->expects($errorDays !== null ? $this->once() : $this->never())
+ ->method('sendErrorNotifications')
+ ->with($errorDays + 1);
} else {
+ $this->config->expects($this->once())
+ ->method('setAppValue')
+ ->with('updatenotification', 'update_check_errors', 0);
+ $job->expects($this->once())
+ ->method('clearErrorNotifications');
$job->expects($this->once())
->method('createNotifications')
- ->willReturn('core', $notification, $readableVersion);
+ ->willReturn('core', $version, $readableVersion);
}
- $this->invokePrivate($job, 'checkCoreUpdate');
+ self::invokePrivate($job, 'checkCoreUpdate');
}
public function dataCheckAppUpdates() {
@@ -198,15 +229,15 @@ class BackgroundJobTest extends TestCase {
->method('getInstalledApps')
->willReturn($apps);
- $job->expects($this->exactly(sizeof($apps)))
+ $job->expects($this->exactly(count($apps)))
->method('isUpdateAvailable')
->willReturnMap($isUpdateAvailable);
- $mockedMethod = $job->expects($this->exactly(sizeof($notifications)))
+ $mockedMethod = $job->expects($this->exactly(count($notifications)))
->method('createNotifications');
call_user_func_array([$mockedMethod, 'withConsecutive'], $notifications);
- $this->invokePrivate($job, 'checkAppUpdates');
+ self::invokePrivate($job, 'checkAppUpdates');
}
public function dataCreateNotifications() {
@@ -264,7 +295,7 @@ class BackgroundJobTest extends TestCase {
}
if ($createNotification) {
- $notification = $this->getMockBuilder('OCP\Notification\INotification')->getMock();
+ $notification = $this->createMock(INotification::class);
$notification->expects($this->once())
->method('setApp')
->with('updatenotification')
@@ -282,12 +313,12 @@ class BackgroundJobTest extends TestCase {
->willReturnSelf();
if ($userNotifications !== null) {
- $mockedMethod = $notification->expects($this->exactly(sizeof($userNotifications)))
+ $mockedMethod = $notification->expects($this->exactly(count($userNotifications)))
->method('setUser')
->willReturnSelf();
call_user_func_array([$mockedMethod, 'withConsecutive'], $userNotifications);
- $this->notificationManager->expects($this->exactly(sizeof($userNotifications)))
+ $this->notificationManager->expects($this->exactly(count($userNotifications)))
->method('notify')
->willReturn($notification);
}
@@ -300,7 +331,7 @@ class BackgroundJobTest extends TestCase {
->method('createNotification');
}
- $this->invokePrivate($job, 'createNotifications', [$app, $version]);
+ self::invokePrivate($job, 'createNotifications', [$app, $version]);
}
public function dataGetUsersToNotify() {
@@ -336,15 +367,15 @@ class BackgroundJobTest extends TestCase {
}
$groupMap[] = [$gid, $group];
}
- $this->groupManager->expects($this->exactly(sizeof($groups)))
+ $this->groupManager->expects($this->exactly(count($groups)))
->method('get')
->willReturnMap($groupMap);
- $result = $this->invokePrivate($job, 'getUsersToNotify');
+ $result = self::invokePrivate($job, 'getUsersToNotify');
$this->assertEquals($expected, $result);
// Test caching
- $result = $this->invokePrivate($job, 'getUsersToNotify');
+ $result = self::invokePrivate($job, 'getUsersToNotify');
$this->assertEquals($expected, $result);
}
@@ -361,7 +392,7 @@ class BackgroundJobTest extends TestCase {
* @param string $version
*/
public function testDeleteOutdatedNotifications($app, $version) {
- $notification = $this->getMockBuilder('OCP\Notification\INotification')->getMock();
+ $notification = $this->createMock(INotification::class);
$notification->expects($this->once())
->method('setApp')
->with('updatenotification')
@@ -379,7 +410,7 @@ class BackgroundJobTest extends TestCase {
->with($notification);
$job = $this->getJob();
- $this->invokePrivate($job, 'deleteOutdatedNotifications', [$app, $version]);
+ self::invokePrivate($job, 'deleteOutdatedNotifications', [$app, $version]);
}
/**
@@ -389,7 +420,7 @@ class BackgroundJobTest extends TestCase {
protected function getUsers(array $userIds) {
$users = [];
foreach ($userIds as $uid) {
- $user = $this->getMockBuilder('OCP\IUser')->getMock();
+ $user = $this->createMock(IUser::class);
$user->expects($this->any())
->method('getUID')
->willReturn($uid);
@@ -403,7 +434,7 @@ class BackgroundJobTest extends TestCase {
* @return \OCP\IGroup|\PHPUnit_Framework_MockObject_MockObject
*/
protected function getGroup($gid) {
- $group = $this->getMockBuilder('OCP\IGroup')->getMock();
+ $group = $this->createMock(IGroup::class);
$group->expects($this->any())
->method('getGID')
->willReturn($gid);
diff --git a/apps/updatenotification/tests/Notification/NotifierTest.php b/apps/updatenotification/tests/Notification/NotifierTest.php
index e809ce11635..34486bf5ba5 100644
--- a/apps/updatenotification/tests/Notification/NotifierTest.php
+++ b/apps/updatenotification/tests/Notification/NotifierTest.php
@@ -24,6 +24,7 @@ namespace OCA\UpdateNotification\Tests\Notification;
use OCA\UpdateNotification\Notification\Notifier;
+use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IURLGenerator;
use OCP\IUserSession;
@@ -36,6 +37,8 @@ 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 */
@@ -49,6 +52,7 @@ class NotifierTest extends TestCase {
parent::setUp();
$this->urlGenerator = $this->createMock(IURLGenerator::class);
+ $this->config = $this->createMock(IConfig::class);
$this->notificationManager = $this->createMock(IManager::class);
$this->l10nFactory = $this->createMock(IFactory::class);
$this->userSession = $this->createMock(IUserSession::class);
@@ -63,6 +67,7 @@ class NotifierTest extends TestCase {
if (empty($methods)) {
return new Notifier(
$this->urlGenerator,
+ $this->config,
$this->notificationManager,
$this->l10nFactory,
$this->userSession,
@@ -72,6 +77,7 @@ class NotifierTest extends TestCase {
return $this->getMockBuilder(Notifier::class)
->setConstructorArgs([
$this->urlGenerator,
+ $this->config,
$this->notificationManager,
$this->l10nFactory,
$this->userSession,