fix(updatenotification): spread the use of new appconfig

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/44165/head
Maxence Lange 2 months ago
parent 5723c13dc0
commit 519e434573

@ -30,6 +30,7 @@ use OC\Profile\TProfileHelper;
use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState; use OCP\AppFramework\Services\IInitialState;
use OCP\AppFramework\Utility\ITimeFactory; use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IAppConfig;
use OCP\IConfig; use OCP\IConfig;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\IL10N; use OCP\IL10N;
@ -39,28 +40,16 @@ use OCP\Settings\IDelegatedSettings;
class Server implements IDelegatedSettings { class Server implements IDelegatedSettings {
use TProfileHelper; use TProfileHelper;
private IDBConnection $connection; public function __construct(
private IInitialState $initialStateService; private IDBConnection $connection,
private ProfileManager $profileManager; private IInitialState $initialStateService,
private ITimeFactory $timeFactory; private ProfileManager $profileManager,
private IConfig $config; private ITimeFactory $timeFactory,
private IL10N $l; private IURLGenerator $urlGenerator,
private IURLGenerator $urlGenerator; private IConfig $config,
private IAppConfig $appConfig,
public function __construct(IDBConnection $connection, private IL10N $l,
IInitialState $initialStateService, ) {
ProfileManager $profileManager,
ITimeFactory $timeFactory,
IURLGenerator $urlGenerator,
IConfig $config,
IL10N $l) {
$this->connection = $connection;
$this->initialStateService = $initialStateService;
$this->profileManager = $profileManager;
$this->timeFactory = $timeFactory;
$this->config = $config;
$this->l = $l;
$this->urlGenerator = $urlGenerator;
} }
/** /**
@ -69,7 +58,7 @@ class Server implements IDelegatedSettings {
public function getForm() { public function getForm() {
// Background jobs // Background jobs
$this->initialStateService->provideInitialState('backgroundJobsMode', $this->config->getAppValue('core', 'backgroundjobs_mode', 'ajax')); $this->initialStateService->provideInitialState('backgroundJobsMode', $this->config->getAppValue('core', 'backgroundjobs_mode', 'ajax'));
$this->initialStateService->provideInitialState('lastCron', (int)$this->config->getAppValue('core', 'lastcron', '0')); $this->initialStateService->provideInitialState('lastCron', $this->appConfig->getValueInt('core', 'lastcron', 0));
$this->initialStateService->provideInitialState('cronMaxAge', $this->cronMaxAge()); $this->initialStateService->provideInitialState('cronMaxAge', $this->cronMaxAge());
$this->initialStateService->provideInitialState('cronErrors', $this->config->getAppValue('core', 'cronErrors')); $this->initialStateService->provideInitialState('cronErrors', $this->config->getAppValue('core', 'cronErrors'));
$this->initialStateService->provideInitialState('cliBasedCronPossible', function_exists('posix_getpwuid')); $this->initialStateService->provideInitialState('cliBasedCronPossible', function_exists('posix_getpwuid'));

@ -26,6 +26,7 @@ declare(strict_types=1);
namespace OCA\Settings\SetupChecks; namespace OCA\Settings\SetupChecks;
use OCP\IAppConfig;
use OCP\IConfig; use OCP\IConfig;
use OCP\IDateTimeFormatter; use OCP\IDateTimeFormatter;
use OCP\IL10N; use OCP\IL10N;
@ -37,6 +38,7 @@ class CronInfo implements ISetupCheck {
public function __construct( public function __construct(
private IL10N $l10n, private IL10N $l10n,
private IConfig $config, private IConfig $config,
private IAppConfig $appConfig,
private IURLGenerator $urlGenerator, private IURLGenerator $urlGenerator,
private IDateTimeFormatter $dateTimeFormatter, private IDateTimeFormatter $dateTimeFormatter,
) { ) {
@ -51,7 +53,7 @@ class CronInfo implements ISetupCheck {
} }
public function run(): SetupResult { public function run(): SetupResult {
$lastCronRun = (int)$this->config->getAppValue('core', 'lastcron', '0'); $lastCronRun = $this->appConfig->getValueInt('core', 'lastcron', 0);
$relativeTime = $this->dateTimeFormatter->formatTimeSpan($lastCronRun); $relativeTime = $this->dateTimeFormatter->formatTimeSpan($lastCronRun);
if ((time() - $lastCronRun) > 3600) { if ((time() - $lastCronRun) > 3600) {

@ -36,6 +36,7 @@ use OCA\Settings\Settings\Admin\Server;
use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState; use OCP\AppFramework\Services\IInitialState;
use OCP\AppFramework\Utility\ITimeFactory; use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IAppConfig;
use OCP\IConfig; use OCP\IConfig;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\IL10N; use OCP\IL10N;
@ -59,6 +60,8 @@ class ServerTest extends TestCase {
private $timeFactory; private $timeFactory;
/** @var IConfig|MockObject */ /** @var IConfig|MockObject */
private $config; private $config;
/** @var IAppConfig|MockObject */
private $appConfig;
/** @var IL10N|MockObject */ /** @var IL10N|MockObject */
private $l10n; private $l10n;
/** @var IUrlGenerator|MockObject */ /** @var IUrlGenerator|MockObject */
@ -71,6 +74,7 @@ class ServerTest extends TestCase {
$this->profileManager = $this->createMock(ProfileManager::class); $this->profileManager = $this->createMock(ProfileManager::class);
$this->timeFactory = $this->createMock(ITimeFactory::class); $this->timeFactory = $this->createMock(ITimeFactory::class);
$this->config = $this->createMock(IConfig::class); $this->config = $this->createMock(IConfig::class);
$this->appConfig = $this->createMock(IAppConfig::class);
$this->l10n = $this->createMock(IL10N::class); $this->l10n = $this->createMock(IL10N::class);
$this->urlGenerator = $this->createMock(IUrlGenerator::class); $this->urlGenerator = $this->createMock(IUrlGenerator::class);
@ -83,6 +87,7 @@ class ServerTest extends TestCase {
$this->timeFactory, $this->timeFactory,
$this->urlGenerator, $this->urlGenerator,
$this->config, $this->config,
$this->appConfig,
$this->l10n, $this->l10n,
]) ])
->getMock(); ->getMock();

@ -33,6 +33,7 @@ use OC\User\Backend;
use OCA\UpdateNotification\UpdateChecker; use OCA\UpdateNotification\UpdateChecker;
use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState; use OCP\AppFramework\Services\IInitialState;
use OCP\IAppConfig;
use OCP\IConfig; use OCP\IConfig;
use OCP\IDateTimeFormatter; use OCP\IDateTimeFormatter;
use OCP\IGroupManager; use OCP\IGroupManager;
@ -45,40 +46,22 @@ use OCP\Util;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
class Admin implements ISettings { class Admin implements ISettings {
private IConfig $config;
private UpdateChecker $updateChecker;
private IGroupManager $groupManager;
private IDateTimeFormatter $dateTimeFormatter;
private IFactory $l10nFactory;
private IRegistry $subscriptionRegistry;
private IUserManager $userManager;
private LoggerInterface $logger;
private IInitialState $initialState;
public function __construct( public function __construct(
IConfig $config, private IConfig $config,
UpdateChecker $updateChecker, private IAppConfig $appConfig,
IGroupManager $groupManager, private UpdateChecker $updateChecker,
IDateTimeFormatter $dateTimeFormatter, private IGroupManager $groupManager,
IFactory $l10nFactory, private IDateTimeFormatter $dateTimeFormatter,
IRegistry $subscriptionRegistry, private IFactory $l10nFactory,
IUserManager $userManager, private IRegistry $subscriptionRegistry,
LoggerInterface $logger, private IUserManager $userManager,
IInitialState $initialState private LoggerInterface $logger,
private IInitialState $initialState
) { ) {
$this->config = $config;
$this->updateChecker = $updateChecker;
$this->groupManager = $groupManager;
$this->dateTimeFormatter = $dateTimeFormatter;
$this->l10nFactory = $l10nFactory;
$this->subscriptionRegistry = $subscriptionRegistry;
$this->userManager = $userManager;
$this->logger = $logger;
$this->initialState = $initialState;
} }
public function getForm(): TemplateResponse { public function getForm(): TemplateResponse {
$lastUpdateCheckTimestamp = (int)$this->config->getAppValue('core', 'lastupdatedat'); $lastUpdateCheckTimestamp = $this->appConfig->getValueInt('core', 'lastupdatedat');
$lastUpdateCheck = $this->dateTimeFormatter->formatDateTime($lastUpdateCheckTimestamp); $lastUpdateCheck = $this->dateTimeFormatter->formatDateTime($lastUpdateCheckTimestamp);
$channels = [ $channels = [

@ -34,6 +34,7 @@ use OCA\UpdateNotification\Settings\Admin;
use OCA\UpdateNotification\UpdateChecker; use OCA\UpdateNotification\UpdateChecker;
use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState; use OCP\AppFramework\Services\IInitialState;
use OCP\IAppConfig;
use OCP\IConfig; use OCP\IConfig;
use OCP\IDateTimeFormatter; use OCP\IDateTimeFormatter;
use OCP\IGroup; use OCP\IGroup;
@ -55,6 +56,8 @@ class AdminTest extends TestCase {
private $admin; private $admin;
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
private $config; private $config;
/** @var IAppConfig|\PHPUnit\Framework\MockObject\MockObject */
private $appConfig;
/** @var UpdateChecker|\PHPUnit\Framework\MockObject\MockObject */ /** @var UpdateChecker|\PHPUnit\Framework\MockObject\MockObject */
private $updateChecker; private $updateChecker;
/** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */ /** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */
@ -74,6 +77,7 @@ class AdminTest extends TestCase {
parent::setUp(); parent::setUp();
$this->config = $this->createMock(IConfig::class); $this->config = $this->createMock(IConfig::class);
$this->appConfig = $this->createMock(IAppConfig::class);
$this->updateChecker = $this->createMock(UpdateChecker::class); $this->updateChecker = $this->createMock(UpdateChecker::class);
$this->groupManager = $this->createMock(IGroupManager::class); $this->groupManager = $this->createMock(IGroupManager::class);
$this->dateTimeFormatter = $this->createMock(IDateTimeFormatter::class); $this->dateTimeFormatter = $this->createMock(IDateTimeFormatter::class);
@ -85,6 +89,7 @@ class AdminTest extends TestCase {
$this->admin = new Admin( $this->admin = new Admin(
$this->config, $this->config,
$this->appConfig,
$this->updateChecker, $this->updateChecker,
$this->groupManager, $this->groupManager,
$this->dateTimeFormatter, $this->dateTimeFormatter,
@ -143,14 +148,16 @@ class AdminTest extends TestCase {
if ($currentChannel === 'git') { if ($currentChannel === 'git') {
$channels[] = 'git'; $channels[] = 'git';
} }
$this->appConfig
->expects($this->once())
->method('getValueInt')
->with('core', 'lastupdatedat', 0)
->willReturn(12345);
$this->config $this->config
->expects($this->exactly(2)) ->expects($this->once())
->method('getAppValue') ->method('getAppValue')
->willReturnMap([ ->with('updatenotification', 'notify_groups', '["admin"]')
['core', 'lastupdatedat', '', '12345'], ->willReturn('["admin"]');
['updatenotification', 'notify_groups', '["admin"]', '["admin"]'],
]);
$this->config $this->config
->method('getSystemValue') ->method('getSystemValue')
->willReturnMap([ ->willReturnMap([
@ -160,7 +167,7 @@ class AdminTest extends TestCase {
$this->dateTimeFormatter $this->dateTimeFormatter
->expects($this->once()) ->expects($this->once())
->method('formatDateTime') ->method('formatDateTime')
->with('12345') ->with(12345)
->willReturn('LastCheckedReturnValue'); ->willReturn('LastCheckedReturnValue');
$this->updateChecker $this->updateChecker
->expects($this->once()) ->expects($this->once())
@ -268,13 +275,16 @@ class AdminTest extends TestCase {
$channels[] = 'git'; $channels[] = 'git';
} }
$this->appConfig
->expects($this->once())
->method('getValueInt')
->with('core', 'lastupdatedat', 0)
->willReturn(12345);
$this->config $this->config
->expects($this->exactly(2)) ->expects($this->once())
->method('getAppValue') ->method('getAppValue')
->willReturnMap([ ->with('updatenotification', 'notify_groups', '["admin"]')
['core', 'lastupdatedat', '', '12345'], ->willReturn('["admin"]');
['updatenotification', 'notify_groups', '["admin"]', '["admin"]'],
]);
$this->config $this->config
->method('getSystemValue') ->method('getSystemValue')
->willReturnMap([ ->willReturnMap([
@ -392,13 +402,16 @@ class AdminTest extends TestCase {
$channels[] = 'git'; $channels[] = 'git';
} }
$this->appConfig
->expects($this->once())
->method('getValueInt')
->with('core', 'lastupdatedat', 0)
->willReturn(12345);
$this->config $this->config
->expects($this->exactly(2)) ->expects($this->once())
->method('getAppValue') ->method('getAppValue')
->willReturnMap([ ->with('updatenotification', 'notify_groups', '["admin"]')
['core', 'lastupdatedat', '', '12345'], ->willReturn('["admin"]');
['updatenotification', 'notify_groups', '["admin"]', '["admin"]'],
]);
$this->config $this->config
->method('getSystemValue') ->method('getSystemValue')
->willReturnMap([ ->willReturnMap([

@ -40,10 +40,13 @@ use OC\Repair\Events\RepairStepEvent;
use OC\Repair\Events\RepairWarningEvent; use OC\Repair\Events\RepairWarningEvent;
use OCP\EventDispatcher\Event; use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventDispatcher; use OCP\EventDispatcher\IEventDispatcher;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IEventSource; use OCP\IEventSource;
use OCP\IEventSourceFactory; use OCP\IEventSourceFactory;
use OCP\IL10N; use OCP\IL10N;
use OCP\L10N\IFactory; use OCP\L10N\IFactory;
use OCP\Server;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
if (!str_contains(@ini_get('disable_functions'), 'set_time_limit')) { if (!str_contains(@ini_get('disable_functions'), 'set_time_limit')) {
@ -111,13 +114,13 @@ if (\OCP\Util::needUpgrade()) {
// avoid side effects // avoid side effects
\OC_User::setIncognitoMode(true); \OC_User::setIncognitoMode(true);
$logger = \OC::$server->get(\Psr\Log\LoggerInterface::class); $config = Server::get(IConfig::class);
$config = \OC::$server->getConfig();
$updater = new \OC\Updater( $updater = new \OC\Updater(
$config, $config,
Server::get(IAppConfig::class),
\OC::$server->getIntegrityCodeChecker(), \OC::$server->getIntegrityCodeChecker(),
$logger, Server::get(LoggerInterface::class),
\OC::$server->query(\OC\Installer::class) Server::get(\OC\Installer::class)
); );
$incompatibleApps = []; $incompatibleApps = [];
$incompatibleOverwrites = $config->getSystemValue('app_install_overwrite', []); $incompatibleOverwrites = $config->getSystemValue('app_install_overwrite', []);
@ -189,7 +192,7 @@ if (\OCP\Util::needUpgrade()) {
try { try {
$updater->upgrade(); $updater->upgrade();
} catch (\Exception $e) { } catch (\Exception $e) {
\OCP\Server::get(LoggerInterface::class)->error( Server::get(LoggerInterface::class)->error(
$e->getMessage(), $e->getMessage(),
[ [
'exception' => $e, 'exception' => $e,

@ -62,6 +62,7 @@ use OC\TextProcessing\RemoveOldTasksBackgroundJob;
use OCP\AppFramework\Utility\ITimeFactory; use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList; use OCP\BackgroundJob\IJobList;
use OCP\Defaults; use OCP\Defaults;
use OCP\IAppConfig;
use OCP\IConfig; use OCP\IConfig;
use OCP\IGroup; use OCP\IGroup;
use OCP\IGroupManager; use OCP\IGroupManager;
@ -382,7 +383,8 @@ class Setup {
$config = Server::get(IConfig::class); $config = Server::get(IConfig::class);
$config->setAppValue('core', 'installedat', (string)microtime(true)); $config->setAppValue('core', 'installedat', (string)microtime(true));
$config->setAppValue('core', 'lastupdatedat', (string)microtime(true)); $appConfig = Server::get(IAppConfig::class);
$appConfig->setValueInt('core', 'lastupdatedat', time());
$vendorData = $this->getVendorData(); $vendorData = $this->getVendorData();
$config->setAppValue('core', 'vendor', $vendorData['vendor']); $config->setAppValue('core', 'vendor', $vendorData['vendor']);

@ -59,6 +59,7 @@ use OCP\App\IAppManager;
use OCP\EventDispatcher\Event; use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventDispatcher; use OCP\EventDispatcher\IEventDispatcher;
use OCP\HintException; use OCP\HintException;
use OCP\IAppConfig;
use OCP\IConfig; use OCP\IConfig;
use OCP\ILogger; use OCP\ILogger;
use OCP\Util; use OCP\Util;
@ -74,19 +75,7 @@ use Psr\Log\LoggerInterface;
* - failure(string $message) * - failure(string $message)
*/ */
class Updater extends BasicEmitter { class Updater extends BasicEmitter {
/** @var LoggerInterface */ private array $logLevelNames = [
private $log;
/** @var IConfig */
private $config;
/** @var Checker */
private $checker;
/** @var Installer */
private $installer;
private $logLevelNames = [
0 => 'Debug', 0 => 'Debug',
1 => 'Info', 1 => 'Info',
2 => 'Warning', 2 => 'Warning',
@ -94,14 +83,13 @@ class Updater extends BasicEmitter {
4 => 'Fatal', 4 => 'Fatal',
]; ];
public function __construct(IConfig $config, public function __construct(
Checker $checker, private IConfig $config,
?LoggerInterface $log, private IAppConfig $appConfig,
Installer $installer) { private Checker $checker,
$this->log = $log; private ?LoggerInterface $log,
$this->config = $config; private Installer $installer
$this->checker = $checker; ) {
$this->installer = $installer;
} }
/** /**
@ -303,7 +291,7 @@ class Updater extends BasicEmitter {
$repair->run(); $repair->run();
//Invalidate update feed //Invalidate update feed
$this->config->setAppValue('core', 'lastupdatedat', '0'); $this->appConfig->setValueInt('core', 'lastupdatedat', 0);
// Check for code integrity if not disabled // Check for code integrity if not disabled
if (\OC::$server->getIntegrityCodeChecker()->isCodeCheckEnforced()) { if (\OC::$server->getIntegrityCodeChecker()->isCodeCheckEnforced()) {

@ -27,6 +27,7 @@
namespace OC\Updater; namespace OC\Updater;
use OCP\Http\Client\IClientService; use OCP\Http\Client\IClientService;
use OCP\IAppConfig;
use OCP\IConfig; use OCP\IConfig;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\Support\Subscription\IRegistry; use OCP\Support\Subscription\IRegistry;
@ -37,6 +38,7 @@ class VersionCheck {
public function __construct( public function __construct(
private IClientService $clientService, private IClientService $clientService,
private IConfig $config, private IConfig $config,
private IAppConfig $appConfig,
private IUserManager $userManager, private IUserManager $userManager,
private IRegistry $registry, private IRegistry $registry,
private LoggerInterface $logger, private LoggerInterface $logger,
@ -56,13 +58,13 @@ class VersionCheck {
} }
// Look up the cache - it is invalidated all 30 minutes // Look up the cache - it is invalidated all 30 minutes
if (((int)$this->config->getAppValue('core', 'lastupdatedat') + 1800) > time()) { if (($this->appConfig->getValueInt('core', 'lastupdatedat') + 1800) > time()) {
return json_decode($this->config->getAppValue('core', 'lastupdateResult'), true); return json_decode($this->config->getAppValue('core', 'lastupdateResult'), true);
} }
$updaterUrl = $this->config->getSystemValueString('updater.server.url', 'https://updates.nextcloud.com/updater_server/'); $updaterUrl = $this->config->getSystemValueString('updater.server.url', 'https://updates.nextcloud.com/updater_server/');
$this->config->setAppValue('core', 'lastupdatedat', (string)time()); $this->appConfig->setValueInt('core', 'lastupdatedat', time());
if ($this->config->getAppValue('core', 'installedat', '') === '') { if ($this->config->getAppValue('core', 'installedat', '') === '') {
$this->config->setAppValue('core', 'installedat', (string)microtime(true)); $this->config->setAppValue('core', 'installedat', (string)microtime(true));
@ -70,7 +72,7 @@ class VersionCheck {
$version = Util::getVersion(); $version = Util::getVersion();
$version['installed'] = $this->config->getAppValue('core', 'installedat'); $version['installed'] = $this->config->getAppValue('core', 'installedat');
$version['updated'] = $this->config->getAppValue('core', 'lastupdatedat'); $version['updated'] = $this->appConfig->getValueInt('core', 'lastupdatedat');
$version['updatechannel'] = \OC_Util::getChannel(); $version['updatechannel'] = \OC_Util::getChannel();
$version['edition'] = ''; $version['edition'] = '';
$version['build'] = \OC_Util::getBuild(); $version['build'] = \OC_Util::getBuild();

@ -24,6 +24,7 @@ namespace Test\Updater;
use OC\Updater\VersionCheck; use OC\Updater\VersionCheck;
use OCP\Http\Client\IClientService; use OCP\Http\Client\IClientService;
use OCP\IAppConfig;
use OCP\IConfig; use OCP\IConfig;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\Support\Subscription\IRegistry; use OCP\Support\Subscription\IRegistry;
@ -33,6 +34,8 @@ use Psr\Log\LoggerInterface;
class VersionCheckTest extends \Test\TestCase { class VersionCheckTest extends \Test\TestCase {
/** @var IConfig| \PHPUnit\Framework\MockObject\MockObject */ /** @var IConfig| \PHPUnit\Framework\MockObject\MockObject */
private $config; private $config;
/** @var IAppConfig| \PHPUnit\Framework\MockObject\MockObject */
private $appConfig;
/** @var VersionCheck | \PHPUnit\Framework\MockObject\MockObject*/ /** @var VersionCheck | \PHPUnit\Framework\MockObject\MockObject*/
private $updater; private $updater;
/** @var IRegistry | \PHPUnit\Framework\Mo2ckObject\MockObject*/ /** @var IRegistry | \PHPUnit\Framework\Mo2ckObject\MockObject*/
@ -45,6 +48,9 @@ class VersionCheckTest extends \Test\TestCase {
$this->config = $this->getMockBuilder(IConfig::class) $this->config = $this->getMockBuilder(IConfig::class)
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$this->appConfig = $this->getMockBuilder(IAppConfig::class)
->disableOriginalConstructor()
->getMock();
$clientService = $this->getMockBuilder(IClientService::class) $clientService = $this->getMockBuilder(IClientService::class)
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
@ -59,6 +65,7 @@ class VersionCheckTest extends \Test\TestCase {
->setConstructorArgs([ ->setConstructorArgs([
$clientService, $clientService,
$this->config, $this->config,
$this->appConfig,
$this->createMock(IUserManager::class), $this->createMock(IUserManager::class),
$this->registry, $this->registry,
$this->logger, $this->logger,
@ -71,7 +78,7 @@ class VersionCheckTest extends \Test\TestCase {
* @return string * @return string
*/ */
private function buildUpdateUrl($baseUrl) { private function buildUpdateUrl($baseUrl) {
return $baseUrl . '?version='.implode('x', Util::getVersion()).'xinstalledatxlastupdatedatx'.\OC_Util::getChannel().'xxx'.PHP_MAJOR_VERSION.'x'.PHP_MINOR_VERSION.'x'.PHP_RELEASE_VERSION.'x0x0'; return $baseUrl . '?version='.implode('x', Util::getVersion()).'xinstalledatx' . time() . 'x'.\OC_Util::getChannel().'xxx'.PHP_MAJOR_VERSION.'x'.PHP_MINOR_VERSION.'x'.PHP_RELEASE_VERSION.'x0x0';
} }
public function testCheckInCache() { public function testCheckInCache() {
@ -88,17 +95,16 @@ class VersionCheckTest extends \Test\TestCase {
->method('getSystemValueBool') ->method('getSystemValueBool')
->with('has_internet_connection', true) ->with('has_internet_connection', true)
->willReturn(true); ->willReturn(true);
$this->appConfig
->expects($this->once())
->method('getValueInt')
->with('core', 'lastupdatedat')
->willReturn(time());
$this->config $this->config
->expects($this->exactly(2)) ->expects($this->once())
->method('getAppValue') ->method('getAppValue')
->withConsecutive( ->with('core', 'lastupdateResult')
['core', 'lastupdatedat'], ->willReturn(json_encode($expectedResult));
['core', 'lastupdateResult']
)
->willReturnOnConsecutiveCalls(
time(),
json_encode($expectedResult)
);
$this->assertSame($expectedResult, $this->updater->check()); $this->assertSame($expectedResult, $this->updater->check());
} }
@ -119,33 +125,32 @@ class VersionCheckTest extends \Test\TestCase {
->method('getSystemValueBool') ->method('getSystemValueBool')
->with('has_internet_connection', true) ->with('has_internet_connection', true)
->willReturn(true); ->willReturn(true);
$this->config $this->appConfig
->expects($this->exactly(4)) ->expects($this->exactly(2))
->method('getAppValue') ->method('getValueInt')
->withConsecutive( ->with('core', 'lastupdatedat')
['core', 'lastupdatedat'],
['core', 'installedat'],
['core', 'installedat'],
['core', 'lastupdatedat'],
)
->willReturnOnConsecutiveCalls( ->willReturnOnConsecutiveCalls(
'0', 0,
'installedat', time(),
'installedat',
'lastupdatedat',
); );
$this->config
->expects($this->exactly(2))
->method('getAppValue')
->with('core', 'installedat')
->willReturn('installedat');
$this->config $this->config
->expects($this->once()) ->expects($this->once())
->method('getSystemValueString') ->method('getSystemValueString')
->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/') ->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/')
->willReturnArgument(1); ->willReturnArgument(1);
$this->appConfig
->expects($this->once())
->method('setValueInt')
->with('core', 'lastupdatedat', time());
$this->config $this->config
->expects($this->exactly(2)) ->expects($this->once())
->method('setAppValue') ->method('setAppValue')
->withConsecutive( ->with('core', 'lastupdateResult', json_encode($expectedResult));
['core', 'lastupdatedat', $this->isType('string')],
['core', 'lastupdateResult', json_encode($expectedResult)]
);
$updateXml = '<?xml version="1.0"?> $updateXml = '<?xml version="1.0"?>
<owncloud> <owncloud>
@ -171,33 +176,32 @@ class VersionCheckTest extends \Test\TestCase {
->method('getSystemValueBool') ->method('getSystemValueBool')
->with('has_internet_connection', true) ->with('has_internet_connection', true)
->willReturn(true); ->willReturn(true);
$this->config $this->appConfig
->expects($this->exactly(4)) ->expects($this->exactly(2))
->method('getAppValue') ->method('getValueInt')
->withConsecutive( ->with('core', 'lastupdatedat')
['core', 'lastupdatedat'],
['core', 'installedat'],
['core', 'installedat'],
['core', 'lastupdatedat'],
)
->willReturnOnConsecutiveCalls( ->willReturnOnConsecutiveCalls(
'0', 0,
'installedat', time(),
'installedat',
'lastupdatedat',
); );
$this->config
->expects($this->exactly(2))
->method('getAppValue')
->with('core', 'installedat')
->willReturn('installedat');
$this->config $this->config
->expects($this->once()) ->expects($this->once())
->method('getSystemValueString') ->method('getSystemValueString')
->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/') ->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/')
->willReturnArgument(1); ->willReturnArgument(1);
$this->appConfig
->expects($this->once())
->method('setValueInt')
->with('core', 'lastupdatedat', time());
$this->config $this->config
->expects($this->exactly(2)) ->expects($this->once())
->method('setAppValue') ->method('setAppValue')
->withConsecutive( ->with('core', 'lastupdateResult', $this->isType('string'));
['core', 'lastupdatedat', $this->isType('string')],
['core', 'lastupdateResult', '[]']
);
$updateXml = 'Invalid XML Response!'; $updateXml = 'Invalid XML Response!';
$this->updater $this->updater
@ -225,33 +229,32 @@ class VersionCheckTest extends \Test\TestCase {
->method('getSystemValueBool') ->method('getSystemValueBool')
->with('has_internet_connection', true) ->with('has_internet_connection', true)
->willReturn(true); ->willReturn(true);
$this->config $this->appConfig
->expects($this->exactly(4)) ->expects($this->exactly(2))
->method('getAppValue') ->method('getValueInt')
->withConsecutive( ->with('core', 'lastupdatedat')
['core', 'lastupdatedat'],
['core', 'installedat'],
['core', 'installedat'],
['core', 'lastupdatedat'],
)
->willReturnOnConsecutiveCalls( ->willReturnOnConsecutiveCalls(
'0', 0,
'installedat', time(),
'installedat',
'lastupdatedat',
); );
$this->config
->expects($this->exactly(2))
->method('getAppValue')
->with('core', 'installedat')
->willReturn('installedat');
$this->config $this->config
->expects($this->once()) ->expects($this->once())
->method('getSystemValueString') ->method('getSystemValueString')
->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/') ->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/')
->willReturnArgument(1); ->willReturnArgument(1);
$this->appConfig
->expects($this->once())
->method('setValueInt')
->with('core', 'lastupdatedat', time());
$this->config $this->config
->expects($this->exactly(2)) ->expects($this->once())
->method('setAppValue') ->method('setAppValue')
->withConsecutive( ->with('core', 'lastupdateResult', $this->isType('string'));
['core', 'lastupdatedat', $this->isType('string')],
['core', 'lastupdateResult', $this->isType('string')]
);
$updateXml = '<?xml version="1.0"?> $updateXml = '<?xml version="1.0"?>
<owncloud> <owncloud>
@ -278,33 +281,32 @@ class VersionCheckTest extends \Test\TestCase {
->method('getSystemValueBool') ->method('getSystemValueBool')
->with('has_internet_connection', true) ->with('has_internet_connection', true)
->willReturn(true); ->willReturn(true);
$this->config $this->appConfig
->expects($this->exactly(4)) ->expects($this->exactly(2))
->method('getAppValue') ->method('getValueInt')
->withConsecutive( ->with('core', 'lastupdatedat')
['core', 'lastupdatedat'],
['core', 'installedat'],
['core', 'installedat'],
['core', 'lastupdatedat'],
)
->willReturnOnConsecutiveCalls( ->willReturnOnConsecutiveCalls(
'0', 0,
'installedat', time(),
'installedat',
'lastupdatedat',
); );
$this->config
->expects($this->exactly(2))
->method('getAppValue')
->with('core', 'installedat')
->willReturn('installedat');
$this->config $this->config
->expects($this->once()) ->expects($this->once())
->method('getSystemValueString') ->method('getSystemValueString')
->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/') ->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/')
->willReturnArgument(1); ->willReturnArgument(1);
$this->appConfig
->expects($this->once())
->method('setValueInt')
->with('core', 'lastupdatedat', time());
$this->config $this->config
->expects($this->exactly(2)) ->expects($this->once())
->method('setAppValue') ->method('setAppValue')
->withConsecutive( ->with('core', 'lastupdateResult', $this->isType('string'));
['core', 'lastupdatedat', $this->isType('string')],
['core', 'lastupdateResult', json_encode($expectedResult)]
);
$updateXml = ''; $updateXml = '';
$this->updater $this->updater
@ -332,33 +334,32 @@ class VersionCheckTest extends \Test\TestCase {
->method('getSystemValueBool') ->method('getSystemValueBool')
->with('has_internet_connection', true) ->with('has_internet_connection', true)
->willReturn(true); ->willReturn(true);
$this->config $this->appConfig
->expects($this->exactly(4)) ->expects($this->exactly(2))
->method('getAppValue') ->method('getValueInt')
->withConsecutive( ->with('core', 'lastupdatedat')
['core', 'lastupdatedat'],
['core', 'installedat'],
['core', 'installedat'],
['core', 'lastupdatedat'],
)
->willReturnOnConsecutiveCalls( ->willReturnOnConsecutiveCalls(
'0', 0,
'installedat', time(),
'installedat',
'lastupdatedat',
); );
$this->config
->expects($this->exactly(2))
->method('getAppValue')
->with('core', 'installedat')
->willReturn('installedat');
$this->config $this->config
->expects($this->once()) ->expects($this->once())
->method('getSystemValueString') ->method('getSystemValueString')
->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/') ->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/')
->willReturnArgument(1); ->willReturnArgument(1);
$this->appConfig
->expects($this->once())
->method('setValueInt')
->with('core', 'lastupdatedat', time());
$this->config $this->config
->expects($this->exactly(2)) ->expects($this->once())
->method('setAppValue') ->method('setAppValue')
->withConsecutive( ->with('core', 'lastupdateResult', $this->isType('string'));
['core', 'lastupdatedat', $this->isType('string')],
['core', 'lastupdateResult', $this->isType('string')]
);
// missing autoupdater element should still not fail // missing autoupdater element should still not fail
$updateXml = '<?xml version="1.0"?> $updateXml = '<?xml version="1.0"?>

@ -25,6 +25,7 @@ namespace Test;
use OC\Installer; use OC\Installer;
use OC\IntegrityCheck\Checker; use OC\IntegrityCheck\Checker;
use OC\Updater; use OC\Updater;
use OCP\IAppConfig;
use OCP\IConfig; use OCP\IConfig;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
@ -32,6 +33,8 @@ use Psr\Log\LoggerInterface;
class UpdaterTest extends TestCase { class UpdaterTest extends TestCase {
/** @var IConfig|MockObject */ /** @var IConfig|MockObject */
private $config; private $config;
/** @var IAppConfig|MockObject */
private $appConfig;
/** @var LoggerInterface|MockObject */ /** @var LoggerInterface|MockObject */
private $logger; private $logger;
/** @var Updater */ /** @var Updater */
@ -46,6 +49,9 @@ class UpdaterTest extends TestCase {
$this->config = $this->getMockBuilder(IConfig::class) $this->config = $this->getMockBuilder(IConfig::class)
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$this->appConfig = $this->getMockBuilder(IAppConfig::class)
->disableOriginalConstructor()
->getMock();
$this->logger = $this->getMockBuilder(LoggerInterface::class) $this->logger = $this->getMockBuilder(LoggerInterface::class)
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
@ -58,6 +64,7 @@ class UpdaterTest extends TestCase {
$this->updater = new Updater( $this->updater = new Updater(
$this->config, $this->config,
$this->appConfig,
$this->checker, $this->checker,
$this->logger, $this->logger,
$this->installer $this->installer

Loading…
Cancel
Save