aboutsummaryrefslogtreecommitdiffstats
path: root/apps/settings/tests/Settings
diff options
context:
space:
mode:
Diffstat (limited to 'apps/settings/tests/Settings')
-rw-r--r--apps/settings/tests/Settings/Admin/MailTest.php7
-rw-r--r--apps/settings/tests/Settings/Admin/SecurityTest.php34
-rw-r--r--apps/settings/tests/Settings/Admin/ServerTest.php27
-rw-r--r--apps/settings/tests/Settings/Admin/SharingTest.php52
-rw-r--r--apps/settings/tests/Settings/Personal/Security/AuthtokensTest.php81
-rw-r--r--apps/settings/tests/Settings/Personal/Security/PasswordTest.php12
6 files changed, 92 insertions, 121 deletions
diff --git a/apps/settings/tests/Settings/Admin/MailTest.php b/apps/settings/tests/Settings/Admin/MailTest.php
index 560e4f8e997..992c7d43dba 100644
--- a/apps/settings/tests/Settings/Admin/MailTest.php
+++ b/apps/settings/tests/Settings/Admin/MailTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -21,8 +22,8 @@ class MailTest extends TestCase {
protected function setUp(): void {
parent::setUp();
- $this->config = $this->getMockBuilder(IConfig::class)->getMock();
- $this->l10n = $this->getMockBuilder(IL10N::class)->getMock();
+ $this->config = $this->createMock(IConfig::class);
+ $this->l10n = $this->createMock(IL10N::class);
$this->admin = new Mail(
$this->config,
@@ -37,7 +38,7 @@ class MailTest extends TestCase {
];
}
- /** @dataProvider dataGetForm */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetForm')]
public function testGetForm(bool $sendmail) {
$finder = $this->createMock(IBinaryFinder::class);
$finder->expects(self::once())
diff --git a/apps/settings/tests/Settings/Admin/SecurityTest.php b/apps/settings/tests/Settings/Admin/SecurityTest.php
index 95b5e988397..89a6d8c0d88 100644
--- a/apps/settings/tests/Settings/Admin/SecurityTest.php
+++ b/apps/settings/tests/Settings/Admin/SecurityTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -16,21 +17,16 @@ use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class SecurityTest extends TestCase {
- /** @var Security */
- private $admin;
- /** @var Manager */
- private $manager;
- /** @var IUserManager */
- private $userManager;
- /** @var MandatoryTwoFactor|MockObject */
- private $mandatoryTwoFactor;
- /** @var IInitialState|MockObject */
- private $initialState;
+ private Manager $manager;
+ private IUserManager $userManager;
+ private MandatoryTwoFactor&MockObject $mandatoryTwoFactor;
+ private IInitialState&MockObject $initialState;
+ private Security $admin;
protected function setUp(): void {
parent::setUp();
- $this->manager = $this->getMockBuilder(Manager::class)->disableOriginalConstructor()->getMock();
- $this->userManager = $this->getMockBuilder(IUserManager::class)->getMock();
+ $this->manager = $this->createMock(Manager::class);
+ $this->userManager = $this->createMock(IUserManager::class);
$this->mandatoryTwoFactor = $this->createMock(MandatoryTwoFactor::class);
$this->initialState = $this->createMock(IInitialState::class);
@@ -43,21 +39,15 @@ class SecurityTest extends TestCase {
);
}
- /**
- * @return array
- */
- public function encryptionSettingsProvider() {
+ public static function encryptionSettingsProvider(): array {
return [
[true],
[false],
];
}
- /**
- * @dataProvider encryptionSettingsProvider
- * @param bool $enabled
- */
- public function testGetFormWithOnlyOneBackend($enabled): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('encryptionSettingsProvider')]
+ public function testGetFormWithOnlyOneBackend(bool $enabled): void {
$this->manager
->expects($this->once())
->method('isEnabled')
@@ -84,9 +74,9 @@ class SecurityTest extends TestCase {
}
/**
- * @dataProvider encryptionSettingsProvider
* @param bool $enabled
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('encryptionSettingsProvider')]
public function testGetFormWithMultipleBackends($enabled): void {
$this->manager
->expects($this->once())
diff --git a/apps/settings/tests/Settings/Admin/ServerTest.php b/apps/settings/tests/Settings/Admin/ServerTest.php
index 35a8a3ce7f7..e2ca4cff3c6 100644
--- a/apps/settings/tests/Settings/Admin/ServerTest.php
+++ b/apps/settings/tests/Settings/Admin/ServerTest.php
@@ -25,24 +25,15 @@ use Test\TestCase;
* @group DB
*/
class ServerTest extends TestCase {
- /** @var IDBConnection */
- private $connection;
- /** @var Server&MockObject */
- private $admin;
- /** @var IInitialState&MockObject */
- private $initialStateService;
- /** @var ProfileManager&MockObject */
- private $profileManager;
- /** @var ITimeFactory&MockObject */
- private $timeFactory;
- /** @var IConfig&MockObject */
- private $config;
- /** @var IAppConfig&MockObject */
- private $appConfig;
- /** @var IL10N&MockObject */
- private $l10n;
- /** @var IUrlGenerator&MockObject */
- private $urlGenerator;
+ private IDBConnection $connection;
+ private Server&MockObject $admin;
+ private IInitialState&MockObject $initialStateService;
+ private ProfileManager&MockObject $profileManager;
+ private ITimeFactory&MockObject $timeFactory;
+ private IConfig&MockObject $config;
+ private IAppConfig&MockObject $appConfig;
+ private IL10N&MockObject $l10n;
+ private IUrlGenerator&MockObject $urlGenerator;
protected function setUp(): void {
parent::setUp();
diff --git a/apps/settings/tests/Settings/Admin/SharingTest.php b/apps/settings/tests/Settings/Admin/SharingTest.php
index 048634be1e0..12ab5c3cada 100644
--- a/apps/settings/tests/Settings/Admin/SharingTest.php
+++ b/apps/settings/tests/Settings/Admin/SharingTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -10,6 +11,7 @@ use OCP\App\IAppManager;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\Constants;
+use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IURLGenerator;
@@ -18,37 +20,30 @@ use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class SharingTest extends TestCase {
- /** @var Sharing */
- private $admin;
- /** @var IConfig&MockObject */
- private $config;
- /** @var IL10N&MockObject */
- private $l10n;
- /** @var IManager|MockObject */
- private $shareManager;
- /** @var IAppManager|MockObject */
- private $appManager;
- /** @var IURLGenerator|MockObject */
- private $urlGenerator;
- /** @var IInitialState|MockObject */
- private $initialState;
+ private Sharing $admin;
+
+ private IConfig&MockObject $config;
+ private IAppConfig&MockObject $appConfig;
+ private IL10N&MockObject $l10n;
+ private IManager&MockObject $shareManager;
+ private IAppManager&MockObject $appManager;
+ private IURLGenerator&MockObject $urlGenerator;
+ private IInitialState&MockObject $initialState;
protected function setUp(): void {
parent::setUp();
- $this->config = $this->getMockBuilder(IConfig::class)->getMock();
- $this->l10n = $this->getMockBuilder(IL10N::class)->getMock();
+ $this->config = $this->createMock(IConfig::class);
+ $this->appConfig = $this->createMock(IAppConfig::class);
+ $this->l10n = $this->createMock(IL10N::class);
- /** @var IManager|MockObject */
- $this->shareManager = $this->getMockBuilder(IManager::class)->getMock();
- /** @var IAppManager|MockObject */
- $this->appManager = $this->getMockBuilder(IAppManager::class)->getMock();
- /** @var IURLGenerator|MockObject */
- $this->urlGenerator = $this->getMockBuilder(IURLGenerator::class)->getMock();
- /** @var IInitialState|MockObject */
- $this->initialState = $this->getMockBuilder(IInitialState::class)->getMock();
+ $this->shareManager = $this->createMock(IManager::class);
+ $this->appManager = $this->createMock(IAppManager::class);
+ $this->urlGenerator = $this->createMock(IURLGenerator::class);
+ $this->initialState = $this->createMock(IInitialState::class);
$this->admin = new Sharing(
$this->config,
+ $this->appConfig,
$this->l10n,
$this->shareManager,
$this->appManager,
@@ -59,6 +54,12 @@ class SharingTest extends TestCase {
}
public function testGetFormWithoutExcludedGroups(): void {
+ $this->appConfig
+ ->method('getValueBool')
+ ->willReturnMap([
+ ['core', 'shareapi_allow_federation_on_public_shares', false, false, true],
+ ]);
+
$this->config
->method('getAppValue')
->willReturnMap([
@@ -104,7 +105,7 @@ class SharingTest extends TestCase {
->willReturnCallback(function (string $key) use (&$initialStateCalls): void {
$initialStateCalls[$key] = func_get_args();
});
-
+
$expectedInitialStateCalls = [
'sharingAppEnabled' => false,
'sharingDocumentation' => '',
@@ -114,6 +115,7 @@ class SharingTest extends TestCase {
'allowPublicUpload' => true,
'allowResharing' => true,
'allowShareDialogUserEnumeration' => true,
+ 'allowFederationOnPublicShares' => true,
'restrictUserEnumerationToGroup' => false,
'restrictUserEnumerationToPhone' => false,
'restrictUserEnumerationFullMatch' => true,
diff --git a/apps/settings/tests/Settings/Personal/Security/AuthtokensTest.php b/apps/settings/tests/Settings/Personal/Security/AuthtokensTest.php
index 44641ee98b3..0a0ff4d84af 100644
--- a/apps/settings/tests/Settings/Personal/Security/AuthtokensTest.php
+++ b/apps/settings/tests/Settings/Personal/Security/AuthtokensTest.php
@@ -20,24 +20,12 @@ use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class AuthtokensTest extends TestCase {
-
- /** @var IAuthTokenProvider|MockObject */
- private $authTokenProvider;
-
- /** @var ISession|MockObject */
- private $session;
-
- /** @var IUserSession|MockObject */
- private $userSession;
-
- /** @var IInitialState|MockObject */
- private $initialState;
-
- /** @var string */
- private $uid;
-
- /** @var Authtokens */
- private $section;
+ private IAuthTokenProvider&MockObject $authTokenProvider;
+ private ISession&MockObject $session;
+ private IUserSession&MockObject $userSession;
+ private IInitialState&MockObject $initialState;
+ private string $uid;
+ private Authtokens $section;
protected function setUp(): void {
parent::setUp();
@@ -80,34 +68,39 @@ class AuthtokensTest extends TestCase {
->method('getToken')
->with('session123')
->willReturn($sessionToken);
+
+ $calls = [
+ [
+ 'app_tokens', [
+ [
+ 'id' => 100,
+ 'name' => null,
+ 'lastActivity' => 0,
+ 'type' => 0,
+ 'canDelete' => false,
+ 'current' => true,
+ 'scope' => [IToken::SCOPE_FILESYSTEM => true],
+ 'canRename' => false,
+ ],
+ [
+ 'id' => 200,
+ 'name' => null,
+ 'lastActivity' => 0,
+ 'type' => 0,
+ 'canDelete' => true,
+ 'scope' => [IToken::SCOPE_FILESYSTEM => true],
+ 'canRename' => true,
+ ],
+ ]
+ ],
+ ['can_create_app_token', true],
+ ];
$this->initialState->expects($this->exactly(2))
->method('provideInitialState')
- ->withConsecutive(
- [
- 'app_tokens', [
- [
- 'id' => 100,
- 'name' => null,
- 'lastActivity' => 0,
- 'type' => 0,
- 'canDelete' => false,
- 'current' => true,
- 'scope' => [IToken::SCOPE_FILESYSTEM => true],
- 'canRename' => false,
- ],
- [
- 'id' => 200,
- 'name' => null,
- 'lastActivity' => 0,
- 'type' => 0,
- 'canDelete' => true,
- 'scope' => [IToken::SCOPE_FILESYSTEM => true],
- 'canRename' => true,
- ],
- ]
- ],
- ['can_create_app_token', true],
- );
+ ->willReturnCallback(function () use (&$calls): void {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, func_get_args());
+ });
$form = $this->section->getForm();
diff --git a/apps/settings/tests/Settings/Personal/Security/PasswordTest.php b/apps/settings/tests/Settings/Personal/Security/PasswordTest.php
index 62f2c998943..34a4b8e296f 100644
--- a/apps/settings/tests/Settings/Personal/Security/PasswordTest.php
+++ b/apps/settings/tests/Settings/Personal/Security/PasswordTest.php
@@ -16,15 +16,9 @@ use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class PasswordTest extends TestCase {
-
- /** @var IUserManager|MockObject */
- private $userManager;
-
- /** @var string */
- private $uid;
-
- /** @var Password */
- private $section;
+ private IUserManager&MockObject $userManager;
+ private string $uid;
+ private Password $section;
protected function setUp(): void {
parent::setUp();