2018-01-15 14:06:03 +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
|
|
|
|
2018-01-15 14:06:03 +03:00
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2018-01-15 14:06:03 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Julius Härtl <jus@bitgrid.net>
|
2018-01-15 14:06:03 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2018-01-15 14:06:03 +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/>
|
2018-01-15 14:06:03 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
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-06-28 23:16:47 +03:00
|
|
|
use OCP\L10N\IFactory;
|
2018-08-16 13:50:44 +03:00
|
|
|
use OCP\L10N\ILanguageIterator;
|
2019-05-13 15:11:07 +03:00
|
|
|
use OCP\Support\Subscription\IRegistry;
|
2018-01-15 14:06:03 +03:00
|
|
|
use OCP\Util;
|
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
class AdminTest extends TestCase {
|
2018-06-28 23:16:47 +03:00
|
|
|
/** @var IFactory|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
protected $l10nFactory;
|
2018-01-15 14:06:03 +03:00
|
|
|
/** @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;
|
2019-05-13 15:11:07 +03:00
|
|
|
/** @var IRegistry|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $subscriptionRegistry;
|
2018-01-15 14:06:03 +03:00
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
protected function setUp(): void {
|
2018-01-15 14:06:03 +03:00
|
|
|
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);
|
2018-06-28 23:16:47 +03:00
|
|
|
$this->l10nFactory = $this->createMock(IFactory::class);
|
2019-05-13 15:11:07 +03:00
|
|
|
$this->subscriptionRegistry = $this->createMock(IRegistry::class);
|
2018-01-15 14:06:03 +03:00
|
|
|
|
|
|
|
$this->admin = new Admin(
|
2019-05-13 15:11:07 +03:00
|
|
|
$this->config, $this->updateChecker, $this->groupManager, $this->dateTimeFormatter, $this->l10nFactory, $this->subscriptionRegistry
|
2018-01-15 14:06:03 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
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',
|
2018-11-09 12:22:19 +03:00
|
|
|
'updateVersionString' => 'Nextcloud 8.1.2',
|
2018-01-15 14:06:03 +03:00
|
|
|
'downloadLink' => 'https://downloads.nextcloud.org/server',
|
2018-06-28 23:16:47 +03:00
|
|
|
'changes' => [],
|
2018-01-15 14:06:03 +03:00
|
|
|
'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);
|
|
|
|
|
2019-05-13 15:11:07 +03:00
|
|
|
$this->subscriptionRegistry
|
|
|
|
->expects($this->once())
|
|
|
|
->method('delegateHasValidSubscription')
|
|
|
|
->willReturn(true);
|
|
|
|
|
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,
|
2018-11-09 12:22:19 +03:00
|
|
|
'newVersion' => '8.1.2',
|
|
|
|
'newVersionString' => 'Nextcloud 8.1.2',
|
2018-01-18 14:25:52 +03:00
|
|
|
'downloadLink' => 'https://downloads.nextcloud.org/server',
|
2018-06-28 23:16:47 +03:00
|
|
|
'changes' => [],
|
2018-01-18 14:25:52 +03:00
|
|
|
'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'],
|
|
|
|
],
|
2019-05-13 15:11:07 +03:00
|
|
|
'hasValidSubscription' => true,
|
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
|
|
|
}
|
2018-08-16 13:50:44 +03: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 14:06:03 +03:00
|
|
|
}
|