diff --git a/apps/encryption/appinfo/app.php b/apps/encryption/appinfo/app.php index 22c35f8791..950166dca2 100644 --- a/apps/encryption/appinfo/app.php +++ b/apps/encryption/appinfo/app.php @@ -31,5 +31,4 @@ $app = new Application([], $encryptionSystemReady); if ($encryptionSystemReady) { $app->registerEncryptionModule(); $app->registerHooks(); - $app->registerSettings(); } diff --git a/apps/encryption/appinfo/info.xml b/apps/encryption/appinfo/info.xml index 36b6774c6e..7cfdc93438 100644 --- a/apps/encryption/appinfo/info.xml +++ b/apps/encryption/appinfo/info.xml @@ -19,7 +19,7 @@ user-encryption admin-encryption - 1.7.0 + 1.7.1 @@ -29,6 +29,7 @@ OCA\Encryption\Settings\Admin + OCA\Encryption\Settings\Personal OCA\Encryption\Command\EnableMasterKey diff --git a/apps/encryption/lib/AppInfo/Application.php b/apps/encryption/lib/AppInfo/Application.php index a43646d86d..56c2dafdab 100644 --- a/apps/encryption/lib/AppInfo/Application.php +++ b/apps/encryption/lib/AppInfo/Application.php @@ -266,9 +266,4 @@ class Application extends \OCP\AppFramework\App { ); } - - public function registerSettings() { - // Register settings scripts - App::registerPersonal('encryption', 'settings/settings-personal'); - } } diff --git a/apps/encryption/lib/Settings/Personal.php b/apps/encryption/lib/Settings/Personal.php new file mode 100644 index 0000000000..5b01c22453 --- /dev/null +++ b/apps/encryption/lib/Settings/Personal.php @@ -0,0 +1,95 @@ + + * + * @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\Encryption\Settings; + + +use OCA\Encryption\Session; +use OCA\Encryption\Util; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\IConfig; +use OCP\IUserSession; +use OCP\Settings\ISettings; + +class Personal implements ISettings { + + /** @var IConfig */ + private $config; + /** @var Session */ + private $session; + /** @var Util */ + private $util; + /** @var IUserSession */ + private $userSession; + + public function __construct(IConfig $config, Session $session, Util $util, IUserSession $userSession) { + $this->config = $config; + $this->session = $session; + $this->util = $util; + $this->userSession = $userSession; + } + + /** + * @return TemplateResponse returns the instance with all parameters set, ready to be rendered + * @since 9.1 + */ + public function getForm() { + $recoveryAdminEnabled = $this->config->getAppValue('encryption', 'recoveryAdminEnabled'); + $privateKeySet = $this->session->isPrivateKeySet(); + + if (!$recoveryAdminEnabled && $privateKeySet) { + return new TemplateResponse('settings', 'settings/empty', [], ''); + } + + $userId = $this->userSession->getUser()->getUID(); + $recoveryEnabledForUser = $this->util->isRecoveryEnabledForUser($userId); + + $parameters = [ + 'recoveryEnabled' => $recoveryAdminEnabled, + 'recoveryEnabledForUser' => $recoveryEnabledForUser, + 'privateKeySet' => $privateKeySet, + 'initialized' => $this->session->getStatus(), + ]; + return new TemplateResponse('encryption', 'settings-personal', $parameters, ''); + } + + /** + * @return string the section ID, e.g. 'sharing' + * @since 9.1 + */ + public function getSection() { + return 'security'; + } + + /** + * @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() { + return 80; + } +} diff --git a/apps/encryption/settings/settings-personal.php b/apps/encryption/settings/settings-personal.php deleted file mode 100644 index 6608340888..0000000000 --- a/apps/encryption/settings/settings-personal.php +++ /dev/null @@ -1,76 +0,0 @@ - - * @author Clark Tomlinson - * @author Thomas Müller - * - * @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 - * - */ - -$session = new \OCA\Encryption\Session(\OC::$server->getSession()); -$userSession = \OC::$server->getUserSession(); - -$template = new OCP\Template('encryption', 'settings-personal'); -$crypt = new \OCA\Encryption\Crypto\Crypt( - \OC::$server->getLogger(), - $userSession, - \OC::$server->getConfig(), - \OC::$server->getL10N('encryption')); - -$util = new \OCA\Encryption\Util( - new \OC\Files\View(), - $crypt, - \OC::$server->getLogger(), - $userSession, - \OC::$server->getConfig(), - \OC::$server->getUserManager()); - -$keyManager = new \OCA\Encryption\KeyManager( - \OC::$server->getEncryptionKeyStorage(), - $crypt, - \OC::$server->getConfig(), - $userSession, - $session, - \OC::$server->getLogger(), $util); - -$user = $userSession->getUser()->getUID(); - -$view = new \OC\Files\View('/'); - - - -$privateKeySet = $session->isPrivateKeySet(); -// did we tried to initialize the keys for this session? -$initialized = $session->getStatus(); - -$recoveryAdminEnabled = \OC::$server->getConfig()->getAppValue('encryption', 'recoveryAdminEnabled'); -$recoveryEnabledForUser = $util->isRecoveryEnabledForUser($user); - -$result = false; - -if ($recoveryAdminEnabled || !$privateKeySet) { - $template->assign('recoveryEnabled', $recoveryAdminEnabled); - $template->assign('recoveryEnabledForUser', $recoveryEnabledForUser); - $template->assign('privateKeySet', $privateKeySet); - $template->assign('initialized', $initialized); - - $result = $template->fetchPage(); -} - -return $result; - diff --git a/apps/federatedfilesharing/appinfo/app.php b/apps/federatedfilesharing/appinfo/app.php index b6a145bcc2..62265ff064 100644 --- a/apps/federatedfilesharing/appinfo/app.php +++ b/apps/federatedfilesharing/appinfo/app.php @@ -26,8 +26,6 @@ use OCA\FederatedFileSharing\Notifier; $app = new \OCA\FederatedFileSharing\AppInfo\Application(); $eventDispatcher = \OC::$server->getEventDispatcher(); -$app->registerSettings(); - $manager = \OC::$server->getNotificationManager(); $manager->registerNotifier(function() { return \OC::$server->query(Notifier::class); diff --git a/apps/federatedfilesharing/appinfo/info.xml b/apps/federatedfilesharing/appinfo/info.xml index aaacf3ec80..ce2e2286be 100644 --- a/apps/federatedfilesharing/appinfo/info.xml +++ b/apps/federatedfilesharing/appinfo/info.xml @@ -6,7 +6,7 @@ AGPL Bjoern Schiessle Roeland Jago Douma - 1.3.0 + 1.3.1 FederatedFileSharing other @@ -14,5 +14,7 @@ OCA\FederatedFileSharing\Settings\Admin + OCA\FederatedFileSharing\Settings\Personal + OCA\FederatedFileSharing\Settings\PersonalSection diff --git a/apps/federatedfilesharing/lib/AppInfo/Application.php b/apps/federatedfilesharing/lib/AppInfo/Application.php index 346d3c4e29..a2e2f76186 100644 --- a/apps/federatedfilesharing/lib/AppInfo/Application.php +++ b/apps/federatedfilesharing/lib/AppInfo/Application.php @@ -69,13 +69,6 @@ class Application extends App { }); } - /** - * register personal and admin settings page - */ - public function registerSettings() { - \OCP\App::registerPersonal('federatedfilesharing', 'settings-personal'); - } - /** * get instance of federated share provider * diff --git a/apps/federatedfilesharing/lib/Settings/Personal.php b/apps/federatedfilesharing/lib/Settings/Personal.php new file mode 100644 index 0000000000..854f5f13ab --- /dev/null +++ b/apps/federatedfilesharing/lib/Settings/Personal.php @@ -0,0 +1,101 @@ + + * + * @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\FederatedFileSharing\Settings; + + +use OCA\FederatedFileSharing\FederatedShareProvider; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\IL10N; +use OCP\IURLGenerator; +use OCP\IUserSession; +use OCP\Settings\ISettings; + +class Personal implements ISettings { + + /** @var FederatedShareProvider */ + private $federatedShareProvider; + /** @var IUserSession */ + private $userSession; + /** @var IL10N */ + private $l; + /** @var IURLGenerator */ + private $urlGenerator; + /** @var \OC_Defaults */ + private $defaults; + + public function __construct( + FederatedShareProvider $federatedShareProvider, # + IUserSession $userSession, + IL10N $l, + IURLGenerator $urlGenerator, + \OC_Defaults $defaults + ) { + $this->federatedShareProvider = $federatedShareProvider; + $this->userSession = $userSession; + $this->l = $l; + $this->urlGenerator = $urlGenerator; + $this->defaults = $defaults; + } + + /** + * @return TemplateResponse returns the instance with all parameters set, ready to be rendered + * @since 9.1 + */ + public function getForm() { + $cloudID = $this->userSession->getUser()->getCloudId(); + $url = 'https://nextcloud.com/federation#' . $cloudID; + + $parameters = [ + 'outgoingServer2serverShareEnabled' => $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(), + 'message_with_URL' => $this->l->t('Share with me through my #Nextcloud Federated Cloud ID, see %s', [$url]), + 'message_without_URL' => $this->l->t('Share with me through my #Nextcloud Federated Cloud ID', [$cloudID]), + 'logoPath' => $this->urlGenerator->imagePath('core', 'logo-icon.svg'), + 'reference' => $url, + 'cloudId' => $cloudID, + 'color' => $this->defaults->getColorPrimary(), + 'textColor' => "#ffffff", + ]; + return new TemplateResponse('federatedfilesharing', 'settings-personal', $parameters, ''); + } + + /** + * @return string the section ID, e.g. 'sharing' + * @since 9.1 + */ + public function getSection() { + return 'sharing'; + } + + /** + * @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() { + return 40; + } +} diff --git a/apps/federatedfilesharing/lib/Settings/PersonalSection.php b/apps/federatedfilesharing/lib/Settings/PersonalSection.php new file mode 100644 index 0000000000..330a4efd7f --- /dev/null +++ b/apps/federatedfilesharing/lib/Settings/PersonalSection.php @@ -0,0 +1,86 @@ + + * + * @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\FederatedFileSharing\Settings; + + +use OCP\IL10N; +use OCP\IURLGenerator; +use OCP\Settings\IIconSection; + +class PersonalSection implements IIconSection { + /** @var IURLGenerator */ + private $urlGenerator; + /** @var IL10N */ + private $l; + + public function __construct(IURLGenerator $urlGenerator, IL10N $l) { + $this->urlGenerator = $urlGenerator; + $this->l = $l; + } + + /** + * returns the relative path to an 16*16 icon describing the section. + * e.g. '/core/img/places/files.svg' + * + * @returns string + * @since 13.0.0 + */ + public function getIcon() { + return $this->urlGenerator->imagePath('core', 'actions/share.svg'); + } + + /** + * returns the ID of the section. It is supposed to be a lower case string, + * e.g. 'ldap' + * + * @returns string + * @since 9.1 + */ + public function getID() { + return 'sharing'; + } + + /** + * returns the translated name as it should be displayed, e.g. 'LDAP / AD + * integration'. Use the L10N service to translate it. + * + * @return string + * @since 9.1 + */ + public function getName() { + return $this->l->t('Sharing'); + } + + /** + * @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 + * @since 9.1 + */ + public function getPriority() { + return 15; + } +} diff --git a/apps/federatedfilesharing/settings-personal.php b/apps/federatedfilesharing/settings-personal.php deleted file mode 100644 index cd22cc1708..0000000000 --- a/apps/federatedfilesharing/settings-personal.php +++ /dev/null @@ -1,72 +0,0 @@ - - * @author Björn Schießle - * @author Jan-Christoph Borchardt - * @author Thomas Müller - * - * @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 - * - */ - -use OCA\FederatedFileSharing\AppInfo\Application; - -\OC_Util::checkLoggedIn(); - -$l = \OC::$server->getL10N('federatedfilesharing'); - -$app = new Application(); -$federatedShareProvider = $app->getFederatedShareProvider(); - -$isIE8 = false; -preg_match('/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $matches); -if (count($matches) > 0 && $matches[1] <= 9) { - $isIE8 = true; -} - -$cloudID = \OC::$server->getUserSession()->getUser()->getCloudId(); -$url = 'https://nextcloud.com/federation#' . $cloudID; -$logoPath = \OC::$server->getURLGenerator()->imagePath('core', 'logo-icon.svg'); -/** @var \OCP\Defaults $theme */ -$theme = \OC::$server->query(\OCP\Defaults::class); -$color = $theme->getColorPrimary(); -$textColor = "#ffffff"; -if(\OC::$server->getAppManager()->isEnabledForUser("theming")) { - $logoPath = $theme->getLogo(); - try { - $util = \OC::$server->query("\OCA\Theming\Util"); - if($util->invertTextColor($color)) { - $textColor = "#000000"; - } - } catch (OCP\AppFramework\QueryException $e) { - - } -} - - -$tmpl = new OCP\Template('federatedfilesharing', 'settings-personal'); -$tmpl->assign('outgoingServer2serverShareEnabled', $federatedShareProvider->isOutgoingServer2serverShareEnabled()); -$tmpl->assign('message_with_URL', $l->t('Share with me through my #Nextcloud Federated Cloud ID, see %s', [$url])); -$tmpl->assign('message_without_URL', $l->t('Share with me through my #Nextcloud Federated Cloud ID', [$cloudID])); -$tmpl->assign('logoPath', $logoPath); -$tmpl->assign('reference', $url); -$tmpl->assign('cloudId', $cloudID); -$tmpl->assign('showShareIT', !$isIE8); -$tmpl->assign('color', $color); -$tmpl->assign('textColor', $textColor); - -return $tmpl->fetchPage(); diff --git a/apps/federatedfilesharing/templates/settings-personal.php b/apps/federatedfilesharing/templates/settings-personal.php index 126daae27d..c6be2a45f1 100644 --- a/apps/federatedfilesharing/templates/settings-personal.php +++ b/apps/federatedfilesharing/templates/settings-personal.php @@ -18,7 +18,6 @@ style('federatedfilesharing', 'settings-personal');
-

t('Share it so your friends can share files with you:')); ?>
+ +

+ diff --git a/settings/templates/settings/personal/sync-clients.php b/settings/templates/settings/personal/sync-clients.php new file mode 100644 index 0000000000..ac76ef4f59 --- /dev/null +++ b/settings/templates/settings/personal/sync-clients.php @@ -0,0 +1,59 @@ + + * + * @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 array $_ */ + +?> + +
+

t('Get the apps to sync your files'));?>

+ + <?php p($l->t('Desktop client'));?> + + + <?php p($l->t('Android app'));?> + + + <?php p($l->t('iOS app'));?> + + +

+ ', + '', + ], + $l->t('If you want to support the project {contributeopen}join development{linkclose} or {contributeopen}spread the word{linkclose}!'))); ?> +

+ + +

t('Show First Run Wizard again'));?>

+ +
diff --git a/tests/Settings/Controller/AdminSettingsControllerTest.php b/tests/Settings/Controller/AdminSettingsControllerTest.php index 6c93bca0d6..51357f67a2 100644 --- a/tests/Settings/Controller/AdminSettingsControllerTest.php +++ b/tests/Settings/Controller/AdminSettingsControllerTest.php @@ -22,7 +22,6 @@ */ namespace Tests\Settings\Controller; - use OC\Settings\Admin\TipsTricks; use OC\Settings\Controller\AdminSettingsController; use OCP\AppFramework\Http\TemplateResponse; @@ -31,6 +30,13 @@ use OCP\IRequest; use OCP\Settings\IManager; use Test\TestCase; +/** + * Class AdminSettingsControllerTest + * + * @group DB + * + * @package Tests\Settings\Controller + */ class AdminSettingsControllerTest extends TestCase { /** @var AdminSettingsController */ private $adminSettingsController; @@ -38,8 +44,10 @@ class AdminSettingsControllerTest extends TestCase { private $request; /** @var INavigationManager */ private $navigationManager; - /** @var IManager */ + /** @var IManager|\PHPUnit_Framework_MockObject_MockObject */ private $settingsManager; + /** @var string */ + private $adminUid = 'lololo'; public function setUp() { parent::setUp(); @@ -54,6 +62,16 @@ class AdminSettingsControllerTest extends TestCase { $this->navigationManager, $this->settingsManager ); + + $user = \OC::$server->getUserManager()->createUser($this->adminUid, 'olo'); + \OC_User::setUserId($user->getUID()); + \OC::$server->getGroupManager()->createGroup('admin')->addUser($user); + } + + public function tearDown() { + \OC::$server->getUserManager()->get($this->adminUid)->delete(); + + parent::tearDown(); } public function testIndex() { @@ -61,12 +79,17 @@ class AdminSettingsControllerTest extends TestCase { ->expects($this->once()) ->method('getAdminSections') ->willReturn([]); + $this->settingsManager + ->expects($this->once()) + ->method('getPersonalSections') + ->willReturn([]); $this->settingsManager ->expects($this->once()) ->method('getAdminSettings') ->with('test') ->willReturn([5 => new TipsTricks($this->getMockBuilder('\OCP\IConfig')->getMock())]); - $expected = new TemplateResponse('settings', 'admin/frame', ['forms' => [], 'content' => '']); + + $expected = new TemplateResponse('settings', 'settings/frame', ['forms' => ['personal' => [], 'admin' => []], 'content' => '']); $this->assertEquals($expected, $this->adminSettingsController->index('test')); } } diff --git a/tests/acceptance/features/access-levels.feature b/tests/acceptance/features/access-levels.feature index 57998899a5..8017029667 100644 --- a/tests/acceptance/features/access-levels.feature +++ b/tests/acceptance/features/access-levels.feature @@ -1,11 +1,10 @@ Feature: access-levels - Scenario: regular users can not see admin-level items in the Settings menu + Scenario: regular users cannot see admin-level items in the Settings menu Given I am logged in When I open the Settings menu Then I see that the Settings menu is shown - And I see that the "Personal" item in the Settings menu is shown - And I see that the "Admin" item in the Settings menu is not shown + And I see that the "Settings" item in the Settings menu is shown And I see that the "Users" item in the Settings menu is not shown And I see that the "Help" item in the Settings menu is shown And I see that the "Log out" item in the Settings menu is shown @@ -14,8 +13,19 @@ Feature: access-levels Given I am logged in as the admin When I open the Settings menu Then I see that the Settings menu is shown - And I see that the "Personal" item in the Settings menu is shown - And I see that the "Admin" item in the Settings menu is shown + And I see that the "Settings" item in the Settings menu is shown And I see that the "Users" item in the Settings menu is shown And I see that the "Help" item in the Settings menu is shown And I see that the "Log out" item in the Settings menu is shown + + Scenario: regular users cannot see admin-level items on the Settings page + Given I am logged in + When I visit the settings page + Then I see that the "Personal" settings panel is shown + And I see that the "Administration" settings panel is not shown + + Scenario: admin users can see admin-level items on the Settings page + Given I am logged in as the admin + When I visit the settings page + Then I see that the "Personal" settings panel is shown + And I see that the "Administration" settings panel is shown diff --git a/tests/acceptance/features/bootstrap/SettingsMenuContext.php b/tests/acceptance/features/bootstrap/SettingsMenuContext.php index 1ff5d94e98..401575c78f 100644 --- a/tests/acceptance/features/bootstrap/SettingsMenuContext.php +++ b/tests/acceptance/features/bootstrap/SettingsMenuContext.php @@ -66,6 +66,15 @@ class SettingsMenuContext implements Context, ActorAwareInterface { describedAs($itemText . " item in Settings menu"); } + /** + * @param string $itemText + * @return Locator + */ + private static function settingsPanelFor($itemText) { + return Locator::forThe()->xpath("//div[@id = 'app-navigation']//ul//li[@class = 'settings-caption' and normalize-space() = '$itemText']")-> + describedAs($itemText . " item in Settings panel"); + } + /** * @When I open the Settings menu */ @@ -82,6 +91,14 @@ class SettingsMenuContext implements Context, ActorAwareInterface { $this->actor->find(self::usersMenuItem(), 2)->click(); } + /** + * @When I visit the settings page + */ + public function iVisitTheSettingsPage() { + $this->iOpenTheSettingsMenu(); + $this->actor->find(self::menuItemFor('Settings'), 2)->click(); + } + /** * @When I log out */ @@ -120,4 +137,25 @@ class SettingsMenuContext implements Context, ActorAwareInterface { } } + /** + * @Then I see that the :itemText settings panel is shown + */ + public function iSeeThatTheItemSettingsPanelIsShown($itemText) { + PHPUnit_Framework_Assert::assertTrue( + $this->actor->find(self::settingsPanelFor($itemText), 10)->isVisible() + ); + } + + /** + * @Then I see that the :itemText settings panel is not shown + */ + public function iSeeThatTheItemSettingsPanelIsNotShown($itemText) { + try { + PHPUnit_Framework_Assert::assertFalse( + $this->actor->find(self::settingsPanelFor($itemText), 10)->isVisible() + ); + } catch (NoSuchElementException $exception) { + } + } + } diff --git a/tests/acceptance/features/core/ElementWrapper.php b/tests/acceptance/features/core/ElementWrapper.php index 6b730903f6..f6ce176817 100644 --- a/tests/acceptance/features/core/ElementWrapper.php +++ b/tests/acceptance/features/core/ElementWrapper.php @@ -119,7 +119,7 @@ class ElementWrapper { /** * Returns whether the wrapped element is visible or not. * - * @return boolbean true if the wrapped element is visible, false otherwise. + * @return bool true if the wrapped element is visible, false otherwise. */ public function isVisible() { $commandCallback = function() { diff --git a/tests/lib/Settings/Admin/AdditionalTest.php b/tests/lib/Settings/Admin/AdditionalTest.php index 420a7110c1..84c63f3aeb 100644 --- a/tests/lib/Settings/Admin/AdditionalTest.php +++ b/tests/lib/Settings/Admin/AdditionalTest.php @@ -97,7 +97,7 @@ class AdditionalTest extends TestCase { $expected = new TemplateResponse( 'settings', - 'admin/additional-mail', + 'settings/admin/additional-mail', [ 'sendmail_is_available' => (bool) \OC_Helper::findBinaryPath('sendmail'), 'mail_domain' => 'mx.nextcloud.com', diff --git a/tests/lib/Settings/Admin/EncryptionTest.php b/tests/lib/Settings/Admin/EncryptionTest.php index a282b059c9..a5f483863e 100644 --- a/tests/lib/Settings/Admin/EncryptionTest.php +++ b/tests/lib/Settings/Admin/EncryptionTest.php @@ -81,7 +81,7 @@ class EncryptionTest extends TestCase { ->willReturn(['entry']); $expected = new TemplateResponse( 'settings', - 'admin/encryption', + 'settings/admin/encryption', [ 'encryptionEnabled' => $enabled, 'encryptionReady' => $enabled, @@ -116,7 +116,7 @@ class EncryptionTest extends TestCase { ->willReturn(['entry', 'entry']); $expected = new TemplateResponse( 'settings', - 'admin/encryption', + 'settings/admin/encryption', [ 'encryptionEnabled' => $enabled, 'encryptionReady' => $enabled, diff --git a/tests/lib/Settings/Admin/ServerTest.php b/tests/lib/Settings/Admin/ServerTest.php index f876ae8513..a71aef0178 100644 --- a/tests/lib/Settings/Admin/ServerTest.php +++ b/tests/lib/Settings/Admin/ServerTest.php @@ -123,7 +123,7 @@ class ServerTest extends TestCase { $envPath = getenv('PATH'); $expected = new TemplateResponse( 'settings', - 'admin/server', + 'settings/admin/server', [ // Diagnosis 'readOnlyConfigEnabled' => \OC_Helper::isReadOnlyConfigEnabled(), diff --git a/tests/lib/Settings/Admin/SharingTest.php b/tests/lib/Settings/Admin/SharingTest.php index 0bf0355968..d9aa14fece 100644 --- a/tests/lib/Settings/Admin/SharingTest.php +++ b/tests/lib/Settings/Admin/SharingTest.php @@ -112,7 +112,7 @@ class SharingTest extends TestCase { $expected = new TemplateResponse( 'settings', - 'admin/sharing', + 'settings/admin/sharing', [ 'allowGroupSharing' => 'yes', 'allowLinks' => 'yes', @@ -205,7 +205,7 @@ class SharingTest extends TestCase { $expected = new TemplateResponse( 'settings', - 'admin/sharing', + 'settings/admin/sharing', [ 'allowGroupSharing' => 'yes', 'allowLinks' => 'yes', diff --git a/tests/lib/Settings/Admin/TipsTricksTest.php b/tests/lib/Settings/Admin/TipsTricksTest.php index 0e8857b56d..cbecd51ed5 100644 --- a/tests/lib/Settings/Admin/TipsTricksTest.php +++ b/tests/lib/Settings/Admin/TipsTricksTest.php @@ -52,7 +52,7 @@ class TipsTrickTest extends TestCase { $expected = new TemplateResponse( 'settings', - 'admin/tipstricks', + 'settings/admin/tipstricks', [ 'databaseOverload' => true, ], @@ -71,7 +71,7 @@ class TipsTrickTest extends TestCase { $expected = new TemplateResponse( 'settings', - 'admin/tipstricks', + 'settings/admin/tipstricks', [ 'databaseOverload' => false, ], diff --git a/tests/lib/Settings/ManagerTest.php b/tests/lib/Settings/ManagerTest.php index 07f7e71fec..6a13b737c8 100644 --- a/tests/lib/Settings/ManagerTest.php +++ b/tests/lib/Settings/ManagerTest.php @@ -23,18 +23,23 @@ namespace Tests\Settings; +use OC\Accounts\AccountManager; use OC\Settings\Admin\Sharing; use OC\Settings\Manager; use OC\Settings\Mapper; +use OC\Settings\Personal\Security; use OC\Settings\Section; +use OCP\App\IAppManager; use OCP\Encryption\IManager; use OCP\IConfig; use OCP\IDBConnection; +use OCP\IGroupManager; use OCP\IL10N; use OCP\ILogger; use OCP\IRequest; use OCP\IURLGenerator; use OCP\IUserManager; +use OCP\L10N\IFactory; use OCP\Lock\ILockingProvider; use Test\TestCase; @@ -61,6 +66,16 @@ class ManagerTest extends TestCase { private $mapper; /** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */ private $url; + /** @var AccountManager|\PHPUnit_Framework_MockObject_MockObject */ + private $accountManager; + /** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject */ + private $groupManager; + /** @var IFactory|\PHPUnit_Framework_MockObject_MockObject */ + private $l10nFactory; + /** @var \OC_Defaults|\PHPUnit_Framework_MockObject_MockObject */ + private $defaults; + /** @var IAppManager */ + private $appManager; public function setUp() { parent::setUp(); @@ -75,6 +90,11 @@ class ManagerTest extends TestCase { $this->request = $this->createMock(IRequest::class); $this->mapper = $this->createMock(Mapper::class); $this->url = $this->createMock(IURLGenerator::class); + $this->accountManager = $this->createMock(AccountManager::class); + $this->groupManager = $this->createMock(IGroupManager::class); + $this->l10nFactory = $this->createMock(IFactory::class); + $this->defaults = $this->createMock(\OC_Defaults::class); + $this->appManager = $this->createMock(IAppManager::class); $this->manager = new Manager( $this->logger, @@ -86,21 +106,40 @@ class ManagerTest extends TestCase { $this->lockingProvider, $this->request, $this->mapper, - $this->url + $this->url, + $this->accountManager, + $this->groupManager, + $this->l10nFactory, + $this->defaults, + $this->appManager ); } - public function testSetupSettingsUpdate() { + public function settingsTypeProvider() { + return [ + ['admin', 'admin_settings'], + ['personal', 'personal_settings'], + ]; + } + + /** + * @dataProvider settingsTypeProvider + * @param string $type + * @param string $table + */ + public function testSetupSettingsUpdate($type, $table) { + $className = 'OCA\Files\Settings\Admin'; + $this->mapper->expects($this->any()) ->method('has') - ->with('admin_settings', 'OCA\Files\Settings\Admin') + ->with($table, $className) ->will($this->returnValue(true)); $this->mapper->expects($this->once()) ->method('update') - ->with('admin_settings', + ->with($table, 'class', - 'OCA\Files\Settings\Admin', [ + $className, [ 'section' => 'additional', 'priority' => 5 ]); @@ -108,19 +147,24 @@ class ManagerTest extends TestCase { ->method('add'); $this->manager->setupSettings([ - 'admin' => 'OCA\Files\Settings\Admin', + $type => $className, ]); } - public function testSetupSettingsAdd() { + /** + * @dataProvider settingsTypeProvider + * @param string $type + * @param string $table + */ + public function testSetupSettingsAdd($type, $table) { $this->mapper->expects($this->any()) ->method('has') - ->with('admin_settings', 'OCA\Files\Settings\Admin') + ->with($table, 'OCA\Files\Settings\Admin') ->will($this->returnValue(false)); $this->mapper->expects($this->once()) ->method('add') - ->with('admin_settings', [ + ->with($table, [ 'class' => 'OCA\Files\Settings\Admin', 'section' => 'additional', 'priority' => 5 @@ -130,7 +174,7 @@ class ManagerTest extends TestCase { ->method('update'); $this->manager->setupSettings([ - 'admin' => 'OCA\Files\Settings\Admin', + $type => 'OCA\Files\Settings\Admin', ]); } @@ -167,6 +211,34 @@ class ManagerTest extends TestCase { ], $this->manager->getAdminSections()); } + public function testGetPersonalSections() { + $this->l10n + ->expects($this->any()) + ->method('t') + ->will($this->returnArgument(0)); + + $this->mapper->expects($this->once()) + ->method('getPersonalSectionsFromDB') + ->will($this->returnValue([ + ['class' => \OCA\WorkflowEngine\Settings\Section::class, 'priority' => 90] + ])); + + $this->url->expects($this->exactly(3)) + ->method('imagePath') + ->willReturnMap([ + ['core', 'actions/info.svg', '1'], + ['settings', 'password.svg', '2'], + ['settings', 'change.svg', '3'], + ]); + + $this->assertArraySubset([ + 0 => [new Section('personal-info', 'Personal info', 0, '1')], + 5 => [new Section('security', 'Security', 0, '2')], + 15 => [new Section('sync-clients', 'Sync clients', 0, '3')], + 90 => [\OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class)], + ], $this->manager->getPersonalSections()); + } + public function testGetAdminSectionsEmptySection() { $this->l10n ->expects($this->any()) @@ -198,6 +270,31 @@ class ManagerTest extends TestCase { ], $this->manager->getAdminSections()); } + public function testGetPersonalSectionsEmptySection() { + $this->l10n + ->expects($this->any()) + ->method('t') + ->will($this->returnArgument(0)); + + $this->mapper->expects($this->once()) + ->method('getPersonalSectionsFromDB') + ->will($this->returnValue([])); + + $this->url->expects($this->exactly(3)) + ->method('imagePath') + ->willReturnMap([ + ['core', 'actions/info.svg', '1'], + ['settings', 'password.svg', '2'], + ['settings', 'change.svg', '3'], + ]); + + $this->assertArraySubset([ + 0 => [new Section('personal-info', 'Personal info', 0, '1')], + 5 => [new Section('security', 'Security', 0, '2')], + 15 => [new Section('sync-clients', 'Sync clients', 0, '3')], + ], $this->manager->getPersonalSections()); + } + public function testGetAdminSettings() { $this->mapper->expects($this->any()) ->method('getAdminSettingsFromDB') @@ -207,4 +304,14 @@ class ManagerTest extends TestCase { 0 => [new Sharing($this->config)], ], $this->manager->getAdminSettings('sharing')); } + + public function testGetPersonalSettings() { + $this->mapper->expects($this->any()) + ->method('getPersonalSettingsFromDB') + ->will($this->returnValue([])); + + $this->assertEquals([ + 10 => [new Security()], + ], $this->manager->getPersonalSettings('security')); + } } diff --git a/version.php b/version.php index e237770c82..d9e26eafce 100644 --- a/version.php +++ b/version.php @@ -26,7 +26,7 @@ // between betas, final and RCs. This is _not_ the public version number. Reset minor/patchlevel // when updating major/minor version number. -$OC_Version = array(13, 0, 0, 0); +$OC_Version = array(13, 0, 0, 1); // The human readable string $OC_VersionString = '13.0.0 alpha';