summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2017-05-19 17:34:57 +0200
committerArthur Schiwon <blizzz@arthur-schiwon.de>2017-06-23 12:37:41 +0200
commit28fd18de43ee4371c614782a2a4b9cf0eb497faa (patch)
tree4c93b484da2c6cfbc87142438e78725936b71fee /tests
parentf87318296578178ceed8ba18c0a3f99e4aa11334 (diff)
downloadnextcloud-server-28fd18de43ee4371c614782a2a4b9cf0eb497faa.tar.gz
nextcloud-server-28fd18de43ee4371c614782a2a4b9cf0eb497faa.zip
add missing pieces to Settings Manager and fix and extend its unit tests
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Settings/ManagerTest.php130
1 files changed, 120 insertions, 10 deletions
diff --git a/tests/lib/Settings/ManagerTest.php b/tests/lib/Settings/ManagerTest.php
index 07f7e71feca..b9f03ea4d0b 100644
--- a/tests/lib/Settings/ManagerTest.php
+++ b/tests/lib/Settings/ManagerTest.php
@@ -23,18 +23,22 @@
namespace Tests\Settings;
+use OC\Accounts\AccountManager;
use OC\Settings\Admin\Sharing;
use OC\Settings\Manager;
use OC\Settings\Mapper;
+use OC\Settings\Personal\AppPasswords;
use OC\Settings\Section;
use OCP\Encryption\IManager;
use OCP\IConfig;
use OCP\IDBConnection;
+use OCP\IGroupManager;
use OCP\IL10N;
use OCP\ILogger;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUserManager;
+use OCP\L10N\IFactory;
use OCP\Lock\ILockingProvider;
use Test\TestCase;
@@ -61,6 +65,14 @@ class ManagerTest extends TestCase {
private $mapper;
/** @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 \OC_Defaults|\PHPUnit_Framework_MockObject_MockObject */
+ private $defaults;
public function setUp() {
parent::setUp();
@@ -75,6 +87,10 @@ class ManagerTest extends TestCase {
$this->request = $this->createMock(IRequest::class);
$this->mapper = $this->createMock(Mapper::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->defaults = $this->createMock(\OC_Defaults::class);
$this->manager = new Manager(
$this->logger,
@@ -86,21 +102,39 @@ class ManagerTest extends TestCase {
$this->lockingProvider,
$this->request,
$this->mapper,
- $this->url
+ $this->url,
+ $this->accountManager,
+ $this->groupManager,
+ $this->l10nFactory,
+ $this->defaults
);
}
- public function testSetupSettingsUpdate() {
+ public function settingsTypeProvider() {
+ return [
+ ['admin', 'admin_settings'],
+ ['personal', 'personal_settings'],
+ ];
+ }
+
+ /**
+ * @dataProvider settingsTypeProvider
+ * @param string $type
+ * @param string $table
+ */
+ public function testSetupSettingsUpdate($type, $table) {
+ $className = 'OCA\Files\Settings\Admin';
+
$this->mapper->expects($this->any())
->method('has')
- ->with('admin_settings', 'OCA\Files\Settings\Admin')
+ ->with($table, $className)
->will($this->returnValue(true));
$this->mapper->expects($this->once())
->method('update')
- ->with('admin_settings',
+ ->with($table,
'class',
- 'OCA\Files\Settings\Admin', [
+ $className, [
'section' => 'additional',
'priority' => 5
]);
@@ -108,19 +142,24 @@ class ManagerTest extends TestCase {
->method('add');
$this->manager->setupSettings([
- 'admin' => 'OCA\Files\Settings\Admin',
+ $type => $className,
]);
}
- public function testSetupSettingsAdd() {
+ /**
+ * @dataProvider settingsTypeProvider
+ * @param string $type
+ * @param string $table
+ */
+ public function testSetupSettingsAdd($type, $table) {
$this->mapper->expects($this->any())
->method('has')
- ->with('admin_settings', 'OCA\Files\Settings\Admin')
+ ->with($table, 'OCA\Files\Settings\Admin')
->will($this->returnValue(false));
$this->mapper->expects($this->once())
->method('add')
- ->with('admin_settings', [
+ ->with($table, [
'class' => 'OCA\Files\Settings\Admin',
'section' => 'additional',
'priority' => 5
@@ -130,7 +169,7 @@ class ManagerTest extends TestCase {
->method('update');
$this->manager->setupSettings([
- 'admin' => 'OCA\Files\Settings\Admin',
+ $type => 'OCA\Files\Settings\Admin',
]);
}
@@ -167,6 +206,38 @@ class ManagerTest extends TestCase {
], $this->manager->getAdminSections());
}
+ public function testGetPersonalSections() {
+ $this->l10n
+ ->expects($this->any())
+ ->method('t')
+ ->will($this->returnArgument(0));
+
+ $this->mapper->expects($this->once())
+ ->method('getPersonalSectionsFromDB')
+ ->will($this->returnValue([
+ ['class' => \OCA\WorkflowEngine\Settings\Section::class, 'priority' => 90]
+ ]));
+
+ $this->url->expects($this->exactly(5))
+ ->method('imagePath')
+ ->willReturnMap([
+ ['core', 'actions/info.svg', '1'],
+ ['settings', 'admin.svg', '2'],
+ ['settings', 'password.svg', '3'],
+ ['settings', 'change.svg', '4'],
+ ['core', 'actions/settings-dark.svg', '5'],
+ ]);
+
+ $this->assertEquals([
+ 0 => [new Section('personal-info', 'Personal info', 0, '1')],
+ 5 => [new Section('sessions', 'Sessions', 0, '2')],
+ 10 => [new Section('app-passwords', 'App passwords', 0, '3')],
+ 15 => [new Section('sync-clients', 'Sync clients', 0, '4')],
+ 90 => [\OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class)],
+ 98 => [new Section('additional', 'Additional settings', 0, '5')],
+ ], $this->manager->getPersonalSections());
+ }
+
public function testGetAdminSectionsEmptySection() {
$this->l10n
->expects($this->any())
@@ -198,6 +269,35 @@ class ManagerTest extends TestCase {
], $this->manager->getAdminSections());
}
+ public function testGetPersonalSectionsEmptySection() {
+ $this->l10n
+ ->expects($this->any())
+ ->method('t')
+ ->will($this->returnArgument(0));
+
+ $this->mapper->expects($this->once())
+ ->method('getPersonalSectionsFromDB')
+ ->will($this->returnValue([]));
+
+ $this->url->expects($this->exactly(5))
+ ->method('imagePath')
+ ->willReturnMap([
+ ['core', 'actions/info.svg', '1'],
+ ['settings', 'admin.svg', '2'],
+ ['settings', 'password.svg', '3'],
+ ['settings', 'change.svg', '4'],
+ ['core', 'actions/settings-dark.svg', '5'],
+ ]);
+
+ $this->assertEquals([
+ 0 => [new Section('personal-info', 'Personal info', 0, '1')],
+ 5 => [new Section('sessions', 'Sessions', 0, '2')],
+ 10 => [new Section('app-passwords', 'App passwords', 0, '3')],
+ 15 => [new Section('sync-clients', 'Sync clients', 0, '4')],
+ 98 => [new Section('additional', 'Additional settings', 0, '5')],
+ ], $this->manager->getPersonalSections());
+ }
+
public function testGetAdminSettings() {
$this->mapper->expects($this->any())
->method('getAdminSettingsFromDB')
@@ -207,4 +307,14 @@ class ManagerTest extends TestCase {
0 => [new Sharing($this->config)],
], $this->manager->getAdminSettings('sharing'));
}
+
+ public function testGetPersonalSettings() {
+ $this->mapper->expects($this->any())
+ ->method('getPersonalSettingsFromDB')
+ ->will($this->returnValue([]));
+
+ $this->assertEquals([
+ 5 => [new AppPasswords()],
+ ], $this->manager->getPersonalSettings('app-passwords'));
+ }
}