mirror of
https://github.com/nextcloud/server.git
synced 2026-04-04 00:25:45 -04:00
Instead of one big monolitic sections this is the first step in breaking down the settings. This should make is easiet to see what does what. As well as nicely splitting up the sections. Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
113 lines
2.9 KiB
PHP
113 lines
2.9 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
|
|
*
|
|
* @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
|
|
*
|
|
* @license GNU AGPL version 3 or any later version
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Affero General Public License as
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
* License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Affero General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
namespace Test\Settings\Personal;
|
|
|
|
use OC\Authentication\TwoFactorAuth\ProviderLoader;
|
|
use OC\Settings\Personal\Security;
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
|
use OCP\IConfig;
|
|
use OCP\IUser;
|
|
use OCP\IUserManager;
|
|
use OCP\IUserSession;
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
|
use Test\TestCase;
|
|
|
|
class SecurityTest extends TestCase {
|
|
|
|
/** @var IUserManager|MockObject */
|
|
private $userManager;
|
|
|
|
/** @var ProviderLoader|MockObject */
|
|
private $providerLoader;
|
|
|
|
/** @var IUserSession|MockObject */
|
|
private $userSession;
|
|
|
|
/** @var IConfig|MockObject */
|
|
private $config;
|
|
|
|
/** @var string */
|
|
private $uid;
|
|
|
|
/** @var Security */
|
|
private $section;
|
|
|
|
public function setUp() {
|
|
parent::setUp();
|
|
|
|
$this->userManager = $this->createMock(IUserManager::class);
|
|
$this->providerLoader = $this->createMock(ProviderLoader::class);
|
|
$this->userSession = $this->createMock(IUserSession::class);
|
|
$this->config = $this->createMock(IConfig::class);
|
|
$this->uid = 'test123';
|
|
|
|
$this->section = new Security(
|
|
$this->userManager,
|
|
$this->providerLoader,
|
|
$this->userSession,
|
|
$this->config,
|
|
$this->uid
|
|
);
|
|
}
|
|
|
|
public function testGetForm() {
|
|
$user = $this->createMock(IUser::class);
|
|
$this->userManager->expects($this->once())
|
|
->method('get')
|
|
->with($this->uid)
|
|
->willReturn($user);
|
|
$user->expects($this->once())
|
|
->method('canChangePassword')
|
|
->willReturn(true);
|
|
$this->userSession->expects($this->once())
|
|
->method('getUser')
|
|
->willReturn($user);
|
|
$this->providerLoader->expects($this->once())
|
|
->method('getProviders')
|
|
->with($user)
|
|
->willReturn([]);
|
|
$this->config->expects($this->once())
|
|
->method('getUserValue')
|
|
->with(
|
|
$this->uid,
|
|
'accessibility',
|
|
'theme',
|
|
false
|
|
)
|
|
->willReturn(false);
|
|
|
|
$form = $this->section->getForm();
|
|
|
|
$expected = new TemplateResponse('settings', 'settings/personal/security', [
|
|
'passwordChangeSupported' => true,
|
|
'twoFactorProviderData' => [
|
|
'providers' => [],
|
|
],
|
|
'themedark' => false,
|
|
]);
|
|
$this->assertEquals($expected, $form);
|
|
}
|
|
|
|
}
|