nextcloud/apps/settings/tests/Settings/Admin/SecurityTest.php

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

114 lines
2.9 KiB
PHP
Raw Normal View History

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