summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLukas Reschke <lukas@statuscode.ch>2016-08-15 16:24:56 +0200
committerLukas Reschke <lukas@statuscode.ch>2016-08-15 16:25:34 +0200
commit8a7a0f328746230dd896ccc53b3ada271a91b930 (patch)
treeaaaaedf7167b74c48a91c90671f705edb71bc541 /tests
parent75a73a5a7301f203a962a17f6b2b8b90078c1884 (diff)
downloadnextcloud-server-8a7a0f328746230dd896ccc53b3ada271a91b930.tar.gz
nextcloud-server-8a7a0f328746230dd896ccc53b3ada271a91b930.zip
Add unit tests
Diffstat (limited to 'tests')
-rw-r--r--tests/Core/Templates/TemplatesTest.php2
-rw-r--r--tests/Settings/Controller/AdminSettingsControllerTest.php72
-rw-r--r--tests/Settings/Controller/CheckSetupControllerTest.php10
-rw-r--r--tests/lib/Settings/Admin/AdditionalTest.php127
-rw-r--r--tests/lib/Settings/Admin/EncryptionTest.php128
-rw-r--r--tests/lib/Settings/Admin/LoggingTest.php91
-rw-r--r--tests/lib/Settings/Admin/ServerTest.php154
-rw-r--r--tests/lib/Settings/Admin/SharingTest.php151
-rw-r--r--tests/lib/Settings/Admin/TipsTricksTest.php91
-rw-r--r--tests/lib/Settings/ManagerTest.php220
-rw-r--r--tests/lib/Settings/SectionTest.php39
11 files changed, 1082 insertions, 3 deletions
diff --git a/tests/Core/Templates/TemplatesTest.php b/tests/Core/Templates/TemplatesTest.php
index 03565411a13..cd1502fd22c 100644
--- a/tests/Core/Templates/TemplatesTest.php
+++ b/tests/Core/Templates/TemplatesTest.php
@@ -13,7 +13,7 @@ class TemplatesTest extends \Test\TestCase {
public function test404() {
$template = \OC::$SERVERROOT . '/core/templates/404.php';
$href = \OC::$server->getURLGenerator()->linkTo('', 'index.php');
- $expectedHtml = "<ul><li class='error'>\n\t\t\tFile not found<br><p class='hint'>The specified document has not been found on the server.</p>\n<p class='hint'><a href='$href'>You can click here to return to ownCloud.</a></p>\n\t\t</li></ul>";
+ $expectedHtml = "<ul><li class='error'>\n\t\t\tFile not found<br><p class='hint'>The specified document has not been found on the server.</p>\n<p class='hint'><a href='$href'>You can click here to return to Nextcloud.</a></p>\n\t\t</li></ul>";
$this->assertTemplate($expectedHtml, $template);
}
diff --git a/tests/Settings/Controller/AdminSettingsControllerTest.php b/tests/Settings/Controller/AdminSettingsControllerTest.php
new file mode 100644
index 00000000000..86950c9aa9d
--- /dev/null
+++ b/tests/Settings/Controller/AdminSettingsControllerTest.php
@@ -0,0 +1,72 @@
+<?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\Controller;
+
+
+use OC\Settings\Admin\TipsTricks;
+use OC\Settings\Controller\AdminSettingsController;
+use OCP\AppFramework\Http\TemplateResponse;
+use OCP\INavigationManager;
+use OCP\IRequest;
+use OCP\Settings\IManager;
+use Test\TestCase;
+
+class AdminSettingsControllerTest extends TestCase {
+ /** @var AdminSettingsController */
+ private $adminSettingsController;
+ /** @var IRequest */
+ private $request;
+ /** @var INavigationManager */
+ private $navigationManager;
+ /** @var IManager */
+ private $settingsManager;
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->request = $this->createMock('\OCP\IRequest');
+ $this->navigationManager = $this->createMock('\OCP\INavigationManager');
+ $this->settingsManager = $this->createMock('\OCP\Settings\IManager');
+
+ $this->adminSettingsController = new AdminSettingsController(
+ 'settings',
+ $this->request,
+ $this->navigationManager,
+ $this->settingsManager
+ );
+ }
+
+ public function testIndex() {
+ $this->settingsManager
+ ->expects($this->once())
+ ->method('getAdminSections')
+ ->willReturn([]);
+ $this->settingsManager
+ ->expects($this->once())
+ ->method('getAdminSettings')
+ ->with('test')
+ ->willReturn([5 => new TipsTricks($this->createMock('\OCP\IConfig'))]);
+ $expected = new TemplateResponse('settings', 'admin/frame', ['forms' => [], 'content' => '']);
+ $this->assertEquals($expected, $this->adminSettingsController->index('test'));
+ }
+}
diff --git a/tests/Settings/Controller/CheckSetupControllerTest.php b/tests/Settings/Controller/CheckSetupControllerTest.php
index f48e9c04f3d..63c8141cedd 100644
--- a/tests/Settings/Controller/CheckSetupControllerTest.php
+++ b/tests/Settings/Controller/CheckSetupControllerTest.php
@@ -29,6 +29,7 @@ use OCP\AppFramework\Http\RedirectResponse;
use OCP\Http\Client\IClientService;
use OCP\IConfig;
use OCP\IL10N;
+use OCP\ILogger;
use OCP\IRequest;
use OCP\IURLGenerator;
use OC_Util;
@@ -68,6 +69,8 @@ class CheckSetupControllerTest extends TestCase {
private $util;
/** @var IL10N */
private $l10n;
+ /** @var ILogger */
+ private $logger;
/** @var Checker */
private $checker;
@@ -95,6 +98,7 @@ class CheckSetupControllerTest extends TestCase {
}));
$this->checker = $this->getMockBuilder('\OC\IntegrityCheck\Checker')
->disableOriginalConstructor()->getMock();
+ $this->logger = $this->createMock('\OCP\ILogger');
$this->checkSetupController = $this->getMockBuilder('\OC\Settings\Controller\CheckSetupController')
->setConstructorArgs([
'settings',
@@ -105,6 +109,7 @@ class CheckSetupControllerTest extends TestCase {
$this->util,
$this->l10n,
$this->checker,
+ $this->logger
])
->setMethods(['getCurlVersion'])->getMock();
}
@@ -373,7 +378,8 @@ class CheckSetupControllerTest extends TestCase {
$this->urlGenerator,
$this->util,
$this->l10n,
- $this->checker
+ $this->checker,
+ $this->logger
])
->setMethods(null)->getMock();
@@ -612,7 +618,7 @@ class CheckSetupControllerTest extends TestCase {
$this->urlGenerator
->expects($this->once())
->method('linkToRoute')
- ->with('settings_admin')
+ ->with('settings.AdminSettings.index')
->will($this->returnValue('/admin'));
$expected = new RedirectResponse('/admin');
diff --git a/tests/lib/Settings/Admin/AdditionalTest.php b/tests/lib/Settings/Admin/AdditionalTest.php
new file mode 100644
index 00000000000..178d7550614
--- /dev/null
+++ b/tests/lib/Settings/Admin/AdditionalTest.php
@@ -0,0 +1,127 @@
+<?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 Test\Settings\Admin;
+
+use OC\Settings\Admin\Additional;
+use OCP\AppFramework\Http\TemplateResponse;
+use OCP\IConfig;
+use Test\TestCase;
+
+class AdditionalTest extends TestCase {
+ /** @var Additional */
+ private $admin;
+ /** @var IConfig */
+ private $config;
+
+ public function setUp() {
+ parent::setUp();
+ $this->config = $this->createMock('\OCP\IConfig');
+
+ $this->admin = new Additional(
+ $this->config
+ );
+ }
+
+ public function testGetForm() {
+ $this->config
+ ->expects($this->at(0))
+ ->method('getSystemValue')
+ ->with('mail_domain', '')
+ ->willReturn('mx.nextcloud.com');
+ $this->config
+ ->expects($this->at(1))
+ ->method('getSystemValue')
+ ->with('mail_from_address', '')
+ ->willReturn('no-reply@nextcloud.com');
+ $this->config
+ ->expects($this->at(2))
+ ->method('getSystemValue')
+ ->with('mail_smtpmode', '')
+ ->willReturn('php');
+ $this->config
+ ->expects($this->at(3))
+ ->method('getSystemValue')
+ ->with('mail_smtpsecure', '')
+ ->willReturn(true);
+ $this->config
+ ->expects($this->at(4))
+ ->method('getSystemValue')
+ ->with('mail_smtphost', '')
+ ->willReturn('smtp.nextcloud.com');
+ $this->config
+ ->expects($this->at(5))
+ ->method('getSystemValue')
+ ->with('mail_smtpport', '')
+ ->willReturn(25);
+ $this->config
+ ->expects($this->at(6))
+ ->method('getSystemValue')
+ ->with('mail_smtpauthtype', '')
+ ->willReturn('login');
+ $this->config
+ ->expects($this->at(7))
+ ->method('getSystemValue')
+ ->with('mail_smtpauth', false)
+ ->willReturn(true);
+ $this->config
+ ->expects($this->at(8))
+ ->method('getSystemValue')
+ ->with('mail_smtpname', '')
+ ->willReturn('smtp.sender.com');
+ $this->config
+ ->expects($this->at(9))
+ ->method('getSystemValue')
+ ->with('mail_smtppassword', '')
+ ->willReturn('mypassword');
+
+ $expected = new TemplateResponse(
+ 'settings',
+ 'admin/additional-mail',
+ [
+ 'sendmail_is_available' => (bool) \OC_Helper::findBinaryPath('sendmail'),
+ 'mail_domain' => 'mx.nextcloud.com',
+ 'mail_from_address' => 'no-reply@nextcloud.com',
+ 'mail_smtpmode' => 'php',
+ 'mail_smtpsecure' => true,
+ 'mail_smtphost' => 'smtp.nextcloud.com',
+ 'mail_smtpport' => 25,
+ 'mail_smtpauthtype' => 'login',
+ 'mail_smtpauth' => true,
+ 'mail_smtpname' => 'smtp.sender.com',
+ 'mail_smtppassword' => 'mypassword',
+ ],
+ ''
+ );
+
+ $this->assertEquals($expected, $this->admin->getForm());
+ }
+
+ public function testGetSection() {
+ $this->assertSame('additional', $this->admin->getSection());
+ }
+
+ public function testGetPriority() {
+ $this->assertSame(0, $this->admin->getPriority());
+ }
+}
diff --git a/tests/lib/Settings/Admin/EncryptionTest.php b/tests/lib/Settings/Admin/EncryptionTest.php
new file mode 100644
index 00000000000..a68b40ae11b
--- /dev/null
+++ b/tests/lib/Settings/Admin/EncryptionTest.php
@@ -0,0 +1,128 @@
+<?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 Test\Settings\Admin;
+
+use OC\Encryption\Manager;
+use OC\Settings\Admin\Encryption;
+use OCP\AppFramework\Http\TemplateResponse;
+use OCP\IUserManager;
+use Test\TestCase;
+
+class EncryptionTest extends TestCase {
+ /** @var Encryption */
+ private $admin;
+ /** @var Manager */
+ private $manager;
+ /** @var IUserManager */
+ private $userManager;
+
+ public function setUp() {
+ parent::setUp();
+ $this->manager = $this->createMock('\OC\Encryption\Manager');
+ $this->userManager = $this->createMock('\OCP\IUserManager');
+
+ $this->admin = new Encryption(
+ $this->manager,
+ $this->userManager
+ );
+ }
+
+ /**
+ * @return array
+ */
+ public function encryptionSettingsProvider() {
+ return [
+ [true],
+ [false],
+ ];
+ }
+
+ /**
+ * @dataProvider encryptionSettingsProvider
+ * @param bool $enabled
+ */
+ public function testGetFormWithOnlyOneBackend($enabled) {
+ $this->manager
+ ->expects($this->once())
+ ->method('isEnabled')
+ ->willReturn($enabled);
+ $this->manager
+ ->expects($this->once())
+ ->method('isReady')
+ ->willReturn($enabled);
+ $this->userManager
+ ->expects($this->once())
+ ->method('getBackends')
+ ->willReturn(['entry']);
+ $expected = new TemplateResponse(
+ 'settings',
+ 'admin/encryption',
+ [
+ 'encryptionEnabled' => $enabled,
+ 'encryptionReady' => $enabled,
+ 'externalBackendsEnabled' => false,
+ ],
+ ''
+ );
+ $this->assertEquals($expected, $this->admin->getForm());
+ }
+
+ /**
+ * @dataProvider encryptionSettingsProvider
+ * @param bool $enabled
+ */
+ public function testGetFormWithMultipleBackends($enabled) {
+ $this->manager
+ ->expects($this->once())
+ ->method('isEnabled')
+ ->willReturn($enabled);
+ $this->manager
+ ->expects($this->once())
+ ->method('isReady')
+ ->willReturn($enabled);
+ $this->userManager
+ ->expects($this->once())
+ ->method('getBackends')
+ ->willReturn(['entry', 'entry']);
+ $expected = new TemplateResponse(
+ 'settings',
+ 'admin/encryption',
+ [
+ 'encryptionEnabled' => $enabled,
+ 'encryptionReady' => $enabled,
+ 'externalBackendsEnabled' => true,
+ ],
+ ''
+ );
+ $this->assertEquals($expected, $this->admin->getForm());
+ }
+
+ public function testGetSection() {
+ $this->assertSame('encryption', $this->admin->getSection());
+ }
+
+ public function testGetPriority() {
+ $this->assertSame(0, $this->admin->getPriority());
+ }
+}
diff --git a/tests/lib/Settings/Admin/LoggingTest.php b/tests/lib/Settings/Admin/LoggingTest.php
new file mode 100644
index 00000000000..10a94f1c59c
--- /dev/null
+++ b/tests/lib/Settings/Admin/LoggingTest.php
@@ -0,0 +1,91 @@
+<?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 Test\Settings\Admin;
+
+use OC\Settings\Admin\Logging;
+use OCP\AppFramework\Http\TemplateResponse;
+use OCP\IConfig;
+use Test\TestCase;
+use OC\Log\File as LogFile;
+
+class LoggingTest extends TestCase {
+ /** @var Logging */
+ private $admin;
+ /** @var IConfig */
+ private $config;
+
+ public function setUp() {
+ parent::setUp();
+ $this->config = $this->createMock('\OCP\IConfig');
+
+ $this->admin = new Logging(
+ $this->config
+ );
+ }
+
+ public function testGetForm() {
+ $this->config
+ ->expects($this->at(0))
+ ->method('getSystemValue')
+ ->with('log_type', 'file')
+ ->willReturn('owncloud');
+ $this->config
+ ->expects($this->at(1))
+ ->method('getSystemValue')
+ ->with('loglevel', 2)
+ ->willReturn(3);
+
+ $numEntriesToLoad = 5;
+ $entries = LogFile::getEntries($numEntriesToLoad + 1);
+ $entriesRemaining = count($entries) > $numEntriesToLoad;
+ $entries = array_slice($entries, 0, $numEntriesToLoad);
+
+ $logFileExists = file_exists(LogFile::getLogFilePath()) ;
+ $logFileSize = $logFileExists ? filesize(LogFile::getLogFilePath()) : 0;
+
+ $expected = new TemplateResponse(
+ 'settings',
+ 'admin/logging',
+ [
+ 'loglevel' => 3,
+ 'entries' => $entries,
+ 'entriesremain' => $entriesRemaining,
+ 'doesLogFileExist' => $logFileExists,
+ 'logFileSize' => $logFileSize,
+ 'showLog' => true,
+ ],
+ ''
+ );
+
+ $this->assertEquals($expected, $this->admin->getForm());
+ }
+
+ public function testGetSection() {
+ $this->assertSame('logging', $this->admin->getSection());
+ }
+
+ public function testGetPriority() {
+ $this->assertSame(0, $this->admin->getPriority());
+ }
+}
diff --git a/tests/lib/Settings/Admin/ServerTest.php b/tests/lib/Settings/Admin/ServerTest.php
new file mode 100644
index 00000000000..5a4fa22920f
--- /dev/null
+++ b/tests/lib/Settings/Admin/ServerTest.php
@@ -0,0 +1,154 @@
+<?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 Test\Settings\Admin;
+
+use Doctrine\DBAL\Platforms\SqlitePlatform;
+use OC\Settings\Admin\Server;
+use OCP\AppFramework\Http\TemplateResponse;
+use OCP\IConfig;
+use OCP\IDBConnection;
+use OCP\IL10N;
+use OCP\Lock\ILockingProvider;
+use Test\TestCase;
+
+class ServerTest extends TestCase {
+ /** @var Server */
+ private $admin;
+ /** @var IDBConnection */
+ private $dbConnection;
+ /** @var IConfig */
+ private $config;
+ /** @var ILockingProvider */
+ private $lockingProvider;
+ /** @var IL10N */
+ private $l10n;
+
+ public function setUp() {
+ parent::setUp();
+ $this->config = $this->createMock('\OCP\IConfig');
+ $this->dbConnection = $this->createMock('\OCP\IDBConnection');
+ $this->lockingProvider = $this->createMock('\OCP\Lock\ILockingProvider');
+ $this->l10n = $this->createMock('\OCP\IL10N');
+
+ $this->admin = new Server(
+ $this->dbConnection,
+ $this->config,
+ $this->lockingProvider,
+ $this->l10n
+ );
+ }
+
+ public function testGetForm() {
+ $this->dbConnection
+ ->expects($this->once())
+ ->method('getDatabasePlatform')
+ ->willReturn(new SqlitePlatform());
+ $this->config
+ ->expects($this->at(0))
+ ->method('getAppValue')
+ ->with('core', 'backgroundjobs_mode', 'ajax')
+ ->willReturn('ajax');
+ $this->config
+ ->expects($this->at(2))
+ ->method('getAppValue')
+ ->with('core', 'backgroundjobs_mode', 'ajax')
+ ->willReturn('ajax');
+ $this->config
+ ->expects($this->at(4))
+ ->method('getAppValue')
+ ->with('core', 'lastcron', false)
+ ->willReturn(false);
+ $this->config
+ ->expects($this->at(5))
+ ->method('getAppValue')
+ ->with('core', 'cronErrors')
+ ->willReturn('');
+ $this->config
+ ->expects($this->at(1))
+ ->method('getSystemValue')
+ ->with('check_for_working_wellknown_setup', true)
+ ->willReturn(true);
+ $this->config
+ ->expects($this->at(3))
+ ->method('getSystemValue')
+ ->with('cron_log', true)
+ ->willReturn(true);
+ $this->l10n
+ ->expects($this->at(0))
+ ->method('t')
+ ->with('APCu')
+ ->willReturn('APCu');
+ $this->l10n
+ ->expects($this->at(1))
+ ->method('t')
+ ->with('Redis')
+ ->willReturn('Redis');
+ $outdatedCaches = [];
+ $caches = [
+ 'apcu' => ['name' => 'APCu', 'version' => '4.0.6'],
+ 'redis' => ['name' => 'Redis', 'version' => '2.2.5'],
+ ];
+ foreach ($caches as $php_module => $data) {
+ $isOutdated = extension_loaded($php_module) && version_compare(phpversion($php_module), $data['version'], '<');
+ if ($isOutdated) {
+ $outdatedCaches[$php_module] = $data;
+ }
+ }
+ $envPath = getenv('PATH');
+ $expected = new TemplateResponse(
+ 'settings',
+ 'admin/server',
+ [
+ // Diagnosis
+ 'readOnlyConfigEnabled' => \OC_Helper::isReadOnlyConfigEnabled(),
+ 'isLocaleWorking' => \OC_Util::isSetLocaleWorking(),
+ 'isAnnotationsWorking' => \OC_Util::isAnnotationsWorking(),
+ 'checkForWorkingWellKnownSetup' => true,
+ 'has_fileinfo' => \OC_Util::fileInfoLoaded(),
+ 'invalidTransactionIsolationLevel' => false,
+ 'getenvServerNotWorking' => empty($envPath),
+ 'OutdatedCacheWarning' => $outdatedCaches,
+ 'fileLockingType' => 'cache',
+ 'suggestedOverwriteCliUrl' => '',
+
+ // Background jobs
+ 'backgroundjobs_mode' => 'ajax',
+ 'cron_log' => true,
+ 'lastcron' => false,
+ 'cronErrors' => ''
+ ],
+ ''
+ );
+
+ $this->assertEquals($expected, $this->admin->getForm());
+ }
+
+ public function testGetSection() {
+ $this->assertSame('server', $this->admin->getSection());
+ }
+
+ public function testGetPriority() {
+ $this->assertSame(0, $this->admin->getPriority());
+ }
+}
diff --git a/tests/lib/Settings/Admin/SharingTest.php b/tests/lib/Settings/Admin/SharingTest.php
new file mode 100644
index 00000000000..7aec187d372
--- /dev/null
+++ b/tests/lib/Settings/Admin/SharingTest.php
@@ -0,0 +1,151 @@
+<?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 Test\Settings\Admin;
+
+use OC\Settings\Admin\Sharing;
+use OCP\AppFramework\Http\TemplateResponse;
+use OCP\IConfig;
+use Test\TestCase;
+
+class SharingTest extends TestCase {
+ /** @var Sharing */
+ private $admin;
+ /** @var IConfig */
+ private $config;
+
+ public function setUp() {
+ parent::setUp();
+ $this->config = $this->createMock('\OCP\IConfig');
+
+ $this->admin = new Sharing(
+ $this->config
+ );
+ }
+
+ public function testGetFormWithoutExcludedGroups() {
+ $this->config
+ ->expects($this->at(0))
+ ->method('getAppValue')
+ ->with('core', 'shareapi_exclude_groups_list', '')
+ ->willReturn('');
+ $this->config
+ ->expects($this->at(1))
+ ->method('getAppValue')
+ ->with('core', 'shareapi_enabled', 'yes')
+ ->willReturn('yes');
+ $this->config
+ ->expects($this->at(2))
+ ->method('getAppValue')
+ ->with('core', 'shareapi_default_expire_date', 'no')
+ ->willReturn('no');
+ $this->config
+ ->expects($this->at(3))
+ ->method('getAppValue')
+ ->with('core', 'shareapi_expire_after_n_days', '7')
+ ->willReturn('7');
+ $this->config
+ ->expects($this->at(4))
+ ->method('getAppValue')
+ ->with('core', 'shareapi_enforce_expire_date', 'no')
+ ->willReturn('no');
+ $this->config
+ ->expects($this->at(5))
+ ->method('getAppValue')
+ ->with('core', 'shareapi_exclude_groups', 'no')
+ ->willReturn('no');
+
+ $expected = new TemplateResponse(
+ 'settings',
+ 'admin/sharing',
+ [
+ 'shareAPIEnabled' => 'yes',
+ 'shareDefaultExpireDateSet' => 'no',
+ 'shareExpireAfterNDays' => '7',
+ 'shareEnforceExpireDate' => 'no',
+ 'shareExcludeGroups' => false,
+ 'shareExcludedGroupsList' => '',
+ ],
+ ''
+ );
+
+ $this->assertEquals($expected, $this->admin->getForm());
+ }
+
+ public function testGetFormWithExcludedGroups() {
+ $this->config
+ ->expects($this->at(0))
+ ->method('getAppValue')
+ ->with('core', 'shareapi_exclude_groups_list', '')
+ ->willReturn('["NoSharers","OtherNoSharers"]');
+ $this->config
+ ->expects($this->at(1))
+ ->method('getAppValue')
+ ->with('core', 'shareapi_enabled', 'yes')
+ ->willReturn('yes');
+ $this->config
+ ->expects($this->at(2))
+ ->method('getAppValue')
+ ->with('core', 'shareapi_default_expire_date', 'no')
+ ->willReturn('no');
+ $this->config
+ ->expects($this->at(3))
+ ->method('getAppValue')
+ ->with('core', 'shareapi_expire_after_n_days', '7')
+ ->willReturn('7');
+ $this->config
+ ->expects($this->at(4))
+ ->method('getAppValue')
+ ->with('core', 'shareapi_enforce_expire_date', 'no')
+ ->willReturn('no');
+ $this->config
+ ->expects($this->at(5))
+ ->method('getAppValue')
+ ->with('core', 'shareapi_exclude_groups', 'no')
+ ->willReturn('yes');
+
+ $expected = new TemplateResponse(
+ 'settings',
+ 'admin/sharing',
+ [
+ 'shareAPIEnabled' => 'yes',
+ 'shareDefaultExpireDateSet' => 'no',
+ 'shareExpireAfterNDays' => '7',
+ 'shareEnforceExpireDate' => 'no',
+ 'shareExcludeGroups' => true,
+ 'shareExcludedGroupsList' => 'NoSharers|OtherNoSharers',
+ ],
+ ''
+ );
+
+ $this->assertEquals($expected, $this->admin->getForm());
+ }
+
+ public function testGetSection() {
+ $this->assertSame('sharing', $this->admin->getSection());
+ }
+
+ public function testGetPriority() {
+ $this->assertSame(0, $this->admin->getPriority());
+ }
+}
diff --git a/tests/lib/Settings/Admin/TipsTricksTest.php b/tests/lib/Settings/Admin/TipsTricksTest.php
new file mode 100644
index 00000000000..afa053e8337
--- /dev/null
+++ b/tests/lib/Settings/Admin/TipsTricksTest.php
@@ -0,0 +1,91 @@
+<?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 Test\Settings\Admin;
+
+use OC\Settings\Admin\TipsTricks;
+use OCP\AppFramework\Http\TemplateResponse;
+use OCP\IConfig;
+use Test\TestCase;
+
+class TipsTrickTest extends TestCase {
+ /** @var TipsTricks */
+ private $admin;
+ /** @var IConfig */
+ private $config;
+
+ public function setUp() {
+ parent::setUp();
+ $this->config = $this->createMock('\OCP\IConfig');
+
+ $this->admin = new TipsTricks(
+ $this->config
+ );
+ }
+
+ public function testGetFormWithExcludedGroupsWithSQLite() {
+ $this->config
+ ->expects($this->once())
+ ->method('getSystemValue')
+ ->with('dbtype')
+ ->willReturn('sqlite');
+
+ $expected = new TemplateResponse(
+ 'settings',
+ 'admin/tipstricks',
+ [
+ 'databaseOverload' => true,
+ ],
+ ''
+ );
+
+ $this->assertEquals($expected, $this->admin->getForm());
+ }
+
+ public function testGetFormWithExcludedGroupsWithoutSQLite() {
+ $this->config
+ ->expects($this->once())
+ ->method('getSystemValue')
+ ->with('dbtype')
+ ->willReturn('mysql');
+
+ $expected = new TemplateResponse(
+ 'settings',
+ 'admin/tipstricks',
+ [
+ 'databaseOverload' => false,
+ ],
+ ''
+ );
+
+ $this->assertEquals($expected, $this->admin->getForm());
+ }
+
+ public function testGetSection() {
+ $this->assertSame('tips-tricks', $this->admin->getSection());
+ }
+
+ public function testGetPriority() {
+ $this->assertSame(0, $this->admin->getPriority());
+ }
+}
diff --git a/tests/lib/Settings/ManagerTest.php b/tests/lib/Settings/ManagerTest.php
new file mode 100644
index 00000000000..01e226225be
--- /dev/null
+++ b/tests/lib/Settings/ManagerTest.php
@@ -0,0 +1,220 @@
+<?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;
+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 {
+ /** @var Manager */
+ private $manager;
+ /** @var ILogger */
+ private $logger;
+ /** @var IDBConnection */
+ private $dbConnection;
+ /** @var IL10N */
+ private $l10n;
+ /** @var IConfig */
+ private $config;
+ /** @var IManager */
+ private $encryptionManager;
+ /** @var IUserManager */
+ private $userManager;
+ /** @var ILockingProvider */
+ private $lockingProvider;
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->logger = $this->createMock('\OCP\ILogger');
+ $this->dbConnection = $this->createMock('\OCP\IDBConnection');
+ $this->l10n = $this->createMock('\OCP\IL10N');
+ $this->config = $this->createMock('\OCP\IConfig');
+ $this->encryptionManager = $this->createMock('\OCP\Encryption\IManager');
+ $this->userManager = $this->createMock('\OCP\IUserManager');
+ $this->lockingProvider = $this->createMock('\OCP\Lock\ILockingProvider');
+
+ $this->manager = new Manager(
+ $this->logger,
+ $this->dbConnection,
+ $this->l10n,
+ $this->config,
+ $this->encryptionManager,
+ $this->userManager,
+ $this->lockingProvider
+ );
+ }
+
+ public function testSetupSettings() {
+ $qb = $this->createMock('\OCP\DB\QueryBuilder\IQueryBuilder');
+ $qb
+ ->expects($this->once())
+ ->method('select')
+ ->with('class')
+ ->willReturn($qb);
+ $this->dbConnection
+ ->expects($this->at(0))
+ ->method('getQueryBuilder')
+ ->willReturn($qb);
+ $qb
+ ->expects($this->once())
+ ->method('from')
+ ->with('admin_settings')
+ ->willReturn($qb);
+ $expressionBuilder = $this->createMock('\OCP\DB\QueryBuilder\IExpressionBuilder');
+ $qb
+ ->expects($this->once())
+ ->method('expr')
+ ->willReturn($expressionBuilder);
+ $param = $this->createMock('\OCP\DB\QueryBuilder\IParameter');
+ $qb
+ ->expects($this->once())
+ ->method('createNamedParameter')
+ ->with('OCA\Files\Settings\Admin')
+ ->willReturn($param);
+ $expressionBuilder
+ ->expects($this->once())
+ ->method('eq')
+ ->with('class', $param)
+ ->willReturn('myString');
+ $qb
+ ->expects($this->once())
+ ->method('where')
+ ->with('myString')
+ ->willReturn($qb);
+ $stmt = $this->createMock('\Doctrine\DBAL\Driver\Statement');
+ $qb
+ ->expects($this->once())
+ ->method('execute')
+ ->willReturn($stmt);
+
+ $qb1 = $this->createMock('\OCP\DB\QueryBuilder\IQueryBuilder');
+ $qb1
+ ->expects($this->once())
+ ->method('insert')
+ ->with('admin_settings')
+ ->willReturn($qb1);
+ $this->dbConnection
+ ->expects($this->at(1))
+ ->method('getQueryBuilder')
+ ->willReturn($qb1);
+
+ $this->manager->setupSettings([
+ 'admin' => 'OCA\Files\Settings\Admin',
+ ]);
+ }
+
+ public function testGetAdminSections() {
+ $qb = $this->createMock('\OCP\DB\QueryBuilder\IQueryBuilder');
+ $qb
+ ->expects($this->once())
+ ->method('select')
+ ->with(['class', 'priority'])
+ ->willReturn($qb);
+ $qb
+ ->expects($this->once())
+ ->method('from')
+ ->with('admin_sections')
+ ->willReturn($qb);
+ $stmt = $this->createMock('\Doctrine\DBAL\Driver\Statement');
+ $qb
+ ->expects($this->once())
+ ->method('execute')
+ ->willReturn($stmt);
+ $this->dbConnection
+ ->expects($this->once())
+ ->method('getQueryBuilder')
+ ->willReturn($qb);
+ $this->l10n
+ ->expects($this->any())
+ ->method('t')
+ ->will($this->returnArgument(0));
+
+ $this->assertEquals([
+ 0 => [new Section('server', 'Server settings', 0)],
+ 5 => [new Section('sharing', 'Sharing', 0)],
+ 45 => [new Section('encryption', 'Encryption', 0)],
+ 90 => [new Section('logging', 'Logging', 0)],
+ 98 => [new Section('additional', 'Additional settings', 0)],
+ 99 => [new Section('tips-tricks', 'Tips & tricks', 0)],
+ ], $this->manager->getAdminSections());
+ }
+
+ public function testGetAdminSettings() {
+ $qb = $this->createMock('\OCP\DB\QueryBuilder\IQueryBuilder');
+ $qb
+ ->expects($this->once())
+ ->method('select')
+ ->with(['class', 'priority'])
+ ->willReturn($qb);
+ $qb
+ ->expects($this->once())
+ ->method('from')
+ ->with('admin_settings')
+ ->willReturn($qb);
+ $expressionBuilder = $this->createMock('\OCP\DB\QueryBuilder\IExpressionBuilder');
+ $qb
+ ->expects($this->once())
+ ->method('expr')
+ ->willReturn($expressionBuilder);
+ $param = $this->createMock('\OCP\DB\QueryBuilder\IParameter');
+ $qb
+ ->expects($this->once())
+ ->method('createParameter')
+ ->with('section')
+ ->willReturn($param);
+ $expressionBuilder
+ ->expects($this->once())
+ ->method('eq')
+ ->with('section', $param)
+ ->willReturn('myString');
+ $qb
+ ->expects($this->once())
+ ->method('where')
+ ->with('myString')
+ ->willReturn($qb);
+ $stmt = $this->createMock('\Doctrine\DBAL\Driver\Statement');
+ $qb
+ ->expects($this->once())
+ ->method('execute')
+ ->willReturn($stmt);
+ $this->dbConnection
+ ->expects($this->exactly(2))
+ ->method('getQueryBuilder')
+ ->willReturn($qb);
+
+ $this->assertEquals([
+ 0 => [new Sharing($this->config)],
+ ], $this->manager->getAdminSettings('sharing'));
+ }
+}
diff --git a/tests/lib/Settings/SectionTest.php b/tests/lib/Settings/SectionTest.php
new file mode 100644
index 00000000000..422b931bb4b
--- /dev/null
+++ b/tests/lib/Settings/SectionTest.php
@@ -0,0 +1,39 @@
+<?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\Section;
+use Test\TestCase;
+
+class SectionTest extends TestCase {
+ public function testGetID() {
+ $this->assertSame('ldap', (new Section('ldap', 'name', 1))->getID());
+ }
+ public function testGetName() {
+ $this->assertSame('name', (new Section('ldap', 'name', 1))->getName());
+ }
+ public function testGetPriority() {
+ $this->assertSame(1, (new Section('ldap', 'name', 1))->getPriority());
+ }
+}