Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2020-02-10 12:14:02 +0300
committerJoas Schilling <coding@schilljs.com>2020-02-10 12:14:02 +0300
commitf464f2313ffd24c43bb9a73994356d6f8c43438f (patch)
treef8b59469529e65ffd2f18520352f620027049671 /apps
parentbf74c4f21bf81cdb2d2e4188529c46215dc3bf6a (diff)
Fix unit tests
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps')
-rw-r--r--apps/settings/lib/Settings/Admin/Server.php33
-rw-r--r--apps/settings/tests/Settings/Admin/ServerTest.php39
2 files changed, 52 insertions, 20 deletions
diff --git a/apps/settings/lib/Settings/Admin/Server.php b/apps/settings/lib/Settings/Admin/Server.php
index 40333e1043c..d82c9e7c256 100644
--- a/apps/settings/lib/Settings/Admin/Server.php
+++ b/apps/settings/lib/Settings/Admin/Server.php
@@ -28,6 +28,7 @@
namespace OCA\Settings\Settings\Admin;
use OCP\AppFramework\Http\TemplateResponse;
+use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\Settings\ISettings;
@@ -36,12 +37,16 @@ class Server implements ISettings {
/** @var IDBConnection */
private $connection;
+ /** @var ITimeFactory */
+ private $timeFactory;
/** @var IConfig */
private $config;
public function __construct(IDBConnection $connection,
+ ITimeFactory $timeFactory,
IConfig $config) {
$this->connection = $connection;
+ $this->timeFactory = $timeFactory;
$this->config = $config;
}
@@ -49,6 +54,20 @@ class Server implements ISettings {
* @return TemplateResponse
*/
public function getForm() {
+ $parameters = [
+ // Background jobs
+ 'backgroundjobs_mode' => $this->config->getAppValue('core', 'backgroundjobs_mode', 'ajax'),
+ 'lastcron' => $this->config->getAppValue('core', 'lastcron', false),
+ 'cronMaxAge' => $this->cronMaxAge(),
+ 'cronErrors' => $this->config->getAppValue('core', 'cronErrors'),
+ 'cli_based_cron_possible' => function_exists('posix_getpwuid'),
+ 'cli_based_cron_user' => function_exists('posix_getpwuid') ? posix_getpwuid(fileowner(\OC::$configDir . 'config.php'))['name'] : '',
+ ];
+
+ return new TemplateResponse('settings', 'settings/admin/server', $parameters, '');
+ }
+
+ protected function cronMaxAge(): int {
$query = $this->connection->getQueryBuilder();
$query->select('last_checked')
->from('jobs')
@@ -59,21 +78,11 @@ class Server implements ISettings {
if ($row = $result->fetch()) {
$maxAge = (int) $row['last_checked'];
} else {
- $maxAge = time();
+ $maxAge = $this->timeFactory->getTime();
}
$result->closeCursor();
- $parameters = [
- // Background jobs
- 'backgroundjobs_mode' => $this->config->getAppValue('core', 'backgroundjobs_mode', 'ajax'),
- 'lastcron' => $this->config->getAppValue('core', 'lastcron', false),
- 'cronMaxAge' => $maxAge,
- 'cronErrors' => $this->config->getAppValue('core', 'cronErrors'),
- 'cli_based_cron_possible' => function_exists('posix_getpwuid'),
- 'cli_based_cron_user' => function_exists('posix_getpwuid') ? posix_getpwuid(fileowner(\OC::$configDir . 'config.php'))['name'] : '',
- ];
-
- return new TemplateResponse('settings', 'settings/admin/server', $parameters, '');
+ return $maxAge;
}
/**
diff --git a/apps/settings/tests/Settings/Admin/ServerTest.php b/apps/settings/tests/Settings/Admin/ServerTest.php
index aeb37f8d6cc..9657ec2d2d4 100644
--- a/apps/settings/tests/Settings/Admin/ServerTest.php
+++ b/apps/settings/tests/Settings/Admin/ServerTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
*
@@ -31,25 +32,46 @@ namespace OCA\Settings\Tests\Settings\Admin;
use OCA\Settings\Settings\Admin\Server;
use OCP\AppFramework\Http\TemplateResponse;
+use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IConfig;
+use OCP\IDBConnection;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
+
+/**
+ * @group DB
+ */
class ServerTest extends TestCase {
/** @var Server */
private $admin;
- /** @var IConfig */
+ /** @var IDBConnection */
+ private $connection;
+ /** @var ITimeFactory|MockObject */
+ private $timeFactory;
+ /** @var IConfig|MockObject */
private $config;
protected function setUp(): void {
parent::setUp();
+ $this->connection = \OC::$server->getDatabaseConnection();
+ $this->timeFactory = $this->createMock(ITimeFactory::class);
$this->config = $this->createMock(IConfig::class);
- $this->admin = new Server(
- $this->config
- );
+ $this->admin = $this->getMockBuilder(Server::class)
+ ->onlyMethods(['cronMaxAge'])
+ ->setConstructorArgs([
+ $this->connection,
+ $this->timeFactory,
+ $this->config,
+ ])
+ ->getMock();
}
- public function testGetForm() {
+ public function testGetForm(): void {
+ $this->admin->expects($this->once())
+ ->method('cronMaxAge')
+ ->willReturn(1337);
$this->config
->expects($this->at(0))
->method('getAppValue')
@@ -71,7 +93,8 @@ class ServerTest extends TestCase {
[
'backgroundjobs_mode' => 'ajax',
'lastcron' => false,
- 'cronErrors' => '',
+ 'cronErrors' => '',
+ 'cronMaxAge' => 1337,
'cli_based_cron_possible' => true,
'cli_based_cron_user' => function_exists('posix_getpwuid') ? posix_getpwuid(fileowner(\OC::$configDir . 'config.php'))['name'] : '', // to not explode here because of posix extension not being disabled - which is already checked in the line above
],
@@ -81,11 +104,11 @@ class ServerTest extends TestCase {
$this->assertEquals($expected, $this->admin->getForm());
}
- public function testGetSection() {
+ public function testGetSection(): void {
$this->assertSame('server', $this->admin->getSection());
}
- public function testGetPriority() {
+ public function testGetPriority(): void {
$this->assertSame(0, $this->admin->getPriority());
}
}