2016-08-15 14:24:56 +00: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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Tests\Settings;
|
|
|
|
|
2017-05-19 15:34:57 +00:00
|
|
|
use OC\Accounts\AccountManager;
|
2016-08-15 14:24:56 +00:00
|
|
|
use OC\Settings\Admin\Sharing;
|
|
|
|
use OC\Settings\Manager;
|
2016-12-28 15:58:02 +00:00
|
|
|
use OC\Settings\Mapper;
|
2017-06-16 13:40:05 +00:00
|
|
|
use OC\Settings\Personal\Security;
|
2016-08-15 14:24:56 +00:00
|
|
|
use OC\Settings\Section;
|
2017-06-16 13:40:05 +00:00
|
|
|
use OCP\App\IAppManager;
|
2016-08-15 14:24:56 +00:00
|
|
|
use OCP\Encryption\IManager;
|
|
|
|
use OCP\IConfig;
|
|
|
|
use OCP\IDBConnection;
|
2017-05-19 15:34:57 +00:00
|
|
|
use OCP\IGroupManager;
|
2016-08-15 14:24:56 +00:00
|
|
|
use OCP\IL10N;
|
|
|
|
use OCP\ILogger;
|
2017-03-17 12:34:23 +00:00
|
|
|
use OCP\IRequest;
|
2017-01-19 10:02:56 +00:00
|
|
|
use OCP\IURLGenerator;
|
2016-08-15 14:24:56 +00:00
|
|
|
use OCP\IUserManager;
|
2017-05-19 15:34:57 +00:00
|
|
|
use OCP\L10N\IFactory;
|
2016-08-15 14:24:56 +00:00
|
|
|
use OCP\Lock\ILockingProvider;
|
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
class ManagerTest extends TestCase {
|
2016-12-28 15:58:02 +00:00
|
|
|
/** @var Manager|\PHPUnit_Framework_MockObject_MockObject */
|
2016-08-15 14:24:56 +00:00
|
|
|
private $manager;
|
2016-12-28 15:58:02 +00:00
|
|
|
/** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
|
2016-08-15 14:24:56 +00:00
|
|
|
private $logger;
|
2016-12-28 15:58:02 +00:00
|
|
|
/** @var IDBConnection|\PHPUnit_Framework_MockObject_MockObject */
|
2016-08-15 14:24:56 +00:00
|
|
|
private $dbConnection;
|
2016-12-28 15:58:02 +00:00
|
|
|
/** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
|
2016-08-15 14:24:56 +00:00
|
|
|
private $l10n;
|
2016-12-28 15:58:02 +00:00
|
|
|
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
|
2016-08-15 14:24:56 +00:00
|
|
|
private $config;
|
2016-12-28 15:58:02 +00:00
|
|
|
/** @var IManager|\PHPUnit_Framework_MockObject_MockObject */
|
2016-08-15 14:24:56 +00:00
|
|
|
private $encryptionManager;
|
2016-12-28 15:58:02 +00:00
|
|
|
/** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
|
2016-08-15 14:24:56 +00:00
|
|
|
private $userManager;
|
2016-12-28 15:58:02 +00:00
|
|
|
/** @var ILockingProvider|\PHPUnit_Framework_MockObject_MockObject */
|
2016-08-15 14:24:56 +00:00
|
|
|
private $lockingProvider;
|
2017-03-17 12:34:23 +00:00
|
|
|
/** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $request;
|
2017-01-19 10:02:56 +00:00
|
|
|
/** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $url;
|
2017-05-19 15:34:57 +00:00
|
|
|
/** @var AccountManager|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $accountManager;
|
|
|
|
/** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $groupManager;
|
|
|
|
/** @var IFactory|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $l10nFactory;
|
2017-06-16 13:40:05 +00:00
|
|
|
/** @var IAppManager */
|
|
|
|
private $appManager;
|
2016-08-15 14:24:56 +00:00
|
|
|
|
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
|
2017-01-19 10:02:56 +00:00
|
|
|
$this->logger = $this->createMock(ILogger::class);
|
|
|
|
$this->dbConnection = $this->createMock(IDBConnection::class);
|
|
|
|
$this->l10n = $this->createMock(IL10N::class);
|
|
|
|
$this->config = $this->createMock(IConfig::class);
|
|
|
|
$this->encryptionManager = $this->createMock(IManager::class);
|
|
|
|
$this->userManager = $this->createMock(IUserManager::class);
|
|
|
|
$this->lockingProvider = $this->createMock(ILockingProvider::class);
|
2017-03-17 12:34:23 +00:00
|
|
|
$this->request = $this->createMock(IRequest::class);
|
2017-01-19 10:02:56 +00:00
|
|
|
$this->url = $this->createMock(IURLGenerator::class);
|
2017-05-19 15:34:57 +00:00
|
|
|
$this->accountManager = $this->createMock(AccountManager::class);
|
|
|
|
$this->groupManager = $this->createMock(IGroupManager::class);
|
|
|
|
$this->l10nFactory = $this->createMock(IFactory::class);
|
2017-06-16 13:40:05 +00:00
|
|
|
$this->appManager = $this->createMock(IAppManager::class);
|
2016-08-15 14:24:56 +00:00
|
|
|
|
|
|
|
$this->manager = new Manager(
|
|
|
|
$this->logger,
|
|
|
|
$this->dbConnection,
|
|
|
|
$this->l10n,
|
|
|
|
$this->config,
|
|
|
|
$this->encryptionManager,
|
|
|
|
$this->userManager,
|
2016-12-28 15:58:02 +00:00
|
|
|
$this->lockingProvider,
|
2017-03-17 12:34:23 +00:00
|
|
|
$this->request,
|
2017-05-19 15:34:57 +00:00
|
|
|
$this->url,
|
|
|
|
$this->accountManager,
|
|
|
|
$this->groupManager,
|
|
|
|
$this->l10nFactory,
|
2017-06-16 13:40:05 +00:00
|
|
|
$this->appManager
|
2016-08-15 14:24:56 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetAdminSections() {
|
|
|
|
$this->l10n
|
|
|
|
->expects($this->any())
|
|
|
|
->method('t')
|
|
|
|
->will($this->returnArgument(0));
|
|
|
|
|
2018-01-29 12:14:56 +00:00
|
|
|
$this->manager->registerSection('admin', \OCA\WorkflowEngine\Settings\Section::class);
|
2016-12-28 15:58:02 +00:00
|
|
|
|
2018-06-12 14:16:29 +00:00
|
|
|
$this->url->expects($this->exactly(6))
|
2017-01-19 10:02:56 +00:00
|
|
|
->method('imagePath')
|
|
|
|
->willReturnMap([
|
2018-04-17 18:03:26 +00:00
|
|
|
['settings', 'admin.svg', '0'],
|
|
|
|
['core', 'actions/settings-dark.svg', '1'],
|
2017-01-19 10:02:56 +00:00
|
|
|
['core', 'actions/share.svg', '2'],
|
|
|
|
['core', 'actions/password.svg', '3'],
|
2018-04-17 18:03:26 +00:00
|
|
|
['settings', 'help.svg', '4'],
|
2017-01-19 10:02:56 +00:00
|
|
|
]);
|
2016-12-28 15:58:02 +00:00
|
|
|
|
|
|
|
$this->assertEquals([
|
2018-04-17 18:03:26 +00:00
|
|
|
0 => [new Section('overview', 'Overview', 0, '0')],
|
|
|
|
1 => [new Section('server', 'Basic settings', 0, '1')],
|
2017-01-19 10:02:56 +00:00
|
|
|
5 => [new Section('sharing', 'Sharing', 0, '2')],
|
2017-03-14 01:44:10 +00:00
|
|
|
10 => [new Section('security', 'Security', 0, '3')],
|
2017-01-19 10:02:56 +00:00
|
|
|
45 => [new Section('encryption', 'Encryption', 0, '3')],
|
2018-01-29 12:14:56 +00:00
|
|
|
55 => [\OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class)],
|
2018-04-17 18:03:26 +00:00
|
|
|
98 => [new Section('additional', 'Additional settings', 0, '1')],
|
2016-12-28 15:58:02 +00:00
|
|
|
], $this->manager->getAdminSections());
|
|
|
|
}
|
|
|
|
|
2017-05-19 15:34:57 +00:00
|
|
|
public function testGetPersonalSections() {
|
|
|
|
$this->l10n
|
|
|
|
->expects($this->any())
|
|
|
|
->method('t')
|
|
|
|
->will($this->returnArgument(0));
|
|
|
|
|
2018-01-29 12:14:56 +00:00
|
|
|
$this->manager->registerSection('personal', \OCA\WorkflowEngine\Settings\Section::class);
|
2017-05-19 15:34:57 +00:00
|
|
|
|
2017-06-23 20:19:18 +00:00
|
|
|
$this->url->expects($this->exactly(3))
|
2017-05-19 15:34:57 +00:00
|
|
|
->method('imagePath')
|
|
|
|
->willReturnMap([
|
|
|
|
['core', 'actions/info.svg', '1'],
|
2017-06-16 13:40:05 +00:00
|
|
|
['settings', 'password.svg', '2'],
|
2018-05-24 13:06:28 +00:00
|
|
|
['core', 'clients/phone.svg', '3'],
|
2017-05-19 15:34:57 +00:00
|
|
|
]);
|
|
|
|
|
2018-01-29 12:14:56 +00:00
|
|
|
$this->assertEquals([
|
2017-05-19 15:34:57 +00:00
|
|
|
0 => [new Section('personal-info', 'Personal info', 0, '1')],
|
2017-06-16 13:40:05 +00:00
|
|
|
5 => [new Section('security', 'Security', 0, '2')],
|
2018-05-24 13:06:28 +00:00
|
|
|
15 => [new Section('sync-clients', 'Mobile & desktop', 0, '3')],
|
2018-01-29 12:14:56 +00:00
|
|
|
55 => [\OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class)],
|
2017-05-19 15:34:57 +00:00
|
|
|
], $this->manager->getPersonalSections());
|
|
|
|
}
|
|
|
|
|
2016-12-28 15:58:02 +00:00
|
|
|
public function testGetAdminSectionsEmptySection() {
|
|
|
|
$this->l10n
|
|
|
|
->expects($this->any())
|
|
|
|
->method('t')
|
|
|
|
->will($this->returnArgument(0));
|
|
|
|
|
2018-06-12 14:16:29 +00:00
|
|
|
$this->url->expects($this->exactly(6))
|
2017-01-19 10:02:56 +00:00
|
|
|
->method('imagePath')
|
|
|
|
->willReturnMap([
|
2018-04-17 18:03:26 +00:00
|
|
|
['settings', 'admin.svg', '0'],
|
|
|
|
['core', 'actions/settings-dark.svg', '1'],
|
2017-01-19 10:02:56 +00:00
|
|
|
['core', 'actions/share.svg', '2'],
|
|
|
|
['core', 'actions/password.svg', '3'],
|
2018-04-17 18:03:26 +00:00
|
|
|
['settings', 'help.svg', '4'],
|
2017-01-19 10:02:56 +00:00
|
|
|
]);
|
2016-12-28 15:58:02 +00:00
|
|
|
|
2016-08-15 14:24:56 +00:00
|
|
|
$this->assertEquals([
|
2018-04-17 18:03:26 +00:00
|
|
|
0 => [new Section('overview', 'Overview', 0, '0')],
|
|
|
|
1 => [new Section('server', 'Basic settings', 0, '1')],
|
2017-01-19 10:02:56 +00:00
|
|
|
5 => [new Section('sharing', 'Sharing', 0, '2')],
|
2017-03-14 01:44:10 +00:00
|
|
|
10 => [new Section('security', 'Security', 0, '3')],
|
2017-01-19 10:02:56 +00:00
|
|
|
45 => [new Section('encryption', 'Encryption', 0, '3')],
|
2018-04-17 18:03:26 +00:00
|
|
|
98 => [new Section('additional', 'Additional settings', 0, '1')],
|
2016-08-15 14:24:56 +00:00
|
|
|
], $this->manager->getAdminSections());
|
|
|
|
}
|
|
|
|
|
2017-05-19 15:34:57 +00:00
|
|
|
public function testGetPersonalSectionsEmptySection() {
|
|
|
|
$this->l10n
|
|
|
|
->expects($this->any())
|
|
|
|
->method('t')
|
|
|
|
->will($this->returnArgument(0));
|
|
|
|
|
2017-06-23 20:19:18 +00:00
|
|
|
$this->url->expects($this->exactly(3))
|
2017-05-19 15:34:57 +00:00
|
|
|
->method('imagePath')
|
|
|
|
->willReturnMap([
|
|
|
|
['core', 'actions/info.svg', '1'],
|
2017-06-16 13:40:05 +00:00
|
|
|
['settings', 'password.svg', '2'],
|
2018-05-24 19:39:34 +00:00
|
|
|
['core', 'clients/phone.svg', '3'],
|
2017-05-19 15:34:57 +00:00
|
|
|
]);
|
|
|
|
|
2017-06-23 20:19:18 +00:00
|
|
|
$this->assertArraySubset([
|
2017-05-19 15:34:57 +00:00
|
|
|
0 => [new Section('personal-info', 'Personal info', 0, '1')],
|
2017-06-16 13:40:05 +00:00
|
|
|
5 => [new Section('security', 'Security', 0, '2')],
|
2018-05-24 19:39:34 +00:00
|
|
|
15 => [new Section('sync-clients', 'Mobile & desktop', 0, '3')],
|
2017-05-19 15:34:57 +00:00
|
|
|
], $this->manager->getPersonalSections());
|
|
|
|
}
|
|
|
|
|
2016-08-15 14:24:56 +00:00
|
|
|
public function testGetAdminSettings() {
|
|
|
|
$this->assertEquals([
|
2017-12-01 10:35:01 +00:00
|
|
|
0 => [new Sharing($this->config, $this->l10n)],
|
2016-08-15 14:24:56 +00:00
|
|
|
], $this->manager->getAdminSettings('sharing'));
|
|
|
|
}
|
2017-05-19 15:34:57 +00:00
|
|
|
|
|
|
|
public function testGetPersonalSettings() {
|
|
|
|
$this->assertEquals([
|
2017-06-16 13:40:05 +00:00
|
|
|
10 => [new Security()],
|
|
|
|
], $this->manager->getPersonalSettings('security'));
|
2017-05-19 15:34:57 +00:00
|
|
|
}
|
2016-08-15 14:24:56 +00:00
|
|
|
}
|