Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2018-09-26 17:46:35 +0300
committerChristoph Wurst <christoph@winzerhof-wurst.at>2018-09-27 10:44:21 +0300
commit0259792614e3ed2dd743c2c292d8d90e2b0a05aa (patch)
tree027a4bd7c17368b9ac6110fc8f03bef8131b85dc /tests
parentcd05670517da0cecfa8c6277c015fa33fae3394d (diff)
Reduce settings manager complexity by loading sections via DI
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Settings/ManagerTest.php81
1 files changed, 32 insertions, 49 deletions
diff --git a/tests/lib/Settings/ManagerTest.php b/tests/lib/Settings/ManagerTest.php
index 6f9af39d591..af472875faf 100644
--- a/tests/lib/Settings/ManagerTest.php
+++ b/tests/lib/Settings/ManagerTest.php
@@ -23,27 +23,20 @@
namespace Tests\Settings;
-use OC\Accounts\AccountManager;
use OC\Settings\Admin\Sharing;
use OC\Settings\Manager;
use OC\Settings\Mapper;
use OC\Settings\Personal\Security;
use OC\Settings\Section;
-use OCP\App\IAppManager;
-use OCP\Encryption\IManager;
-use OCP\IConfig;
use OCP\IDBConnection;
-use OCP\IGroupManager;
use OCP\IL10N;
use OCP\ILogger;
-use OCP\IRequest;
+use OCP\IServerContainer;
use OCP\IURLGenerator;
-use OCP\IUserManager;
-use OCP\L10N\IFactory;
-use OCP\Lock\ILockingProvider;
use Test\TestCase;
class ManagerTest extends TestCase {
+
/** @var Manager|\PHPUnit_Framework_MockObject_MockObject */
private $manager;
/** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
@@ -52,26 +45,10 @@ class ManagerTest extends TestCase {
private $dbConnection;
/** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
private $l10n;
- /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
- private $config;
- /** @var IManager|\PHPUnit_Framework_MockObject_MockObject */
- private $encryptionManager;
- /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
- private $userManager;
- /** @var ILockingProvider|\PHPUnit_Framework_MockObject_MockObject */
- private $lockingProvider;
- /** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */
- private $request;
/** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
private $url;
- /** @var AccountManager|\PHPUnit_Framework_MockObject_MockObject */
- private $accountManager;
- /** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject */
- private $groupManager;
- /** @var IFactory|\PHPUnit_Framework_MockObject_MockObject */
- private $l10nFactory;
- /** @var IAppManager */
- private $appManager;
+ /** @var IServerContainer|\PHPUnit_Framework_MockObject_MockObject */
+ private $container;
public function setUp() {
parent::setUp();
@@ -79,31 +56,15 @@ class ManagerTest extends TestCase {
$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);
- $this->request = $this->createMock(IRequest::class);
$this->url = $this->createMock(IURLGenerator::class);
- $this->accountManager = $this->createMock(AccountManager::class);
- $this->groupManager = $this->createMock(IGroupManager::class);
- $this->l10nFactory = $this->createMock(IFactory::class);
- $this->appManager = $this->createMock(IAppManager::class);
+ $this->container = $this->createMock(IServerContainer::class);
$this->manager = new Manager(
$this->logger,
$this->dbConnection,
$this->l10n,
- $this->config,
- $this->encryptionManager,
- $this->userManager,
- $this->lockingProvider,
- $this->request,
$this->url,
- $this->accountManager,
- $this->groupManager,
- $this->l10nFactory,
- $this->appManager
+ $this->container
);
}
@@ -210,15 +171,37 @@ class ManagerTest extends TestCase {
}
public function testGetAdminSettings() {
+ $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');
+
$this->assertEquals([
- 0 => [new Sharing($this->config, $this->l10n)],
- ], $this->manager->getAdminSettings('sharing'));
+ 13 => [$section]
+ ], $settings);
}
public function testGetPersonalSettings() {
+ $section = $this->createMock(Security::class);
+ $section->expects($this->once())
+ ->method('getPriority')
+ ->willReturn(16);
+ $this->container->expects($this->once())
+ ->method('query')
+ ->with(Security::class)
+ ->willReturn($section);
+
+ $settings = $this->manager->getPersonalSettings('security');
+
$this->assertEquals([
- 10 => [new Security($this->userManager)],
- ], $this->manager->getPersonalSettings('security'));
+ 16 => [$section]
+ ], $settings);
}
public function testSameSectionAsPersonalAndAdmin() {