2016-08-15 17:24:56 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
|
|
|
|
*
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2020-03-31 11:49:10 +03:00
|
|
|
* @author Julius Härtl <jus@bitgrid.net>
|
2016-08-15 17:24:56 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2016-08-15 17:24:56 +03:00
|
|
|
*
|
|
|
|
* @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
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2016-08-15 17:24:56 +03:00
|
|
|
*
|
|
|
|
*/
|
2019-11-22 22:52:10 +03:00
|
|
|
|
2019-09-17 17:33:27 +03:00
|
|
|
namespace OCA\Settings\Tests\Controller;
|
2016-08-15 17:24:56 +03:00
|
|
|
|
2019-09-17 17:33:27 +03:00
|
|
|
use OCA\Settings\Controller\AdminSettingsController;
|
2020-01-30 15:30:45 +03:00
|
|
|
use OCA\Settings\Settings\Personal\ServerDevNotice;
|
2016-08-15 17:24:56 +03:00
|
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
2019-05-22 11:48:51 +03:00
|
|
|
use OCP\Group\ISubAdmin;
|
|
|
|
use OCP\IGroupManager;
|
2016-08-15 17:24:56 +03:00
|
|
|
use OCP\INavigationManager;
|
|
|
|
use OCP\IRequest;
|
2019-05-22 11:48:51 +03:00
|
|
|
use OCP\IUser;
|
|
|
|
use OCP\IUserSession;
|
2016-08-15 17:24:56 +03:00
|
|
|
use OCP\Settings\IManager;
|
2019-05-22 11:48:51 +03:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2016-08-15 17:24:56 +03:00
|
|
|
use Test\TestCase;
|
|
|
|
|
2017-06-16 17:50:13 +03:00
|
|
|
/**
|
|
|
|
* Class AdminSettingsControllerTest
|
|
|
|
*
|
|
|
|
* @group DB
|
|
|
|
*
|
|
|
|
* @package Tests\Settings\Controller
|
|
|
|
*/
|
2016-08-15 17:24:56 +03:00
|
|
|
class AdminSettingsControllerTest extends TestCase {
|
2019-05-22 11:48:51 +03:00
|
|
|
|
2016-08-15 17:24:56 +03:00
|
|
|
/** @var AdminSettingsController */
|
|
|
|
private $adminSettingsController;
|
2019-05-22 11:48:51 +03:00
|
|
|
/** @var IRequest|MockObject */
|
2016-08-15 17:24:56 +03:00
|
|
|
private $request;
|
2019-05-22 11:48:51 +03:00
|
|
|
/** @var INavigationManager|MockObject */
|
2016-08-15 17:24:56 +03:00
|
|
|
private $navigationManager;
|
2019-05-22 11:48:51 +03:00
|
|
|
/** @var IManager|MockObject */
|
2016-08-15 17:24:56 +03:00
|
|
|
private $settingsManager;
|
2019-05-22 11:48:51 +03:00
|
|
|
/** @var IUserSession|MockObject */
|
|
|
|
private $userSession;
|
|
|
|
/** @var IGroupManager|MockObject */
|
|
|
|
private $groupManager;
|
|
|
|
/** @var ISubAdmin|MockObject */
|
|
|
|
private $subAdmin;
|
2017-06-16 18:18:06 +03:00
|
|
|
/** @var string */
|
|
|
|
private $adminUid = 'lololo';
|
2016-08-15 17:24:56 +03:00
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
protected function setUp(): void {
|
2016-08-15 17:24:56 +03:00
|
|
|
parent::setUp();
|
|
|
|
|
2019-05-22 11:48:51 +03:00
|
|
|
$this->request = $this->createMock(IRequest::class);
|
|
|
|
$this->navigationManager = $this->createMock(INavigationManager::class);
|
|
|
|
$this->settingsManager = $this->createMock(IManager::class);
|
|
|
|
$this->userSession = $this->createMock(IUserSession::class);
|
|
|
|
$this->groupManager = $this->createMock(IGroupManager::class);
|
|
|
|
$this->subAdmin = $this->createMock(ISubAdmin::class);
|
2016-08-15 17:24:56 +03:00
|
|
|
|
|
|
|
$this->adminSettingsController = new AdminSettingsController(
|
|
|
|
'settings',
|
|
|
|
$this->request,
|
|
|
|
$this->navigationManager,
|
2019-05-22 11:48:51 +03:00
|
|
|
$this->settingsManager,
|
|
|
|
$this->userSession,
|
|
|
|
$this->groupManager,
|
|
|
|
$this->subAdmin
|
2016-08-15 17:24:56 +03:00
|
|
|
);
|
2017-06-16 18:18:06 +03:00
|
|
|
|
2020-08-06 23:55:30 +03:00
|
|
|
$user = \OC::$server->getUserManager()->createUser($this->adminUid, 'mylongrandompassword');
|
2017-06-16 18:18:06 +03:00
|
|
|
\OC_User::setUserId($user->getUID());
|
|
|
|
\OC::$server->getGroupManager()->createGroup('admin')->addUser($user);
|
|
|
|
}
|
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
protected function tearDown(): void {
|
2017-06-16 18:18:06 +03:00
|
|
|
\OC::$server->getUserManager()->get($this->adminUid)->delete();
|
|
|
|
|
|
|
|
parent::tearDown();
|
2016-08-15 17:24:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testIndex() {
|
2019-05-22 11:48:51 +03:00
|
|
|
$user = $this->createMock(IUser::class);
|
|
|
|
$this->userSession
|
|
|
|
->method('getUser')
|
|
|
|
->willReturn($user);
|
|
|
|
$user->method('getUID')->willReturn('user123');
|
|
|
|
$this->groupManager
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('user123')
|
|
|
|
->willReturn(true);
|
|
|
|
$this->subAdmin
|
|
|
|
->method('isSubAdmin')
|
|
|
|
->with($user)
|
|
|
|
->willReturn(false);
|
2016-08-15 17:24:56 +03:00
|
|
|
$this->settingsManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getAdminSections')
|
|
|
|
->willReturn([]);
|
2017-06-16 17:50:13 +03:00
|
|
|
$this->settingsManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getPersonalSections')
|
|
|
|
->willReturn([]);
|
2016-08-15 17:24:56 +03:00
|
|
|
$this->settingsManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getAdminSettings')
|
|
|
|
->with('test')
|
2020-08-06 23:55:30 +03:00
|
|
|
->willReturn([5 => $this->createMock(ServerDevNotice::class)]);
|
2017-06-16 17:50:13 +03:00
|
|
|
|
2019-05-22 11:48:51 +03:00
|
|
|
$idx = $this->adminSettingsController->index('test');
|
|
|
|
|
2017-06-16 17:50:13 +03:00
|
|
|
$expected = new TemplateResponse('settings', 'settings/frame', ['forms' => ['personal' => [], 'admin' => []], 'content' => '']);
|
2019-05-22 11:48:51 +03:00
|
|
|
$this->assertEquals($expected, $idx);
|
2016-08-15 17:24:56 +03:00
|
|
|
}
|
|
|
|
}
|