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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Tests\Settings;
|
|
|
|
|
|
|
|
use OC\Settings\Admin\Sharing;
|
|
|
|
use OC\Settings\Manager;
|
2016-12-28 18:58:02 +03:00
|
|
|
use OC\Settings\Mapper;
|
2016-08-15 17:24:56 +03:00
|
|
|
use OC\Settings\Section;
|
|
|
|
use OCP\Encryption\IManager;
|
|
|
|
use OCP\IConfig;
|
|
|
|
use OCP\IDBConnection;
|
|
|
|
use OCP\IL10N;
|
|
|
|
use OCP\ILogger;
|
|
|
|
use OCP\IUserManager;
|
|
|
|
use OCP\Lock\ILockingProvider;
|
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
class ManagerTest extends TestCase {
|
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 $dbConnection;
|
2016-12-28 18:58:02 +03:00
|
|
|
/** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
|
2016-08-15 17:24:56 +03:00
|
|
|
private $l10n;
|
2016-12-28 18:58:02 +03:00
|
|
|
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
|
2016-08-15 17:24:56 +03:00
|
|
|
private $config;
|
2016-12-28 18:58:02 +03:00
|
|
|
/** @var IManager|\PHPUnit_Framework_MockObject_MockObject */
|
2016-08-15 17:24:56 +03:00
|
|
|
private $encryptionManager;
|
2016-12-28 18:58:02 +03:00
|
|
|
/** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
|
2016-08-15 17:24:56 +03:00
|
|
|
private $userManager;
|
2016-12-28 18:58:02 +03:00
|
|
|
/** @var ILockingProvider|\PHPUnit_Framework_MockObject_MockObject */
|
2016-08-15 17:24:56 +03:00
|
|
|
private $lockingProvider;
|
2016-12-28 18:58:02 +03:00
|
|
|
/** @var Mapper|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $mapper;
|
2016-08-15 17:24:56 +03:00
|
|
|
|
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
|
2016-08-15 17:43:22 +03:00
|
|
|
$this->logger = $this->getMockBuilder('\OCP\ILogger')->getMock();
|
|
|
|
$this->dbConnection = $this->getMockBuilder('\OCP\IDBConnection')->getMock();
|
|
|
|
$this->l10n = $this->getMockBuilder('\OCP\IL10N')->getMock();
|
|
|
|
$this->config = $this->getMockBuilder('\OCP\IConfig')->getMock();
|
|
|
|
$this->encryptionManager = $this->getMockBuilder('\OCP\Encryption\IManager')->getMock();
|
|
|
|
$this->userManager = $this->getMockBuilder('\OCP\IUserManager')->getMock();
|
|
|
|
$this->lockingProvider = $this->getMockBuilder('\OCP\Lock\ILockingProvider')->getMock();
|
2016-12-28 18:58:02 +03:00
|
|
|
$this->mapper = $this->getMockBuilder(Mapper::class)->disableOriginalConstructor()->getMock();
|
2016-08-15 17:24:56 +03:00
|
|
|
|
|
|
|
$this->manager = new Manager(
|
|
|
|
$this->logger,
|
|
|
|
$this->dbConnection,
|
|
|
|
$this->l10n,
|
|
|
|
$this->config,
|
|
|
|
$this->encryptionManager,
|
|
|
|
$this->userManager,
|
2016-12-28 18:58:02 +03:00
|
|
|
$this->lockingProvider,
|
|
|
|
$this->mapper
|
2016-08-15 17:24:56 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-28 18:58:02 +03:00
|
|
|
public function testSetupSettingsUpdate() {
|
|
|
|
$this->mapper->expects($this->any())
|
|
|
|
->method('has')
|
|
|
|
->with('admin_settings', 'OCA\Files\Settings\Admin')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
|
|
|
$this->mapper->expects($this->once())
|
|
|
|
->method('update')
|
|
|
|
->with('admin_settings',
|
|
|
|
'class',
|
|
|
|
'OCA\Files\Settings\Admin', [
|
|
|
|
'section' => 'additional',
|
|
|
|
'priority' => 5
|
|
|
|
]);
|
|
|
|
$this->mapper->expects($this->never())
|
|
|
|
->method('add');
|
|
|
|
|
|
|
|
$this->manager->setupSettings([
|
|
|
|
'admin' => 'OCA\Files\Settings\Admin',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSetupSettingsAdd() {
|
|
|
|
$this->mapper->expects($this->any())
|
|
|
|
->method('has')
|
|
|
|
->with('admin_settings', 'OCA\Files\Settings\Admin')
|
|
|
|
->will($this->returnValue(false));
|
|
|
|
|
|
|
|
$this->mapper->expects($this->once())
|
|
|
|
->method('add')
|
|
|
|
->with('admin_settings', [
|
|
|
|
'class' => 'OCA\Files\Settings\Admin',
|
|
|
|
'section' => 'additional',
|
|
|
|
'priority' => 5
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->mapper->expects($this->never())
|
|
|
|
->method('update');
|
2016-08-15 17:24:56 +03:00
|
|
|
|
|
|
|
$this->manager->setupSettings([
|
|
|
|
'admin' => 'OCA\Files\Settings\Admin',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetAdminSections() {
|
|
|
|
$this->l10n
|
|
|
|
->expects($this->any())
|
|
|
|
->method('t')
|
|
|
|
->will($this->returnArgument(0));
|
|
|
|
|
2016-12-28 18:58:02 +03:00
|
|
|
$this->mapper->expects($this->once())
|
|
|
|
->method('getAdminSectionsFromDB')
|
|
|
|
->will($this->returnValue([
|
|
|
|
['class' => '\OCA\LogReader\Settings\Section', 'priority' => 90]
|
|
|
|
]));
|
|
|
|
|
|
|
|
$this->mapper->expects($this->once())
|
|
|
|
->method('getAdminSettingsCountFromDB')
|
|
|
|
->will($this->returnValue([
|
|
|
|
'logging' => 1
|
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals([
|
|
|
|
0 => [new Section('server', 'Server settings', 0)],
|
|
|
|
5 => [new Section('sharing', 'Sharing', 0)],
|
|
|
|
45 => [new Section('encryption', 'Encryption', 0)],
|
|
|
|
90 => [new \OCA\LogReader\Settings\Section(\OC::$server->getL10N('logreader'))],
|
|
|
|
98 => [new Section('additional', 'Additional settings', 0)],
|
|
|
|
99 => [new Section('tips-tricks', 'Tips & tricks', 0)],
|
|
|
|
], $this->manager->getAdminSections());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetAdminSectionsEmptySection() {
|
|
|
|
$this->l10n
|
|
|
|
->expects($this->any())
|
|
|
|
->method('t')
|
|
|
|
->will($this->returnArgument(0));
|
|
|
|
|
|
|
|
$this->mapper->expects($this->once())
|
|
|
|
->method('getAdminSectionsFromDB')
|
|
|
|
->will($this->returnValue([
|
|
|
|
['class' => '\OCA\LogReader\Settings\Section', 'priority' => 90]
|
|
|
|
]));
|
|
|
|
|
|
|
|
$this->mapper->expects($this->once())
|
|
|
|
->method('getAdminSettingsCountFromDB')
|
|
|
|
->will($this->returnValue([]));
|
|
|
|
|
2016-08-15 17:24:56 +03:00
|
|
|
$this->assertEquals([
|
|
|
|
0 => [new Section('server', 'Server settings', 0)],
|
|
|
|
5 => [new Section('sharing', 'Sharing', 0)],
|
|
|
|
45 => [new Section('encryption', 'Encryption', 0)],
|
|
|
|
98 => [new Section('additional', 'Additional settings', 0)],
|
|
|
|
99 => [new Section('tips-tricks', 'Tips & tricks', 0)],
|
|
|
|
], $this->manager->getAdminSections());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetAdminSettings() {
|
2016-12-28 18:58:02 +03:00
|
|
|
$this->mapper->expects($this->any())
|
|
|
|
->method('getAdminSettingsFromDB')
|
|
|
|
->will($this->returnValue([]));
|
2016-08-15 17:24:56 +03:00
|
|
|
|
|
|
|
$this->assertEquals([
|
|
|
|
0 => [new Sharing($this->config)],
|
|
|
|
], $this->manager->getAdminSettings('sharing'));
|
|
|
|
}
|
|
|
|
}
|