aboutsummaryrefslogtreecommitdiffstats
path: root/apps/settings/tests/Controller/AdminSettingsControllerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/settings/tests/Controller/AdminSettingsControllerTest.php')
-rw-r--r--apps/settings/tests/Controller/AdminSettingsControllerTest.php88
1 files changed, 43 insertions, 45 deletions
diff --git a/apps/settings/tests/Controller/AdminSettingsControllerTest.php b/apps/settings/tests/Controller/AdminSettingsControllerTest.php
index acdcaa136aa..fbdc506457b 100644
--- a/apps/settings/tests/Controller/AdminSettingsControllerTest.php
+++ b/apps/settings/tests/Controller/AdminSettingsControllerTest.php
@@ -1,40 +1,24 @@
<?php
+
/**
- * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Jan C. Borchardt <hey@jancborchardt.net>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Settings\Tests\Controller;
use OCA\Settings\Controller\AdminSettingsController;
use OCA\Settings\Settings\Personal\ServerDevNotice;
use OCP\AppFramework\Http\TemplateResponse;
+use OCP\AppFramework\Services\IInitialState;
use OCP\Group\ISubAdmin;
use OCP\IGroupManager;
use OCP\INavigationManager;
use OCP\IRequest;
use OCP\IUser;
+use OCP\IUserManager;
use OCP\IUserSession;
+use OCP\Server;
+use OCP\Settings\IDeclarativeManager;
use OCP\Settings\IManager;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
@@ -48,22 +32,17 @@ use Test\TestCase;
*/
class AdminSettingsControllerTest extends TestCase {
- /** @var AdminSettingsController */
- private $adminSettingsController;
- /** @var IRequest|MockObject */
- private $request;
- /** @var INavigationManager|MockObject */
- private $navigationManager;
- /** @var IManager|MockObject */
- private $settingsManager;
- /** @var IUserSession|MockObject */
- private $userSession;
- /** @var IGroupManager|MockObject */
- private $groupManager;
- /** @var ISubAdmin|MockObject */
- private $subAdmin;
- /** @var string */
- private $adminUid = 'lololo';
+ private IRequest&MockObject $request;
+ private INavigationManager&MockObject $navigationManager;
+ private IManager&MockObject $settingsManager;
+ private IUserSession&MockObject $userSession;
+ private IGroupManager&MockObject $groupManager;
+ private ISubAdmin&MockObject $subAdmin;
+ private IDeclarativeManager&MockObject $declarativeSettingsManager;
+ private IInitialState&MockObject $initialState;
+
+ private string $adminUid = 'lololo';
+ private AdminSettingsController $adminSettingsController;
protected function setUp(): void {
parent::setUp();
@@ -74,6 +53,8 @@ class AdminSettingsControllerTest extends TestCase {
$this->userSession = $this->createMock(IUserSession::class);
$this->groupManager = $this->createMock(IGroupManager::class);
$this->subAdmin = $this->createMock(ISubAdmin::class);
+ $this->declarativeSettingsManager = $this->createMock(IDeclarativeManager::class);
+ $this->initialState = $this->createMock(IInitialState::class);
$this->adminSettingsController = new AdminSettingsController(
'settings',
@@ -82,21 +63,27 @@ class AdminSettingsControllerTest extends TestCase {
$this->settingsManager,
$this->userSession,
$this->groupManager,
- $this->subAdmin
+ $this->subAdmin,
+ $this->declarativeSettingsManager,
+ $this->initialState,
);
- $user = \OC::$server->getUserManager()->createUser($this->adminUid, 'mylongrandompassword');
+ $user = Server::get(IUserManager::class)->createUser($this->adminUid, 'mylongrandompassword');
\OC_User::setUserId($user->getUID());
- \OC::$server->getGroupManager()->createGroup('admin')->addUser($user);
+ Server::get(IGroupManager::class)->createGroup('admin')->addUser($user);
}
protected function tearDown(): void {
- \OC::$server->getUserManager()->get($this->adminUid)->delete();
+ Server::get(IUserManager::class)
+ ->get($this->adminUid)
+ ->delete();
+ \OC_User::setUserId(null);
+ Server::get(IUserSession::class)->setUser(null);
parent::tearDown();
}
- public function testIndex() {
+ public function testIndex(): void {
$user = $this->createMock(IUser::class);
$this->userSession
->method('getUser')
@@ -110,6 +97,12 @@ class AdminSettingsControllerTest extends TestCase {
->method('isSubAdmin')
->with($user)
->willReturn(false);
+
+ $form = new TemplateResponse('settings', 'settings/empty');
+ $setting = $this->createMock(ServerDevNotice::class);
+ $setting->expects(self::any())
+ ->method('getForm')
+ ->willReturn($form);
$this->settingsManager
->expects($this->once())
->method('getAdminSections')
@@ -122,7 +115,12 @@ class AdminSettingsControllerTest extends TestCase {
->expects($this->once())
->method('getAllowedAdminSettings')
->with('test')
- ->willReturn([5 => $this->createMock(ServerDevNotice::class)]);
+ ->willReturn([5 => [$setting]]);
+ $this->declarativeSettingsManager
+ ->expects($this->any())
+ ->method('getFormIDs')
+ ->with($user, 'admin', 'test')
+ ->willReturn([]);
$idx = $this->adminSettingsController->index('test');