0
0
Fork 0
mirror of https://github.com/nextcloud/server.git synced 2025-05-17 19:52:39 +00:00
nextcloud_server/apps/settings/tests/Settings/Admin/SecurityTest.php

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

124 lines
3 KiB
PHP
Raw Permalink Normal View History

2016-08-15 16:24:56 +02:00
<?php
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
2016-08-15 16:24:56 +02:00
*/
namespace OCA\Settings\Tests\Settings\Admin;
2016-08-15 16:24:56 +02:00
use OC\Authentication\TwoFactorAuth\MandatoryTwoFactor;
2016-08-15 16:24:56 +02:00
use OC\Encryption\Manager;
use OCA\Settings\Settings\Admin\Security;
2016-08-15 16:24:56 +02:00
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\IURLGenerator;
2016-08-15 16:24:56 +02:00
use OCP\IUserManager;
use PHPUnit\Framework\MockObject\MockObject;
2016-08-15 16:24:56 +02:00
use Test\TestCase;
class SecurityTest extends TestCase {
/** @var Security */
2016-08-15 16:24:56 +02:00
private $admin;
/** @var Manager */
private $manager;
/** @var IUserManager */
private $userManager;
/** @var MandatoryTwoFactor|MockObject */
private $mandatoryTwoFactor;
/** @var IInitialState|MockObject */
private $initialState;
2016-08-15 16:24:56 +02:00
protected function setUp(): void {
2016-08-15 16:24:56 +02:00
parent::setUp();
$this->manager = $this->getMockBuilder(Manager::class)->disableOriginalConstructor()->getMock();
$this->userManager = $this->getMockBuilder(IUserManager::class)->getMock();
$this->mandatoryTwoFactor = $this->createMock(MandatoryTwoFactor::class);
$this->initialState = $this->createMock(IInitialState::class);
2016-08-15 16:24:56 +02:00
$this->admin = new Security(
2016-08-15 16:24:56 +02:00
$this->manager,
$this->userManager,
$this->mandatoryTwoFactor,
$this->initialState,
$this->createMock(IURLGenerator::class)
2016-08-15 16:24:56 +02:00
);
}
/**
* @return array
*/
public function encryptionSettingsProvider() {
return [
[true],
[false],
];
}
/**
* @dataProvider encryptionSettingsProvider
* @param bool $enabled
*/
public function testGetFormWithOnlyOneBackend($enabled): void {
$this->manager
->expects($this->once())
->method('isEnabled')
->willReturn($enabled);
$this->manager
->expects($this->once())
->method('isReady')
->willReturn($enabled);
2016-08-16 18:59:45 +02:00
$this->manager
->expects($this->once())
->method('getEncryptionModules')
->willReturn([]);
2016-08-15 16:24:56 +02:00
$this->userManager
->expects($this->once())
->method('getBackends')
->willReturn(['entry']);
$expected = new TemplateResponse(
'settings',
'settings/admin/security',
[],
2016-08-15 16:24:56 +02:00
''
);
$this->assertEquals($expected, $this->admin->getForm());
}
/**
* @dataProvider encryptionSettingsProvider
* @param bool $enabled
*/
public function testGetFormWithMultipleBackends($enabled): void {
$this->manager
->expects($this->once())
->method('isEnabled')
->willReturn($enabled);
$this->manager
->expects($this->once())
->method('isReady')
->willReturn($enabled);
2016-08-16 18:59:45 +02:00
$this->manager
->expects($this->once())
->method('getEncryptionModules')
->willReturn([]);
2016-08-15 16:24:56 +02:00
$this->userManager
->expects($this->once())
->method('getBackends')
->willReturn(['entry', 'entry']);
$expected = new TemplateResponse(
'settings',
'settings/admin/security',
[ ],
2016-08-15 16:24:56 +02:00
''
);
$this->assertEquals($expected, $this->admin->getForm());
}
public function testGetSection(): void {
$this->assertSame('security', $this->admin->getSection());
2016-08-15 16:24:56 +02:00
}
public function testGetPriority(): void {
$this->assertSame(10, $this->admin->getPriority());
2016-08-15 16:24:56 +02:00
}
}