Add unit tests
This commit is contained in:
parent
1ebbcdcc96
commit
687f5bee94
|
@ -0,0 +1,100 @@
|
|||
<?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 OCA\Encryption\Tests\Settings;
|
||||
|
||||
use OCA\Encryption\Settings\Admin;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\IConfig;
|
||||
use OCP\ISession;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IUserSession;
|
||||
use OCP\IL10N;
|
||||
use OCP\ILogger;
|
||||
use Test\TestCase;
|
||||
|
||||
class AdminTest extends TestCase {
|
||||
/** @var Admin */
|
||||
private $admin;
|
||||
/** @var IL10N */
|
||||
private $l;
|
||||
/** @var ILogger */
|
||||
private $logger;
|
||||
/** @var IUserSession */
|
||||
private $userSession;
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
/** @var ISession */
|
||||
private $session;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->l = $this->createMock('\OCP\IL10N');
|
||||
$this->logger = $this->createMock('\OCP\ILogger');
|
||||
$this->userSession = $this->createMock('\OCP\IUserSession');
|
||||
$this->config = $this->createMock('\OCP\IConfig');
|
||||
$this->userManager = $this->createMock('\OCP\IUserManager');
|
||||
$this->session = $this->createMock('\OCP\ISession');
|
||||
|
||||
$this->admin = new Admin(
|
||||
$this->l,
|
||||
$this->logger,
|
||||
$this->userSession,
|
||||
$this->config,
|
||||
$this->userManager,
|
||||
$this->session
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetForm() {
|
||||
$this->config
|
||||
->expects($this->at(0))
|
||||
->method('getAppValue')
|
||||
->with('encryption', 'recoveryAdminEnabled', '0')
|
||||
->willReturn(1);
|
||||
$this->config
|
||||
->expects($this->at(1))
|
||||
->method('getAppValue')
|
||||
->with('encryption', 'encryptHomeStorage', '1')
|
||||
->willReturn(1);
|
||||
$params = [
|
||||
'recoveryEnabled' => 1,
|
||||
'initStatus' => '0',
|
||||
'encryptHomeStorage' => false,
|
||||
'masterKeyEnabled' => false
|
||||
];
|
||||
$expected = new TemplateResponse('encryption', 'settings-admin', $params, '');
|
||||
$this->assertEquals($expected, $this->admin->getForm());
|
||||
}
|
||||
|
||||
public function testGetSection() {
|
||||
$this->assertSame('encryption', $this->admin->getSection());
|
||||
}
|
||||
|
||||
public function testGetPriority() {
|
||||
$this->assertSame(5, $this->admin->getPriority());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
<?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 OCA\FederatedFileSharing\Tests\Settings;
|
||||
|
||||
use OCA\FederatedFileSharing\Settings\Admin;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use Test\TestCase;
|
||||
|
||||
class AdminTest extends TestCase {
|
||||
/** @var Admin */
|
||||
private $admin;
|
||||
/** @var \OCA\FederatedFileSharing\FederatedShareProvider */
|
||||
private $federatedShareProvider;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->federatedShareProvider = $this->createMock('\OCA\FederatedFileSharing\FederatedShareProvider');
|
||||
$this->admin = new Admin(
|
||||
$this->federatedShareProvider
|
||||
);
|
||||
}
|
||||
|
||||
public function sharingStateProvider() {
|
||||
return [
|
||||
[
|
||||
true,
|
||||
],
|
||||
[
|
||||
false,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider sharingStateProvider
|
||||
* @param bool $state
|
||||
*/
|
||||
public function testGetForm($state) {
|
||||
$this->federatedShareProvider
|
||||
->expects($this->once())
|
||||
->method('isOutgoingServer2serverShareEnabled')
|
||||
->willReturn($state);
|
||||
$this->federatedShareProvider
|
||||
->expects($this->once())
|
||||
->method('isIncomingServer2serverShareEnabled')
|
||||
->willReturn($state);
|
||||
|
||||
$params = [
|
||||
'outgoingServer2serverShareEnabled' => $state,
|
||||
'incomingServer2serverShareEnabled' => $state,
|
||||
];
|
||||
$expected = new TemplateResponse('federatedfilesharing', 'settings-admin', $params, '');
|
||||
$this->assertEquals($expected, $this->admin->getForm());
|
||||
}
|
||||
|
||||
public function testGetSection() {
|
||||
$this->assertSame('sharing', $this->admin->getSection());
|
||||
}
|
||||
|
||||
public function testGetPriority() {
|
||||
$this->assertSame(20, $this->admin->getPriority());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
<?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 OCA\Federation\Tests\Settings;
|
||||
|
||||
use OCA\Federation\Settings\Admin;
|
||||
use OCA\Federation\TrustedServers;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use Test\TestCase;
|
||||
|
||||
class AdminTest extends TestCase {
|
||||
/** @var Admin */
|
||||
private $admin;
|
||||
/** @var TrustedServers */
|
||||
private $trustedServers;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->trustedServers = $this->createMock('\OCA\Federation\TrustedServers');
|
||||
$this->admin = new Admin(
|
||||
$this->trustedServers
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetForm() {
|
||||
$this->trustedServers
|
||||
->expects($this->once())
|
||||
->method('getServers')
|
||||
->willReturn(['myserver', 'secondserver']);
|
||||
$this->trustedServers
|
||||
->expects($this->once())
|
||||
->method('getAutoAddServers')
|
||||
->willReturn(['autoserver1', 'autoserver2']);
|
||||
|
||||
$params = [
|
||||
'trustedServers' => ['myserver', 'secondserver'],
|
||||
'autoAddServers' => ['autoserver1', 'autoserver2'],
|
||||
];
|
||||
$expected = new TemplateResponse('federation', 'settings-admin', $params, '');
|
||||
$this->assertEquals($expected, $this->admin->getForm());
|
||||
}
|
||||
|
||||
public function testGetSection() {
|
||||
$this->assertSame('sharing', $this->admin->getSection());
|
||||
}
|
||||
|
||||
public function testGetPriority() {
|
||||
$this->assertSame(30, $this->admin->getPriority());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
<?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 OCA\Files\Tests\Settings;
|
||||
|
||||
use bantu\IniGetWrapper\IniGetWrapper;
|
||||
use OCA\Files\Settings\Admin;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\IRequest;
|
||||
use OCP\Util;
|
||||
use Test\TestCase;
|
||||
|
||||
class AdminTest extends TestCase {
|
||||
/** @var Admin */
|
||||
private $admin;
|
||||
/** @var IniGetWrapper */
|
||||
private $iniGetWrapper;
|
||||
/** @var IRequest */
|
||||
private $request;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->iniGetWrapper = $this->createMock('\bantu\IniGetWrapper\IniGetWrapper');
|
||||
$this->request = $this->createMock('\OCP\IRequest');
|
||||
$this->admin = new Admin(
|
||||
$this->iniGetWrapper,
|
||||
$this->request
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetForm() {
|
||||
$htaccessWorking = (getenv('htaccessWorking') == 'true');
|
||||
$htaccessWritable = is_writable(\OC::$SERVERROOT.'/.htaccess');
|
||||
$userIniWritable = is_writable(\OC::$SERVERROOT.'/.user.ini');
|
||||
|
||||
$this->iniGetWrapper
|
||||
->expects($this->at(0))
|
||||
->method('getBytes')
|
||||
->with('upload_max_filesize')
|
||||
->willReturn(1234);
|
||||
$this->iniGetWrapper
|
||||
->expects($this->at(1))
|
||||
->method('getBytes')
|
||||
->with('post_max_size')
|
||||
->willReturn(1234);
|
||||
$params = [
|
||||
'uploadChangable' => (($htaccessWorking and $htaccessWritable) or $userIniWritable ),
|
||||
'uploadMaxFilesize' => '1 KB',
|
||||
'displayMaxPossibleUploadSize' => PHP_INT_SIZE === 4,
|
||||
'maxPossibleUploadSize' => Util::humanFileSize(PHP_INT_MAX),
|
||||
];
|
||||
$expected = new TemplateResponse('files', 'admin', $params, '');
|
||||
$this->assertEquals($expected, $this->admin->getForm());
|
||||
}
|
||||
|
||||
public function testGetSection() {
|
||||
$this->assertSame('additional', $this->admin->getSection());
|
||||
}
|
||||
|
||||
public function testGetPriority() {
|
||||
$this->assertSame(5, $this->admin->getPriority());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
<?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 OCA\Files_External\Tests\Settings;
|
||||
|
||||
use OCA\Files_External\Lib\Auth\Password\GlobalAuth;
|
||||
use OCA\Files_External\Service\BackendService;
|
||||
use OCA\Files_External\Service\GlobalStoragesService;
|
||||
use OCA\Files_External\Settings\Admin;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\Encryption\IManager;
|
||||
use Test\TestCase;
|
||||
|
||||
class AdminTest extends TestCase {
|
||||
/** @var Admin */
|
||||
private $admin;
|
||||
/** @var IManager */
|
||||
private $encryptionManager;
|
||||
/** @var GlobalStoragesService */
|
||||
private $globalStoragesService;
|
||||
/** @var BackendService */
|
||||
private $backendService;
|
||||
/** @var GlobalAuth */
|
||||
private $globalAuth;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->encryptionManager = $this->createMock('\OCP\Encryption\IManager');
|
||||
$this->globalStoragesService = $this->createMock('\OCA\Files_External\Service\GlobalStoragesService');
|
||||
$this->backendService = $this->createMock('\OCA\Files_External\Service\BackendService');
|
||||
$this->globalAuth = $this->createMock('\OCA\Files_External\Lib\Auth\Password\GlobalAuth');
|
||||
|
||||
$this->admin = new Admin(
|
||||
$this->encryptionManager,
|
||||
$this->globalStoragesService,
|
||||
$this->backendService,
|
||||
$this->globalAuth
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetForm() {
|
||||
$this->encryptionManager
|
||||
->expects($this->once())
|
||||
->method('isEnabled')
|
||||
->willReturn(false);
|
||||
$this->globalStoragesService
|
||||
->expects($this->once())
|
||||
->method('getStorages')
|
||||
->willReturn(['a', 'b', 'c']);
|
||||
$this->backendService
|
||||
->expects($this->once())
|
||||
->method('getAvailableBackends')
|
||||
->willReturn(['d', 'e', 'f']);
|
||||
$this->backendService
|
||||
->expects($this->once())
|
||||
->method('getAuthMechanisms')
|
||||
->willReturn(['g', 'h', 'i']);
|
||||
$this->backendService
|
||||
->expects($this->once())
|
||||
->method('isUserMountingAllowed')
|
||||
->willReturn(true);
|
||||
$this->globalAuth
|
||||
->expects($this->once())
|
||||
->method('getAuth')
|
||||
->with('')
|
||||
->willReturn('asdf:asdf');
|
||||
$params = [
|
||||
'encryptionEnabled' => false,
|
||||
'visibilityType' => BackendService::VISIBILITY_ADMIN,
|
||||
'storages' => ['a', 'b', 'c'],
|
||||
'backends' => ['d', 'e', 'f'],
|
||||
'authMechanisms' => ['g', 'h', 'i'],
|
||||
'dependencies' => \OC_Mount_Config::dependencyMessage($this->backendService->getBackends()),
|
||||
'allowUserMounting' => true,
|
||||
'globalCredentials' => 'asdf:asdf',
|
||||
'globalCredentialsUid' => '',
|
||||
];
|
||||
$expected = new TemplateResponse('files_external', 'settings', $params, '');
|
||||
$this->assertEquals($expected, $this->admin->getForm());
|
||||
}
|
||||
|
||||
public function testGetSection() {
|
||||
$this->assertSame('externalstorages', $this->admin->getSection());
|
||||
}
|
||||
|
||||
public function testGetPriority() {
|
||||
$this->assertSame(40, $this->admin->getPriority());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
<?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 OCA\Files_External\Tests\Settings;
|
||||
|
||||
use OCA\Files_External\Settings\Section;
|
||||
use OCP\IL10N;
|
||||
use Test\TestCase;
|
||||
|
||||
class SectionTest extends TestCase {
|
||||
/** @var IL10N */
|
||||
private $l;
|
||||
/** @var Section */
|
||||
private $section;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->l = $this->createMock('\OCP\IL10N');
|
||||
|
||||
$this->section = new Section(
|
||||
$this->l
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetID() {
|
||||
$this->assertSame('externalstorages', $this->section->getID());
|
||||
}
|
||||
|
||||
public function testGetName() {
|
||||
$this->l
|
||||
->expects($this->once())
|
||||
->method('t')
|
||||
->with('External storages')
|
||||
->willReturn('External storages');
|
||||
|
||||
$this->assertSame('External storages', $this->section->getName());
|
||||
}
|
||||
|
||||
public function testGetPriority() {
|
||||
$this->assertSame(10, $this->section->getPriority());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
<?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 OCA\SystemTags\Tests\Settings;
|
||||
|
||||
use OCA\SystemTags\Settings\Admin;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use Test\TestCase;
|
||||
|
||||
class AdminTest extends TestCase {
|
||||
/** @var Admin */
|
||||
private $admin;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->admin = new Admin();
|
||||
}
|
||||
|
||||
public function testGetForm() {
|
||||
$expected = new TemplateResponse('systemtags', 'admin', [], '');
|
||||
$this->assertEquals($expected, $this->admin->getForm());
|
||||
}
|
||||
|
||||
public function testGetSection() {
|
||||
$this->assertSame('sharing', $this->admin->getSection());
|
||||
}
|
||||
|
||||
public function testGetPriority() {
|
||||
$this->assertSame(70, $this->admin->getPriority());
|
||||
}
|
||||
}
|
|
@ -31,20 +31,19 @@ use OCP\IURLGenerator;
|
|||
use OCP\Settings\ISettings;
|
||||
|
||||
class Admin implements ISettings {
|
||||
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
|
||||
/** @var IL10N */
|
||||
private $l;
|
||||
|
||||
/** @var ThemingDefaults */
|
||||
private $themingDefaults;
|
||||
|
||||
/** @var IURLGenerator */
|
||||
private $urlGenerator;
|
||||
|
||||
public function __construct(IConfig $config, IL10N $l, ThemingDefaults $themingDefaults, IURLGenerator $urlGenerator) {
|
||||
public function __construct(IConfig $config,
|
||||
IL10N $l,
|
||||
ThemingDefaults $themingDefaults,
|
||||
IURLGenerator $urlGenerator) {
|
||||
$this->config = $config;
|
||||
$this->l = $l;
|
||||
$this->themingDefaults = $themingDefaults;
|
||||
|
|
|
@ -33,6 +33,7 @@ use OCP\IConfig;
|
|||
use OCP\IL10N;
|
||||
use OCP\IRequest;
|
||||
use Test\TestCase;
|
||||
use OCA\Theming\ThemingDefaults;
|
||||
|
||||
class ThemingControllerTest extends TestCase {
|
||||
/** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */
|
||||
|
|
|
@ -0,0 +1,155 @@
|
|||
<?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 OCA\Theming\Tests\Settings;
|
||||
|
||||
use OCA\Theming\Settings\Admin;
|
||||
use OCA\Theming\ThemingDefaults;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\IConfig;
|
||||
use OCP\IL10N;
|
||||
use OCP\IURLGenerator;
|
||||
use Test\TestCase;
|
||||
|
||||
class AdminTest extends TestCase {
|
||||
/** @var Admin */
|
||||
private $admin;
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
/** @var ThemingDefaults */
|
||||
private $themingDefaults;
|
||||
/** @var IURLGenerator */
|
||||
private $urlGenerator;
|
||||
/** @var IL10N */
|
||||
private $l10n;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->config = $this->createMock('\OCP\IConfig');
|
||||
$this->l10n = $this->createMock('\OCP\IL10N');
|
||||
$this->themingDefaults = $this->createMock('\OCA\Theming\ThemingDefaults');
|
||||
$this->urlGenerator = $this->createMock('\OCP\IURLGenerator');
|
||||
|
||||
$this->admin = new Admin(
|
||||
$this->config,
|
||||
$this->l10n,
|
||||
$this->themingDefaults,
|
||||
$this->urlGenerator
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetFormNoErrors() {
|
||||
$this->config
|
||||
->expects($this->once())
|
||||
->method('getSystemValue')
|
||||
->with('theme', '')
|
||||
->willReturn('');
|
||||
$this->themingDefaults
|
||||
->expects($this->once())
|
||||
->method('getEntity')
|
||||
->willReturn('MyEntity');
|
||||
$this->themingDefaults
|
||||
->expects($this->once())
|
||||
->method('getBaseUrl')
|
||||
->willReturn('https://example.com');
|
||||
$this->themingDefaults
|
||||
->expects($this->once())
|
||||
->method('getSlogan')
|
||||
->willReturn('MySlogan');
|
||||
$this->themingDefaults
|
||||
->expects($this->once())
|
||||
->method('getMailHeaderColor')
|
||||
->willReturn('#fff');
|
||||
$this->urlGenerator
|
||||
->expects($this->once())
|
||||
->method('linkToRoute')
|
||||
->with('theming.Theming.updateLogo')
|
||||
->willReturn('/my/route');
|
||||
$params = [
|
||||
'themable' => true,
|
||||
'errorMessage' => '',
|
||||
'name' => 'MyEntity',
|
||||
'url' => 'https://example.com',
|
||||
'slogan' => 'MySlogan',
|
||||
'color' => '#fff',
|
||||
'uploadLogoRoute' => '/my/route',
|
||||
];
|
||||
|
||||
$expected = new TemplateResponse('theming', 'settings-admin', $params, '');
|
||||
$this->assertEquals($expected, $this->admin->getForm());
|
||||
}
|
||||
|
||||
public function testGetFormWithErrors() {
|
||||
$this->config
|
||||
->expects($this->once())
|
||||
->method('getSystemValue')
|
||||
->with('theme', '')
|
||||
->willReturn('MyCustomTheme');
|
||||
$this->l10n
|
||||
->expects($this->once())
|
||||
->method('t')
|
||||
->with('You already use a custom theme')
|
||||
->willReturn('You already use a custom theme');
|
||||
$this->themingDefaults
|
||||
->expects($this->once())
|
||||
->method('getEntity')
|
||||
->willReturn('MyEntity');
|
||||
$this->themingDefaults
|
||||
->expects($this->once())
|
||||
->method('getBaseUrl')
|
||||
->willReturn('https://example.com');
|
||||
$this->themingDefaults
|
||||
->expects($this->once())
|
||||
->method('getSlogan')
|
||||
->willReturn('MySlogan');
|
||||
$this->themingDefaults
|
||||
->expects($this->once())
|
||||
->method('getMailHeaderColor')
|
||||
->willReturn('#fff');
|
||||
$this->urlGenerator
|
||||
->expects($this->once())
|
||||
->method('linkToRoute')
|
||||
->with('theming.Theming.updateLogo')
|
||||
->willReturn('/my/route');
|
||||
$params = [
|
||||
'themable' => false,
|
||||
'errorMessage' => 'You already use a custom theme',
|
||||
'name' => 'MyEntity',
|
||||
'url' => 'https://example.com',
|
||||
'slogan' => 'MySlogan',
|
||||
'color' => '#fff',
|
||||
'uploadLogoRoute' => '/my/route',
|
||||
];
|
||||
|
||||
$expected = new TemplateResponse('theming', 'settings-admin', $params, '');
|
||||
$this->assertEquals($expected, $this->admin->getForm());
|
||||
}
|
||||
|
||||
public function testGetSection() {
|
||||
$this->assertSame('theming', $this->admin->getSection());
|
||||
}
|
||||
|
||||
public function testGetPriority() {
|
||||
$this->assertSame(5, $this->admin->getPriority());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
<?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 OCA\Theming\Tests\Settings;
|
||||
|
||||
use OCA\Theming\Settings\Section;
|
||||
use OCP\IL10N;
|
||||
use Test\TestCase;
|
||||
|
||||
class SectionTest extends TestCase {
|
||||
/** @var IL10N */
|
||||
private $l;
|
||||
/** @var Section */
|
||||
private $section;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->l = $this->createMock('\OCP\IL10N');
|
||||
|
||||
$this->section = new Section(
|
||||
$this->l
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetID() {
|
||||
$this->assertSame('theming', $this->section->getID());
|
||||
}
|
||||
|
||||
public function testGetName() {
|
||||
$this->l
|
||||
->expects($this->once())
|
||||
->method('t')
|
||||
->with('Theming')
|
||||
->willReturn('Theming');
|
||||
|
||||
$this->assertSame('Theming', $this->section->getName());
|
||||
}
|
||||
|
||||
public function testGetPriority() {
|
||||
$this->assertSame(30, $this->section->getPriority());
|
||||
}
|
||||
}
|
|
@ -59,15 +59,14 @@ class AdminControllerTest extends TestCase {
|
|||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->request = $this->getMock('\\OCP\\IRequest');
|
||||
$this->jobList = $this->getMock('\\OCP\\BackgroundJob\\IJobList');
|
||||
$this->secureRandom = $this->getMock('\\OCP\\Security\\ISecureRandom');
|
||||
$this->config = $this->getMock('\\OCP\\IConfig');
|
||||
$this->timeFactory = $this->getMock('\\OCP\\AppFramework\\Utility\\ITimeFactory');
|
||||
$this->l10n = $this->getMock('\\OCP\\IL10N');
|
||||
$this->updateChecker = $this->getMockBuilder('\\OCA\\UpdateNotification\\UpdateChecker')
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->dateTimeFormatter = $this->getMock('\\OCP\\IDateTimeFormatter');
|
||||
$this->request = $this->createMock('\\OCP\\IRequest');
|
||||
$this->jobList = $this->createMock('\\OCP\\BackgroundJob\\IJobList');
|
||||
$this->secureRandom = $this->createMock('\\OCP\\Security\\ISecureRandom');
|
||||
$this->config = $this->createMock('\\OCP\\IConfig');
|
||||
$this->timeFactory = $this->createMock('\\OCP\\AppFramework\\Utility\\ITimeFactory');
|
||||
$this->l10n = $this->createMock('\\OCP\\IL10N');
|
||||
$this->updateChecker = $this->createMock('\\OCA\\UpdateNotification\\UpdateChecker');
|
||||
$this->dateTimeFormatter = $this->createMock('\\OCP\\IDateTimeFormatter');
|
||||
|
||||
$this->adminController = new AdminController(
|
||||
'updatenotification',
|
||||
|
@ -197,4 +196,12 @@ class AdminControllerTest extends TestCase {
|
|||
$expected = new DataResponse('MyGeneratedToken');
|
||||
$this->assertEquals($expected, $this->adminController->createCredentials());
|
||||
}
|
||||
|
||||
public function testGetSection() {
|
||||
$this->assertSame('server', $this->adminController->getSection());
|
||||
}
|
||||
|
||||
public function testGetPriority() {
|
||||
$this->assertSame(1, $this->adminController->getPriority());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,10 +31,12 @@ use OCP\Settings\ISettings;
|
|||
use OCP\Template;
|
||||
|
||||
class Admin implements ISettings {
|
||||
|
||||
/** @var IL10N */
|
||||
private $l;
|
||||
|
||||
/**
|
||||
* @param IL10N $l
|
||||
*/
|
||||
public function __construct(IL10N $l) {
|
||||
$this->l = $l;
|
||||
}
|
||||
|
@ -84,10 +86,4 @@ class Admin implements ISettings {
|
|||
public function getPriority() {
|
||||
return 5;
|
||||
}
|
||||
|
||||
private function renderControls() {
|
||||
$controls = new Template('user_ldap', 'part.settingcontrols');
|
||||
return $controls->fetchPage();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
<?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 OCA\User_LDAP\Tests\Settings;
|
||||
|
||||
use OCA\User_LDAP\Configuration;
|
||||
use OCA\User_LDAP\Helper;
|
||||
use OCA\User_LDAP\Settings\Admin;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\IL10N;
|
||||
use OCP\Template;
|
||||
use Test\TestCase;
|
||||
|
||||
/**
|
||||
* @group DB
|
||||
* @package OCA\User_LDAP\Tests\Settings
|
||||
*/
|
||||
class AdminTest extends TestCase {
|
||||
/** @var Admin */
|
||||
private $admin;
|
||||
/** @var IL10N */
|
||||
private $l10n;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->l10n = $this->createMock('\OCP\IL10N');
|
||||
|
||||
$this->admin = new Admin(
|
||||
$this->l10n
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @UseDB
|
||||
*/
|
||||
public function testGetForm() {
|
||||
|
||||
$helper = new Helper();
|
||||
$prefixes = $helper->getServerConfigurationPrefixes();
|
||||
$hosts = $helper->getServerConfigurationHosts();
|
||||
|
||||
$wControls = new Template('user_ldap', 'part.wizardcontrols');
|
||||
$wControls = $wControls->fetchPage();
|
||||
$sControls = new Template('user_ldap', 'part.settingcontrols');
|
||||
$sControls = $sControls->fetchPage();
|
||||
|
||||
$parameters['serverConfigurationPrefixes'] = $prefixes;
|
||||
$parameters['serverConfigurationHosts'] = $hosts;
|
||||
$parameters['settingControls'] = $sControls;
|
||||
$parameters['wizardControls'] = $wControls;
|
||||
|
||||
// assign default values
|
||||
$config = new Configuration('', false);
|
||||
$defaults = $config->getDefaults();
|
||||
foreach($defaults as $key => $default) {
|
||||
$parameters[$key.'_default'] = $default;
|
||||
}
|
||||
|
||||
$expected = new TemplateResponse('user_ldap', 'settings', $parameters);
|
||||
$this->assertEquals($expected, $this->admin->getForm());
|
||||
}
|
||||
|
||||
public function testGetSection() {
|
||||
$this->assertSame('ldap', $this->admin->getSection());
|
||||
}
|
||||
|
||||
public function testGetPriority() {
|
||||
$this->assertSame(5, $this->admin->getPriority());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
<?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 OCA\User_LDAP\Tests\Settings;
|
||||
|
||||
use OCA\User_LDAP\Settings\Section;
|
||||
use OCP\IL10N;
|
||||
use Test\TestCase;
|
||||
|
||||
class SectionTest extends TestCase {
|
||||
/** @var IL10N */
|
||||
private $l;
|
||||
/** @var Section */
|
||||
private $section;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->l = $this->createMock('\OCP\IL10N');
|
||||
|
||||
$this->section = new Section(
|
||||
$this->l
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetID() {
|
||||
$this->assertSame('ldap', $this->section->getID());
|
||||
}
|
||||
|
||||
public function testGetName() {
|
||||
$this->l
|
||||
->expects($this->once())
|
||||
->method('t')
|
||||
->with('LDAP / AD integration')
|
||||
->willReturn('LDAP / AD integration');
|
||||
|
||||
$this->assertSame('LDAP / AD integration', $this->section->getName());
|
||||
}
|
||||
|
||||
public function testGetPriority() {
|
||||
$this->assertSame(25, $this->section->getPriority());
|
||||
}
|
||||
}
|
|
@ -36,10 +36,12 @@ use OCP\Lock\ILockingProvider;
|
|||
use OCP\Settings\ISettings;
|
||||
|
||||
class Additional implements ISettings {
|
||||
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @param IConfig $config
|
||||
*/
|
||||
public function __construct(IConfig $config) {
|
||||
$this->config = $config;
|
||||
}
|
||||
|
|
|
@ -35,6 +35,10 @@ class Encryption implements ISettings {
|
|||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
|
||||
/**
|
||||
* @param Manager $manager
|
||||
* @param IUserManager $userManager
|
||||
*/
|
||||
public function __construct(Manager $manager, IUserManager $userManager) {
|
||||
$this->manager = $manager;
|
||||
$this->userManager = $userManager;
|
||||
|
|
|
@ -32,6 +32,9 @@ class Logging implements ISettings {
|
|||
/** @var IConfig */
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @param IConfig $config
|
||||
*/
|
||||
public function __construct(IConfig $config) {
|
||||
$this->config = $config;
|
||||
}
|
||||
|
|
|
@ -36,20 +36,25 @@ use OCP\Lock\ILockingProvider;
|
|||
use OCP\Settings\ISettings;
|
||||
|
||||
class Server implements ISettings {
|
||||
|
||||
/** @var IDBConnection|Connection */
|
||||
private $db;
|
||||
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
|
||||
/** @var ILockingProvider */
|
||||
private $lockingProvider;
|
||||
|
||||
/** @var IL10N */
|
||||
private $l;
|
||||
|
||||
public function __construct(IDBConnection $db, IConfig $config, ILockingProvider $lockingProvider, IL10N $l) {
|
||||
/**
|
||||
* @param IDBConnection $db
|
||||
* @param IConfig $config
|
||||
* @param ILockingProvider $lockingProvider
|
||||
* @param IL10N $l
|
||||
*/
|
||||
public function __construct(IDBConnection $db,
|
||||
IConfig $config,
|
||||
ILockingProvider $lockingProvider,
|
||||
IL10N $l) {
|
||||
$this->db = $db;
|
||||
$this->config = $config;
|
||||
$this->lockingProvider = $lockingProvider;
|
||||
|
|
|
@ -31,6 +31,9 @@ class Sharing implements ISettings {
|
|||
/** @var IConfig */
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @param IConfig $config
|
||||
*/
|
||||
public function __construct(IConfig $config) {
|
||||
$this->config = $config;
|
||||
}
|
||||
|
@ -39,8 +42,9 @@ class Sharing implements ISettings {
|
|||
* @return TemplateResponse
|
||||
*/
|
||||
public function getForm() {
|
||||
$excludeGroupsList = !is_null(json_decode($this->config->getAppValue('core', 'shareapi_exclude_groups_list', '')))
|
||||
? implode('|', $this->config->getAppValue('core', 'shareapi_exclude_groups_list', '')) : '';
|
||||
$excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', '');
|
||||
$excludeGroupsList = !is_null(json_decode($excludedGroups))
|
||||
? implode('|', json_decode($excludedGroups, true)) : '';
|
||||
|
||||
$parameters = [
|
||||
// Built-In Sharing
|
||||
|
|
|
@ -31,6 +31,9 @@ class TipsTricks implements ISettings {
|
|||
/** @var IConfig */
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @param IConfig $config
|
||||
*/
|
||||
public function __construct(IConfig $config) {
|
||||
$this->config = $config;
|
||||
}
|
||||
|
|
|
@ -41,25 +41,28 @@ class Manager implements IManager {
|
|||
|
||||
/** @var ILogger */
|
||||
private $log;
|
||||
|
||||
/** @var IDBConnection */
|
||||
private $dbc;
|
||||
|
||||
/** @var IL10N */
|
||||
private $l;
|
||||
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
|
||||
/** @var EncryptionManager */
|
||||
private $encryptionManager;
|
||||
|
||||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
|
||||
/** @var ILockingProvider */
|
||||
private $lockingProvider;
|
||||
|
||||
/**
|
||||
* @param ILogger $log
|
||||
* @param IDBConnection $dbc
|
||||
* @param IL10N $l
|
||||
* @param IConfig $config
|
||||
* @param EncryptionManager $encryptionManager
|
||||
* @param IUserManager $userManager
|
||||
* @param ILockingProvider $lockingProvider
|
||||
*/
|
||||
public function __construct(
|
||||
ILogger $log,
|
||||
IDBConnection $dbc,
|
||||
|
@ -135,7 +138,11 @@ class Manager implements IManager {
|
|||
]);
|
||||
}
|
||||
|
||||
private function add($table, $values) {
|
||||
/**
|
||||
* @param string $table
|
||||
* @param array $values
|
||||
*/
|
||||
private function add($table, array $values) {
|
||||
$query = $this->dbc->getQueryBuilder();
|
||||
$values = array_map(function($value) use ($query) {
|
||||
return $query->createNamedParameter($value);
|
||||
|
@ -196,7 +203,11 @@ class Manager implements IManager {
|
|||
return $this->has(self::TABLE_ADMIN_SETTINGS, $className);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $table
|
||||
* @param string $className
|
||||
* @return bool
|
||||
*/
|
||||
private function has($table, $className) {
|
||||
$query = $this->dbc->getQueryBuilder();
|
||||
$query->select('class')
|
||||
|
@ -249,9 +260,7 @@ class Manager implements IManager {
|
|||
}
|
||||
|
||||
/**
|
||||
* returns a list of the admin sections
|
||||
*
|
||||
* @return ISection[]
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getAdminSections() {
|
||||
$query = $this->dbc->getQueryBuilder();
|
||||
|
@ -347,11 +356,12 @@ class Manager implements IManager {
|
|||
ksort($settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getAdminSettings($section) {
|
||||
$settings = $this->getBuiltInAdminSettings($section);
|
||||
$this->getAdminSettingsFromDB($section, $settings);
|
||||
return $settings;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -21,23 +21,23 @@
|
|||
*
|
||||
*/
|
||||
|
||||
|
||||
namespace OC\Settings;
|
||||
|
||||
|
||||
use OCP\Settings\ISection;
|
||||
|
||||
class Section implements ISection {
|
||||
|
||||
/** @var string */
|
||||
private $id;
|
||||
|
||||
/** @var string */
|
||||
private $name;
|
||||
|
||||
/** @var int */
|
||||
private $priority;
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
* @param string $name
|
||||
* @param int $priority
|
||||
*/
|
||||
public function __construct($id, $name, $priority) {
|
||||
$this->id = $id;
|
||||
$this->name = $name;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
* @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
* @author Lukas Reschke <lukas@statuscode.ch>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
|
@ -23,16 +24,10 @@
|
|||
|
||||
namespace OC\Settings\Controller;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OC\Encryption\Manager as EncryptionManager;
|
||||
use OCP\IConfig;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IL10N;
|
||||
use OCP\INavigationManager;
|
||||
use OCP\IRequest;
|
||||
use OCP\IUserManager;
|
||||
use OCP\Settings\IManager as ISettingsManager;
|
||||
use OCP\Template;
|
||||
|
||||
|
@ -40,22 +35,21 @@ use OCP\Template;
|
|||
* @package OC\Settings\Controller
|
||||
*/
|
||||
class AdminSettingsController extends Controller {
|
||||
|
||||
/** @var INavigationManager */
|
||||
private $navigationManager;
|
||||
|
||||
/** @var ISettingsManager */
|
||||
private $settingsManager;
|
||||
|
||||
/**
|
||||
* @param string $appName
|
||||
* @param IRequest $request
|
||||
* @param INavigationManager $navigationManager
|
||||
* @param ISettingsManager $settingsManager
|
||||
*/
|
||||
public function __construct(
|
||||
$appName,
|
||||
IRequest $request,
|
||||
INavigationManager $navigationManager,
|
||||
IL10N $l,
|
||||
IConfig $config,
|
||||
EncryptionManager $encryptionManager,
|
||||
IUserManager $userManager,
|
||||
IDBConnection $db,
|
||||
ISettingsManager $settingsManager
|
||||
) {
|
||||
parent::__construct($appName, $request);
|
||||
|
@ -79,10 +73,10 @@ class AdminSettingsController extends Controller {
|
|||
return new TemplateResponse('settings', 'admin/frame', $templateParams);
|
||||
}
|
||||
|
||||
public function form() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $section
|
||||
* @return array
|
||||
*/
|
||||
private function getSettings($section) {
|
||||
$html = '';
|
||||
$settings = $this->settingsManager->getAdminSettings($section);
|
||||
|
@ -99,6 +93,9 @@ class AdminSettingsController extends Controller {
|
|||
return ['content' => $html];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool|string
|
||||
*/
|
||||
private function getLegacyForms() {
|
||||
$forms = \OC_App::getForms('admin');
|
||||
|
||||
|
@ -133,6 +130,7 @@ class AdminSettingsController extends Controller {
|
|||
private function getNavigationParameters($currentSection) {
|
||||
$sections = $this->settingsManager->getAdminSections();
|
||||
$templateParameters = [];
|
||||
/** @var \OC\Settings\Section[] $prioritizedSections */
|
||||
foreach($sections as $prioritizedSections) {
|
||||
foreach ($prioritizedSections as $section) {
|
||||
$templateParameters[] = [
|
||||
|
|
|
@ -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'));
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
@ -55,6 +56,8 @@ class CheckSetupControllerTest extends TestCase {
|
|||
private $util;
|
||||
/** @var IL10N */
|
||||
private $l10n;
|
||||
/** @var ILogger */
|
||||
private $logger;
|
||||
/** @var Checker */
|
||||
private $checker;
|
||||
|
||||
|
@ -82,6 +85,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',
|
||||
|
@ -92,6 +96,7 @@ class CheckSetupControllerTest extends TestCase {
|
|||
$this->util,
|
||||
$this->l10n,
|
||||
$this->checker,
|
||||
$this->logger
|
||||
])
|
||||
->setMethods(['getCurlVersion', 'isPhpOutdated'])->getMock();
|
||||
}
|
||||
|
@ -366,7 +371,8 @@ class CheckSetupControllerTest extends TestCase {
|
|||
$this->urlGenerator,
|
||||
$this->util,
|
||||
$this->l10n,
|
||||
$this->checker
|
||||
$this->checker,
|
||||
$this->logger
|
||||
])
|
||||
->setMethods(null)->getMock();
|
||||
|
||||
|
@ -605,7 +611,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');
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
}
|
|
@ -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'));
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue