2018-01-15 14:06:03 +03:00
|
|
|
<?php
|
2018-01-17 15:42:02 +03:00
|
|
|
declare(strict_types=1);
|
2018-01-15 14:06:03 +03:00
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
|
|
|
*
|
|
|
|
* @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,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\UpdateNotification\Tests\Settings;
|
|
|
|
|
|
|
|
use OCA\UpdateNotification\Settings\Admin;
|
|
|
|
use OCA\UpdateNotification\UpdateChecker;
|
|
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
|
|
|
use OCP\IConfig;
|
|
|
|
use OCP\IDateTimeFormatter;
|
2018-02-23 11:06:43 +03:00
|
|
|
use OCP\IGroup;
|
|
|
|
use OCP\IGroupManager;
|
2018-01-15 14:06:03 +03:00
|
|
|
use OCP\Util;
|
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
class AdminTest extends TestCase {
|
|
|
|
/** @var Admin */
|
|
|
|
private $admin;
|
|
|
|
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $config;
|
|
|
|
/** @var UpdateChecker|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $updateChecker;
|
2018-02-23 11:06:43 +03:00
|
|
|
/** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $groupManager;
|
2018-01-15 14:06:03 +03:00
|
|
|
/** @var IDateTimeFormatter|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $dateTimeFormatter;
|
|
|
|
|
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->config = $this->createMock(IConfig::class);
|
|
|
|
$this->updateChecker = $this->createMock(UpdateChecker::class);
|
2018-02-23 11:06:43 +03:00
|
|
|
$this->groupManager = $this->createMock(IGroupManager::class);
|
2018-01-15 14:06:03 +03:00
|
|
|
$this->dateTimeFormatter = $this->createMock(IDateTimeFormatter::class);
|
|
|
|
|
|
|
|
$this->admin = new Admin(
|
|
|
|
$this->config,
|
|
|
|
$this->updateChecker,
|
2018-02-23 11:06:43 +03:00
|
|
|
$this->groupManager,
|
2018-01-15 14:06:03 +03:00
|
|
|
$this->dateTimeFormatter
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetFormWithUpdate() {
|
|
|
|
$channels = [
|
|
|
|
'daily',
|
|
|
|
'beta',
|
|
|
|
'stable',
|
|
|
|
'production',
|
|
|
|
];
|
|
|
|
$currentChannel = Util::getChannel();
|
2018-01-18 14:25:52 +03:00
|
|
|
if ($currentChannel === 'git') {
|
|
|
|
$channels[] = 'git';
|
2018-01-15 14:06:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->config
|
|
|
|
->expects($this->exactly(2))
|
|
|
|
->method('getAppValue')
|
|
|
|
->willReturnMap([
|
|
|
|
['core', 'lastupdatedat', '', '12345'],
|
|
|
|
['updatenotification', 'notify_groups', '["admin"]', '["admin"]'],
|
|
|
|
]);
|
|
|
|
$this->config
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSystemValue')
|
2018-02-01 15:22:36 +03:00
|
|
|
->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/')
|
|
|
|
->willReturn('https://updates.nextcloud.com/updater_server/');
|
2018-01-15 14:06:03 +03:00
|
|
|
$this->dateTimeFormatter
|
|
|
|
->expects($this->once())
|
|
|
|
->method('formatDateTime')
|
|
|
|
->with('12345')
|
|
|
|
->willReturn('LastCheckedReturnValue');
|
|
|
|
$this->updateChecker
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUpdateState')
|
|
|
|
->willReturn([
|
|
|
|
'updateAvailable' => true,
|
|
|
|
'updateVersion' => '8.1.2',
|
|
|
|
'downloadLink' => 'https://downloads.nextcloud.org/server',
|
|
|
|
'updaterEnabled' => true,
|
2018-03-14 16:21:49 +03:00
|
|
|
'versionIsEol' => false,
|
2018-01-15 14:06:03 +03:00
|
|
|
]);
|
|
|
|
|
2018-02-23 11:06:43 +03:00
|
|
|
$group = $this->createMock(IGroup::class);
|
|
|
|
$group->expects($this->any())
|
|
|
|
->method('getDisplayName')
|
|
|
|
->willReturn('Administrators');
|
|
|
|
$group->expects($this->any())
|
|
|
|
->method('getGID')
|
|
|
|
->willReturn('admin');
|
|
|
|
$this->groupManager->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('admin')
|
|
|
|
->willReturn($group);
|
|
|
|
|
2018-01-15 14:06:03 +03:00
|
|
|
$params = [
|
2018-01-18 14:25:52 +03:00
|
|
|
'json' => json_encode([
|
|
|
|
'isNewVersionAvailable' => true,
|
|
|
|
'isUpdateChecked' => true,
|
|
|
|
'lastChecked' => 'LastCheckedReturnValue',
|
|
|
|
'currentChannel' => Util::getChannel(),
|
|
|
|
'channels' => $channels,
|
|
|
|
'newVersionString' => '8.1.2',
|
|
|
|
'downloadLink' => 'https://downloads.nextcloud.org/server',
|
|
|
|
'updaterEnabled' => true,
|
2018-03-14 16:21:49 +03:00
|
|
|
'versionIsEol' => false,
|
2018-01-18 14:25:52 +03:00
|
|
|
'isDefaultUpdateServerURL' => true,
|
|
|
|
'updateServerURL' => 'https://updates.nextcloud.com/updater_server/',
|
2018-02-23 11:06:43 +03:00
|
|
|
'notifyGroups' => [
|
|
|
|
['value' => 'admin', 'label' => 'Administrators'],
|
|
|
|
],
|
2018-01-18 14:25:52 +03:00
|
|
|
]),
|
2018-01-15 14:06:03 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
$expected = new TemplateResponse('updatenotification', 'admin', $params, '');
|
|
|
|
$this->assertEquals($expected, $this->admin->getForm());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testGetSection() {
|
2018-04-19 21:10:29 +03:00
|
|
|
$this->assertSame('overview', $this->admin->getSection());
|
2018-01-15 14:06:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPriority() {
|
2018-04-19 21:10:29 +03:00
|
|
|
$this->assertSame(11, $this->admin->getPriority());
|
2018-01-15 14:06:03 +03:00
|
|
|
}
|
|
|
|
}
|