2016-08-15 17:24:56 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
|
|
|
|
*
|
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-09-17 17:33:27 +03:00
|
|
|
namespace OCA\Settings\Tests\AppInfo;
|
2016-08-15 17:24:56 +03:00
|
|
|
|
2019-09-17 17:33:27 +03:00
|
|
|
use OCA\Settings\Admin\Sharing;
|
2016-08-15 17:24:56 +03:00
|
|
|
use OC\Settings\Manager;
|
2019-09-17 17:33:27 +03:00
|
|
|
use OCA\Settings\Personal\Security;
|
2016-08-15 17:24:56 +03:00
|
|
|
use OC\Settings\Section;
|
|
|
|
use OCP\IDBConnection;
|
|
|
|
use OCP\IL10N;
|
|
|
|
use OCP\ILogger;
|
2018-09-26 17:46:35 +03:00
|
|
|
use OCP\IServerContainer;
|
2017-01-19 13:02:56 +03:00
|
|
|
use OCP\IURLGenerator;
|
2019-05-21 23:25:11 +03:00
|
|
|
use OCP\L10N\IFactory;
|
2019-05-22 11:48:51 +03:00
|
|
|
use OCP\Settings\ISubAdminSettings;
|
2016-08-15 17:24:56 +03:00
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
class ManagerTest extends TestCase {
|
2018-09-26 17:46:35 +03:00
|
|
|
|
2016-12-28 18:58:02 +03:00
|
|
|
/** @var Manager|\PHPUnit_Framework_MockObject_MockObject */
|
2016-08-15 17:24:56 +03:00
|
|
|
private $manager;
|
2016-12-28 18:58:02 +03:00
|
|
|
/** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
|
2016-08-15 17:24:56 +03:00
|
|
|
private $logger;
|
2016-12-28 18:58:02 +03:00
|
|
|
/** @var IDBConnection|\PHPUnit_Framework_MockObject_MockObject */
|
2016-08-15 17:24:56 +03:00
|
|
|
private $l10n;
|
2019-05-21 23:25:11 +03:00
|
|
|
/** @var IFactory|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $l10nFactory;
|
2017-01-19 13:02:56 +03:00
|
|
|
/** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $url;
|
2018-09-26 17:46:35 +03:00
|
|
|
/** @var IServerContainer|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $container;
|
2016-08-15 17:24:56 +03:00
|
|
|
|
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
|
2017-01-19 13:02:56 +03:00
|
|
|
$this->logger = $this->createMock(ILogger::class);
|
|
|
|
$this->l10n = $this->createMock(IL10N::class);
|
2019-05-21 23:25:11 +03:00
|
|
|
$this->l10nFactory = $this->createMock(IFactory::class);
|
2017-01-19 13:02:56 +03:00
|
|
|
$this->url = $this->createMock(IURLGenerator::class);
|
2018-09-26 17:46:35 +03:00
|
|
|
$this->container = $this->createMock(IServerContainer::class);
|
2016-08-15 17:24:56 +03:00
|
|
|
|
|
|
|
$this->manager = new Manager(
|
|
|
|
$this->logger,
|
2019-05-21 23:25:11 +03:00
|
|
|
$this->l10nFactory,
|
2017-05-19 18:34:57 +03:00
|
|
|
$this->url,
|
2018-09-26 17:46:35 +03:00
|
|
|
$this->container
|
2016-08-15 17:24:56 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetAdminSections() {
|
2019-05-21 23:25:11 +03:00
|
|
|
$this->l10nFactory
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('lib')
|
|
|
|
->willReturn($this->l10n);
|
2016-08-15 17:24:56 +03:00
|
|
|
$this->l10n
|
|
|
|
->expects($this->any())
|
|
|
|
->method('t')
|
|
|
|
->will($this->returnArgument(0));
|
|
|
|
|
2018-01-29 15:14:56 +03:00
|
|
|
$this->manager->registerSection('admin', \OCA\WorkflowEngine\Settings\Section::class);
|
2016-12-28 18:58:02 +03:00
|
|
|
|
2019-03-20 00:24:16 +03:00
|
|
|
$this->url->expects($this->exactly(6))
|
2017-01-19 13:02:56 +03:00
|
|
|
->method('imagePath')
|
|
|
|
->willReturnMap([
|
2018-04-17 21:03:26 +03:00
|
|
|
['settings', 'admin.svg', '0'],
|
|
|
|
['core', 'actions/settings-dark.svg', '1'],
|
2017-01-19 13:02:56 +03:00
|
|
|
['core', 'actions/share.svg', '2'],
|
|
|
|
['core', 'actions/password.svg', '3'],
|
2018-07-04 19:50:49 +03:00
|
|
|
['core', 'places/contacts.svg', '5'],
|
2018-04-17 21:03:26 +03:00
|
|
|
['settings', 'help.svg', '4'],
|
2017-01-19 13:02:56 +03:00
|
|
|
]);
|
2016-12-28 18:58:02 +03:00
|
|
|
|
|
|
|
$this->assertEquals([
|
2018-04-17 21:03:26 +03:00
|
|
|
0 => [new Section('overview', 'Overview', 0, '0')],
|
|
|
|
1 => [new Section('server', 'Basic settings', 0, '1')],
|
2017-01-19 13:02:56 +03:00
|
|
|
5 => [new Section('sharing', 'Sharing', 0, '2')],
|
2017-03-14 04:44:10 +03:00
|
|
|
10 => [new Section('security', 'Security', 0, '3')],
|
2018-06-27 20:16:21 +03:00
|
|
|
50 => [new Section('groupware', 'Groupware', 0, '5')],
|
2018-01-29 15:14:56 +03:00
|
|
|
55 => [\OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class)],
|
2018-04-17 21:03:26 +03:00
|
|
|
98 => [new Section('additional', 'Additional settings', 0, '1')],
|
2016-12-28 18:58:02 +03:00
|
|
|
], $this->manager->getAdminSections());
|
|
|
|
}
|
|
|
|
|
2017-05-19 18:34:57 +03:00
|
|
|
public function testGetPersonalSections() {
|
2019-05-21 23:25:11 +03:00
|
|
|
$this->l10nFactory
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('lib')
|
|
|
|
->willReturn($this->l10n);
|
2017-05-19 18:34:57 +03:00
|
|
|
$this->l10n
|
|
|
|
->expects($this->any())
|
|
|
|
->method('t')
|
|
|
|
->will($this->returnArgument(0));
|
|
|
|
|
2018-01-29 15:14:56 +03:00
|
|
|
$this->manager->registerSection('personal', \OCA\WorkflowEngine\Settings\Section::class);
|
2017-05-19 18:34:57 +03:00
|
|
|
|
2017-06-23 23:19:18 +03:00
|
|
|
$this->url->expects($this->exactly(3))
|
2017-05-19 18:34:57 +03:00
|
|
|
->method('imagePath')
|
|
|
|
->willReturnMap([
|
|
|
|
['core', 'actions/info.svg', '1'],
|
2017-06-16 16:40:05 +03:00
|
|
|
['settings', 'password.svg', '2'],
|
2018-05-24 16:06:28 +03:00
|
|
|
['core', 'clients/phone.svg', '3'],
|
2017-05-19 18:34:57 +03:00
|
|
|
]);
|
|
|
|
|
2018-01-29 15:14:56 +03:00
|
|
|
$this->assertEquals([
|
2017-05-19 18:34:57 +03:00
|
|
|
0 => [new Section('personal-info', 'Personal info', 0, '1')],
|
2017-06-16 16:40:05 +03:00
|
|
|
5 => [new Section('security', 'Security', 0, '2')],
|
2018-05-24 16:06:28 +03:00
|
|
|
15 => [new Section('sync-clients', 'Mobile & desktop', 0, '3')],
|
2018-01-29 15:14:56 +03:00
|
|
|
55 => [\OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class)],
|
2017-05-19 18:34:57 +03:00
|
|
|
], $this->manager->getPersonalSections());
|
|
|
|
}
|
|
|
|
|
2016-12-28 18:58:02 +03:00
|
|
|
public function testGetAdminSectionsEmptySection() {
|
2019-05-21 23:25:11 +03:00
|
|
|
$this->l10nFactory
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('lib')
|
|
|
|
->willReturn($this->l10n);
|
2016-12-28 18:58:02 +03:00
|
|
|
$this->l10n
|
|
|
|
->expects($this->any())
|
|
|
|
->method('t')
|
|
|
|
->will($this->returnArgument(0));
|
|
|
|
|
2019-03-20 00:24:16 +03:00
|
|
|
$this->url->expects($this->exactly(6))
|
2017-01-19 13:02:56 +03:00
|
|
|
->method('imagePath')
|
|
|
|
->willReturnMap([
|
2018-04-17 21:03:26 +03:00
|
|
|
['settings', 'admin.svg', '0'],
|
|
|
|
['core', 'actions/settings-dark.svg', '1'],
|
2017-01-19 13:02:56 +03:00
|
|
|
['core', 'actions/share.svg', '2'],
|
|
|
|
['core', 'actions/password.svg', '3'],
|
2018-07-04 19:50:49 +03:00
|
|
|
['core', 'places/contacts.svg', '5'],
|
2018-04-17 21:03:26 +03:00
|
|
|
['settings', 'help.svg', '4'],
|
2017-01-19 13:02:56 +03:00
|
|
|
]);
|
2016-12-28 18:58:02 +03:00
|
|
|
|
2016-08-15 17:24:56 +03:00
|
|
|
$this->assertEquals([
|
2018-04-17 21:03:26 +03:00
|
|
|
0 => [new Section('overview', 'Overview', 0, '0')],
|
|
|
|
1 => [new Section('server', 'Basic settings', 0, '1')],
|
2017-01-19 13:02:56 +03:00
|
|
|
5 => [new Section('sharing', 'Sharing', 0, '2')],
|
2017-03-14 04:44:10 +03:00
|
|
|
10 => [new Section('security', 'Security', 0, '3')],
|
2018-06-27 20:16:21 +03:00
|
|
|
50 => [new Section('groupware', 'Groupware', 0, '5')],
|
2018-04-17 21:03:26 +03:00
|
|
|
98 => [new Section('additional', 'Additional settings', 0, '1')],
|
2016-08-15 17:24:56 +03:00
|
|
|
], $this->manager->getAdminSections());
|
|
|
|
}
|
|
|
|
|
2017-05-19 18:34:57 +03:00
|
|
|
public function testGetPersonalSectionsEmptySection() {
|
2019-05-21 23:25:11 +03:00
|
|
|
$this->l10nFactory
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('lib')
|
|
|
|
->willReturn($this->l10n);
|
2017-05-19 18:34:57 +03:00
|
|
|
$this->l10n
|
|
|
|
->expects($this->any())
|
|
|
|
->method('t')
|
|
|
|
->will($this->returnArgument(0));
|
|
|
|
|
2017-06-23 23:19:18 +03:00
|
|
|
$this->url->expects($this->exactly(3))
|
2017-05-19 18:34:57 +03:00
|
|
|
->method('imagePath')
|
|
|
|
->willReturnMap([
|
|
|
|
['core', 'actions/info.svg', '1'],
|
2017-06-16 16:40:05 +03:00
|
|
|
['settings', 'password.svg', '2'],
|
2018-05-24 22:39:34 +03:00
|
|
|
['core', 'clients/phone.svg', '3'],
|
2017-05-19 18:34:57 +03:00
|
|
|
]);
|
|
|
|
|
2017-06-23 23:19:18 +03:00
|
|
|
$this->assertArraySubset([
|
2017-05-19 18:34:57 +03:00
|
|
|
0 => [new Section('personal-info', 'Personal info', 0, '1')],
|
2017-06-16 16:40:05 +03:00
|
|
|
5 => [new Section('security', 'Security', 0, '2')],
|
2018-05-24 22:39:34 +03:00
|
|
|
15 => [new Section('sync-clients', 'Mobile & desktop', 0, '3')],
|
2017-05-19 18:34:57 +03:00
|
|
|
], $this->manager->getPersonalSections());
|
|
|
|
}
|
|
|
|
|
2016-08-15 17:24:56 +03:00
|
|
|
public function testGetAdminSettings() {
|
2018-09-26 17:46:35 +03:00
|
|
|
$section = $this->createMock(Sharing::class);
|
|
|
|
$section->expects($this->once())
|
|
|
|
->method('getPriority')
|
|
|
|
->willReturn(13);
|
|
|
|
$this->container->expects($this->once())
|
|
|
|
->method('query')
|
|
|
|
->with(Sharing::class)
|
|
|
|
->willReturn($section);
|
|
|
|
|
|
|
|
$settings = $this->manager->getAdminSettings('sharing');
|
|
|
|
|
2016-08-15 17:24:56 +03:00
|
|
|
$this->assertEquals([
|
2018-09-26 17:46:35 +03:00
|
|
|
13 => [$section]
|
|
|
|
], $settings);
|
2016-08-15 17:24:56 +03:00
|
|
|
}
|
2017-05-19 18:34:57 +03:00
|
|
|
|
2019-05-22 11:48:51 +03:00
|
|
|
public function testGetAdminSettingsAsSubAdmin() {
|
|
|
|
$section = $this->createMock(Sharing::class);
|
|
|
|
$this->container->expects($this->once())
|
|
|
|
->method('query')
|
|
|
|
->with(Sharing::class)
|
|
|
|
->willReturn($section);
|
|
|
|
|
|
|
|
$settings = $this->manager->getAdminSettings('sharing', true);
|
|
|
|
|
|
|
|
$this->assertEquals([], $settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetSubAdminSettingsAsSubAdmin() {
|
|
|
|
$section = $this->createMock(ISubAdminSettings::class);
|
|
|
|
$section->expects($this->once())
|
|
|
|
->method('getPriority')
|
|
|
|
->willReturn(13);
|
|
|
|
$this->container->expects($this->once())
|
|
|
|
->method('query')
|
|
|
|
->with(Sharing::class)
|
|
|
|
->willReturn($section);
|
|
|
|
|
|
|
|
$settings = $this->manager->getAdminSettings('sharing', true);
|
|
|
|
|
|
|
|
$this->assertEquals([
|
|
|
|
13 => [$section]
|
|
|
|
], $settings);
|
|
|
|
}
|
|
|
|
|
2017-05-19 18:34:57 +03:00
|
|
|
public function testGetPersonalSettings() {
|
2018-09-26 17:46:35 +03:00
|
|
|
$section = $this->createMock(Security::class);
|
|
|
|
$section->expects($this->once())
|
|
|
|
->method('getPriority')
|
|
|
|
->willReturn(16);
|
2019-09-09 23:12:29 +03:00
|
|
|
$section2 = $this->createMock(Security\Authtokens::class);
|
|
|
|
$section2->expects($this->once())
|
|
|
|
->method('getPriority')
|
|
|
|
->willReturn(100);
|
|
|
|
$this->container->expects($this->at(0))
|
2018-09-26 17:46:35 +03:00
|
|
|
->method('query')
|
|
|
|
->with(Security::class)
|
|
|
|
->willReturn($section);
|
2019-09-09 23:12:29 +03:00
|
|
|
$this->container->expects($this->at(1))
|
|
|
|
->method('query')
|
|
|
|
->with(Security\Authtokens::class)
|
|
|
|
->willReturn($section2);
|
2018-09-26 17:46:35 +03:00
|
|
|
|
|
|
|
$settings = $this->manager->getPersonalSettings('security');
|
|
|
|
|
2017-05-19 18:34:57 +03:00
|
|
|
$this->assertEquals([
|
2019-09-09 23:12:29 +03:00
|
|
|
16 => [$section],
|
|
|
|
100 => [$section2],
|
2018-09-26 17:46:35 +03:00
|
|
|
], $settings);
|
2017-05-19 18:34:57 +03:00
|
|
|
}
|
2018-08-25 17:48:37 +03:00
|
|
|
|
|
|
|
public function testSameSectionAsPersonalAndAdmin() {
|
2019-05-21 23:25:11 +03:00
|
|
|
$this->l10nFactory
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('lib')
|
|
|
|
->willReturn($this->l10n);
|
2018-08-25 17:48:37 +03:00
|
|
|
$this->l10n
|
|
|
|
->expects($this->any())
|
|
|
|
->method('t')
|
|
|
|
->will($this->returnArgument(0));
|
|
|
|
|
|
|
|
$this->manager->registerSection('personal', \OCA\WorkflowEngine\Settings\Section::class);
|
|
|
|
$this->manager->registerSection('admin', \OCA\WorkflowEngine\Settings\Section::class);
|
|
|
|
|
2019-03-20 00:24:16 +03:00
|
|
|
$this->url->expects($this->exactly(9))
|
2018-08-25 17:48:37 +03:00
|
|
|
->method('imagePath')
|
|
|
|
->willReturnMap([
|
|
|
|
['core', 'actions/info.svg', '1'],
|
|
|
|
['settings', 'password.svg', '2'],
|
|
|
|
['core', 'clients/phone.svg', '3'],
|
|
|
|
['settings', 'admin.svg', '0'],
|
|
|
|
['core', 'actions/settings-dark.svg', '1'],
|
|
|
|
['core', 'actions/share.svg', '2'],
|
|
|
|
['core', 'actions/password.svg', '3'],
|
|
|
|
['core', 'places/contacts.svg', '5'],
|
|
|
|
['settings', 'help.svg', '4'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals([
|
|
|
|
0 => [new Section('personal-info', 'Personal info', 0, '1')],
|
|
|
|
5 => [new Section('security', 'Security', 0, '2')],
|
|
|
|
15 => [new Section('sync-clients', 'Mobile & desktop', 0, '3')],
|
|
|
|
55 => [\OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class)],
|
|
|
|
], $this->manager->getPersonalSections());
|
|
|
|
|
|
|
|
$this->assertEquals([
|
|
|
|
0 => [new Section('overview', 'Overview', 0, '0')],
|
|
|
|
1 => [new Section('server', 'Basic settings', 0, '1')],
|
|
|
|
5 => [new Section('sharing', 'Sharing', 0, '2')],
|
|
|
|
10 => [new Section('security', 'Security', 0, '3')],
|
|
|
|
50 => [new Section('groupware', 'Groupware', 0, '5')],
|
|
|
|
55 => [\OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class)],
|
|
|
|
98 => [new Section('additional', 'Additional settings', 0, '1')],
|
|
|
|
], $this->manager->getAdminSections());
|
|
|
|
}
|
2016-08-15 17:24:56 +03:00
|
|
|
}
|