From ceeb44bd04f2606bea4c94107850157719127581 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Mon, 8 Aug 2016 23:31:26 +0200 Subject: Initial work on Apps page split: * interfaces for the Admin settings (IAdmin) and section (ISection) * SettingsManager service * example setup with LDAP app --- apps/user_ldap/appinfo/info.xml | 7 +- apps/user_ldap/lib/Settings/Admin.php | 115 ++++++++++++++++++++++++++++++++ apps/user_ldap/lib/Settings/Section.php | 67 +++++++++++++++++++ 3 files changed, 188 insertions(+), 1 deletion(-) create mode 100644 apps/user_ldap/lib/Settings/Admin.php create mode 100644 apps/user_ldap/lib/Settings/Section.php (limited to 'apps/user_ldap') diff --git a/apps/user_ldap/appinfo/info.xml b/apps/user_ldap/appinfo/info.xml index b0984dcf624..dac4f62879d 100644 --- a/apps/user_ldap/appinfo/info.xml +++ b/apps/user_ldap/appinfo/info.xml @@ -9,7 +9,7 @@ A user logs into ownCloud with their LDAP or AD credentials, and is granted acce AGPL Dominik Schmidt and Arthur Schiwon - 1.1.0 + 1.1.1 @@ -27,4 +27,9 @@ A user logs into ownCloud with their LDAP or AD credentials, and is granted acce OCA\User_LDAP\Jobs\UpdateGroups OCA\User_LDAP\Jobs\CleanUp + + + \OCA\User_LDAP\Settings\Admin + \OCA\User_LDAP\Settings\Section + diff --git a/apps/user_ldap/lib/Settings/Admin.php b/apps/user_ldap/lib/Settings/Admin.php new file mode 100644 index 00000000000..11e2627dedd --- /dev/null +++ b/apps/user_ldap/lib/Settings/Admin.php @@ -0,0 +1,115 @@ + + * + * @author Arthur Schiwon + * + * @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 . + * + */ + +namespace OCA\User_LDAP\Settings; + + +use OCA\User_LDAP\Configuration; +use OCA\User_LDAP\Helper; +use OCP\IL10N; +use OCP\Settings\IAdmin; +use OCP\Template; + +class Admin implements IAdmin { + + /** @var IL10N */ + private $l; + + public function __construct(IL10N $l) { + $this->l = $l; + } + + /** + * @return Template all parameters are supposed to be assigned + */ + public function render() { + $settings = new Template('user_ldap', 'settings'); + + $helper = new Helper(); + $prefixes = $helper->getServerConfigurationPrefixes(); + $hosts = $helper->getServerConfigurationHosts(); + + $wizardHtml = ''; + $toc = []; + + $wControls = new Template('user_ldap', 'part.wizardcontrols'); + $wControls = $wControls->fetchPage(); + $sControls = new Template('user_ldap', 'part.settingcontrols'); + $sControls = $sControls->fetchPage(); + + $wizTabs = [ + ['tpl' => 'part.wizard-server', 'cap' => $this->l->t('Server')], + ['tpl' => 'part.wizard-userfilter', 'cap' => $this->l->t('Users')], + ['tpl' => 'part.wizard-loginfilter', 'cap' => $this->l->t('Login Attributes')], + ['tpl' => 'part.wizard-groupfilter', 'cap' => $this->l->t('Groups')], + ]; + $wizTabsCount = count($wizTabs); + for($i = 0; $i < $wizTabsCount; $i++) { + $tab = new Template('user_ldap', $wizTabs[$i]['tpl']); + if($i === 0) { + $tab->assign('serverConfigurationPrefixes', $prefixes); + $tab->assign('serverConfigurationHosts', $hosts); + } + $tab->assign('wizardControls', $wControls); + $wizardHtml .= $tab->fetchPage(); + $toc['#ldapWizard'.($i+1)] = $wizTabs[$i]['cap']; + } + + $settings->assign('tabs', $wizardHtml); + $settings->assign('toc', $toc); + $settings->assign('settingControls', $sControls); + + // assign default values + $config = new Configuration('', false); + $defaults = $config->getDefaults(); + foreach($defaults as $key => $default) { + $settings->assign($key.'_default', $default); + } + + return $settings; + } + + /** + * @return string the section ID, e.g. 'sharing' + */ + public function getSection() { + return 'ldap'; + } + + /** + * @return int whether the form should be rather on the top or bottom of + * the admin section. The forms are arranged in ascending order of the + * priority values. It is required to return a value between 0 and 100. + * + * E.g.: 70 + */ + public function getPriority() { + return 5; + } + + private function renderControls() { + $controls = new Template('user_ldap', 'part.settingcontrols'); + return $controls->fetchPage(); + + } +} diff --git a/apps/user_ldap/lib/Settings/Section.php b/apps/user_ldap/lib/Settings/Section.php new file mode 100644 index 00000000000..a10bd7cbb93 --- /dev/null +++ b/apps/user_ldap/lib/Settings/Section.php @@ -0,0 +1,67 @@ + + * + * @author Arthur Schiwon + * + * @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 . + * + */ + +namespace OCA\User_LDAP\Settings; + +use OCP\IL10N; +use OCP\Settings\ISection; + +class Section implements ISection { + /** @var IL10N */ + private $l; + + public function __construct(IL10N $l) { + $this->l = $l; + } + + /** + * returns the ID of the section. It is supposed to be a lower case string, + * e.g. 'ldap' + * + * @returns string + */ + public function getID() { + return 'ldap'; + } + + /** + * returns the translated name as it should be displayed, e.g. 'LDAP / AD + * integration'. Use the L10N service to translate it. + * + * @return string + */ + public function getName() { + return $this->l->t('LDAP / AD Integration'); + } + + /** + * @return int whether the form should be rather on the top or bottom of + * the settings navigation. The sections are arranged in ascending order of + * the priority values. It is required to return a value between 0 and 99. + * + * E.g.: 70 + */ + public function getPriority() { + return 25; + } +} -- cgit v1.2.3 From 518545fc2fc93f31d1885f143a0386c5449679f4 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 9 Aug 2016 23:30:07 +0200 Subject: Fallback for legacy settings. They are placed into Additional Settings --- apps/user_ldap/settings.php | 75 ------------------------- settings/Controller/AdminSettingsController.php | 31 ++++++++++ settings/templates/admin/additional.php | 36 ++++++++++++ 3 files changed, 67 insertions(+), 75 deletions(-) delete mode 100644 apps/user_ldap/settings.php create mode 100644 settings/templates/admin/additional.php (limited to 'apps/user_ldap') diff --git a/apps/user_ldap/settings.php b/apps/user_ldap/settings.php deleted file mode 100644 index f20f873e134..00000000000 --- a/apps/user_ldap/settings.php +++ /dev/null @@ -1,75 +0,0 @@ - - * @author Dominik Schmidt - * @author Joas Schilling - * @author Lukas Reschke - * @author Morris Jobke - * @author Robin Appelman - * @author Robin McCorkell - * @author Volkan Gezer - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * 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, version 3, - * along with this program. If not, see - * - */ - -// fill template -$tmpl = new OCP\Template('user_ldap', 'settings'); - -$helper = new \OCA\User_LDAP\Helper(); -$prefixes = $helper->getServerConfigurationPrefixes(); -$hosts = $helper->getServerConfigurationHosts(); - -$wizardHtml = ''; -$toc = array(); - -$wControls = new OCP\Template('user_ldap', 'part.wizardcontrols'); -$wControls = $wControls->fetchPage(); -$sControls = new OCP\Template('user_ldap', 'part.settingcontrols'); -$sControls = $sControls->fetchPage(); - -$l = \OC::$server->getL10N('user_ldap'); - -$wizTabs = array(); -$wizTabs[] = array('tpl' => 'part.wizard-server', 'cap' => $l->t('Server')); -$wizTabs[] = array('tpl' => 'part.wizard-userfilter', 'cap' => $l->t('Users')); -$wizTabs[] = array('tpl' => 'part.wizard-loginfilter', 'cap' => $l->t('Login Attributes')); -$wizTabs[] = array('tpl' => 'part.wizard-groupfilter', 'cap' => $l->t('Groups')); -$wizTabsCount = count($wizTabs); -for($i = 0; $i < $wizTabsCount; $i++) { - $tab = new OCP\Template('user_ldap', $wizTabs[$i]['tpl']); - if($i === 0) { - $tab->assign('serverConfigurationPrefixes', $prefixes); - $tab->assign('serverConfigurationHosts', $hosts); - } - $tab->assign('wizardControls', $wControls); - $wizardHtml .= $tab->fetchPage(); - $toc['#ldapWizard'.($i+1)] = $wizTabs[$i]['cap']; -} - -$tmpl->assign('tabs', $wizardHtml); -$tmpl->assign('toc', $toc); -$tmpl->assign('settingControls', $sControls); - -// assign default values -$config = new \OCA\User_LDAP\Configuration('', false); -$defaults = $config->getDefaults(); -foreach($defaults as $key => $default) { - $tmpl->assign($key.'_default', $default); -} - -return $tmpl->fetchPage(); diff --git a/settings/Controller/AdminSettingsController.php b/settings/Controller/AdminSettingsController.php index 68707addfe4..b6a6e74705f 100644 --- a/settings/Controller/AdminSettingsController.php +++ b/settings/Controller/AdminSettingsController.php @@ -83,6 +83,10 @@ class AdminSettingsController extends Controller { } private function getSettings($section) { + if($section === 'additional') { + return $this->getLegacyForms(); + } + $settings = $this->settingsManager->getAdminSettings($section); $html = ''; foreach ($settings as $prioritizedSettings) { @@ -95,6 +99,33 @@ class AdminSettingsController extends Controller { return ['content' => $html]; } + private function getLegacyForms() { + $forms = \OC_App::getForms('admin'); + + $forms = array_map(function ($form) { + if (preg_match('%([^>]*)>.*?)%i', $form, $regs)) { + $sectionName = str_replace('', '', $regs[0]); + $sectionName = str_replace('', '', $sectionName); + $anchor = strtolower($sectionName); + $anchor = str_replace(' ', '-', $anchor); + + return array( + 'anchor' => $anchor, + 'section-name' => $sectionName, + 'form' => $form + ); + } + return array( + 'form' => $form + ); + }, $forms); + + $out = new \OCP\Template('settings', 'admin/additional'); + $out->assign('forms', $forms); + + return ['content' => $out->fetchPage()]; + } + private function getNavigationParameters() { $a = 'anchor'; $name = 'section-name'; diff --git a/settings/templates/admin/additional.php b/settings/templates/admin/additional.php new file mode 100644 index 00000000000..c4e70dbddb2 --- /dev/null +++ b/settings/templates/admin/additional.php @@ -0,0 +1,36 @@ + + * + * @author Arthur Schiwon + * + * @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 . + * + */ + +/** @var \OCP\IL10N $l */ +/** @var array $_ */ + +?> + +
+

t('Additional Settings'));?>

+ +
+ +
-- cgit v1.2.3 From 1eb8b951c2eb6388efdd628c878110d78ae4e77d Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 10 Aug 2016 15:21:25 +0200 Subject: more admin page splitup improvements * bump version to ensure tables are created * make updatenotification app use settings api * change IAdmin::render() to getForm() and change return type from Template to TemplateResponse * adjust User_LDAP accordingly, as well as built-in forms * add IDateTimeFormatter to AppFramework/DependencyInjection/DIContainer.php. This is important so that \OC::$server->query() is able to resolve the constructor parameters. We should ensure that all OCP/* stuff that is available from \OC::$server is available here. Kudos to @LukasReschke * make sure apps that have settings info in their info.xml are loaded before triggering adding the settings setup method --- apps/updatenotification/admin.php | 26 -------------- apps/updatenotification/appinfo/info.xml | 6 +++- .../lib/Controller/AdminController.php | 28 ++++++++++++++- apps/user_ldap/appinfo/info.xml | 4 +-- apps/user_ldap/lib/Settings/Admin.php | 40 +++++----------------- apps/user_ldap/templates/settings.php | 29 ++++++++++------ .../DependencyInjection/DIContainer.php | 4 +++ lib/private/Settings/Admin/Encryption.php | 12 +++---- lib/private/Settings/Admin/Logging.php | 12 +++---- lib/private/Settings/Admin/Server.php | 12 +++---- lib/private/Settings/Admin/Sharing.php | 12 +++---- lib/private/Settings/Admin/TipsTricks.php | 12 +++---- lib/private/legacy/app.php | 1 + lib/public/Settings/IAdmin.php | 6 ++-- settings/Controller/AdminSettingsController.php | 4 +-- version.php | 2 +- 16 files changed, 92 insertions(+), 118 deletions(-) delete mode 100644 apps/updatenotification/admin.php (limited to 'apps/user_ldap') diff --git a/apps/updatenotification/admin.php b/apps/updatenotification/admin.php deleted file mode 100644 index 81c7a8fb557..00000000000 --- a/apps/updatenotification/admin.php +++ /dev/null @@ -1,26 +0,0 @@ - - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * 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, version 3, - * along with this program. If not, see - * - */ - -$app = new \OCA\UpdateNotification\AppInfo\Application(); -/** @var OCA\UpdateNotification\Controller\AdminController $controller */ -$controller = $app->getContainer()->query('AdminController'); -return $controller->displayPanel()->render(); diff --git a/apps/updatenotification/appinfo/info.xml b/apps/updatenotification/appinfo/info.xml index 4070e90f221..2fe400a3587 100644 --- a/apps/updatenotification/appinfo/info.xml +++ b/apps/updatenotification/appinfo/info.xml @@ -5,7 +5,7 @@ Displays update notifications for ownCloud and provides the SSO for the updater. AGPL Lukas Reschke - 1.1.0 + 1.1.1 UpdateNotification @@ -15,4 +15,8 @@ OCA\UpdateNotification\Notification\BackgroundJob + + + OCA\UpdateNotification\Controller\AdminController + diff --git a/apps/updatenotification/lib/Controller/AdminController.php b/apps/updatenotification/lib/Controller/AdminController.php index ada04bdd68c..5f137120435 100644 --- a/apps/updatenotification/lib/Controller/AdminController.php +++ b/apps/updatenotification/lib/Controller/AdminController.php @@ -34,8 +34,9 @@ use OCP\IDateTimeFormatter; use OCP\IL10N; use OCP\IRequest; use OCP\Security\ISecureRandom; +use OCP\Settings\IAdmin; -class AdminController extends Controller { +class AdminController extends Controller implements IAdmin { /** @var IJobList */ private $jobList; /** @var ISecureRandom */ @@ -144,4 +145,29 @@ class AdminController extends Controller { return new DataResponse($newToken); } + + /** + * @return TemplateResponse returns the instance with all parameters set, ready to be rendered + */ + public function getForm() { + return $this->displayPanel(); + } + + /** + * @return string the section ID, e.g. 'sharing' + */ + public function getSection() { + return 'server'; + } + + /** + * @return int whether the form should be rather on the top or bottom of + * the admin section. The forms are arranged in ascending order of the + * priority values. It is required to return a value between 0 and 100. + * + * E.g.: 70 + */ + public function getPriority() { + return 5; + } } diff --git a/apps/user_ldap/appinfo/info.xml b/apps/user_ldap/appinfo/info.xml index dac4f62879d..b16824925c0 100644 --- a/apps/user_ldap/appinfo/info.xml +++ b/apps/user_ldap/appinfo/info.xml @@ -29,7 +29,7 @@ A user logs into ownCloud with their LDAP or AD credentials, and is granted acce - \OCA\User_LDAP\Settings\Admin - \OCA\User_LDAP\Settings\Section + OCA\User_LDAP\Settings\Admin + OCA\User_LDAP\Settings\Section diff --git a/apps/user_ldap/lib/Settings/Admin.php b/apps/user_ldap/lib/Settings/Admin.php index 11e2627dedd..f155f1cec8d 100644 --- a/apps/user_ldap/lib/Settings/Admin.php +++ b/apps/user_ldap/lib/Settings/Admin.php @@ -23,9 +23,9 @@ namespace OCA\User_LDAP\Settings; - use OCA\User_LDAP\Configuration; use OCA\User_LDAP\Helper; +use OCP\AppFramework\Http\TemplateResponse; use OCP\IL10N; use OCP\Settings\IAdmin; use OCP\Template; @@ -40,53 +40,31 @@ class Admin implements IAdmin { } /** - * @return Template all parameters are supposed to be assigned + * @return TemplateResponse */ - public function render() { - $settings = new Template('user_ldap', 'settings'); - + public function getForm() { $helper = new Helper(); $prefixes = $helper->getServerConfigurationPrefixes(); $hosts = $helper->getServerConfigurationHosts(); - $wizardHtml = ''; - $toc = []; - $wControls = new Template('user_ldap', 'part.wizardcontrols'); $wControls = $wControls->fetchPage(); $sControls = new Template('user_ldap', 'part.settingcontrols'); $sControls = $sControls->fetchPage(); - $wizTabs = [ - ['tpl' => 'part.wizard-server', 'cap' => $this->l->t('Server')], - ['tpl' => 'part.wizard-userfilter', 'cap' => $this->l->t('Users')], - ['tpl' => 'part.wizard-loginfilter', 'cap' => $this->l->t('Login Attributes')], - ['tpl' => 'part.wizard-groupfilter', 'cap' => $this->l->t('Groups')], - ]; - $wizTabsCount = count($wizTabs); - for($i = 0; $i < $wizTabsCount; $i++) { - $tab = new Template('user_ldap', $wizTabs[$i]['tpl']); - if($i === 0) { - $tab->assign('serverConfigurationPrefixes', $prefixes); - $tab->assign('serverConfigurationHosts', $hosts); - } - $tab->assign('wizardControls', $wControls); - $wizardHtml .= $tab->fetchPage(); - $toc['#ldapWizard'.($i+1)] = $wizTabs[$i]['cap']; - } - - $settings->assign('tabs', $wizardHtml); - $settings->assign('toc', $toc); - $settings->assign('settingControls', $sControls); + $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) { - $settings->assign($key.'_default', $default); + $parameters[$key.'_default'] = $default; } - return $settings; + return new TemplateResponse('user_ldap', 'settings', $parameters); } /** diff --git a/apps/user_ldap/templates/settings.php b/apps/user_ldap/templates/settings.php index a1511071af4..eb4c7b99127 100644 --- a/apps/user_ldap/templates/settings.php +++ b/apps/user_ldap/templates/settings.php @@ -49,6 +49,9 @@ script('user_ldap', [ style('user_ldap', 'settings'); +/** @var \OCP\IL10N $l */ +/** @var array $_ */ + ?>
@@ -56,20 +59,24 @@ style('user_ldap', 'settings');
- '.$l->t('Warning: Apps user_ldap and user_webdavauth are incompatible. You may experience unexpected behavior. Please ask your system administrator to disable one of them.').'

'); - } - if(!function_exists('ldap_connect')) { - print_unescaped('

'.$l->t('Warning: The PHP LDAP module is not installed, the backend will not work. Please ask your system administrator to install it.').'

'); - } - ?> - + '.$l->t('Warning: Apps user_ldap and user_webdavauth are incompatible. You may experience unexpected behavior. Please ask your system administrator to disable one of them.').'

'); + } + if(!function_exists('ldap_connect')) { + print_unescaped('

'.$l->t('Warning: The PHP LDAP module is not installed, the backend will not work. Please ask your system administrator to install it.').'

'); + } + ?> + + + +

t('Connection Settings'));?>

diff --git a/lib/private/AppFramework/DependencyInjection/DIContainer.php b/lib/private/AppFramework/DependencyInjection/DIContainer.php index 66ca59d26e2..5ddfebc2c7f 100644 --- a/lib/private/AppFramework/DependencyInjection/DIContainer.php +++ b/lib/private/AppFramework/DependencyInjection/DIContainer.php @@ -124,6 +124,10 @@ class DIContainer extends SimpleContainer implements IAppContainer { return $this->getServer()->getDateTimeZone(); }); + $this->registerService('OCP\\IDateTimeFormatter', function($c) { + return $this->getServer()->getDateTimeFormatter(); + }); + $this->registerService('OCP\\IDb', function($c) { return $this->getServer()->getDb(); }); diff --git a/lib/private/Settings/Admin/Encryption.php b/lib/private/Settings/Admin/Encryption.php index 38197f71143..331ddf54520 100644 --- a/lib/private/Settings/Admin/Encryption.php +++ b/lib/private/Settings/Admin/Encryption.php @@ -24,9 +24,9 @@ namespace OC\Settings\Admin; use OC\Encryption\Manager; +use OCP\AppFramework\Http\TemplateResponse; use OCP\IUserManager; use OCP\Settings\IAdmin; -use OCP\Template; class Encryption implements IAdmin { /** @var Manager */ @@ -41,9 +41,9 @@ class Encryption implements IAdmin { } /** - * @return Template all parameters are supposed to be assigned + * @return TemplateResponse */ - public function render() { + public function getForm() { $parameters = [ // Encryption API 'encryptionEnabled' => $this->manager->isEnabled(), @@ -51,11 +51,7 @@ class Encryption implements IAdmin { 'externalBackendsEnabled' => count($this->userManager->getBackends()) > 1, ]; - $form = new Template('settings', 'admin/encryption'); - foreach ($parameters as $key => $value) { - $form->assign($key, $value); - } - return $form; + return new TemplateResponse('settings', 'admin/encryption', $parameters, ''); } /** diff --git a/lib/private/Settings/Admin/Logging.php b/lib/private/Settings/Admin/Logging.php index ead55810ec1..b05ea93388d 100644 --- a/lib/private/Settings/Admin/Logging.php +++ b/lib/private/Settings/Admin/Logging.php @@ -24,9 +24,9 @@ namespace OC\Settings\Admin; use OC\Log\File as LogFile; +use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; use OCP\Settings\IAdmin; -use OCP\Template; class Logging implements IAdmin { /** @var IConfig */ @@ -37,9 +37,9 @@ class Logging implements IAdmin { } /** - * @return Template all parameters are supposed to be assigned + * @return TemplateResponse */ - public function render() { + public function getForm() { $logType = $this->config->getSystemValue('log_type', 'file'); $showLog = ($logType === 'file' || $logType === 'owncloud'); @@ -60,11 +60,7 @@ class Logging implements IAdmin { 'showLog' => $showLog, ]; - $form = new Template('settings', 'admin/logging'); - foreach ($parameters as $key => $value) { - $form->assign($key, $value); - } - return $form; + return new TemplateResponse('settings', 'admin/logging', $parameters, ''); } /** diff --git a/lib/private/Settings/Admin/Server.php b/lib/private/Settings/Admin/Server.php index c0f3584c0af..ee2da154da2 100644 --- a/lib/private/Settings/Admin/Server.php +++ b/lib/private/Settings/Admin/Server.php @@ -26,10 +26,10 @@ namespace OC\Settings\Admin; use Doctrine\DBAL\Connection; use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Platforms\SqlitePlatform; +use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; use OCP\IDBConnection; use OCP\Settings\IAdmin; -use OCP\Template; class Server implements IAdmin { @@ -45,9 +45,9 @@ class Server implements IAdmin { } /** - * @return Template all parameters are supposed to be assigned + * @return TemplateResponse */ - public function render() { + public function getForm() { try { if ($this->db->getDatabasePlatform() instanceof SqlitePlatform) { $invalidTransactionIsolationLevel = false; @@ -87,11 +87,7 @@ class Server implements IAdmin { 'mail_smtppassword' => $this->config->getSystemValue('mail_smtppassword', ''), ]; - $form = new Template('settings', 'admin/server'); - foreach ($parameters as $key => $value) { - $form->assign($key, $value); - } - return $form; + return new TemplateResponse('settings', 'admin/server', $parameters, ''); } /** diff --git a/lib/private/Settings/Admin/Sharing.php b/lib/private/Settings/Admin/Sharing.php index 7fefa4008a0..088021f9057 100644 --- a/lib/private/Settings/Admin/Sharing.php +++ b/lib/private/Settings/Admin/Sharing.php @@ -23,9 +23,9 @@ namespace OC\Settings\Admin; +use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; use OCP\Settings\IAdmin; -use OCP\Template; class Sharing implements IAdmin { /** @var IConfig */ @@ -36,9 +36,9 @@ class Sharing implements IAdmin { } /** - * @return Template all parameters are supposed to be assigned + * @return TemplateResponse */ - public function render() { + 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', '')) : ''; @@ -52,11 +52,7 @@ class Sharing implements IAdmin { 'shareExcludedGroupsList' => $excludeGroupsList, ]; - $form = new Template('settings', 'admin/sharing'); - foreach ($parameters as $key => $value) { - $form->assign($key, $value); - } - return $form; + return new TemplateResponse('settings', 'admin/sharing', $parameters, ''); } /** diff --git a/lib/private/Settings/Admin/TipsTricks.php b/lib/private/Settings/Admin/TipsTricks.php index a0465f5e3ca..331c33db1c1 100644 --- a/lib/private/Settings/Admin/TipsTricks.php +++ b/lib/private/Settings/Admin/TipsTricks.php @@ -23,9 +23,9 @@ namespace OC\Settings\Admin; +use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; use OCP\Settings\IAdmin; -use OCP\Template; class TipsTricks implements IAdmin { /** @var IConfig */ @@ -36,20 +36,16 @@ class TipsTricks implements IAdmin { } /** - * @return Template all parameters are supposed to be assigned + * @return TemplateResponse */ - public function render() { + public function getForm() { $databaseOverload = (strpos($this->config->getSystemValue('dbtype'), 'sqlite') !== false); $parameters = [ 'databaseOverload' => $databaseOverload, ]; - $form = new Template('settings', 'admin/tipstricks'); - foreach ($parameters as $key => $value) { - $form->assign($key, $value); - } - return $form; + return new TemplateResponse('settings', 'admin/tipstricks', $parameters, ''); } /** diff --git a/lib/private/legacy/app.php b/lib/private/legacy/app.php index 39f2f1a0efe..bba4f59555e 100644 --- a/lib/private/legacy/app.php +++ b/lib/private/legacy/app.php @@ -1200,6 +1200,7 @@ class OC_App { } self::setupBackgroundJobs($appData['background-jobs']); if(isset($appData['settings']) && is_array($appData['settings'])) { + self::loadApp($appId, false); \OC::$server->getSettingsManager()->setupSettings($appData['settings']); } diff --git a/lib/public/Settings/IAdmin.php b/lib/public/Settings/IAdmin.php index ce52e3da725..74977256a18 100644 --- a/lib/public/Settings/IAdmin.php +++ b/lib/public/Settings/IAdmin.php @@ -23,14 +23,14 @@ namespace OCP\Settings; -use OCP\Template; +use OCP\AppFramework\Http\TemplateResponse; interface IAdmin { /** - * @return Template all parameters are supposed to be assigned + * @return TemplateResponse returns the instance with all parameters set, ready to be rendered */ - public function render(); + public function getForm(); /** * @return string the section ID, e.g. 'sharing' diff --git a/settings/Controller/AdminSettingsController.php b/settings/Controller/AdminSettingsController.php index b6a6e74705f..f27bdd3ec33 100644 --- a/settings/Controller/AdminSettingsController.php +++ b/settings/Controller/AdminSettingsController.php @@ -92,8 +92,8 @@ class AdminSettingsController extends Controller { foreach ($settings as $prioritizedSettings) { foreach ($prioritizedSettings as $setting) { /** @var \OCP\Settings\IAdmin $setting */ - $form = $setting->render(); - $html .= $form->fetchPage(); + $form = $setting->getForm(); + $html .= $form->renderAs('')->render(); } } return ['content' => $html]; diff --git a/version.php b/version.php index e6298ae238f..7787884db7a 100644 --- a/version.php +++ b/version.php @@ -25,7 +25,7 @@ // We only can count up. The 4. digit is only for the internal patchlevel to trigger DB upgrades // between betas, final and RCs. This is _not_ the public version number. Reset minor/patchlevel // when updating major/minor version number. -$OC_Version = array(9, 2, 0, 1); +$OC_Version = array(9, 2, 0, 2); // The human readable string $OC_VersionString = '11.0 alpha'; -- cgit v1.2.3 From 14ddf9d923ba78a9b938d6eb6050d71aaef22ed6 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 11 Aug 2016 14:48:21 +0200 Subject: rename IAdmin to ISettings, the interface is not bound to a specific settings scope --- apps/encryption/lib/Settings/Admin.php | 4 +- .../lib/Controller/AdminController.php | 4 +- apps/user_ldap/lib/Settings/Admin.php | 4 +- lib/private/Settings/Admin/Encryption.php | 4 +- lib/private/Settings/Admin/Logging.php | 4 +- lib/private/Settings/Admin/Server.php | 4 +- lib/private/Settings/Admin/Sharing.php | 4 +- lib/private/Settings/Admin/TipsTricks.php | 4 +- lib/private/Settings/Manager.php | 20 ++++----- lib/public/Settings/IAdmin.php | 48 -------------------- lib/public/Settings/ISettings.php | 51 ++++++++++++++++++++++ settings/Controller/AdminSettingsController.php | 2 +- 12 files changed, 78 insertions(+), 75 deletions(-) delete mode 100644 lib/public/Settings/IAdmin.php create mode 100644 lib/public/Settings/ISettings.php (limited to 'apps/user_ldap') diff --git a/apps/encryption/lib/Settings/Admin.php b/apps/encryption/lib/Settings/Admin.php index 71a365caee1..2faa118e2a2 100644 --- a/apps/encryption/lib/Settings/Admin.php +++ b/apps/encryption/lib/Settings/Admin.php @@ -33,10 +33,10 @@ use OCP\ILogger; use OCP\ISession; use OCP\IUserManager; use OCP\IUserSession; -use OCP\Settings\IAdmin; +use OCP\Settings\ISettings; use OCP\IConfig; -class Admin implements IAdmin { +class Admin implements ISettings { /** @var IL10N */ private $l; diff --git a/apps/updatenotification/lib/Controller/AdminController.php b/apps/updatenotification/lib/Controller/AdminController.php index 5f137120435..3c6ab463059 100644 --- a/apps/updatenotification/lib/Controller/AdminController.php +++ b/apps/updatenotification/lib/Controller/AdminController.php @@ -34,9 +34,9 @@ use OCP\IDateTimeFormatter; use OCP\IL10N; use OCP\IRequest; use OCP\Security\ISecureRandom; -use OCP\Settings\IAdmin; +use OCP\Settings\ISettings; -class AdminController extends Controller implements IAdmin { +class AdminController extends Controller implements ISettings { /** @var IJobList */ private $jobList; /** @var ISecureRandom */ diff --git a/apps/user_ldap/lib/Settings/Admin.php b/apps/user_ldap/lib/Settings/Admin.php index f155f1cec8d..606cfe6cf01 100644 --- a/apps/user_ldap/lib/Settings/Admin.php +++ b/apps/user_ldap/lib/Settings/Admin.php @@ -27,10 +27,10 @@ use OCA\User_LDAP\Configuration; use OCA\User_LDAP\Helper; use OCP\AppFramework\Http\TemplateResponse; use OCP\IL10N; -use OCP\Settings\IAdmin; +use OCP\Settings\ISettings; use OCP\Template; -class Admin implements IAdmin { +class Admin implements ISettings { /** @var IL10N */ private $l; diff --git a/lib/private/Settings/Admin/Encryption.php b/lib/private/Settings/Admin/Encryption.php index 331ddf54520..ceae5aa6d3f 100644 --- a/lib/private/Settings/Admin/Encryption.php +++ b/lib/private/Settings/Admin/Encryption.php @@ -26,9 +26,9 @@ namespace OC\Settings\Admin; use OC\Encryption\Manager; use OCP\AppFramework\Http\TemplateResponse; use OCP\IUserManager; -use OCP\Settings\IAdmin; +use OCP\Settings\ISettings; -class Encryption implements IAdmin { +class Encryption implements ISettings { /** @var Manager */ private $manager; diff --git a/lib/private/Settings/Admin/Logging.php b/lib/private/Settings/Admin/Logging.php index b05ea93388d..3097070577d 100644 --- a/lib/private/Settings/Admin/Logging.php +++ b/lib/private/Settings/Admin/Logging.php @@ -26,9 +26,9 @@ namespace OC\Settings\Admin; use OC\Log\File as LogFile; use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; -use OCP\Settings\IAdmin; +use OCP\Settings\ISettings; -class Logging implements IAdmin { +class Logging implements ISettings { /** @var IConfig */ private $config; diff --git a/lib/private/Settings/Admin/Server.php b/lib/private/Settings/Admin/Server.php index ee2da154da2..4f1edcf4691 100644 --- a/lib/private/Settings/Admin/Server.php +++ b/lib/private/Settings/Admin/Server.php @@ -29,9 +29,9 @@ use Doctrine\DBAL\Platforms\SqlitePlatform; use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; use OCP\IDBConnection; -use OCP\Settings\IAdmin; +use OCP\Settings\ISettings; -class Server implements IAdmin { +class Server implements ISettings { /** @var IDBConnection|Connection */ private $db; diff --git a/lib/private/Settings/Admin/Sharing.php b/lib/private/Settings/Admin/Sharing.php index 088021f9057..d186dbed981 100644 --- a/lib/private/Settings/Admin/Sharing.php +++ b/lib/private/Settings/Admin/Sharing.php @@ -25,9 +25,9 @@ namespace OC\Settings\Admin; use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; -use OCP\Settings\IAdmin; +use OCP\Settings\ISettings; -class Sharing implements IAdmin { +class Sharing implements ISettings { /** @var IConfig */ private $config; diff --git a/lib/private/Settings/Admin/TipsTricks.php b/lib/private/Settings/Admin/TipsTricks.php index 331c33db1c1..217ddacd443 100644 --- a/lib/private/Settings/Admin/TipsTricks.php +++ b/lib/private/Settings/Admin/TipsTricks.php @@ -25,9 +25,9 @@ namespace OC\Settings\Admin; use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; -use OCP\Settings\IAdmin; +use OCP\Settings\ISettings; -class TipsTricks implements IAdmin { +class TipsTricks implements ISettings { /** @var IConfig */ private $config; diff --git a/lib/private/Settings/Manager.php b/lib/private/Settings/Manager.php index fa762003c1d..4c96dd07fde 100644 --- a/lib/private/Settings/Manager.php +++ b/lib/private/Settings/Manager.php @@ -30,7 +30,7 @@ use OCP\IDBConnection; use OCP\IL10N; use OCP\ILogger; use OCP\IUserManager; -use OCP\Settings\IAdmin; +use OCP\Settings\ISettings; use OCP\Settings\IManager; use OCP\Settings\ISection; @@ -119,7 +119,7 @@ class Manager implements IManager { ]); } - private function addAdminSettings(IAdmin $settings) { + private function addAdminSettings(ISettings $settings) { $this->add(self::TABLE_ADMIN_SETTINGS, [ 'class' => get_class($settings), 'section' => $settings->getSection(), @@ -136,7 +136,7 @@ class Manager implements IManager { $query->execute(); } - private function updateAdminSettings(IAdmin $settings) { + private function updateAdminSettings(ISettings $settings) { $this->update( self::TABLE_ADMIN_SETTINGS, 'class', @@ -210,14 +210,14 @@ class Manager implements IManager { } try { - /** @var IAdmin $settings */ + /** @var ISettings $settings */ $settings = $this->query($settingsClassName); } catch (QueryException $e) { // cancel return; } - if(!$settings instanceof IAdmin) { + if(!$settings instanceof ISettings) { $this->log->error( 'Admin section instance must implement \OCP\ISection. Invalid class: {class}', ['class' => $settingsClassName] @@ -283,27 +283,27 @@ class Manager implements IManager { $forms = []; try { if($section === 'server') { - /** @var IAdmin $form */ + /** @var ISettings $form */ $form = new Admin\Server($this->dbc, $this->config); $forms[$form->getPriority()] = [$form]; } if($section === 'encryption') { - /** @var IAdmin $form */ + /** @var ISettings $form */ $form = new Admin\Encryption($this->encryptionManager, $this->userManager); $forms[$form->getPriority()] = [$form]; } if($section === 'sharing') { - /** @var IAdmin $form */ + /** @var ISettings $form */ $form = new Admin\Sharing($this->config); $forms[$form->getPriority()] = [$form]; } if($section === 'logging') { - /** @var IAdmin $form */ + /** @var ISettings $form */ $form = new Admin\Logging($this->config); $forms[$form->getPriority()] = [$form]; } if($section === 'tips-tricks') { - /** @var IAdmin $form */ + /** @var ISettings $form */ $form = new Admin\TipsTricks($this->config); $forms[$form->getPriority()] = [$form]; } diff --git a/lib/public/Settings/IAdmin.php b/lib/public/Settings/IAdmin.php deleted file mode 100644 index 74977256a18..00000000000 --- a/lib/public/Settings/IAdmin.php +++ /dev/null @@ -1,48 +0,0 @@ - - * - * @author Arthur Schiwon - * - * @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 . - * - */ - -namespace OCP\Settings; - -use OCP\AppFramework\Http\TemplateResponse; - -interface IAdmin { - - /** - * @return TemplateResponse returns the instance with all parameters set, ready to be rendered - */ - public function getForm(); - - /** - * @return string the section ID, e.g. 'sharing' - */ - public function getSection(); - - /** - * @return int whether the form should be rather on the top or bottom of - * the admin section. The forms are arranged in ascending order of the - * priority values. It is required to return a value between 0 and 100. - * - * E.g.: 70 - */ - public function getPriority(); -} diff --git a/lib/public/Settings/ISettings.php b/lib/public/Settings/ISettings.php new file mode 100644 index 00000000000..07d265a533e --- /dev/null +++ b/lib/public/Settings/ISettings.php @@ -0,0 +1,51 @@ + + * + * @author Arthur Schiwon + * + * @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 . + * + */ + +namespace OCP\Settings; + +use OCP\AppFramework\Http\TemplateResponse; + +interface ISettings { + + /** + * @return TemplateResponse returns the instance with all parameters set, ready to be rendered + * @since 9.1 + */ + public function getForm(); + + /** + * @return string the section ID, e.g. 'sharing' + * @since 9.1 + */ + public function getSection(); + + /** + * @return int whether the form should be rather on the top or bottom of + * the admin section. The forms are arranged in ascending order of the + * priority values. It is required to return a value between 0 and 100. + * + * E.g.: 70 + * @since 9.1 + */ + public function getPriority(); +} diff --git a/settings/Controller/AdminSettingsController.php b/settings/Controller/AdminSettingsController.php index f27bdd3ec33..271aa05265b 100644 --- a/settings/Controller/AdminSettingsController.php +++ b/settings/Controller/AdminSettingsController.php @@ -91,7 +91,7 @@ class AdminSettingsController extends Controller { $html = ''; foreach ($settings as $prioritizedSettings) { foreach ($prioritizedSettings as $setting) { - /** @var \OCP\Settings\IAdmin $setting */ + /** @var \OCP\Settings\ISettings $setting */ $form = $setting->getForm(); $html .= $form->renderAs('')->render(); } -- cgit v1.2.3 From c0a2a1ff64633bc2a15e4f2fa28b57f708616255 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 11 Aug 2016 18:40:19 +0200 Subject: superfluous --- apps/user_ldap/appinfo/app.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'apps/user_ldap') diff --git a/apps/user_ldap/appinfo/app.php b/apps/user_ldap/appinfo/app.php index 10cc003a3f5..caacbea5619 100644 --- a/apps/user_ldap/appinfo/app.php +++ b/apps/user_ldap/appinfo/app.php @@ -27,8 +27,6 @@ * */ -OCP\App::registerAdmin('user_ldap', 'settings'); - $helper = new \OCA\User_LDAP\Helper(); $configPrefixes = $helper->getServerConfigurationPrefixes(true); $ldapWrapper = new OCA\User_LDAP\LDAP(); -- cgit v1.2.3 From 7a2b96c7e65eaaf58e0ad77b91532df0a2b6da5d Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Sat, 13 Aug 2016 00:06:10 +0200 Subject: change casing in section display names --- apps/files/lib/Settings/Section.php | 2 +- apps/user_ldap/lib/Settings/Section.php | 2 +- lib/private/Settings/Manager.php | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'apps/user_ldap') diff --git a/apps/files/lib/Settings/Section.php b/apps/files/lib/Settings/Section.php index 2323870cf97..0a1ddcab6fd 100644 --- a/apps/files/lib/Settings/Section.php +++ b/apps/files/lib/Settings/Section.php @@ -51,7 +51,7 @@ class Section implements ISection { * @return string */ public function getName() { - return $this->l->t('Files & Storages'); + return $this->l->t('Files & storages'); } /** diff --git a/apps/user_ldap/lib/Settings/Section.php b/apps/user_ldap/lib/Settings/Section.php index a10bd7cbb93..82d8d0c84fa 100644 --- a/apps/user_ldap/lib/Settings/Section.php +++ b/apps/user_ldap/lib/Settings/Section.php @@ -51,7 +51,7 @@ class Section implements ISection { * @return string */ public function getName() { - return $this->l->t('LDAP / AD Integration'); + return $this->l->t('LDAP / AD integration'); } /** diff --git a/lib/private/Settings/Manager.php b/lib/private/Settings/Manager.php index 7e22d0a3b8c..4b1b5befb21 100644 --- a/lib/private/Settings/Manager.php +++ b/lib/private/Settings/Manager.php @@ -260,13 +260,13 @@ class Manager implements IManager { // built-in sections $sections = [ - 0 => [new Section('server', $this->l->t('Server Settings'), 0)], + 0 => [new Section('server', $this->l->t('Server settings'), 0)], 5 => [new Section('sharing', $this->l->t('Sharing'), 0)], 15 => [new Section('collaboration', $this->l->t('Collaboration'), 0)], 45 => [new Section('encryption', $this->l->t('Encryption'), 0)], 90 => [new Section('logging', $this->l->t('Logging'), 0)], - 98 => [new Section('additional', $this->l->t('Additional Settings'), 0)], - 99 => [new Section('tips-tricks', $this->l->t('Tips & Tricks'), 0)], + 98 => [new Section('additional', $this->l->t('Additional settings'), 0)], + 99 => [new Section('tips-tricks', $this->l->t('Tips & tricks'), 0)], ]; $result = $query->execute(); -- cgit v1.2.3 From 8a7a0f328746230dd896ccc53b3ada271a91b930 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Mon, 15 Aug 2016 16:24:56 +0200 Subject: Add unit tests --- apps/encryption/tests/Settings/AdminTest.php | 100 ++++++++++ .../tests/Settings/AdminTest.php | 84 ++++++++ apps/federation/tests/Settings/AdminTest.php | 70 +++++++ apps/files/tests/Settings/AdminTest.php | 83 ++++++++ apps/files_external/tests/Settings/AdminTest.php | 109 ++++++++++ apps/files_external/tests/Settings/SectionTest.php | 62 ++++++ apps/systemtags/tests/Settings/AdminTest.php | 52 +++++ apps/theming/lib/Settings/Admin.php | 9 +- .../tests/Controller/ThemingControllerTest.php | 1 + apps/theming/tests/Settings/AdminTest.php | 155 +++++++++++++++ apps/theming/tests/Settings/SectionTest.php | 62 ++++++ .../tests/Controller/AdminControllerTest.php | 25 ++- apps/user_ldap/lib/Settings/Admin.php | 10 +- apps/user_ldap/tests/Settings/AdminTest.php | 90 +++++++++ apps/user_ldap/tests/Settings/SectionTest.php | 62 ++++++ lib/private/Settings/Admin/Additional.php | 4 +- lib/private/Settings/Admin/Encryption.php | 4 + lib/private/Settings/Admin/Logging.php | 3 + lib/private/Settings/Admin/Server.php | 15 +- lib/private/Settings/Admin/Sharing.php | 8 +- lib/private/Settings/Admin/TipsTricks.php | 3 + lib/private/Settings/Manager.php | 36 ++-- lib/private/Settings/Section.php | 10 +- settings/Controller/AdminSettingsController.php | 32 ++- tests/Core/Templates/TemplatesTest.php | 2 +- .../Controller/AdminSettingsControllerTest.php | 72 +++++++ .../Controller/CheckSetupControllerTest.php | 10 +- tests/lib/Settings/Admin/AdditionalTest.php | 127 ++++++++++++ tests/lib/Settings/Admin/EncryptionTest.php | 128 ++++++++++++ tests/lib/Settings/Admin/LoggingTest.php | 91 +++++++++ tests/lib/Settings/Admin/ServerTest.php | 154 +++++++++++++++ tests/lib/Settings/Admin/SharingTest.php | 151 ++++++++++++++ tests/lib/Settings/Admin/TipsTricksTest.php | 91 +++++++++ tests/lib/Settings/ManagerTest.php | 220 +++++++++++++++++++++ tests/lib/Settings/SectionTest.php | 39 ++++ 35 files changed, 2107 insertions(+), 67 deletions(-) create mode 100644 apps/encryption/tests/Settings/AdminTest.php create mode 100644 apps/federatedfilesharing/tests/Settings/AdminTest.php create mode 100644 apps/federation/tests/Settings/AdminTest.php create mode 100644 apps/files/tests/Settings/AdminTest.php create mode 100644 apps/files_external/tests/Settings/AdminTest.php create mode 100644 apps/files_external/tests/Settings/SectionTest.php create mode 100644 apps/systemtags/tests/Settings/AdminTest.php create mode 100644 apps/theming/tests/Settings/AdminTest.php create mode 100644 apps/theming/tests/Settings/SectionTest.php create mode 100644 apps/user_ldap/tests/Settings/AdminTest.php create mode 100644 apps/user_ldap/tests/Settings/SectionTest.php create mode 100644 tests/Settings/Controller/AdminSettingsControllerTest.php create mode 100644 tests/lib/Settings/Admin/AdditionalTest.php create mode 100644 tests/lib/Settings/Admin/EncryptionTest.php create mode 100644 tests/lib/Settings/Admin/LoggingTest.php create mode 100644 tests/lib/Settings/Admin/ServerTest.php create mode 100644 tests/lib/Settings/Admin/SharingTest.php create mode 100644 tests/lib/Settings/Admin/TipsTricksTest.php create mode 100644 tests/lib/Settings/ManagerTest.php create mode 100644 tests/lib/Settings/SectionTest.php (limited to 'apps/user_ldap') diff --git a/apps/encryption/tests/Settings/AdminTest.php b/apps/encryption/tests/Settings/AdminTest.php new file mode 100644 index 00000000000..5b0b577e058 --- /dev/null +++ b/apps/encryption/tests/Settings/AdminTest.php @@ -0,0 +1,100 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ + +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()); + } +} diff --git a/apps/federatedfilesharing/tests/Settings/AdminTest.php b/apps/federatedfilesharing/tests/Settings/AdminTest.php new file mode 100644 index 00000000000..e082e7bff23 --- /dev/null +++ b/apps/federatedfilesharing/tests/Settings/AdminTest.php @@ -0,0 +1,84 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ + +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()); + } +} diff --git a/apps/federation/tests/Settings/AdminTest.php b/apps/federation/tests/Settings/AdminTest.php new file mode 100644 index 00000000000..78cb7201dcd --- /dev/null +++ b/apps/federation/tests/Settings/AdminTest.php @@ -0,0 +1,70 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ + +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()); + } +} diff --git a/apps/files/tests/Settings/AdminTest.php b/apps/files/tests/Settings/AdminTest.php new file mode 100644 index 00000000000..c536377af93 --- /dev/null +++ b/apps/files/tests/Settings/AdminTest.php @@ -0,0 +1,83 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ + +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()); + } +} diff --git a/apps/files_external/tests/Settings/AdminTest.php b/apps/files_external/tests/Settings/AdminTest.php new file mode 100644 index 00000000000..1918e800c9b --- /dev/null +++ b/apps/files_external/tests/Settings/AdminTest.php @@ -0,0 +1,109 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ + +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()); + } +} diff --git a/apps/files_external/tests/Settings/SectionTest.php b/apps/files_external/tests/Settings/SectionTest.php new file mode 100644 index 00000000000..9ab456fe307 --- /dev/null +++ b/apps/files_external/tests/Settings/SectionTest.php @@ -0,0 +1,62 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ + +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()); + } +} diff --git a/apps/systemtags/tests/Settings/AdminTest.php b/apps/systemtags/tests/Settings/AdminTest.php new file mode 100644 index 00000000000..b1faf82cf25 --- /dev/null +++ b/apps/systemtags/tests/Settings/AdminTest.php @@ -0,0 +1,52 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ + +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()); + } +} diff --git a/apps/theming/lib/Settings/Admin.php b/apps/theming/lib/Settings/Admin.php index 8aba4696e00..1f79449e658 100644 --- a/apps/theming/lib/Settings/Admin.php +++ b/apps/theming/lib/Settings/Admin.php @@ -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; diff --git a/apps/theming/tests/Controller/ThemingControllerTest.php b/apps/theming/tests/Controller/ThemingControllerTest.php index 2662cb16e0f..688e3d62bff 100644 --- a/apps/theming/tests/Controller/ThemingControllerTest.php +++ b/apps/theming/tests/Controller/ThemingControllerTest.php @@ -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 */ diff --git a/apps/theming/tests/Settings/AdminTest.php b/apps/theming/tests/Settings/AdminTest.php new file mode 100644 index 00000000000..ff42c6997a6 --- /dev/null +++ b/apps/theming/tests/Settings/AdminTest.php @@ -0,0 +1,155 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ + +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()); + } +} diff --git a/apps/theming/tests/Settings/SectionTest.php b/apps/theming/tests/Settings/SectionTest.php new file mode 100644 index 00000000000..e8a9a217f1f --- /dev/null +++ b/apps/theming/tests/Settings/SectionTest.php @@ -0,0 +1,62 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ + +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()); + } +} diff --git a/apps/updatenotification/tests/Controller/AdminControllerTest.php b/apps/updatenotification/tests/Controller/AdminControllerTest.php index 0343542ef41..a4398715885 100644 --- a/apps/updatenotification/tests/Controller/AdminControllerTest.php +++ b/apps/updatenotification/tests/Controller/AdminControllerTest.php @@ -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()); + } } diff --git a/apps/user_ldap/lib/Settings/Admin.php b/apps/user_ldap/lib/Settings/Admin.php index 606cfe6cf01..ca7db66c788 100644 --- a/apps/user_ldap/lib/Settings/Admin.php +++ b/apps/user_ldap/lib/Settings/Admin.php @@ -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(); - - } } diff --git a/apps/user_ldap/tests/Settings/AdminTest.php b/apps/user_ldap/tests/Settings/AdminTest.php new file mode 100644 index 00000000000..e92684f3ce4 --- /dev/null +++ b/apps/user_ldap/tests/Settings/AdminTest.php @@ -0,0 +1,90 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ + +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()); + } +} diff --git a/apps/user_ldap/tests/Settings/SectionTest.php b/apps/user_ldap/tests/Settings/SectionTest.php new file mode 100644 index 00000000000..b5b1f97ce3c --- /dev/null +++ b/apps/user_ldap/tests/Settings/SectionTest.php @@ -0,0 +1,62 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ + +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()); + } +} diff --git a/lib/private/Settings/Admin/Additional.php b/lib/private/Settings/Admin/Additional.php index 106f0f65b8a..d133e4737a7 100644 --- a/lib/private/Settings/Admin/Additional.php +++ b/lib/private/Settings/Admin/Additional.php @@ -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; } diff --git a/lib/private/Settings/Admin/Encryption.php b/lib/private/Settings/Admin/Encryption.php index ceae5aa6d3f..69c6bd17f03 100644 --- a/lib/private/Settings/Admin/Encryption.php +++ b/lib/private/Settings/Admin/Encryption.php @@ -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; diff --git a/lib/private/Settings/Admin/Logging.php b/lib/private/Settings/Admin/Logging.php index 3097070577d..407248ac4b1 100644 --- a/lib/private/Settings/Admin/Logging.php +++ b/lib/private/Settings/Admin/Logging.php @@ -32,6 +32,9 @@ class Logging implements ISettings { /** @var IConfig */ private $config; + /** + * @param IConfig $config + */ public function __construct(IConfig $config) { $this->config = $config; } diff --git a/lib/private/Settings/Admin/Server.php b/lib/private/Settings/Admin/Server.php index 20c3a6d7557..6b381ab48ed 100644 --- a/lib/private/Settings/Admin/Server.php +++ b/lib/private/Settings/Admin/Server.php @@ -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; diff --git a/lib/private/Settings/Admin/Sharing.php b/lib/private/Settings/Admin/Sharing.php index d186dbed981..e110a3d81b7 100644 --- a/lib/private/Settings/Admin/Sharing.php +++ b/lib/private/Settings/Admin/Sharing.php @@ -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 diff --git a/lib/private/Settings/Admin/TipsTricks.php b/lib/private/Settings/Admin/TipsTricks.php index 217ddacd443..fd0fd595844 100644 --- a/lib/private/Settings/Admin/TipsTricks.php +++ b/lib/private/Settings/Admin/TipsTricks.php @@ -31,6 +31,9 @@ class TipsTricks implements ISettings { /** @var IConfig */ private $config; + /** + * @param IConfig $config + */ public function __construct(IConfig $config) { $this->config = $config; } diff --git a/lib/private/Settings/Manager.php b/lib/private/Settings/Manager.php index fd360ede7f0..1304a60949e 100644 --- a/lib/private/Settings/Manager.php +++ b/lib/private/Settings/Manager.php @@ -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; } - - } diff --git a/lib/private/Settings/Section.php b/lib/private/Settings/Section.php index 2ea614b365e..b3cf242279f 100644 --- a/lib/private/Settings/Section.php +++ b/lib/private/Settings/Section.php @@ -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; diff --git a/settings/Controller/AdminSettingsController.php b/settings/Controller/AdminSettingsController.php index 3954497443b..ef70caf5690 100644 --- a/settings/Controller/AdminSettingsController.php +++ b/settings/Controller/AdminSettingsController.php @@ -3,6 +3,7 @@ * @copyright Copyright (c) 2016 Arthur Schiwon * * @author Arthur Schiwon + * @author Lukas Reschke * * @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[] = [ 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 = ""; + $expectedHtml = ""; $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 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ +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 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ + +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 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ + +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 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ + +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 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ + +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 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ + +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 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ + +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 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ + +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 @@ + + * + * @author Lukas Reschke + * + * @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 . + * + */ + +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()); + } +} -- cgit v1.2.3 From 7ffb7b0d846241c8cc6b45a3c85b2374c6d026ae Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Mon, 15 Aug 2016 16:43:22 +0200 Subject: Use MockBuilder instead of createMock CI uses an older PHPUnit --- apps/encryption/tests/Settings/AdminTest.php | 12 ++++---- .../tests/Settings/AdminTest.php | 2 +- apps/federation/tests/Settings/AdminTest.php | 2 +- apps/files/tests/Settings/AdminTest.php | 4 +-- apps/files_external/tests/Settings/AdminTest.php | 8 ++--- apps/files_external/tests/Settings/SectionTest.php | 2 +- apps/theming/tests/Settings/AdminTest.php | 8 ++--- apps/theming/tests/Settings/SectionTest.php | 2 +- .../tests/Controller/AdminControllerTest.php | 16 +++++----- apps/user_ldap/tests/Settings/AdminTest.php | 2 +- apps/user_ldap/tests/Settings/SectionTest.php | 2 +- .../Controller/AdminSettingsControllerTest.php | 8 ++--- .../Controller/CheckSetupControllerTest.php | 2 +- tests/lib/Settings/Admin/AdditionalTest.php | 2 +- tests/lib/Settings/Admin/EncryptionTest.php | 4 +-- tests/lib/Settings/Admin/LoggingTest.php | 2 +- tests/lib/Settings/Admin/ServerTest.php | 8 ++--- tests/lib/Settings/Admin/SharingTest.php | 2 +- tests/lib/Settings/Admin/TipsTricksTest.php | 2 +- tests/lib/Settings/ManagerTest.php | 36 +++++++++++----------- 20 files changed, 63 insertions(+), 63 deletions(-) (limited to 'apps/user_ldap') diff --git a/apps/encryption/tests/Settings/AdminTest.php b/apps/encryption/tests/Settings/AdminTest.php index 5b0b577e058..93896585dad 100644 --- a/apps/encryption/tests/Settings/AdminTest.php +++ b/apps/encryption/tests/Settings/AdminTest.php @@ -52,12 +52,12 @@ class AdminTest extends TestCase { 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->l = $this->getMockBuilder('\OCP\IL10N')->getMock(); + $this->logger = $this->getMockBuilder('\OCP\ILogger')->getMock(); + $this->userSession = $this->getMockBuilder('\OCP\IUserSession')->getMock(); + $this->config = $this->getMockBuilder('\OCP\IConfig')->getMock(); + $this->userManager = $this->getMockBuilder('\OCP\IUserManager')->getMock(); + $this->session = $this->getMockBuilder('\OCP\ISession')->getMock(); $this->admin = new Admin( $this->l, diff --git a/apps/federatedfilesharing/tests/Settings/AdminTest.php b/apps/federatedfilesharing/tests/Settings/AdminTest.php index e082e7bff23..60fadca7b56 100644 --- a/apps/federatedfilesharing/tests/Settings/AdminTest.php +++ b/apps/federatedfilesharing/tests/Settings/AdminTest.php @@ -35,7 +35,7 @@ class AdminTest extends TestCase { public function setUp() { parent::setUp(); - $this->federatedShareProvider = $this->createMock('\OCA\FederatedFileSharing\FederatedShareProvider'); + $this->federatedShareProvider = $this->getMockBuilder('\OCA\FederatedFileSharing\FederatedShareProvider')->disableOriginalConstructor()->getMock(); $this->admin = new Admin( $this->federatedShareProvider ); diff --git a/apps/federation/tests/Settings/AdminTest.php b/apps/federation/tests/Settings/AdminTest.php index 78cb7201dcd..758bda6bc5e 100644 --- a/apps/federation/tests/Settings/AdminTest.php +++ b/apps/federation/tests/Settings/AdminTest.php @@ -36,7 +36,7 @@ class AdminTest extends TestCase { public function setUp() { parent::setUp(); - $this->trustedServers = $this->createMock('\OCA\Federation\TrustedServers'); + $this->trustedServers = $this->getMockBuilder('\OCA\Federation\TrustedServers')->disableOriginalConstructor()->getMock(); $this->admin = new Admin( $this->trustedServers ); diff --git a/apps/files/tests/Settings/AdminTest.php b/apps/files/tests/Settings/AdminTest.php index c536377af93..1ab8a992879 100644 --- a/apps/files/tests/Settings/AdminTest.php +++ b/apps/files/tests/Settings/AdminTest.php @@ -40,8 +40,8 @@ class AdminTest extends TestCase { public function setUp() { parent::setUp(); - $this->iniGetWrapper = $this->createMock('\bantu\IniGetWrapper\IniGetWrapper'); - $this->request = $this->createMock('\OCP\IRequest'); + $this->iniGetWrapper = $this->getMockBuilder('\bantu\IniGetWrapper\IniGetWrapper')->disableOriginalConstructor()->getMock(); + $this->request = $this->getMockBuilder('\OCP\IRequest')->getMock(); $this->admin = new Admin( $this->iniGetWrapper, $this->request diff --git a/apps/files_external/tests/Settings/AdminTest.php b/apps/files_external/tests/Settings/AdminTest.php index 1918e800c9b..fdf9680e7c3 100644 --- a/apps/files_external/tests/Settings/AdminTest.php +++ b/apps/files_external/tests/Settings/AdminTest.php @@ -45,10 +45,10 @@ class AdminTest extends TestCase { 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->encryptionManager = $this->getMockBuilder('\OCP\Encryption\IManager')->getMock(); + $this->globalStoragesService = $this->getMockBuilder('\OCA\Files_External\Service\GlobalStoragesService')->disableOriginalConstructor()->getMock(); + $this->backendService = $this->getMockBuilder('\OCA\Files_External\Service\BackendService')->disableOriginalConstructor()->getMock(); + $this->globalAuth = $this->getMockBuilder('\OCA\Files_External\Lib\Auth\Password\GlobalAuth')->disableOriginalConstructor()->getMock(); $this->admin = new Admin( $this->encryptionManager, diff --git a/apps/files_external/tests/Settings/SectionTest.php b/apps/files_external/tests/Settings/SectionTest.php index 9ab456fe307..b5dfb28b382 100644 --- a/apps/files_external/tests/Settings/SectionTest.php +++ b/apps/files_external/tests/Settings/SectionTest.php @@ -35,7 +35,7 @@ class SectionTest extends TestCase { public function setUp() { parent::setUp(); - $this->l = $this->createMock('\OCP\IL10N'); + $this->l = $this->getMockBuilder('\OCP\IL10N')->disableOriginalConstructor()->getMock(); $this->section = new Section( $this->l diff --git a/apps/theming/tests/Settings/AdminTest.php b/apps/theming/tests/Settings/AdminTest.php index ff42c6997a6..18c2064e8ce 100644 --- a/apps/theming/tests/Settings/AdminTest.php +++ b/apps/theming/tests/Settings/AdminTest.php @@ -45,10 +45,10 @@ class AdminTest extends TestCase { 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->config = $this->getMockBuilder('\OCP\IConfig')->getMock(); + $this->l10n = $this->getMockBuilder('\OCP\IL10N')->getMock(); + $this->themingDefaults = $this->getMockBuilder('\OCA\Theming\ThemingDefaults')->disableOriginalConstructor()->getMock(); + $this->urlGenerator = $this->getMockBuilder('\OCP\IURLGenerator')->getMock(); $this->admin = new Admin( $this->config, diff --git a/apps/theming/tests/Settings/SectionTest.php b/apps/theming/tests/Settings/SectionTest.php index e8a9a217f1f..3a3a4375236 100644 --- a/apps/theming/tests/Settings/SectionTest.php +++ b/apps/theming/tests/Settings/SectionTest.php @@ -35,7 +35,7 @@ class SectionTest extends TestCase { public function setUp() { parent::setUp(); - $this->l = $this->createMock('\OCP\IL10N'); + $this->l = $this->getMockBuilder('\OCP\IL10N')->getMock(); $this->section = new Section( $this->l diff --git a/apps/updatenotification/tests/Controller/AdminControllerTest.php b/apps/updatenotification/tests/Controller/AdminControllerTest.php index a4398715885..cf99679e680 100644 --- a/apps/updatenotification/tests/Controller/AdminControllerTest.php +++ b/apps/updatenotification/tests/Controller/AdminControllerTest.php @@ -59,14 +59,14 @@ class AdminControllerTest extends TestCase { public function setUp() { parent::setUp(); - $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->request = $this->getMockBuilder('\\OCP\\IRequest')->getMock(); + $this->jobList = $this->getMockBuilder('\\OCP\\BackgroundJob\\IJobList')->getMock(); + $this->secureRandom = $this->getMockBuilder('\\OCP\\Security\\ISecureRandom')->getMock(); + $this->config = $this->getMockBuilder('\\OCP\\IConfig')->getMock(); + $this->timeFactory = $this->getMockBuilder('\\OCP\\AppFramework\\Utility\\ITimeFactory')->getMock(); + $this->l10n = $this->getMockBuilder('\\OCP\\IL10N')->getMock(); + $this->updateChecker = $this->getMockBuilder('\\OCA\\UpdateNotification\\UpdateChecker')->disableOriginalConstructor()->getMock(); + $this->dateTimeFormatter = $this->getMockBuilder('\\OCP\\IDateTimeFormatter')->getMock(); $this->adminController = new AdminController( 'updatenotification', diff --git a/apps/user_ldap/tests/Settings/AdminTest.php b/apps/user_ldap/tests/Settings/AdminTest.php index e92684f3ce4..4ac5a14f58b 100644 --- a/apps/user_ldap/tests/Settings/AdminTest.php +++ b/apps/user_ldap/tests/Settings/AdminTest.php @@ -43,7 +43,7 @@ class AdminTest extends TestCase { public function setUp() { parent::setUp(); - $this->l10n = $this->createMock('\OCP\IL10N'); + $this->l10n = $this->getMockBuilder('\OCP\IL10N')->getMock(); $this->admin = new Admin( $this->l10n diff --git a/apps/user_ldap/tests/Settings/SectionTest.php b/apps/user_ldap/tests/Settings/SectionTest.php index b5b1f97ce3c..2d2165b8e56 100644 --- a/apps/user_ldap/tests/Settings/SectionTest.php +++ b/apps/user_ldap/tests/Settings/SectionTest.php @@ -35,7 +35,7 @@ class SectionTest extends TestCase { public function setUp() { parent::setUp(); - $this->l = $this->createMock('\OCP\IL10N'); + $this->l = $this->getMockBuilder('\OCP\IL10N')->getMock(); $this->section = new Section( $this->l diff --git a/tests/Settings/Controller/AdminSettingsControllerTest.php b/tests/Settings/Controller/AdminSettingsControllerTest.php index 86950c9aa9d..6c93bca0d68 100644 --- a/tests/Settings/Controller/AdminSettingsControllerTest.php +++ b/tests/Settings/Controller/AdminSettingsControllerTest.php @@ -44,9 +44,9 @@ class AdminSettingsControllerTest extends TestCase { 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->request = $this->getMockBuilder('\OCP\IRequest')->getMock(); + $this->navigationManager = $this->getMockBuilder('\OCP\INavigationManager')->getMock(); + $this->settingsManager = $this->getMockBuilder('\OCP\Settings\IManager')->getMock(); $this->adminSettingsController = new AdminSettingsController( 'settings', @@ -65,7 +65,7 @@ class AdminSettingsControllerTest extends TestCase { ->expects($this->once()) ->method('getAdminSettings') ->with('test') - ->willReturn([5 => new TipsTricks($this->createMock('\OCP\IConfig'))]); + ->willReturn([5 => new TipsTricks($this->getMockBuilder('\OCP\IConfig')->getMock())]); $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 63c8141cedd..770d5a4934e 100644 --- a/tests/Settings/Controller/CheckSetupControllerTest.php +++ b/tests/Settings/Controller/CheckSetupControllerTest.php @@ -98,7 +98,7 @@ class CheckSetupControllerTest extends TestCase { })); $this->checker = $this->getMockBuilder('\OC\IntegrityCheck\Checker') ->disableOriginalConstructor()->getMock(); - $this->logger = $this->createMock('\OCP\ILogger'); + $this->logger = $this->getMockBuilder('\OCP\ILogger')->getMock(); $this->checkSetupController = $this->getMockBuilder('\OC\Settings\Controller\CheckSetupController') ->setConstructorArgs([ 'settings', diff --git a/tests/lib/Settings/Admin/AdditionalTest.php b/tests/lib/Settings/Admin/AdditionalTest.php index 178d7550614..3a99893cf7c 100644 --- a/tests/lib/Settings/Admin/AdditionalTest.php +++ b/tests/lib/Settings/Admin/AdditionalTest.php @@ -36,7 +36,7 @@ class AdditionalTest extends TestCase { public function setUp() { parent::setUp(); - $this->config = $this->createMock('\OCP\IConfig'); + $this->config = $this->getMockBuilder('\OCP\IConfig')->getMock(); $this->admin = new Additional( $this->config diff --git a/tests/lib/Settings/Admin/EncryptionTest.php b/tests/lib/Settings/Admin/EncryptionTest.php index a68b40ae11b..f9763d85c1f 100644 --- a/tests/lib/Settings/Admin/EncryptionTest.php +++ b/tests/lib/Settings/Admin/EncryptionTest.php @@ -39,8 +39,8 @@ class EncryptionTest extends TestCase { public function setUp() { parent::setUp(); - $this->manager = $this->createMock('\OC\Encryption\Manager'); - $this->userManager = $this->createMock('\OCP\IUserManager'); + $this->manager = $this->getMockBuilder('\OC\Encryption\Manager')->disableOriginalConstructor()->getMock(); + $this->userManager = $this->getMockBuilder('\OCP\IUserManager')->getMock(); $this->admin = new Encryption( $this->manager, diff --git a/tests/lib/Settings/Admin/LoggingTest.php b/tests/lib/Settings/Admin/LoggingTest.php index 10a94f1c59c..181553d3894 100644 --- a/tests/lib/Settings/Admin/LoggingTest.php +++ b/tests/lib/Settings/Admin/LoggingTest.php @@ -37,7 +37,7 @@ class LoggingTest extends TestCase { public function setUp() { parent::setUp(); - $this->config = $this->createMock('\OCP\IConfig'); + $this->config = $this->getMockBuilder('\OCP\IConfig')->getMock(); $this->admin = new Logging( $this->config diff --git a/tests/lib/Settings/Admin/ServerTest.php b/tests/lib/Settings/Admin/ServerTest.php index 5a4fa22920f..874422307e0 100644 --- a/tests/lib/Settings/Admin/ServerTest.php +++ b/tests/lib/Settings/Admin/ServerTest.php @@ -46,10 +46,10 @@ class ServerTest extends TestCase { 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->config = $this->getMockBuilder('\OCP\IConfig')->getMock(); + $this->dbConnection = $this->getMockBuilder('\OCP\IDBConnection')->getMock(); + $this->lockingProvider = $this->getMockBuilder('\OCP\Lock\ILockingProvider')->getMock(); + $this->l10n = $this->getMockBuilder('\OCP\IL10N')->getMock(); $this->admin = new Server( $this->dbConnection, diff --git a/tests/lib/Settings/Admin/SharingTest.php b/tests/lib/Settings/Admin/SharingTest.php index 7aec187d372..261e631363a 100644 --- a/tests/lib/Settings/Admin/SharingTest.php +++ b/tests/lib/Settings/Admin/SharingTest.php @@ -36,7 +36,7 @@ class SharingTest extends TestCase { public function setUp() { parent::setUp(); - $this->config = $this->createMock('\OCP\IConfig'); + $this->config = $this->getMockBuilder('\OCP\IConfig')->getMock(); $this->admin = new Sharing( $this->config diff --git a/tests/lib/Settings/Admin/TipsTricksTest.php b/tests/lib/Settings/Admin/TipsTricksTest.php index afa053e8337..0e8857b56d0 100644 --- a/tests/lib/Settings/Admin/TipsTricksTest.php +++ b/tests/lib/Settings/Admin/TipsTricksTest.php @@ -36,7 +36,7 @@ class TipsTrickTest extends TestCase { public function setUp() { parent::setUp(); - $this->config = $this->createMock('\OCP\IConfig'); + $this->config = $this->getMockBuilder('\OCP\IConfig')->getMock(); $this->admin = new TipsTricks( $this->config diff --git a/tests/lib/Settings/ManagerTest.php b/tests/lib/Settings/ManagerTest.php index 01e226225be..cd5100eff6d 100644 --- a/tests/lib/Settings/ManagerTest.php +++ b/tests/lib/Settings/ManagerTest.php @@ -56,13 +56,13 @@ class ManagerTest extends TestCase { 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->logger = $this->getMockBuilder('\OCP\ILogger')->getMock(); + $this->dbConnection = $this->getMockBuilder('\OCP\IDBConnection')->getMock(); + $this->l10n = $this->getMockBuilder('\OCP\IL10N')->getMock(); + $this->config = $this->getMockBuilder('\OCP\IConfig')->getMock(); + $this->encryptionManager = $this->getMockBuilder('\OCP\Encryption\IManager')->getMock(); + $this->userManager = $this->getMockBuilder('\OCP\IUserManager')->getMock(); + $this->lockingProvider = $this->getMockBuilder('\OCP\Lock\ILockingProvider')->getMock(); $this->manager = new Manager( $this->logger, @@ -76,7 +76,7 @@ class ManagerTest extends TestCase { } public function testSetupSettings() { - $qb = $this->createMock('\OCP\DB\QueryBuilder\IQueryBuilder'); + $qb = $this->getMockBuilder('\OCP\DB\QueryBuilder\IQueryBuilder')->getMock(); $qb ->expects($this->once()) ->method('select') @@ -91,12 +91,12 @@ class ManagerTest extends TestCase { ->method('from') ->with('admin_settings') ->willReturn($qb); - $expressionBuilder = $this->createMock('\OCP\DB\QueryBuilder\IExpressionBuilder'); + $expressionBuilder = $this->getMockBuilder('\OCP\DB\QueryBuilder\IExpressionBuilder')->getMock(); $qb ->expects($this->once()) ->method('expr') ->willReturn($expressionBuilder); - $param = $this->createMock('\OCP\DB\QueryBuilder\IParameter'); + $param = $this->getMockBuilder('\OCP\DB\QueryBuilder\IParameter')->getMock(); $qb ->expects($this->once()) ->method('createNamedParameter') @@ -112,13 +112,13 @@ class ManagerTest extends TestCase { ->method('where') ->with('myString') ->willReturn($qb); - $stmt = $this->createMock('\Doctrine\DBAL\Driver\Statement'); + $stmt = $this->getMockBuilder('\Doctrine\DBAL\Driver\Statement')->getMock(); $qb ->expects($this->once()) ->method('execute') ->willReturn($stmt); - $qb1 = $this->createMock('\OCP\DB\QueryBuilder\IQueryBuilder'); + $qb1 = $this->getMockBuilder('\OCP\DB\QueryBuilder\IQueryBuilder')->getMock(); $qb1 ->expects($this->once()) ->method('insert') @@ -135,7 +135,7 @@ class ManagerTest extends TestCase { } public function testGetAdminSections() { - $qb = $this->createMock('\OCP\DB\QueryBuilder\IQueryBuilder'); + $qb = $this->getMockBuilder('\OCP\DB\QueryBuilder\IQueryBuilder')->getMock(); $qb ->expects($this->once()) ->method('select') @@ -146,7 +146,7 @@ class ManagerTest extends TestCase { ->method('from') ->with('admin_sections') ->willReturn($qb); - $stmt = $this->createMock('\Doctrine\DBAL\Driver\Statement'); + $stmt = $this->getMockBuilder('\Doctrine\DBAL\Driver\Statement')->getMock(); $qb ->expects($this->once()) ->method('execute') @@ -171,7 +171,7 @@ class ManagerTest extends TestCase { } public function testGetAdminSettings() { - $qb = $this->createMock('\OCP\DB\QueryBuilder\IQueryBuilder'); + $qb = $this->getMockBuilder('\OCP\DB\QueryBuilder\IQueryBuilder')->getMock(); $qb ->expects($this->once()) ->method('select') @@ -182,12 +182,12 @@ class ManagerTest extends TestCase { ->method('from') ->with('admin_settings') ->willReturn($qb); - $expressionBuilder = $this->createMock('\OCP\DB\QueryBuilder\IExpressionBuilder'); + $expressionBuilder = $this->getMockBuilder('\OCP\DB\QueryBuilder\IExpressionBuilder')->getMock(); $qb ->expects($this->once()) ->method('expr') ->willReturn($expressionBuilder); - $param = $this->createMock('\OCP\DB\QueryBuilder\IParameter'); + $param = $this->getMockBuilder('\OCP\DB\QueryBuilder\IParameter')->getMock(); $qb ->expects($this->once()) ->method('createParameter') @@ -203,7 +203,7 @@ class ManagerTest extends TestCase { ->method('where') ->with('myString') ->willReturn($qb); - $stmt = $this->createMock('\Doctrine\DBAL\Driver\Statement'); + $stmt = $this->getMockBuilder('\Doctrine\DBAL\Driver\Statement')->getMock(); $qb ->expects($this->once()) ->method('execute') -- cgit v1.2.3