2016-05-09 13:04:32 +03:00
|
|
|
<?php
|
2019-12-03 21:57:53 +03:00
|
|
|
|
2018-01-17 15:42:02 +03:00
|
|
|
declare(strict_types=1);
|
2019-12-03 21:57:53 +03:00
|
|
|
|
2016-05-09 13:04:32 +03:00
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
2016-07-21 17:49:16 +03:00
|
|
|
*
|
2020-04-29 12:57:22 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2016-07-21 17:49:16 +03:00
|
|
|
*
|
2016-05-09 13:04:32 +03:00
|
|
|
* @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,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2016-05-09 13:04:32 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\UpdateNotification\Tests\Notification;
|
|
|
|
|
2017-11-24 12:41:51 +03:00
|
|
|
use OC\Installer;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OC\Updater\VersionCheck;
|
2016-05-09 13:04:32 +03:00
|
|
|
use OCA\UpdateNotification\Notification\BackgroundJob;
|
|
|
|
use OCP\App\IAppManager;
|
|
|
|
use OCP\Http\Client\IClientService;
|
|
|
|
use OCP\IConfig;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\IGroup;
|
2016-05-09 13:04:32 +03:00
|
|
|
use OCP\IGroupManager;
|
|
|
|
use OCP\IUser;
|
|
|
|
use OCP\Notification\IManager;
|
2017-03-17 14:47:26 +03:00
|
|
|
use OCP\Notification\INotification;
|
2019-11-22 22:52:10 +03:00
|
|
|
use Test\TestCase;
|
2016-05-09 13:04:32 +03:00
|
|
|
|
|
|
|
class BackgroundJobTest extends TestCase {
|
|
|
|
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
|
2016-05-09 13:04:32 +03:00
|
|
|
protected $config;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
|
2016-05-09 13:04:32 +03:00
|
|
|
protected $notificationManager;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */
|
2016-05-09 13:04:32 +03:00
|
|
|
protected $groupManager;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IAppManager|\PHPUnit\Framework\MockObject\MockObject */
|
2016-05-09 13:04:32 +03:00
|
|
|
protected $appManager;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IClientService|\PHPUnit\Framework\MockObject\MockObject */
|
2016-05-09 13:04:32 +03:00
|
|
|
protected $client;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var Installer|\PHPUnit\Framework\MockObject\MockObject */
|
2017-11-24 12:41:51 +03:00
|
|
|
protected $installer;
|
2016-05-09 13:04:32 +03:00
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
protected function setUp(): void {
|
2016-05-09 13:04:32 +03:00
|
|
|
parent::setUp();
|
|
|
|
|
2017-03-17 14:47:26 +03:00
|
|
|
$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);
|
2017-11-24 12:41:51 +03:00
|
|
|
$this->installer = $this->createMock(Installer::class);
|
2016-05-09 13:04:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $methods
|
2020-08-11 22:32:18 +03:00
|
|
|
* @return BackgroundJob|\PHPUnit\Framework\MockObject\MockObject
|
2016-05-09 13:04:32 +03:00
|
|
|
*/
|
|
|
|
protected function getJob(array $methods = []) {
|
|
|
|
if (empty($methods)) {
|
|
|
|
return new BackgroundJob(
|
|
|
|
$this->config,
|
|
|
|
$this->notificationManager,
|
|
|
|
$this->groupManager,
|
|
|
|
$this->appManager,
|
2017-11-24 12:41:51 +03:00
|
|
|
$this->client,
|
|
|
|
$this->installer
|
2016-05-09 13:04:32 +03:00
|
|
|
);
|
2020-04-10 15:19:56 +03:00
|
|
|
}
|
|
|
|
{
|
2017-03-17 14:47:26 +03:00
|
|
|
return $this->getMockBuilder(BackgroundJob::class)
|
2016-05-09 13:04:32 +03:00
|
|
|
->setConstructorArgs([
|
|
|
|
$this->config,
|
|
|
|
$this->notificationManager,
|
|
|
|
$this->groupManager,
|
|
|
|
$this->appManager,
|
|
|
|
$this->client,
|
2017-11-24 12:41:51 +03:00
|
|
|
$this->installer,
|
2016-05-09 13:04:32 +03:00
|
|
|
])
|
|
|
|
->setMethods($methods)
|
|
|
|
->getMock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRun() {
|
|
|
|
$job = $this->getJob([
|
|
|
|
'checkCoreUpdate',
|
|
|
|
'checkAppUpdates',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$job->expects($this->once())
|
|
|
|
->method('checkCoreUpdate');
|
|
|
|
$job->expects($this->once())
|
|
|
|
->method('checkAppUpdates');
|
|
|
|
|
2017-03-17 14:47:26 +03:00
|
|
|
self::invokePrivate($job, 'run', [null]);
|
2016-05-09 13:04:32 +03:00
|
|
|
}
|
|
|
|
|
2018-01-17 15:42:02 +03:00
|
|
|
public function dataCheckCoreUpdate(): array {
|
2016-05-09 13:04:32 +03:00
|
|
|
return [
|
2017-03-17 14:47:26 +03:00
|
|
|
['daily', null, null, null, null],
|
|
|
|
['git', null, null, null, null],
|
|
|
|
['beta', [], null, null, null],
|
|
|
|
['beta', false, false, null, null],
|
|
|
|
['beta', false, false, null, 13],
|
2016-05-09 13:04:32 +03:00
|
|
|
['beta', [
|
|
|
|
'version' => '9.2.0',
|
2016-10-04 13:48:17 +03:00
|
|
|
'versionstring' => 'Nextcloud 11.0.0',
|
2017-03-17 14:47:26 +03:00
|
|
|
], '9.2.0', 'Nextcloud 11.0.0', null],
|
|
|
|
['stable', [], null, null, null],
|
|
|
|
['stable', false, false, null, null],
|
|
|
|
['stable', false, false, null, 6],
|
2016-05-09 13:04:32 +03:00
|
|
|
['stable', [
|
|
|
|
'version' => '9.2.0',
|
2016-10-04 13:48:17 +03:00
|
|
|
'versionstring' => 'Nextcloud 11.0.0',
|
2017-03-17 14:47:26 +03:00
|
|
|
], '9.2.0', 'Nextcloud 11.0.0', null],
|
|
|
|
['production', [], null, null, null],
|
|
|
|
['production', false, false, null, null],
|
|
|
|
['production', false, false, null, 2],
|
2016-05-09 13:04:32 +03:00
|
|
|
['production', [
|
|
|
|
'version' => '9.2.0',
|
2016-10-04 13:48:17 +03:00
|
|
|
'versionstring' => 'Nextcloud 11.0.0',
|
2017-03-17 14:47:26 +03:00
|
|
|
], '9.2.0', 'Nextcloud 11.0.0', null],
|
2016-05-09 13:04:32 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataCheckCoreUpdate
|
|
|
|
*
|
|
|
|
* @param string $channel
|
|
|
|
* @param mixed $versionCheck
|
2017-03-17 14:47:26 +03:00
|
|
|
* @param null|string $version
|
2016-10-04 13:48:17 +03:00
|
|
|
* @param null|string $readableVersion
|
2017-03-17 14:47:26 +03:00
|
|
|
* @param null|int $errorDays
|
2016-05-09 13:04:32 +03:00
|
|
|
*/
|
2018-01-17 15:42:02 +03:00
|
|
|
public function testCheckCoreUpdate(string $channel, $versionCheck, $version, $readableVersion, $errorDays) {
|
2016-05-09 13:04:32 +03:00
|
|
|
$job = $this->getJob([
|
|
|
|
'getChannel',
|
|
|
|
'createVersionCheck',
|
|
|
|
'createNotifications',
|
2017-03-17 14:47:26 +03:00
|
|
|
'clearErrorNotifications',
|
|
|
|
'sendErrorNotifications',
|
2016-05-09 13:04:32 +03:00
|
|
|
]);
|
|
|
|
|
|
|
|
$job->expects($this->once())
|
|
|
|
->method('getChannel')
|
|
|
|
->willReturn($channel);
|
2016-05-10 12:31:03 +03:00
|
|
|
|
2016-05-09 13:04:32 +03:00
|
|
|
if ($versionCheck === null) {
|
|
|
|
$job->expects($this->never())
|
|
|
|
->method('createVersionCheck');
|
|
|
|
} else {
|
2017-03-17 14:47:26 +03:00
|
|
|
$check = $this->createMock(VersionCheck::class);
|
2016-05-09 13:04:32 +03:00
|
|
|
$check->expects($this->once())
|
|
|
|
->method('check')
|
|
|
|
->willReturn($versionCheck);
|
|
|
|
|
|
|
|
$job->expects($this->once())
|
|
|
|
->method('createVersionCheck')
|
|
|
|
->willReturn($check);
|
|
|
|
}
|
|
|
|
|
2017-03-17 14:47:26 +03:00
|
|
|
if ($version === null) {
|
|
|
|
$job->expects($this->never())
|
|
|
|
->method('createNotifications');
|
2017-03-20 14:31:15 +03:00
|
|
|
$job->expects($versionCheck === null ? $this->never() : $this->once())
|
2017-03-17 14:47:26 +03:00
|
|
|
->method('clearErrorNotifications');
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($version === false) {
|
2016-05-09 13:04:32 +03:00
|
|
|
$job->expects($this->never())
|
|
|
|
->method('createNotifications');
|
2017-03-17 14:47:26 +03:00
|
|
|
$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);
|
2016-05-09 13:04:32 +03:00
|
|
|
} else {
|
2017-03-17 14:47:26 +03:00
|
|
|
$this->config->expects($this->once())
|
|
|
|
->method('setAppValue')
|
|
|
|
->with('updatenotification', 'update_check_errors', 0);
|
|
|
|
$job->expects($this->once())
|
|
|
|
->method('clearErrorNotifications');
|
2016-05-09 13:04:32 +03:00
|
|
|
$job->expects($this->once())
|
|
|
|
->method('createNotifications')
|
2018-01-17 15:42:02 +03:00
|
|
|
->with('core', $version, $readableVersion);
|
2016-05-09 13:04:32 +03:00
|
|
|
}
|
|
|
|
|
2017-03-17 14:47:26 +03:00
|
|
|
self::invokePrivate($job, 'checkCoreUpdate');
|
2016-05-09 13:04:32 +03:00
|
|
|
}
|
|
|
|
|
2018-01-17 15:42:02 +03:00
|
|
|
public function dataCheckAppUpdates(): array {
|
2016-05-09 13:04:32 +03:00
|
|
|
return [
|
|
|
|
[
|
|
|
|
['app1', 'app2'],
|
|
|
|
[
|
|
|
|
['app1', false],
|
|
|
|
['app2', '1.9.2'],
|
|
|
|
],
|
|
|
|
[
|
2017-01-09 14:09:47 +03:00
|
|
|
['app2', '1.9.2'],
|
2016-05-09 13:04:32 +03:00
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataCheckAppUpdates
|
|
|
|
*
|
|
|
|
* @param string[] $apps
|
|
|
|
* @param array $isUpdateAvailable
|
|
|
|
* @param array $notifications
|
|
|
|
*/
|
|
|
|
public function testCheckAppUpdates(array $apps, array $isUpdateAvailable, array $notifications) {
|
|
|
|
$job = $this->getJob([
|
|
|
|
'isUpdateAvailable',
|
|
|
|
'createNotifications',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->appManager->expects($this->once())
|
|
|
|
->method('getInstalledApps')
|
|
|
|
->willReturn($apps);
|
|
|
|
|
2018-01-17 15:42:02 +03:00
|
|
|
$job->expects($this->exactly(\count($apps)))
|
2016-05-09 13:04:32 +03:00
|
|
|
->method('isUpdateAvailable')
|
|
|
|
->willReturnMap($isUpdateAvailable);
|
|
|
|
|
2018-01-17 15:42:02 +03:00
|
|
|
$mockedMethod = $job->expects($this->exactly(\count($notifications)))
|
2016-05-09 13:04:32 +03:00
|
|
|
->method('createNotifications');
|
2018-01-17 15:42:02 +03:00
|
|
|
\call_user_func_array([$mockedMethod, 'withConsecutive'], $notifications);
|
2016-05-09 13:04:32 +03:00
|
|
|
|
2017-03-17 14:47:26 +03:00
|
|
|
self::invokePrivate($job, 'checkAppUpdates');
|
2016-05-09 13:04:32 +03:00
|
|
|
}
|
|
|
|
|
2018-01-17 15:42:02 +03:00
|
|
|
public function dataCreateNotifications(): array {
|
2016-05-09 13:04:32 +03:00
|
|
|
return [
|
2017-01-09 14:09:47 +03:00
|
|
|
['app1', '1.0.0', '1.0.0', false, false, null, null],
|
|
|
|
['app2', '1.0.1', '1.0.0', '1.0.0', true, ['user1'], [['user1']]],
|
|
|
|
['app3', '1.0.1', false, false, true, ['user2', 'user3'], [['user2'], ['user3']]],
|
2016-05-09 13:04:32 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
2018-01-17 15:42:02 +03:00
|
|
|
public function testCreateNotifications(string $app, string $version, $lastNotification, $callDelete, $createNotification, $users, $userNotifications) {
|
2016-05-09 13:04:32 +03:00
|
|
|
$job = $this->getJob([
|
|
|
|
'deleteOutdatedNotifications',
|
|
|
|
'getUsersToNotify',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->config->expects($this->once())
|
|
|
|
->method('getAppValue')
|
|
|
|
->with('updatenotification', $app, false)
|
|
|
|
->willReturn($lastNotification);
|
|
|
|
|
|
|
|
if ($lastNotification !== $version) {
|
|
|
|
$this->config->expects($this->once())
|
|
|
|
->method('setAppValue')
|
|
|
|
->with('updatenotification', $app, $version);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($callDelete === false) {
|
|
|
|
$job->expects($this->never())
|
|
|
|
->method('deleteOutdatedNotifications');
|
|
|
|
} else {
|
|
|
|
$job->expects($this->once())
|
|
|
|
->method('deleteOutdatedNotifications')
|
|
|
|
->with($app, $callDelete);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($users === null) {
|
|
|
|
$job->expects($this->never())
|
|
|
|
->method('getUsersToNotify');
|
|
|
|
} else {
|
|
|
|
$job->expects($this->once())
|
|
|
|
->method('getUsersToNotify')
|
|
|
|
->willReturn($users);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($createNotification) {
|
2017-03-17 14:47:26 +03:00
|
|
|
$notification = $this->createMock(INotification::class);
|
2016-05-09 13:04:32 +03:00
|
|
|
$notification->expects($this->once())
|
|
|
|
->method('setApp')
|
|
|
|
->with('updatenotification')
|
|
|
|
->willReturnSelf();
|
|
|
|
$notification->expects($this->once())
|
|
|
|
->method('setDateTime')
|
|
|
|
->willReturnSelf();
|
|
|
|
$notification->expects($this->once())
|
|
|
|
->method('setObject')
|
|
|
|
->with($app, $version)
|
|
|
|
->willReturnSelf();
|
|
|
|
$notification->expects($this->once())
|
|
|
|
->method('setSubject')
|
|
|
|
->with('update_available')
|
|
|
|
->willReturnSelf();
|
|
|
|
|
|
|
|
if ($userNotifications !== null) {
|
2018-01-17 15:42:02 +03:00
|
|
|
$mockedMethod = $notification->expects($this->exactly(\count($userNotifications)))
|
2016-05-09 13:04:32 +03:00
|
|
|
->method('setUser')
|
|
|
|
->willReturnSelf();
|
2018-01-17 15:42:02 +03:00
|
|
|
\call_user_func_array([$mockedMethod, 'withConsecutive'], $userNotifications);
|
2016-05-09 13:04:32 +03:00
|
|
|
|
2018-01-17 15:42:02 +03:00
|
|
|
$this->notificationManager->expects($this->exactly(\count($userNotifications)))
|
2016-05-09 13:04:32 +03:00
|
|
|
->method('notify')
|
|
|
|
->willReturn($notification);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->notificationManager->expects($this->once())
|
|
|
|
->method('createNotification')
|
|
|
|
->willReturn($notification);
|
|
|
|
} else {
|
|
|
|
$this->notificationManager->expects($this->never())
|
|
|
|
->method('createNotification');
|
|
|
|
}
|
|
|
|
|
2017-03-17 14:47:26 +03:00
|
|
|
self::invokePrivate($job, 'createNotifications', [$app, $version]);
|
2016-05-09 13:04:32 +03:00
|
|
|
}
|
|
|
|
|
2018-01-17 15:42:02 +03:00
|
|
|
public function dataGetUsersToNotify(): array {
|
2016-05-09 13:04:32 +03:00
|
|
|
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
|
|
|
|
*/
|
2018-01-17 15:42:02 +03:00
|
|
|
public function testGetUsersToNotify(array $groups, array $groupUsers, array $expected) {
|
2016-05-09 13:04:32 +03:00
|
|
|
$job = $this->getJob();
|
|
|
|
|
|
|
|
$this->config->expects($this->once())
|
|
|
|
->method('getAppValue')
|
|
|
|
->with('updatenotification', 'notify_groups', '["admin"]')
|
|
|
|
->willReturn(json_encode($groups));
|
|
|
|
|
|
|
|
$groupMap = [];
|
|
|
|
foreach ($groupUsers as $gid => $uids) {
|
|
|
|
if ($uids === null) {
|
|
|
|
$group = null;
|
|
|
|
} else {
|
|
|
|
$group = $this->getGroup($gid);
|
|
|
|
$group->expects($this->any())
|
|
|
|
->method('getUsers')
|
|
|
|
->willReturn($this->getUsers($uids));
|
|
|
|
}
|
|
|
|
$groupMap[] = [$gid, $group];
|
|
|
|
}
|
2018-01-17 15:42:02 +03:00
|
|
|
$this->groupManager->expects($this->exactly(\count($groups)))
|
2016-05-09 13:04:32 +03:00
|
|
|
->method('get')
|
|
|
|
->willReturnMap($groupMap);
|
|
|
|
|
2017-03-17 14:47:26 +03:00
|
|
|
$result = self::invokePrivate($job, 'getUsersToNotify');
|
2016-05-09 13:04:32 +03:00
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
// Test caching
|
2017-03-17 14:47:26 +03:00
|
|
|
$result = self::invokePrivate($job, 'getUsersToNotify');
|
2016-05-09 13:04:32 +03:00
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
2018-01-17 15:42:02 +03:00
|
|
|
public function dataDeleteOutdatedNotifications(): array {
|
2016-05-09 13:04:32 +03:00
|
|
|
return [
|
|
|
|
['app1', '1.1.0'],
|
|
|
|
['app2', '1.2.0'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataDeleteOutdatedNotifications
|
|
|
|
* @param string $app
|
|
|
|
* @param string $version
|
|
|
|
*/
|
2018-01-17 15:42:02 +03:00
|
|
|
public function testDeleteOutdatedNotifications(string $app, string $version) {
|
2017-03-17 14:47:26 +03:00
|
|
|
$notification = $this->createMock(INotification::class);
|
2016-05-09 13:04:32 +03:00
|
|
|
$notification->expects($this->once())
|
|
|
|
->method('setApp')
|
|
|
|
->with('updatenotification')
|
|
|
|
->willReturnSelf();
|
|
|
|
$notification->expects($this->once())
|
|
|
|
->method('setObject')
|
|
|
|
->with($app, $version)
|
|
|
|
->willReturnSelf();
|
|
|
|
|
|
|
|
$this->notificationManager->expects($this->once())
|
|
|
|
->method('createNotification')
|
|
|
|
->willReturn($notification);
|
|
|
|
$this->notificationManager->expects($this->once())
|
|
|
|
->method('markProcessed')
|
|
|
|
->with($notification);
|
|
|
|
|
|
|
|
$job = $this->getJob();
|
2017-03-17 14:47:26 +03:00
|
|
|
self::invokePrivate($job, 'deleteOutdatedNotifications', [$app, $version]);
|
2016-05-09 13:04:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string[] $userIds
|
2020-08-11 22:32:18 +03:00
|
|
|
* @return IUser[]|\PHPUnit\Framework\MockObject\MockObject[]
|
2016-05-09 13:04:32 +03:00
|
|
|
*/
|
2018-01-17 15:42:02 +03:00
|
|
|
protected function getUsers(array $userIds): array {
|
2016-05-09 13:04:32 +03:00
|
|
|
$users = [];
|
|
|
|
foreach ($userIds as $uid) {
|
2017-03-17 14:47:26 +03:00
|
|
|
$user = $this->createMock(IUser::class);
|
2016-05-09 13:04:32 +03:00
|
|
|
$user->expects($this->any())
|
|
|
|
->method('getUID')
|
|
|
|
->willReturn($uid);
|
|
|
|
$users[] = $user;
|
|
|
|
}
|
|
|
|
return $users;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-01-17 15:42:02 +03:00
|
|
|
* @param string $gid
|
2020-08-11 22:32:18 +03:00
|
|
|
* @return \OCP\IGroup|\PHPUnit\Framework\MockObject\MockObject
|
2016-05-09 13:04:32 +03:00
|
|
|
*/
|
2018-01-17 15:42:02 +03:00
|
|
|
protected function getGroup(string $gid) {
|
2017-03-17 14:47:26 +03:00
|
|
|
$group = $this->createMock(IGroup::class);
|
2016-05-09 13:04:32 +03:00
|
|
|
$group->expects($this->any())
|
|
|
|
->method('getGID')
|
|
|
|
->willReturn($gid);
|
|
|
|
return $group;
|
|
|
|
}
|
|
|
|
}
|