2018-01-15 12:06:03 +01:00
|
|
|
<?php
|
2018-01-17 13:42:02 +01:00
|
|
|
declare(strict_types=1);
|
2018-01-15 12:06:03 +01: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 09:06:43 +01:00
|
|
|
use OCP\IGroup;
|
|
|
|
use OCP\IGroupManager;
|
2018-06-28 22:16:47 +02:00
|
|
|
use OCP\IUserSession;
|
|
|
|
use OCP\L10N\IFactory;
|
2018-08-16 12:50:44 +02:00
|
|
|
use OCP\L10N\ILanguageIterator;
|
2018-01-15 12:06:03 +01:00
|
|
|
use OCP\Util;
|
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
class AdminTest extends TestCase {
|
2018-06-28 22:16:47 +02:00
|
|
|
/** @var IFactory|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
protected $l10nFactory;
|
2018-01-15 12:06:03 +01:00
|
|
|
/** @var Admin */
|
|
|
|
private $admin;
|
|
|
|
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $config;
|
|
|
|
/** @var UpdateChecker|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $updateChecker;
|
2018-02-23 09:06:43 +01:00
|
|
|
/** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $groupManager;
|
2018-01-15 12:06:03 +01: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 09:06:43 +01:00
|
|
|
$this->groupManager = $this->createMock(IGroupManager::class);
|
2018-01-15 12:06:03 +01:00
|
|
|
$this->dateTimeFormatter = $this->createMock(IDateTimeFormatter::class);
|
2018-06-28 22:16:47 +02:00
|
|
|
$this->l10nFactory = $this->createMock(IFactory::class);
|
2018-01-15 12:06:03 +01:00
|
|
|
|
|
|
|
$this->admin = new Admin(
|
2019-03-20 12:22:15 +01:00
|
|
|
$this->config, $this->updateChecker, $this->groupManager, $this->dateTimeFormatter, $this->l10nFactory
|
2018-01-15 12:06:03 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetFormWithUpdate() {
|
|
|
|
$channels = [
|
|
|
|
'daily',
|
|
|
|
'beta',
|
|
|
|
'stable',
|
|
|
|
'production',
|
|
|
|
];
|
|
|
|
$currentChannel = Util::getChannel();
|
2018-01-18 12:25:52 +01:00
|
|
|
if ($currentChannel === 'git') {
|
|
|
|
$channels[] = 'git';
|
2018-01-15 12:06:03 +01: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 13:22:36 +01:00
|
|
|
->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/')
|
|
|
|
->willReturn('https://updates.nextcloud.com/updater_server/');
|
2018-01-15 12:06:03 +01: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',
|
2018-11-09 10:22:19 +01:00
|
|
|
'updateVersionString' => 'Nextcloud 8.1.2',
|
2018-01-15 12:06:03 +01:00
|
|
|
'downloadLink' => 'https://downloads.nextcloud.org/server',
|
2018-06-28 22:16:47 +02:00
|
|
|
'changes' => [],
|
2018-01-15 12:06:03 +01:00
|
|
|
'updaterEnabled' => true,
|
2018-03-14 14:21:49 +01:00
|
|
|
'versionIsEol' => false,
|
2018-01-15 12:06:03 +01:00
|
|
|
]);
|
|
|
|
|
2018-02-23 09:06:43 +01: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 12:06:03 +01:00
|
|
|
$params = [
|
2018-01-18 12:25:52 +01:00
|
|
|
'json' => json_encode([
|
|
|
|
'isNewVersionAvailable' => true,
|
|
|
|
'isUpdateChecked' => true,
|
|
|
|
'lastChecked' => 'LastCheckedReturnValue',
|
|
|
|
'currentChannel' => Util::getChannel(),
|
|
|
|
'channels' => $channels,
|
2018-11-09 10:22:19 +01:00
|
|
|
'newVersion' => '8.1.2',
|
|
|
|
'newVersionString' => 'Nextcloud 8.1.2',
|
2018-01-18 12:25:52 +01:00
|
|
|
'downloadLink' => 'https://downloads.nextcloud.org/server',
|
2018-06-28 22:16:47 +02:00
|
|
|
'changes' => [],
|
2018-01-18 12:25:52 +01:00
|
|
|
'updaterEnabled' => true,
|
2018-03-14 14:21:49 +01:00
|
|
|
'versionIsEol' => false,
|
2018-01-18 12:25:52 +01:00
|
|
|
'isDefaultUpdateServerURL' => true,
|
|
|
|
'updateServerURL' => 'https://updates.nextcloud.com/updater_server/',
|
2018-02-23 09:06:43 +01:00
|
|
|
'notifyGroups' => [
|
|
|
|
['value' => 'admin', 'label' => 'Administrators'],
|
|
|
|
],
|
2018-01-18 12:25:52 +01:00
|
|
|
]),
|
2018-01-15 12:06:03 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
$expected = new TemplateResponse('updatenotification', 'admin', $params, '');
|
|
|
|
$this->assertEquals($expected, $this->admin->getForm());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testGetSection() {
|
2018-04-19 20:10:29 +02:00
|
|
|
$this->assertSame('overview', $this->admin->getSection());
|
2018-01-15 12:06:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPriority() {
|
2018-04-19 20:10:29 +02:00
|
|
|
$this->assertSame(11, $this->admin->getPriority());
|
2018-01-15 12:06:03 +01:00
|
|
|
}
|
2018-08-16 12:50:44 +02:00
|
|
|
|
|
|
|
public function changesProvider() {
|
|
|
|
return [
|
|
|
|
[ #0, all info, en
|
|
|
|
[
|
|
|
|
'changelogURL' => 'https://go.to.changelog',
|
|
|
|
'whatsNew' => [
|
|
|
|
'en' => [
|
|
|
|
'regular' => ['content'],
|
|
|
|
],
|
|
|
|
'de' => [
|
|
|
|
'regular' => ['inhalt'],
|
|
|
|
]
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'en',
|
|
|
|
[
|
|
|
|
'changelogURL' => 'https://go.to.changelog',
|
|
|
|
'whatsNew' => [
|
|
|
|
'regular' => ['content'],
|
|
|
|
],
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[ #1, all info, de
|
|
|
|
[
|
|
|
|
'changelogURL' => 'https://go.to.changelog',
|
|
|
|
'whatsNew' => [
|
|
|
|
'en' => [
|
|
|
|
'regular' => ['content'],
|
|
|
|
],
|
|
|
|
'de' => [
|
|
|
|
'regular' => ['inhalt'],
|
|
|
|
]
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'de',
|
|
|
|
[
|
|
|
|
'changelogURL' => 'https://go.to.changelog',
|
|
|
|
'whatsNew' => [
|
|
|
|
'regular' => ['inhalt'],
|
|
|
|
]
|
|
|
|
],
|
|
|
|
],
|
|
|
|
[ #2, just changelog
|
|
|
|
[ 'changelogURL' => 'https://go.to.changelog' ],
|
|
|
|
'en',
|
|
|
|
[ 'changelogURL' => 'https://go.to.changelog' ],
|
|
|
|
],
|
|
|
|
[ #3 nothing
|
|
|
|
[],
|
|
|
|
'ru',
|
|
|
|
[]
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider changesProvider
|
|
|
|
*/
|
|
|
|
public function testFilterChanges($changes, $userLang, $expectation) {
|
|
|
|
$iterator = $this->createMock(ILanguageIterator::class);
|
|
|
|
$iterator->expects($this->any())
|
|
|
|
->method('current')
|
|
|
|
->willReturnOnConsecutiveCalls('es', $userLang, 'it', 'en');
|
|
|
|
$iterator->expects($this->any())
|
|
|
|
->method('valid')
|
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
$this->l10nFactory->expects($this->atMost(1))
|
|
|
|
->method('getLanguageIterator')
|
|
|
|
->willReturn($iterator);
|
|
|
|
$result = $this->invokePrivate($this->admin, 'filterChanges', [$changes]);
|
|
|
|
$this->assertSame($expectation, $result);
|
|
|
|
}
|
2018-01-15 12:06:03 +01:00
|
|
|
}
|