aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_external/tests
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_external/tests')
-rw-r--r--apps/files_external/tests/Auth/AuthMechanismTest.php24
-rw-r--r--apps/files_external/tests/Auth/Password/GlobalAuthTest.php (renamed from apps/files_external/tests/Auth/Password/GlobalAuth.php)35
-rw-r--r--apps/files_external/tests/Backend/BackendTest.php18
-rw-r--r--apps/files_external/tests/Backend/LegacyBackendTest.php26
-rw-r--r--apps/files_external/tests/Command/ApplicableTest.php25
-rw-r--r--apps/files_external/tests/Command/CommandTestCase.php (renamed from apps/files_external/tests/Command/CommandTest.php)19
-rw-r--r--apps/files_external/tests/Command/ListCommandTest.php24
-rw-r--r--apps/files_external/tests/Config/UserPlaceholderHandlerTest.php44
-rw-r--r--apps/files_external/tests/Controller/AjaxControllerTest.php68
-rw-r--r--apps/files_external/tests/Controller/GlobalStoragesControllerTest.php12
-rw-r--r--apps/files_external/tests/Controller/StoragesControllerTestCase.php (renamed from apps/files_external/tests/Controller/StoragesControllerTest.php)115
-rw-r--r--apps/files_external/tests/Controller/UserStoragesControllerTest.php22
-rw-r--r--apps/files_external/tests/DefinitionParameterTest.php23
-rw-r--r--apps/files_external/tests/FrontendDefinitionTraitTest.php20
-rw-r--r--apps/files_external/tests/LegacyDependencyCheckPolyfillTest.php11
-rw-r--r--apps/files_external/tests/Listener/StorePasswordListenerTest.php21
-rw-r--r--apps/files_external/tests/OwnCloudFunctionsTest.php14
-rw-r--r--apps/files_external/tests/PersonalMountTest.php18
-rw-r--r--apps/files_external/tests/Service/BackendServiceTest.php100
-rw-r--r--apps/files_external/tests/Service/DBConfigServiceTest.php64
-rw-r--r--apps/files_external/tests/Service/GlobalStoragesServiceTest.php133
-rw-r--r--apps/files_external/tests/Service/StoragesServiceTestCase.php (renamed from apps/files_external/tests/Service/StoragesServiceTest.php)132
-rw-r--r--apps/files_external/tests/Service/UserGlobalStoragesServiceTest.php83
-rw-r--r--apps/files_external/tests/Service/UserStoragesServiceTest.php49
-rw-r--r--apps/files_external/tests/Settings/AdminTest.php27
-rw-r--r--apps/files_external/tests/Settings/SectionTest.php22
-rw-r--r--apps/files_external/tests/Storage/Amazons3MultiPartTest.php13
-rw-r--r--apps/files_external/tests/Storage/Amazons3Test.php13
-rw-r--r--apps/files_external/tests/Storage/FtpTest.php6
-rw-r--r--apps/files_external/tests/Storage/OwncloudTest.php2
-rw-r--r--apps/files_external/tests/Storage/SFTP_KeyTest.php24
-rw-r--r--apps/files_external/tests/Storage/SftpTest.php10
-rw-r--r--apps/files_external/tests/Storage/SmbTest.php20
-rw-r--r--apps/files_external/tests/Storage/SwiftTest.php4
-rw-r--r--apps/files_external/tests/Storage/VersionedAmazonS3Test.php9
-rw-r--r--apps/files_external/tests/Storage/WebdavTest.php8
-rw-r--r--apps/files_external/tests/StorageConfigTest.php16
-rw-r--r--apps/files_external/tests/appSpec.js83
-rw-r--r--apps/files_external/tests/config.php1
-rw-r--r--apps/files_external/tests/js/mountsfilelistSpec.js148
-rw-r--r--apps/files_external/tests/js/settingsSpec.js447
-rw-r--r--apps/files_external/tests/sso-setup/apps.config.php14
-rwxr-xr-xapps/files_external/tests/sso-setup/start-apache.sh3
-rwxr-xr-xapps/files_external/tests/sso-setup/test-sso-smb.sh2
44 files changed, 618 insertions, 1354 deletions
diff --git a/apps/files_external/tests/Auth/AuthMechanismTest.php b/apps/files_external/tests/Auth/AuthMechanismTest.php
index 3297d93fe94..e999cecf181 100644
--- a/apps/files_external/tests/Auth/AuthMechanismTest.php
+++ b/apps/files_external/tests/Auth/AuthMechanismTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2020-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -11,9 +13,9 @@ use OCA\Files_External\Lib\Backend\Backend;
use OCA\Files_External\Lib\StorageConfig;
class AuthMechanismTest extends \Test\TestCase {
- public function testJsonSerialization() {
+ public function testJsonSerialization(): void {
$mechanism = $this->getMockBuilder(AuthMechanism::class)
- ->setMethods(['jsonSerializeDefinition'])
+ ->onlyMethods(['jsonSerializeDefinition'])
->getMock();
$mechanism->expects($this->once())
->method('jsonSerializeDefinition')
@@ -26,7 +28,7 @@ class AuthMechanismTest extends \Test\TestCase {
$this->assertEquals('scheme', $json['scheme']);
}
- public function validateStorageProvider() {
+ public static function validateStorageProvider(): array {
return [
[true, 'scheme', true],
[false, 'scheme', false],
@@ -35,12 +37,10 @@ class AuthMechanismTest extends \Test\TestCase {
];
}
- /**
- * @dataProvider validateStorageProvider
- */
- public function testValidateStorage($expectedSuccess, $scheme, $definitionSuccess) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('validateStorageProvider')]
+ public function testValidateStorage(bool $expectedSuccess, string $scheme, bool $definitionSuccess): void {
$mechanism = $this->getMockBuilder(AuthMechanism::class)
- ->setMethods(['validateStorageDefinition'])
+ ->onlyMethods(['validateStorageDefinition'])
->getMock();
$mechanism->expects($this->atMost(1))
->method('validateStorageDefinition')
@@ -48,16 +48,12 @@ class AuthMechanismTest extends \Test\TestCase {
$mechanism->setScheme($scheme);
- $backend = $this->getMockBuilder(Backend::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $backend = $this->createMock(Backend::class);
$backend->expects($this->once())
->method('getAuthSchemes')
->willReturn(['scheme' => true, 'foobar' => true]);
- $storageConfig = $this->getMockBuilder(StorageConfig::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $storageConfig = $this->createMock(StorageConfig::class);
$storageConfig->expects($this->once())
->method('getBackend')
->willReturn($backend);
diff --git a/apps/files_external/tests/Auth/Password/GlobalAuth.php b/apps/files_external/tests/Auth/Password/GlobalAuthTest.php
index 85a2c1fb27c..6d83655403e 100644
--- a/apps/files_external/tests/Auth/Password/GlobalAuth.php
+++ b/apps/files_external/tests/Auth/Password/GlobalAuthTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -7,26 +9,17 @@
namespace OCA\Files_External\Tests\Auth\Password;
use OCA\Files_External\Lib\Auth\Password\GlobalAuth;
-use OCA\Files_external\Lib\StorageConfig;
+use OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException;
+use OCA\Files_External\Lib\StorageConfig;
use OCP\IL10N;
use OCP\Security\ICredentialsManager;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class GlobalAuthTest extends TestCase {
- /**
- * @var \OCP\IL10N|\PHPUnit\Framework\MockObject\MockObject
- */
- private $l10n;
-
- /**
- * @var \OCP\Security\ICredentialsManager|\PHPUnit\Framework\MockObject\MockObject
- */
- private $credentialsManager;
-
- /**
- * @var GlobalAuth
- */
- private $instance;
+ private IL10N&MockObject $l10n;
+ private ICredentialsManager&MockObject $credentialsManager;
+ private GlobalAuth $instance;
protected function setUp(): void {
parent::setUp();
@@ -36,7 +29,7 @@ class GlobalAuthTest extends TestCase {
}
private function getStorageConfig($type, $config = []) {
- /** @var \OCA\Files_External\Lib\StorageConfig|\PHPUnit\Framework\MockObject\MockObject $storageConfig */
+ /** @var StorageConfig&MockObject $storageConfig */
$storageConfig = $this->createMock(StorageConfig::class);
$storageConfig->expects($this->any())
->method('getType')
@@ -53,14 +46,14 @@ class GlobalAuthTest extends TestCase {
});
$storageConfig->expects($this->any())
->method('setBackendOption')
- ->willReturnCallback(function ($key, $value) use (&$config) {
+ ->willReturnCallback(function ($key, $value) use (&$config): void {
$config[$key] = $value;
});
return $storageConfig;
}
- public function testNoCredentials() {
+ public function testNoCredentials(): void {
$this->credentialsManager->expects($this->once())
->method('retrieve')
->willReturn(null);
@@ -71,7 +64,7 @@ class GlobalAuthTest extends TestCase {
$this->assertEquals([], $storage->getBackendOptions());
}
- public function testSavedCredentials() {
+ public function testSavedCredentials(): void {
$this->credentialsManager->expects($this->once())
->method('retrieve')
->willReturn([
@@ -89,8 +82,8 @@ class GlobalAuthTest extends TestCase {
}
- public function testNoCredentialsPersonal() {
- $this->expectException(\OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException::class);
+ public function testNoCredentialsPersonal(): void {
+ $this->expectException(InsufficientDataForMeaningfulAnswerException::class);
$this->credentialsManager->expects($this->never())
->method('retrieve');
diff --git a/apps/files_external/tests/Backend/BackendTest.php b/apps/files_external/tests/Backend/BackendTest.php
index 771c053982c..1653c354e16 100644
--- a/apps/files_external/tests/Backend/BackendTest.php
+++ b/apps/files_external/tests/Backend/BackendTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -10,9 +12,9 @@ use OCA\Files_External\Lib\Backend\Backend;
use OCA\Files_External\Lib\StorageConfig;
class BackendTest extends \Test\TestCase {
- public function testJsonSerialization() {
+ public function testJsonSerialization(): void {
$backend = $this->getMockBuilder(Backend::class)
- ->setMethods(['jsonSerializeDefinition'])
+ ->onlyMethods(['jsonSerializeDefinition'])
->getMock();
$backend->expects($this->once())
->method('jsonSerializeDefinition')
@@ -32,19 +34,17 @@ class BackendTest extends \Test\TestCase {
$this->assertContains('barauth', array_keys($json['authSchemes']));
}
- public function validateStorageProvider() {
+ public static function validateStorageProvider(): array {
return [
[true, true],
[false, false],
];
}
- /**
- * @dataProvider validateStorageProvider
- */
- public function testValidateStorage($expectedSuccess, $definitionSuccess) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('validateStorageProvider')]
+ public function testValidateStorage(bool $expectedSuccess, bool $definitionSuccess): void {
$backend = $this->getMockBuilder(Backend::class)
- ->setMethods(['validateStorageDefinition'])
+ ->onlyMethods(['validateStorageDefinition'])
->getMock();
$backend->expects($this->atMost(1))
->method('validateStorageDefinition')
@@ -57,7 +57,7 @@ class BackendTest extends \Test\TestCase {
$this->assertEquals($expectedSuccess, $backend->validateStorage($storageConfig));
}
- public function testLegacyAuthMechanismCallback() {
+ public function testLegacyAuthMechanismCallback(): void {
$backend = new Backend();
$backend->setLegacyAuthMechanismCallback(function (array $params) {
if (isset($params['ping'])) {
diff --git a/apps/files_external/tests/Backend/LegacyBackendTest.php b/apps/files_external/tests/Backend/LegacyBackendTest.php
index 2d041e69f26..c4ddfedf6e2 100644
--- a/apps/files_external/tests/Backend/LegacyBackendTest.php
+++ b/apps/files_external/tests/Backend/LegacyBackendTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -6,6 +7,7 @@
*/
namespace OCA\Files_External\Tests\Backend;
+use OCA\Files_External\Lib\Auth\Builtin;
use OCA\Files_External\Lib\Backend\LegacyBackend;
use OCA\Files_External\Lib\DefinitionParameter;
use OCA\Files_External\Lib\MissingDependency;
@@ -15,24 +17,21 @@ class LegacyBackendTest extends \Test\TestCase {
/**
* @return MissingDependency[]
*/
- public static function checkDependencies() {
+ public static function checkDependencies(): array {
return [
(new MissingDependency('abc'))->setMessage('foobar')
];
}
- public function testConstructor() {
- $auth = $this->getMockBuilder('\OCA\Files_External\Lib\Auth\Builtin')
- ->disableOriginalConstructor()
- ->getMock();
+ public function testConstructor(): void {
+ $auth = $this->createMock(Builtin::class);
- $class = '\OCA\Files_External\Tests\Backend\LegacyBackendTest';
+ $class = self::class;
$definition = [
'configuration' => [
'textfield' => 'Text field',
'passwordfield' => '*Password field',
'checkbox' => '!Checkbox',
- 'hiddenfield' => '#Hidden field',
'optionaltext' => '&Optional text field',
'optionalpassword' => '&*Optional password field',
],
@@ -44,7 +43,7 @@ class LegacyBackendTest extends \Test\TestCase {
$backend = new LegacyBackend($class, $definition, $auth);
- $this->assertEquals('\OCA\Files_External\Tests\Backend\LegacyBackendTest', $backend->getStorageClass());
+ $this->assertEquals(self::class, $backend->getStorageClass());
$this->assertEquals('Backend text', $backend->getText());
$this->assertEquals(123, $backend->getPriority());
$this->assertContains('foo/bar.js', $backend->getCustomJs());
@@ -66,9 +65,6 @@ class LegacyBackendTest extends \Test\TestCase {
$this->assertEquals('Checkbox', $parameters['checkbox']->getText());
$this->assertEquals(DefinitionParameter::VALUE_BOOLEAN, $parameters['checkbox']->getType());
$this->assertEquals(DefinitionParameter::FLAG_NONE, $parameters['checkbox']->getFlags());
- $this->assertEquals('Hidden field', $parameters['hiddenfield']->getText());
- $this->assertEquals(DefinitionParameter::VALUE_HIDDEN, $parameters['hiddenfield']->getType());
- $this->assertEquals(DefinitionParameter::FLAG_NONE, $parameters['hiddenfield']->getFlags());
$this->assertEquals('Optional text field', $parameters['optionaltext']->getText());
$this->assertEquals(DefinitionParameter::VALUE_TEXT, $parameters['optionaltext']->getType());
$this->assertEquals(DefinitionParameter::FLAG_OPTIONAL, $parameters['optionaltext']->getFlags());
@@ -77,12 +73,10 @@ class LegacyBackendTest extends \Test\TestCase {
$this->assertEquals(DefinitionParameter::FLAG_OPTIONAL, $parameters['optionalpassword']->getFlags());
}
- public function testNoDependencies() {
- $auth = $this->getMockBuilder('\OCA\Files_External\Lib\Auth\Builtin')
- ->disableOriginalConstructor()
- ->getMock();
+ public function testNoDependencies(): void {
+ $auth = $this->createMock(Builtin::class);
- $class = '\OCA\Files_External\Tests\Backend\LegacyBackendTest';
+ $class = self::class;
$definition = [
'configuration' => [
],
diff --git a/apps/files_external/tests/Command/ApplicableTest.php b/apps/files_external/tests/Command/ApplicableTest.php
index d4caadad343..59db18a42de 100644
--- a/apps/files_external/tests/Command/ApplicableTest.php
+++ b/apps/files_external/tests/Command/ApplicableTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -9,12 +11,13 @@ namespace OCA\Files_External\Tests\Command;
use OCA\Files_External\Command\Applicable;
use OCP\IGroupManager;
use OCP\IUserManager;
+use PHPUnit\Framework\MockObject\MockObject;
-class ApplicableTest extends CommandTest {
- private function getInstance($storageService) {
- /** @var \OCP\IUserManager|\PHPUnit\Framework\MockObject\MockObject $userManager */
+class ApplicableTest extends CommandTestCase {
+ private function getInstance($storageService): Applicable {
+ /** @var IUserManager&MockObject $userManager */
$userManager = $this->createMock(IUserManager::class);
- /** @var \OCP\IGroupManager|\PHPUnit\Framework\MockObject\MockObject $groupManager */
+ /** @var IGroupManager&MockObject $groupManager */
$groupManager = $this->createMock(IGroupManager::class);
$userManager->expects($this->any())
@@ -28,7 +31,7 @@ class ApplicableTest extends CommandTest {
return new Applicable($storageService, $userManager, $groupManager);
}
- public function testListEmpty() {
+ public function testListEmpty(): void {
$mount = $this->getMount(1, '', '');
$storageService = $this->getGlobalStorageService([$mount]);
@@ -45,7 +48,7 @@ class ApplicableTest extends CommandTest {
$this->assertEquals(['users' => [], 'groups' => []], $result);
}
- public function testList() {
+ public function testList(): void {
$mount = $this->getMount(1, '', '', '', [], [], ['test', 'asd']);
$storageService = $this->getGlobalStorageService([$mount]);
@@ -62,7 +65,7 @@ class ApplicableTest extends CommandTest {
$this->assertEquals(['users' => ['test', 'asd'], 'groups' => []], $result);
}
- public function testAddSingle() {
+ public function testAddSingle(): void {
$mount = $this->getMount(1, '', '', '', [], [], []);
$storageService = $this->getGlobalStorageService([$mount]);
@@ -80,7 +83,7 @@ class ApplicableTest extends CommandTest {
$this->assertEquals(['foo'], $mount->getApplicableUsers());
}
- public function testAddDuplicate() {
+ public function testAddDuplicate(): void {
$mount = $this->getMount(1, '', '', '', [], [], ['foo']);
$storageService = $this->getGlobalStorageService([$mount]);
@@ -98,7 +101,7 @@ class ApplicableTest extends CommandTest {
$this->assertEquals(['foo', 'bar'], $mount->getApplicableUsers());
}
- public function testRemoveSingle() {
+ public function testRemoveSingle(): void {
$mount = $this->getMount(1, '', '', '', [], [], ['foo', 'bar']);
$storageService = $this->getGlobalStorageService([$mount]);
@@ -116,7 +119,7 @@ class ApplicableTest extends CommandTest {
$this->assertEquals(['foo'], $mount->getApplicableUsers());
}
- public function testRemoveNonExisting() {
+ public function testRemoveNonExisting(): void {
$mount = $this->getMount(1, '', '', '', [], [], ['foo', 'bar']);
$storageService = $this->getGlobalStorageService([$mount]);
@@ -134,7 +137,7 @@ class ApplicableTest extends CommandTest {
$this->assertEquals(['foo'], $mount->getApplicableUsers());
}
- public function testRemoveAddRemove() {
+ public function testRemoveAddRemove(): void {
$mount = $this->getMount(1, '', '', '', [], [], ['foo', 'bar']);
$storageService = $this->getGlobalStorageService([$mount]);
diff --git a/apps/files_external/tests/Command/CommandTest.php b/apps/files_external/tests/Command/CommandTestCase.php
index eb47fe08ac4..e42ad9cd68a 100644
--- a/apps/files_external/tests/Command/CommandTest.php
+++ b/apps/files_external/tests/Command/CommandTestCase.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -8,21 +9,21 @@ namespace OCA\Files_External\Tests\Command;
use OCA\Files_External\Lib\StorageConfig;
use OCA\Files_External\NotFoundException;
+use OCA\Files_External\Service\GlobalStoragesService;
+use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\Input;
use Symfony\Component\Console\Output\BufferedOutput;
use Test\TestCase;
-abstract class CommandTest extends TestCase {
+abstract class CommandTestCase extends TestCase {
/**
* @param StorageConfig[] $mounts
- * @return \OCA\Files_External\Service\GlobalStoragesService|\PHPUnit\Framework\MockObject\MockObject
+ * @return GlobalStoragesService&MockObject
*/
protected function getGlobalStorageService(array $mounts = []) {
- $mock = $this->getMockBuilder('OCA\Files_External\Service\GlobalStoragesService')
- ->disableOriginalConstructor()
- ->getMock();
+ $mock = $this->createMock(GlobalStoragesService::class);
$this->bindMounts($mock, $mounts);
@@ -30,10 +31,10 @@ abstract class CommandTest extends TestCase {
}
/**
- * @param \PHPUnit\Framework\MockObject\MockObject $mock
+ * @param MockObject $mock
* @param StorageConfig[] $mounts
*/
- protected function bindMounts(\PHPUnit\Framework\MockObject\MockObject $mock, array $mounts) {
+ protected function bindMounts(MockObject $mock, array $mounts) {
$mock->expects($this->any())
->method('getStorage')
->willReturnCallback(function ($id) use ($mounts) {
@@ -69,7 +70,7 @@ abstract class CommandTest extends TestCase {
return $mount;
}
- protected function getInput(Command $command, array $arguments = [], array $options = []) {
+ protected function getInput(Command $command, array $arguments = [], array $options = []): ArrayInput {
$input = new ArrayInput([]);
$input->bind($command->getDefinition());
foreach ($arguments as $key => $value) {
@@ -81,7 +82,7 @@ abstract class CommandTest extends TestCase {
return $input;
}
- protected function executeCommand(Command $command, Input $input) {
+ protected function executeCommand(Command $command, Input $input): string {
$output = new BufferedOutput();
$this->invokePrivate($command, 'execute', [$input, $output]);
return $output->fetch();
diff --git a/apps/files_external/tests/Command/ListCommandTest.php b/apps/files_external/tests/Command/ListCommandTest.php
index 8375ba89f2a..5b84e500e3f 100644
--- a/apps/files_external/tests/Command/ListCommandTest.php
+++ b/apps/files_external/tests/Command/ListCommandTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -16,33 +18,27 @@ use OCA\Files_External\Service\GlobalStoragesService;
use OCA\Files_External\Service\UserStoragesService;
use OCP\Authentication\LoginCredentials\IStore;
use OCP\IL10N;
-use OCP\ISession;
use OCP\IUserManager;
use OCP\IUserSession;
-use OCP\Security\ICrypto;
+use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\Console\Output\BufferedOutput;
-class ListCommandTest extends CommandTest {
- /**
- * @return ListCommand|\PHPUnit\Framework\MockObject\MockObject
- */
- private function getInstance() {
- /** @var GlobalStoragesService|\PHPUnit\Framework\MockObject\MockObject $globalService */
+class ListCommandTest extends CommandTestCase {
+ private function getInstance(): ListCommand {
+ /** @var GlobalStoragesService&MockObject $globalService */
$globalService = $this->createMock(GlobalStoragesService::class);
- /** @var UserStoragesService|\PHPUnit\Framework\MockObject\MockObject $userService */
+ /** @var UserStoragesService&MockObject $userService */
$userService = $this->createMock(UserStoragesService::class);
- /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject $userManager */
+ /** @var IUserManager&MockObject $userManager */
$userManager = $this->createMock(IUserManager::class);
- /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject $userSession */
+ /** @var IUserSession&MockObject $userSession */
$userSession = $this->createMock(IUserSession::class);
return new ListCommand($globalService, $userService, $userSession, $userManager);
}
- public function testListAuthIdentifier() {
+ public function testListAuthIdentifier(): void {
$l10n = $this->createMock(IL10N::class);
- $session = $this->createMock(ISession::class);
- $crypto = $this->createMock(ICrypto::class);
$instance = $this->getInstance();
$mount1 = new StorageConfig();
$mount1->setAuthMechanism(new Password($l10n));
diff --git a/apps/files_external/tests/Config/UserPlaceholderHandlerTest.php b/apps/files_external/tests/Config/UserPlaceholderHandlerTest.php
index 767ae04fc79..13d25ce5075 100644
--- a/apps/files_external/tests/Config/UserPlaceholderHandlerTest.php
+++ b/apps/files_external/tests/Config/UserPlaceholderHandlerTest.php
@@ -1,9 +1,11 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
-namespace OCA\files_external\tests\Config;
+namespace OCA\Files_External\Tests\Config;
use OCA\Files_External\Config\UserPlaceholderHandler;
use OCP\IRequest;
@@ -12,25 +14,15 @@ use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager;
+use PHPUnit\Framework\MockObject\MockObject;
class UserPlaceholderHandlerTest extends \Test\TestCase {
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject */
- protected $user;
-
- /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
- protected $session;
-
- /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
- private $shareManager;
-
- /** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
- private $request;
-
- /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
- private $userManager;
-
- /** @var UserPlaceholderHandler */
- protected $handler;
+ protected IUser&MockObject $user;
+ protected IUserSession&MockObject $session;
+ protected IManager&MockObject $shareManager;
+ protected IRequest&MockObject $request;
+ protected IUserManager&MockObject $userManager;
+ protected UserPlaceholderHandler $handler;
protected function setUp(): void {
parent::setUp();
@@ -47,13 +39,13 @@ class UserPlaceholderHandlerTest extends \Test\TestCase {
$this->handler = new UserPlaceholderHandler($this->session, $this->shareManager, $this->request, $this->userManager);
}
- protected function setUser() {
+ protected function setUser(): void {
$this->session->expects($this->any())
->method('getUser')
->willReturn($this->user);
}
- public function optionProvider() {
+ public static function optionProvider(): array {
return [
['/foo/bar/$user/foobar', '/foo/bar/alice/foobar'],
[['/foo/bar/$user/foobar'], ['/foo/bar/alice/foobar']],
@@ -61,18 +53,14 @@ class UserPlaceholderHandlerTest extends \Test\TestCase {
];
}
- /**
- * @dataProvider optionProvider
- */
- public function testHandle($option, $expected) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('optionProvider')]
+ public function testHandle(string|array $option, string|array $expected): void {
$this->setUser();
$this->assertSame($expected, $this->handler->handle($option));
}
- /**
- * @dataProvider optionProvider
- */
- public function testHandleNoUser($option) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('optionProvider')]
+ public function testHandleNoUser(string|array $option): void {
$this->shareManager->expects($this->once())
->method('getShareByToken')
->willThrowException(new ShareNotFound());
diff --git a/apps/files_external/tests/Controller/AjaxControllerTest.php b/apps/files_external/tests/Controller/AjaxControllerTest.php
index 4b2f973e9b0..b1ea7a2b1b1 100644
--- a/apps/files_external/tests/Controller/AjaxControllerTest.php
+++ b/apps/files_external/tests/Controller/AjaxControllerTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -10,35 +12,29 @@ use OCA\Files_External\Lib\Auth\Password\GlobalAuth;
use OCA\Files_External\Lib\Auth\PublicKey\RSA;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IGroupManager;
+use OCP\IL10N;
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserSession;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class AjaxControllerTest extends TestCase {
- /** @var IRequest */
- private $request;
- /** @var RSA */
- private $rsa;
- /** @var GlobalAuth */
- private $globalAuth;
- /** @var IUserSession */
- private $userSession;
- /** @var IGroupManager */
- private $groupManager;
- /** @var AjaxController */
- private $ajaxController;
+ private IRequest&MockObject $request;
+ private RSA&MockObject $rsa;
+ private GlobalAuth&MockObject $globalAuth;
+ private IUserSession&MockObject $userSession;
+ private IGroupManager&MockObject $groupManager;
+ private IL10N&MockObject $l10n;
+ private AjaxController $ajaxController;
protected function setUp(): void {
$this->request = $this->createMock(IRequest::class);
- $this->rsa = $this->getMockBuilder('\\OCA\\Files_External\\Lib\\Auth\\PublicKey\\RSA')
- ->disableOriginalConstructor()
- ->getMock();
- $this->globalAuth = $this->getMockBuilder('\\OCA\\Files_External\\Lib\\Auth\\Password\GlobalAuth')
- ->disableOriginalConstructor()
- ->getMock();
+ $this->rsa = $this->createMock(RSA::class);
+ $this->globalAuth = $this->createMock(GlobalAuth::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->groupManager = $this->createMock(IGroupManager::class);
+ $this->l10n = $this->createMock(IL10N::class);
$this->ajaxController = new AjaxController(
'files_external',
@@ -46,13 +42,23 @@ class AjaxControllerTest extends TestCase {
$this->rsa,
$this->globalAuth,
$this->userSession,
- $this->groupManager
+ $this->groupManager,
+ $this->l10n,
);
+ $this->l10n->expects($this->any())
+ ->method('t')
+ ->willReturnCallback(function ($string, $args) {
+ if (!is_array($args)) {
+ $args = [$args];
+ }
+ return vsprintf($string, $args);
+ });
+
parent::setUp();
}
- public function testGetSshKeys() {
+ public function testGetSshKeys(): void {
$this->rsa
->expects($this->once())
->method('createKey')
@@ -73,7 +79,7 @@ class AjaxControllerTest extends TestCase {
$this->assertEquals($expected, $this->ajaxController->getSshKeys());
}
- public function testSaveGlobalCredentialsAsAdminForAnotherUser() {
+ public function testSaveGlobalCredentialsAsAdminForAnotherUser(): void {
$user = $this->createMock(IUser::class);
$user
->expects($this->once())
@@ -87,10 +93,12 @@ class AjaxControllerTest extends TestCase {
->expects($this->never())
->method('saveAuth');
- $this->assertSame(false, $this->ajaxController->saveGlobalCredentials('UidOfTestUser', 'test', 'password'));
+ $response = $this->ajaxController->saveGlobalCredentials('UidOfTestUser', 'test', 'password');
+ $this->assertSame($response->getStatus(), 403);
+ $this->assertSame('Permission denied', $response->getData()['message']);
}
- public function testSaveGlobalCredentialsAsAdminForSelf() {
+ public function testSaveGlobalCredentialsAsAdminForSelf(): void {
$user = $this->createMock(IUser::class);
$user
->expects($this->once())
@@ -105,10 +113,11 @@ class AjaxControllerTest extends TestCase {
->method('saveAuth')
->with('MyAdminUid', 'test', 'password');
- $this->assertSame(true, $this->ajaxController->saveGlobalCredentials('MyAdminUid', 'test', 'password'));
+ $response = $this->ajaxController->saveGlobalCredentials('MyAdminUid', 'test', 'password');
+ $this->assertSame($response->getStatus(), 200);
}
- public function testSaveGlobalCredentialsAsNormalUserForSelf() {
+ public function testSaveGlobalCredentialsAsNormalUserForSelf(): void {
$user = $this->createMock(IUser::class);
$user
->method('getUID')
@@ -120,10 +129,11 @@ class AjaxControllerTest extends TestCase {
->method('saveAuth')
->with('MyUserUid', 'test', 'password');
- $this->assertSame(true, $this->ajaxController->saveGlobalCredentials('MyUserUid', 'test', 'password'));
+ $response = $this->ajaxController->saveGlobalCredentials('MyUserUid', 'test', 'password');
+ $this->assertSame($response->getStatus(), 200);
}
- public function testSaveGlobalCredentialsAsNormalUserForAnotherUser() {
+ public function testSaveGlobalCredentialsAsNormalUserForAnotherUser(): void {
$user = $this->createMock(IUser::class);
$user
->method('getUID')
@@ -135,6 +145,8 @@ class AjaxControllerTest extends TestCase {
->expects($this->never())
->method('saveAuth');
- $this->assertSame(false, $this->ajaxController->saveGlobalCredentials('AnotherUserUid', 'test', 'password'));
+ $response = $this->ajaxController->saveGlobalCredentials('AnotherUserUid', 'test', 'password');
+ $this->assertSame($response->getStatus(), 403);
+ $this->assertSame('Permission denied', $response->getData()['message']);
}
}
diff --git a/apps/files_external/tests/Controller/GlobalStoragesControllerTest.php b/apps/files_external/tests/Controller/GlobalStoragesControllerTest.php
index cc905a20ff4..74a27eb15e4 100644
--- a/apps/files_external/tests/Controller/GlobalStoragesControllerTest.php
+++ b/apps/files_external/tests/Controller/GlobalStoragesControllerTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -9,6 +10,7 @@ namespace OCA\Files_External\Tests\Controller;
use OC\User\User;
use OCA\Files_External\Controller\GlobalStoragesController;
use OCA\Files_External\Service\BackendService;
+use OCA\Files_External\Service\GlobalStoragesService;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IGroupManager;
@@ -17,13 +19,11 @@ use OCP\IRequest;
use OCP\IUserSession;
use Psr\Log\LoggerInterface;
-class GlobalStoragesControllerTest extends StoragesControllerTest {
+class GlobalStoragesControllerTest extends StoragesControllerTestCase {
protected function setUp(): void {
parent::setUp();
- $this->service = $this->getMockBuilder('\OCA\Files_External\Service\GlobalStoragesService')
- ->disableOriginalConstructor()
- ->getMock();
+ $this->service = $this->createMock(GlobalStoragesService::class);
$this->service->method('getVisibilityType')
->willReturn(BackendService::VISIBILITY_ADMIN);
@@ -31,7 +31,7 @@ class GlobalStoragesControllerTest extends StoragesControllerTest {
$this->controller = $this->createController(true);
}
- private function createController($allowCreateLocal = true) {
+ private function createController(bool $allowCreateLocal = true): GlobalStoragesController {
$session = $this->createMock(IUserSession::class);
$session->method('getUser')
->willReturn(new User('test', null, $this->createMock(IEventDispatcher::class)));
@@ -53,7 +53,7 @@ class GlobalStoragesControllerTest extends StoragesControllerTest {
);
}
- public function testAddLocalStorageWhenDisabled() {
+ public function testAddLocalStorageWhenDisabled(): void {
$this->controller = $this->createController(false);
parent::testAddLocalStorageWhenDisabled();
}
diff --git a/apps/files_external/tests/Controller/StoragesControllerTest.php b/apps/files_external/tests/Controller/StoragesControllerTestCase.php
index 85f3ca81498..1eb52f9b459 100644
--- a/apps/files_external/tests/Controller/StoragesControllerTest.php
+++ b/apps/files_external/tests/Controller/StoragesControllerTestCase.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -7,70 +9,63 @@
namespace OCA\Files_External\Tests\Controller;
use OCA\Files_External\Controller\GlobalStoragesController;
+use OCA\Files_External\Controller\UserStoragesController;
use OCA\Files_External\Lib\Auth\AuthMechanism;
+use OCA\Files_External\Lib\Auth\NullMechanism;
use OCA\Files_External\Lib\Backend\Backend;
-
+use OCA\Files_External\Lib\Backend\SMB;
use OCA\Files_External\Lib\StorageConfig;
+use OCA\Files_External\MountConfig;
use OCA\Files_External\NotFoundException;
use OCA\Files_External\Service\GlobalStoragesService;
use OCA\Files_External\Service\UserStoragesService;
use OCP\AppFramework\Http;
use PHPUnit\Framework\MockObject\MockObject;
-abstract class StoragesControllerTest extends \Test\TestCase {
-
- /**
- * @var GlobalStoragesController
- */
- protected $controller;
-
- /**
- * @var GlobalStoragesService|UserStoragesService|MockObject
- */
- protected $service;
+abstract class StoragesControllerTestCase extends \Test\TestCase {
+ protected GlobalStoragesController|UserStoragesController $controller;
+ protected GlobalStoragesService|UserStoragesService|MockObject $service;
protected function setUp(): void {
- \OCA\Files_External\MountConfig::$skipTest = true;
+ parent::setUp();
+ MountConfig::$skipTest = true;
}
protected function tearDown(): void {
- \OCA\Files_External\MountConfig::$skipTest = false;
+ MountConfig::$skipTest = false;
+ parent::tearDown();
}
/**
- * @return \OCA\Files_External\Lib\Backend\Backend|MockObject
+ * @return \OCA\Files_External\Lib\Backend\Backend&MockObject
*/
- protected function getBackendMock($class = '\OCA\Files_External\Lib\Backend\SMB', $storageClass = '\OCA\Files_External\Lib\Storage\SMB') {
- $backend = $this->getMockBuilder(Backend::class)
- ->disableOriginalConstructor()
- ->getMock();
+ protected function getBackendMock($class = SMB::class, $storageClass = \OCA\Files_External\Lib\Storage\SMB::class) {
+ $backend = $this->createMock(Backend::class);
$backend->method('getStorageClass')
->willReturn($storageClass);
$backend->method('getIdentifier')
- ->willReturn('identifier:'.$class);
+ ->willReturn('identifier:' . $class);
$backend->method('getParameters')
->willReturn([]);
return $backend;
}
/**
- * @return \OCA\Files_External\Lib\Auth\AuthMechanism|MockObject
+ * @return AuthMechanism|MockObject
*/
- protected function getAuthMechMock($scheme = 'null', $class = '\OCA\Files_External\Lib\Auth\NullMechanism') {
- $authMech = $this->getMockBuilder(AuthMechanism::class)
- ->disableOriginalConstructor()
- ->getMock();
+ protected function getAuthMechMock($scheme = 'null', $class = NullMechanism::class) {
+ $authMech = $this->createMock(AuthMechanism::class);
$authMech->method('getScheme')
->willReturn($scheme);
$authMech->method('getIdentifier')
- ->willReturn('identifier:'.$class);
+ ->willReturn('identifier:' . $class);
$authMech->method('getParameters')
->willReturn([]);
return $authMech;
}
- public function testAddStorage() {
+ public function testAddStorage(): void {
$authMech = $this->getAuthMechMock();
$authMech->method('validateStorage')
->willReturn(true);
@@ -97,8 +92,8 @@ abstract class StoragesControllerTest extends \Test\TestCase {
$response = $this->controller->create(
'mount',
- '\OCA\Files_External\Lib\Storage\SMB',
- '\OCA\Files_External\Lib\Auth\NullMechanism',
+ \OCA\Files_External\Lib\Storage\SMB::class,
+ NullMechanism::class,
[],
[],
[],
@@ -111,7 +106,7 @@ abstract class StoragesControllerTest extends \Test\TestCase {
$this->assertEquals($storageConfig->jsonSerialize(), $data);
}
- public function testAddLocalStorageWhenDisabled() {
+ public function testAddLocalStorageWhenDisabled(): void {
$authMech = $this->getAuthMechMock();
$backend = $this->getBackendMock();
@@ -129,7 +124,7 @@ abstract class StoragesControllerTest extends \Test\TestCase {
$response = $this->controller->create(
'mount',
'local',
- '\OCA\Files_External\Lib\Auth\NullMechanism',
+ NullMechanism::class,
[],
[],
[],
@@ -141,7 +136,7 @@ abstract class StoragesControllerTest extends \Test\TestCase {
$this->assertEquals(Http::STATUS_FORBIDDEN, $response->getStatus());
}
- public function testUpdateStorage() {
+ public function testUpdateStorage(): void {
$authMech = $this->getAuthMechMock();
$authMech->method('validateStorage')
->willReturn(true);
@@ -169,8 +164,8 @@ abstract class StoragesControllerTest extends \Test\TestCase {
$response = $this->controller->update(
1,
'mount',
- '\OCA\Files_External\Lib\Storage\SMB',
- '\OCA\Files_External\Lib\Auth\NullMechanism',
+ \OCA\Files_External\Lib\Storage\SMB::class,
+ NullMechanism::class,
[],
[],
[],
@@ -183,7 +178,7 @@ abstract class StoragesControllerTest extends \Test\TestCase {
$this->assertEquals($storageConfig->jsonSerialize(), $data);
}
- public function mountPointNamesProvider() {
+ public static function mountPointNamesProvider(): array {
return [
[''],
['/'],
@@ -191,10 +186,8 @@ abstract class StoragesControllerTest extends \Test\TestCase {
];
}
- /**
- * @dataProvider mountPointNamesProvider
- */
- public function testAddOrUpdateStorageInvalidMountPoint($mountPoint) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('mountPointNamesProvider')]
+ public function testAddOrUpdateStorageInvalidMountPoint($mountPoint): void {
$storageConfig = new StorageConfig(1);
$storageConfig->setMountPoint($mountPoint);
$storageConfig->setBackend($this->getBackendMock());
@@ -211,8 +204,8 @@ abstract class StoragesControllerTest extends \Test\TestCase {
$response = $this->controller->create(
$mountPoint,
- '\OCA\Files_External\Lib\Storage\SMB',
- '\OCA\Files_External\Lib\Auth\NullMechanism',
+ \OCA\Files_External\Lib\Storage\SMB::class,
+ NullMechanism::class,
[],
[],
[],
@@ -225,8 +218,8 @@ abstract class StoragesControllerTest extends \Test\TestCase {
$response = $this->controller->update(
1,
$mountPoint,
- '\OCA\Files_External\Lib\Storage\SMB',
- '\OCA\Files_External\Lib\Auth\NullMechanism',
+ \OCA\Files_External\Lib\Storage\SMB::class,
+ NullMechanism::class,
[],
[],
[],
@@ -237,10 +230,10 @@ abstract class StoragesControllerTest extends \Test\TestCase {
$this->assertEquals(Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus());
}
- public function testAddOrUpdateStorageInvalidBackend() {
+ public function testAddOrUpdateStorageInvalidBackend(): void {
$this->service->expects($this->exactly(2))
->method('createStorage')
- ->will($this->throwException(new \InvalidArgumentException()));
+ ->willThrowException(new \InvalidArgumentException());
$this->service->expects($this->never())
->method('addStorage');
$this->service->expects($this->never())
@@ -249,7 +242,7 @@ abstract class StoragesControllerTest extends \Test\TestCase {
$response = $this->controller->create(
'mount',
'\OC\Files\Storage\InvalidStorage',
- '\OCA\Files_External\Lib\Auth\NullMechanism',
+ NullMechanism::class,
[],
[],
[],
@@ -263,7 +256,7 @@ abstract class StoragesControllerTest extends \Test\TestCase {
1,
'mount',
'\OC\Files\Storage\InvalidStorage',
- '\OCA\Files_External\Lib\Auth\NullMechanism',
+ NullMechanism::class,
[],
[],
[],
@@ -274,7 +267,7 @@ abstract class StoragesControllerTest extends \Test\TestCase {
$this->assertEquals(Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus());
}
- public function testUpdateStorageNonExisting() {
+ public function testUpdateStorageNonExisting(): void {
$authMech = $this->getAuthMechMock();
$authMech->method('validateStorage')
->willReturn(true);
@@ -297,13 +290,13 @@ abstract class StoragesControllerTest extends \Test\TestCase {
->willReturn($storageConfig);
$this->service->expects($this->once())
->method('updateStorage')
- ->will($this->throwException(new NotFoundException()));
+ ->willThrowException(new NotFoundException());
$response = $this->controller->update(
255,
'mount',
- '\OCA\Files_External\Lib\Storage\SMB',
- '\OCA\Files_External\Lib\Auth\NullMechanism',
+ \OCA\Files_External\Lib\Storage\SMB::class,
+ NullMechanism::class,
[],
[],
[],
@@ -314,7 +307,7 @@ abstract class StoragesControllerTest extends \Test\TestCase {
$this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
}
- public function testDeleteStorage() {
+ public function testDeleteStorage(): void {
$this->service->expects($this->once())
->method('removeStorage');
@@ -322,16 +315,16 @@ abstract class StoragesControllerTest extends \Test\TestCase {
$this->assertEquals(Http::STATUS_NO_CONTENT, $response->getStatus());
}
- public function testDeleteStorageNonExisting() {
+ public function testDeleteStorageNonExisting(): void {
$this->service->expects($this->once())
->method('removeStorage')
- ->will($this->throwException(new NotFoundException()));
+ ->willThrowException(new NotFoundException());
$response = $this->controller->destroy(255);
$this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
}
- public function testGetStorage() {
+ public function testGetStorage(): void {
$backend = $this->getBackendMock();
$authMech = $this->getAuthMechMock();
$storageConfig = new StorageConfig(1);
@@ -353,7 +346,7 @@ abstract class StoragesControllerTest extends \Test\TestCase {
$this->assertEquals($expected, $response->getData());
}
- public function validateStorageProvider() {
+ public static function validateStorageProvider(): array {
return [
[true, true, true],
[false, true, false],
@@ -362,10 +355,8 @@ abstract class StoragesControllerTest extends \Test\TestCase {
];
}
- /**
- * @dataProvider validateStorageProvider
- */
- public function testValidateStorage($backendValidate, $authMechValidate, $expectSuccess) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('validateStorageProvider')]
+ public function testValidateStorage(bool $backendValidate, bool $authMechValidate, bool $expectSuccess): void {
$backend = $this->getBackendMock();
$backend->method('validateStorage')
->willReturn($backendValidate);
@@ -400,8 +391,8 @@ abstract class StoragesControllerTest extends \Test\TestCase {
$response = $this->controller->create(
'mount',
- '\OCA\Files_External\Lib\Storage\SMB',
- '\OCA\Files_External\Lib\Auth\NullMechanism',
+ \OCA\Files_External\Lib\Storage\SMB::class,
+ NullMechanism::class,
[],
[],
[],
diff --git a/apps/files_external/tests/Controller/UserStoragesControllerTest.php b/apps/files_external/tests/Controller/UserStoragesControllerTest.php
index 0ac2197f67c..3e8d89ec060 100644
--- a/apps/files_external/tests/Controller/UserStoragesControllerTest.php
+++ b/apps/files_external/tests/Controller/UserStoragesControllerTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -8,8 +10,10 @@ namespace OCA\Files_External\Tests\Controller;
use OC\User\User;
use OCA\Files_External\Controller\UserStoragesController;
+use OCA\Files_External\Lib\Storage\SMB;
use OCA\Files_External\Lib\StorageConfig;
use OCA\Files_External\Service\BackendService;
+use OCA\Files_External\Service\UserStoragesService;
use OCP\AppFramework\Http;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
@@ -19,18 +23,16 @@ use OCP\IRequest;
use OCP\IUserSession;
use Psr\Log\LoggerInterface;
-class UserStoragesControllerTest extends StoragesControllerTest {
+class UserStoragesControllerTest extends StoragesControllerTestCase {
/**
* @var array
*/
- private $oldAllowedBackends;
+ private array $oldAllowedBackends;
protected function setUp(): void {
parent::setUp();
- $this->service = $this->getMockBuilder('\OCA\Files_External\Service\UserStoragesService')
- ->disableOriginalConstructor()
- ->getMock();
+ $this->service = $this->createMock(UserStoragesService::class);
$this->service->method('getVisibilityType')
->willReturn(BackendService::VISIBILITY_PERSONAL);
@@ -38,7 +40,7 @@ class UserStoragesControllerTest extends StoragesControllerTest {
$this->controller = $this->createController(true);
}
- private function createController($allowCreateLocal = true) {
+ private function createController(bool $allowCreateLocal = true) {
$session = $this->createMock(IUserSession::class);
$session->method('getUser')
->willReturn(new User('test', null, $this->createMock(IEventDispatcher::class)));
@@ -60,12 +62,12 @@ class UserStoragesControllerTest extends StoragesControllerTest {
);
}
- public function testAddLocalStorageWhenDisabled() {
+ public function testAddLocalStorageWhenDisabled(): void {
$this->controller = $this->createController(false);
parent::testAddLocalStorageWhenDisabled();
}
- public function testAddOrUpdateStorageDisallowedBackend() {
+ public function testAddOrUpdateStorageDisallowedBackend(): void {
$backend = $this->getBackendMock();
$backend->method('isVisibleFor')
->with(BackendService::VISIBILITY_PERSONAL)
@@ -88,7 +90,7 @@ class UserStoragesControllerTest extends StoragesControllerTest {
$response = $this->controller->create(
'mount',
- '\OCA\Files_External\Lib\Storage\SMB',
+ SMB::class,
'\Auth\Mechanism',
[],
[],
@@ -102,7 +104,7 @@ class UserStoragesControllerTest extends StoragesControllerTest {
$response = $this->controller->update(
1,
'mount',
- '\OCA\Files_External\Lib\Storage\SMB',
+ SMB::class,
'\Auth\Mechanism',
[],
[],
diff --git a/apps/files_external/tests/DefinitionParameterTest.php b/apps/files_external/tests/DefinitionParameterTest.php
index f9d50e7a34c..c535481bf66 100644
--- a/apps/files_external/tests/DefinitionParameterTest.php
+++ b/apps/files_external/tests/DefinitionParameterTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -9,7 +11,7 @@ namespace OCA\Files_External\Tests;
use OCA\Files_External\Lib\DefinitionParameter as Param;
class DefinitionParameterTest extends \Test\TestCase {
- public function testJsonSerialization() {
+ public function testJsonSerialization(): void {
$param = new Param('foo', 'bar');
$this->assertEquals([
'value' => 'bar',
@@ -38,21 +40,22 @@ class DefinitionParameterTest extends \Test\TestCase {
'tooltip' => '',
], $param->jsonSerialize());
- $param->setType(Param::VALUE_HIDDEN);
- $param->setFlags(Param::FLAG_NONE);
+ $param->setType(Param::VALUE_TEXT);
+ $param->setFlags(Param::FLAG_HIDDEN);
$this->assertEquals([
'value' => 'bar',
- 'flags' => Param::FLAG_NONE,
- 'type' => Param::VALUE_HIDDEN,
+ 'flags' => Param::FLAG_HIDDEN,
+ 'type' => Param::VALUE_TEXT,
'tooltip' => '',
], $param->jsonSerialize());
}
- public function validateValueProvider() {
+ public static function validateValueProvider(): array {
return [
[Param::VALUE_TEXT, Param::FLAG_NONE, 'abc', true],
[Param::VALUE_TEXT, Param::FLAG_NONE, '', false],
[Param::VALUE_TEXT, Param::FLAG_OPTIONAL, '', true],
+ [Param::VALUE_TEXT, Param::FLAG_HIDDEN, '', false],
[Param::VALUE_BOOLEAN, Param::FLAG_NONE, false, true],
[Param::VALUE_BOOLEAN, Param::FLAG_NONE, 123, false],
@@ -62,15 +65,11 @@ class DefinitionParameterTest extends \Test\TestCase {
[Param::VALUE_PASSWORD, Param::FLAG_NONE, 'foobar', true],
[Param::VALUE_PASSWORD, Param::FLAG_NONE, '', false],
-
- [Param::VALUE_HIDDEN, Param::FLAG_NONE, '', false]
];
}
- /**
- * @dataProvider validateValueProvider
- */
- public function testValidateValue($type, $flags, $value, $success, $expectedValue = null) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('validateValueProvider')]
+ public function testValidateValue($type, $flags, $value, $success, $expectedValue = null): void {
$param = new Param('foo', 'bar');
$param->setType($type);
$param->setFlags($flags);
diff --git a/apps/files_external/tests/FrontendDefinitionTraitTest.php b/apps/files_external/tests/FrontendDefinitionTraitTest.php
index e5dc0547d74..e0bf066e70a 100644
--- a/apps/files_external/tests/FrontendDefinitionTraitTest.php
+++ b/apps/files_external/tests/FrontendDefinitionTraitTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -7,16 +8,17 @@
namespace OCA\Files_External\Tests;
use OCA\Files_External\Lib\DefinitionParameter;
+use OCA\Files_External\Lib\FrontendDefinitionTrait;
use OCA\Files_External\Lib\StorageConfig;
class FrontendDefinitionTraitTest extends \Test\TestCase {
- public function testJsonSerialization() {
+ public function testJsonSerialization(): void {
$param = $this->getMockBuilder(DefinitionParameter::class)
->disableOriginalConstructor()
->getMock();
$param->method('getName')->willReturn('foo');
- $trait = $this->getMockForTrait('\OCA\Files_External\Lib\FrontendDefinitionTrait');
+ $trait = $this->getMockForTrait(FrontendDefinitionTrait::class);
$trait->setText('test');
$trait->addParameters([$param]);
$trait->addCustomJs('foo/bar.js');
@@ -32,17 +34,15 @@ class FrontendDefinitionTraitTest extends \Test\TestCase {
$this->assertArrayHasKey('foo', $configuration);
}
- public function validateStorageProvider() {
+ public static function validateStorageProvider(): array {
return [
[true, ['foo' => true, 'bar' => true, 'baz' => true]],
[false, ['foo' => true, 'bar' => false]]
];
}
- /**
- * @dataProvider validateStorageProvider
- */
- public function testValidateStorage($expectedSuccess, $params) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('validateStorageProvider')]
+ public function testValidateStorage(bool $expectedSuccess, array $params): void {
$backendParams = [];
foreach ($params as $name => $valid) {
$param = $this->getMockBuilder(DefinitionParameter::class)
@@ -67,14 +67,14 @@ class FrontendDefinitionTraitTest extends \Test\TestCase {
$storageConfig->expects($this->any())
->method('setBackendOption');
- $trait = $this->getMockForTrait('\OCA\Files_External\Lib\FrontendDefinitionTrait');
+ $trait = $this->getMockForTrait(FrontendDefinitionTrait::class);
$trait->setText('test');
$trait->addParameters($backendParams);
$this->assertEquals($expectedSuccess, $trait->validateStorageDefinition($storageConfig));
}
- public function testValidateStorageSet() {
+ public function testValidateStorageSet(): void {
$param = $this->getMockBuilder(DefinitionParameter::class)
->disableOriginalConstructor()
->getMock();
@@ -98,7 +98,7 @@ class FrontendDefinitionTraitTest extends \Test\TestCase {
->method('setBackendOption')
->with('param', 'foobar');
- $trait = $this->getMockForTrait('\OCA\Files_External\Lib\FrontendDefinitionTrait');
+ $trait = $this->getMockForTrait(FrontendDefinitionTrait::class);
$trait->setText('test');
$trait->addParameter($param);
diff --git a/apps/files_external/tests/LegacyDependencyCheckPolyfillTest.php b/apps/files_external/tests/LegacyDependencyCheckPolyfillTest.php
index 931421551eb..d26aa752ea1 100644
--- a/apps/files_external/tests/LegacyDependencyCheckPolyfillTest.php
+++ b/apps/files_external/tests/LegacyDependencyCheckPolyfillTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -6,6 +8,7 @@
*/
namespace OCA\Files_External\Tests;
+use OCA\Files_External\Lib\LegacyDependencyCheckPolyfill;
use OCA\Files_External\Lib\MissingDependency;
class LegacyDependencyCheckPolyfillTest extends \Test\TestCase {
@@ -13,18 +16,18 @@ class LegacyDependencyCheckPolyfillTest extends \Test\TestCase {
/**
* @return MissingDependency[]
*/
- public static function checkDependencies() {
+ public static function checkDependencies(): array {
return [
(new MissingDependency('dependency'))->setMessage('missing dependency'),
(new MissingDependency('program'))->setMessage('cannot find program'),
];
}
- public function testCheckDependencies() {
- $trait = $this->getMockForTrait('\OCA\Files_External\Lib\LegacyDependencyCheckPolyfill');
+ public function testCheckDependencies(): void {
+ $trait = $this->getMockForTrait(LegacyDependencyCheckPolyfill::class);
$trait->expects($this->once())
->method('getStorageClass')
- ->willReturn('\OCA\Files_External\Tests\LegacyDependencyCheckPolyfillTest');
+ ->willReturn(self::class);
$dependencies = $trait->checkDependencies();
$this->assertCount(2, $dependencies);
diff --git a/apps/files_external/tests/Listener/StorePasswordListenerTest.php b/apps/files_external/tests/Listener/StorePasswordListenerTest.php
index a028e1ac0ef..04635b7dafd 100644
--- a/apps/files_external/tests/Listener/StorePasswordListenerTest.php
+++ b/apps/files_external/tests/Listener/StorePasswordListenerTest.php
@@ -22,15 +22,12 @@ use Test\TestCase;
* @group DB
*/
class StorePasswordListenerTest extends TestCase {
- /** @var MockObject|IUser */
- protected $mockedUser;
+ protected IUser&MockObject $mockedUser;
protected function setUp(): void {
parent::setUp();
$this->mockedUser = $this->createMock(IUser::class);
- $this->mockedUser
- ->expects($this->any())
- ->method('getUID')
+ $this->mockedUser->method('getUID')
->willReturn('test');
}
@@ -76,7 +73,7 @@ class StorePasswordListenerTest extends TestCase {
$storePasswordListener->handle($event);
}
- public function testClassicLoginSameCredentials() {
+ public function testClassicLoginSameCredentials(): void {
$this->getMockedCredentialManager(
[
'user' => 'test',
@@ -87,7 +84,7 @@ class StorePasswordListenerTest extends TestCase {
);
}
- public function testClassicLoginNewPassword() {
+ public function testClassicLoginNewPassword(): void {
$this->getMockedCredentialManager(
[
'user' => 'test',
@@ -101,7 +98,7 @@ class StorePasswordListenerTest extends TestCase {
);
}
- public function testClassicLoginNewUser() {
+ public function testClassicLoginNewUser(): void {
$this->getMockedCredentialManager(
[
'user' => 'test',
@@ -115,7 +112,7 @@ class StorePasswordListenerTest extends TestCase {
);
}
- public function testSSOLogin() {
+ public function testSSOLogin(): void {
$this->getMockedCredentialManager(
[
'user' => 'test',
@@ -126,7 +123,7 @@ class StorePasswordListenerTest extends TestCase {
);
}
- public function testPasswordUpdated() {
+ public function testPasswordUpdated(): void {
$this->getMockedCredentialManager(
[
'user' => 'test',
@@ -140,7 +137,7 @@ class StorePasswordListenerTest extends TestCase {
);
}
- public function testUserLoginWithToken() {
+ public function testUserLoginWithToken(): void {
$this->getMockedCredentialManager(
null,
new UserLoggedInEvent($this->mockedUser, 'test', 'password', true),
@@ -148,7 +145,7 @@ class StorePasswordListenerTest extends TestCase {
);
}
- public function testNoInitialCredentials() {
+ public function testNoInitialCredentials(): void {
$this->getMockedCredentialManager(
false,
new PasswordUpdatedEvent($this->mockedUser, 'test', 'password'),
diff --git a/apps/files_external/tests/OwnCloudFunctionsTest.php b/apps/files_external/tests/OwnCloudFunctionsTest.php
index 9efefe8e4dd..2e052cb86b0 100644
--- a/apps/files_external/tests/OwnCloudFunctionsTest.php
+++ b/apps/files_external/tests/OwnCloudFunctionsTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -6,6 +8,8 @@
*/
namespace OCA\Files_External\Tests;
+use OCA\Files_External\Lib\Storage\OwnCloud;
+
/**
* Class OwnCloudFunctions
*
@@ -14,7 +18,7 @@ namespace OCA\Files_External\Tests;
* @package OCA\Files_External\Tests
*/
class OwnCloudFunctionsTest extends \Test\TestCase {
- public function configUrlProvider() {
+ public static function configUrlProvider(): array {
return [
[
[
@@ -83,13 +87,11 @@ class OwnCloudFunctionsTest extends \Test\TestCase {
];
}
- /**
- * @dataProvider configUrlProvider
- */
- public function testConfig($config, $expectedUri) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('configUrlProvider')]
+ public function testConfig(array $config, string $expectedUri): void {
$config['user'] = 'someuser';
$config['password'] = 'somepassword';
- $instance = new \OCA\Files_External\Lib\Storage\OwnCloud($config);
+ $instance = new OwnCloud($config);
$this->assertEquals($expectedUri, $instance->createBaseUri());
}
}
diff --git a/apps/files_external/tests/PersonalMountTest.php b/apps/files_external/tests/PersonalMountTest.php
index aec0a8b6f75..618048c3335 100644
--- a/apps/files_external/tests/PersonalMountTest.php
+++ b/apps/files_external/tests/PersonalMountTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -8,21 +10,19 @@ namespace OCA\Files_External\Tests;
use OC\Files\Mount\Manager;
use OC\Files\SetupManagerFactory;
+use OC\Files\Storage\Storage;
use OCA\Files_External\Lib\PersonalMount;
use OCA\Files_External\Lib\StorageConfig;
+use OCA\Files_External\Service\UserStoragesService;
use Test\TestCase;
class PersonalMountTest extends TestCase {
- public function testFindByStorageId() {
+ public function testFindByStorageId(): void {
$storageConfig = $this->createMock(StorageConfig::class);
- /** @var \OCA\Files_External\Service\UserStoragesService $storageService */
- $storageService = $this->getMockBuilder('\OCA\Files_External\Service\UserStoragesService')
- ->disableOriginalConstructor()
- ->getMock();
-
- $storage = $this->getMockBuilder('\OC\Files\Storage\Storage')
- ->disableOriginalConstructor()
- ->getMock();
+ /** @var UserStoragesService $storageService */
+ $storageService = $this->createMock(UserStoragesService::class);
+
+ $storage = $this->createMock(Storage::class);
$storage->expects($this->any())
->method('getId')
diff --git a/apps/files_external/tests/Service/BackendServiceTest.php b/apps/files_external/tests/Service/BackendServiceTest.php
index bda96550317..ef545688040 100644
--- a/apps/files_external/tests/Service/BackendServiceTest.php
+++ b/apps/files_external/tests/Service/BackendServiceTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -12,54 +13,45 @@ use OCA\Files_External\Lib\Backend\Backend;
use OCA\Files_External\Lib\Config\IAuthMechanismProvider;
use OCA\Files_External\Lib\Config\IBackendProvider;
use OCA\Files_External\Service\BackendService;
-use OCP\IConfig;
+use OCP\IAppConfig;
+use PHPUnit\Framework\MockObject\MockObject;
class BackendServiceTest extends \Test\TestCase {
-
- /** @var \OCP\IConfig|\PHPUnit\Framework\MockObject\MockObject */
- protected $config;
+ protected IAppConfig&MockObject $appConfig;
protected function setUp(): void {
- $this->config = $this->createMock(IConfig::class);
+ $this->appConfig = $this->createMock(IAppConfig::class);
}
/**
- * @param string $class
- *
- * @return \OCA\Files_External\Lib\Backend\Backend|\PHPUnit\Framework\MockObject\MockObject
+ * @return \OCA\Files_External\Lib\Backend\Backend&MockObject
*/
- protected function getBackendMock($class) {
- $backend = $this->getMockBuilder(Backend::class)
- ->disableOriginalConstructor()
- ->getMock();
- $backend->method('getIdentifier')->willReturn('identifier:'.$class);
- $backend->method('getIdentifierAliases')->willReturn(['identifier:'.$class]);
+ protected function getBackendMock(string $class) {
+ $backend = $this->createMock(Backend::class);
+ $backend->method('getIdentifier')->willReturn('identifier:' . $class);
+ $backend->method('getIdentifierAliases')->willReturn(['identifier:' . $class]);
return $backend;
}
/**
* @param string $class
*
- * @return \OCA\Files_External\Lib\Auth\AuthMechanism|\PHPUnit\Framework\MockObject\MockObject
+ * @return AuthMechanism&MockObject
*/
protected function getAuthMechanismMock($class) {
- $backend = $this->getMockBuilder(AuthMechanism::class)
- ->disableOriginalConstructor()
- ->getMock();
- $backend->method('getIdentifier')->willReturn('identifier:'.$class);
- $backend->method('getIdentifierAliases')->willReturn(['identifier:'.$class]);
+ $backend = $this->createMock(AuthMechanism::class);
+ $backend->method('getIdentifier')->willReturn('identifier:' . $class);
+ $backend->method('getIdentifierAliases')->willReturn(['identifier:' . $class]);
return $backend;
}
- public function testRegisterBackend() {
- $service = new BackendService($this->config);
+ public function testRegisterBackend(): void {
+ $service = new BackendService($this->appConfig);
$backend = $this->getBackendMock('\Foo\Bar');
- /** @var \OCA\Files_External\Lib\Backend\Backend|\PHPUnit\Framework\MockObject\MockObject $backendAlias */
- $backendAlias = $this->getMockBuilder(Backend::class)
- ->disableOriginalConstructor()
- ->getMock();
+ /** @var \OCA\Files_External\Lib\Backend\Backend&MockObject $backendAlias */
+ $backendAlias = $this->createMock(Backend::class);
$backendAlias->method('getIdentifierAliases')
->willReturn(['identifier_real', 'identifier_alias']);
$backendAlias->method('getIdentifier')
@@ -79,13 +71,13 @@ class BackendServiceTest extends \Test\TestCase {
$this->assertArrayNotHasKey('identifier_alias', $backends);
}
- public function testBackendProvider() {
- $service = new BackendService($this->config);
+ public function testBackendProvider(): void {
+ $service = new BackendService($this->appConfig);
$backend1 = $this->getBackendMock('\Foo\Bar');
$backend2 = $this->getBackendMock('\Bar\Foo');
- /** @var IBackendProvider|\PHPUnit\Framework\MockObject\MockObject $providerMock */
+ /** @var IBackendProvider&MockObject $providerMock */
$providerMock = $this->createMock(IBackendProvider::class);
$providerMock->expects($this->once())
->method('getBackends')
@@ -98,13 +90,13 @@ class BackendServiceTest extends \Test\TestCase {
$this->assertCount(2, $service->getBackends());
}
- public function testAuthMechanismProvider() {
- $service = new BackendService($this->config);
+ public function testAuthMechanismProvider(): void {
+ $service = new BackendService($this->appConfig);
$backend1 = $this->getAuthMechanismMock('\Foo\Bar');
$backend2 = $this->getAuthMechanismMock('\Bar\Foo');
- /** @var IAuthMechanismProvider|\PHPUnit\Framework\MockObject\MockObject $providerMock */
+ /** @var IAuthMechanismProvider&MockObject $providerMock */
$providerMock = $this->createMock(IAuthMechanismProvider::class);
$providerMock->expects($this->once())
->method('getAuthMechanisms')
@@ -117,21 +109,21 @@ class BackendServiceTest extends \Test\TestCase {
$this->assertCount(2, $service->getAuthMechanisms());
}
- public function testMultipleBackendProviders() {
- $service = new BackendService($this->config);
+ public function testMultipleBackendProviders(): void {
+ $service = new BackendService($this->appConfig);
$backend1a = $this->getBackendMock('\Foo\Bar');
$backend1b = $this->getBackendMock('\Bar\Foo');
$backend2 = $this->getBackendMock('\Dead\Beef');
- /** @var IBackendProvider|\PHPUnit\Framework\MockObject\MockObject $provider1Mock */
+ /** @var IBackendProvider&MockObject $provider1Mock */
$provider1Mock = $this->createMock(IBackendProvider::class);
$provider1Mock->expects($this->once())
->method('getBackends')
->willReturn([$backend1a, $backend1b]);
$service->registerBackendProvider($provider1Mock);
- /** @var IBackendProvider|\PHPUnit\Framework\MockObject\MockObject $provider2Mock */
+ /** @var IBackendProvider&MockObject $provider2Mock */
$provider2Mock = $this->createMock(IBackendProvider::class);
$provider2Mock->expects($this->once())
->method('getBackends')
@@ -145,15 +137,17 @@ class BackendServiceTest extends \Test\TestCase {
$this->assertCount(3, $service->getBackends());
}
- public function testUserMountingBackends() {
- $this->config->expects($this->exactly(2))
- ->method('getAppValue')
- ->willReturnMap([
- ['files_external', 'allow_user_mounting', 'yes', 'yes'],
- ['files_external', 'user_mounting_backends', '', 'identifier:\User\Mount\Allowed,identifier_alias']
- ]);
+ public function testUserMountingBackends(): void {
+ $this->appConfig->expects($this->once())
+ ->method('getValueString')
+ ->with('files_external', 'user_mounting_backends')
+ ->willReturn('identifier:\User\Mount\Allowed,identifier_alias');
+ $this->appConfig->expects($this->once())
+ ->method('getValueBool')
+ ->with('files_external', 'allow_user_mounting')
+ ->willReturn(true);
- $service = new BackendService($this->config);
+ $service = new BackendService($this->appConfig);
$backendAllowed = $this->getBackendMock('\User\Mount\Allowed');
$backendAllowed->expects($this->never())
@@ -176,8 +170,8 @@ class BackendServiceTest extends \Test\TestCase {
$service->registerBackend($backendAlias);
}
- public function testGetAvailableBackends() {
- $service = new BackendService($this->config);
+ public function testGetAvailableBackends(): void {
+ $service = new BackendService($this->appConfig);
$backendAvailable = $this->getBackendMock('\Backend\Available');
$backendAvailable->expects($this->once())
@@ -200,7 +194,7 @@ class BackendServiceTest extends \Test\TestCase {
$this->assertArrayNotHasKey('identifier:\Backend\NotAvailable', $availableBackends);
}
- public function invalidConfigPlaceholderProvider() {
+ public static function invalidConfigPlaceholderProvider(): array {
return [
[['@user']],
[['$user']],
@@ -214,13 +208,11 @@ class BackendServiceTest extends \Test\TestCase {
];
}
- /**
- * @dataProvider invalidConfigPlaceholderProvider
- */
- public function testRegisterConfigHandlerInvalid(array $placeholders) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('invalidConfigPlaceholderProvider')]
+ public function testRegisterConfigHandlerInvalid(array $placeholders): void {
$this->expectException(\RuntimeException::class);
- $service = new BackendService($this->config);
+ $service = new BackendService($this->appConfig);
$mock = $this->createMock(IConfigHandler::class);
$cb = function () use ($mock) {
return $mock;
@@ -230,8 +222,8 @@ class BackendServiceTest extends \Test\TestCase {
}
}
- public function testConfigHandlers() {
- $service = new BackendService($this->config);
+ public function testConfigHandlers(): void {
+ $service = new BackendService($this->appConfig);
$mock = $this->createMock(IConfigHandler::class);
$mock->expects($this->exactly(3))
->method('handle');
diff --git a/apps/files_external/tests/Service/DBConfigServiceTest.php b/apps/files_external/tests/Service/DBConfigServiceTest.php
index 1c2cafc93f0..85d8b70fda7 100644
--- a/apps/files_external/tests/Service/DBConfigServiceTest.php
+++ b/apps/files_external/tests/Service/DBConfigServiceTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -8,28 +10,23 @@ namespace OCA\Files_External\Tests\Service;
use OCA\Files_External\Service\DBConfigService;
use OCP\IDBConnection;
+use OCP\Security\ICrypto;
+use OCP\Server;
use Test\TestCase;
/**
* @group DB
*/
class DBConfigServiceTest extends TestCase {
- /**
- * @var DBConfigService
- */
- private $dbConfig;
-
- /**
- * @var IDBConnection
- */
- private $connection;
+ private IDBConnection $connection;
+ private DBConfigService $dbConfig;
- private $mounts = [];
+ private array $mounts = [];
protected function setUp(): void {
parent::setUp();
- $this->connection = \OC::$server->getDatabaseConnection();
- $this->dbConfig = new DBConfigService($this->connection, \OC::$server->getCrypto());
+ $this->connection = Server::get(IDBConnection::class);
+ $this->dbConfig = new DBConfigService($this->connection, Server::get(ICrypto::class));
}
protected function tearDown(): void {
@@ -37,15 +34,16 @@ class DBConfigServiceTest extends TestCase {
$this->dbConfig->removeMount($mount);
}
$this->mounts = [];
+ parent::tearDown();
}
- private function addMount($mountPoint, $storageBackend, $authBackend, $priority, $type) {
+ private function addMount(string $mountPoint, string $storageBackend, string $authBackend, int $priority, int $type) {
$id = $this->dbConfig->addMount($mountPoint, $storageBackend, $authBackend, $priority, $type);
$this->mounts[] = $id;
return $id;
}
- public function testAddSimpleMount() {
+ public function testAddSimpleMount(): void {
$id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$mount = $this->dbConfig->getMountById($id);
@@ -59,7 +57,7 @@ class DBConfigServiceTest extends TestCase {
$this->assertEquals([], $mount['options']);
}
- public function testAddApplicable() {
+ public function testAddApplicable(): void {
$id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test');
@@ -72,14 +70,14 @@ class DBConfigServiceTest extends TestCase {
$this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
$mount = $this->dbConfig->getMountById($id);
- $this->assertEquals([
+ $this->assertEqualsCanonicalizing([
['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id],
['type' => DBConfigService::APPLICABLE_TYPE_GROUP, 'value' => 'bar', 'mount_id' => $id],
['type' => DBConfigService::APPLICABLE_TYPE_GLOBAL, 'value' => null, 'mount_id' => $id]
], $mount['applicable']);
}
- public function testAddApplicableDouble() {
+ public function testAddApplicableDouble(): void {
$id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test');
$this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test');
@@ -90,7 +88,7 @@ class DBConfigServiceTest extends TestCase {
], $mount['applicable']);
}
- public function testDeleteMount() {
+ public function testDeleteMount(): void {
$id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$this->dbConfig->removeMount($id);
@@ -99,7 +97,7 @@ class DBConfigServiceTest extends TestCase {
$this->assertEquals(null, $mount);
}
- public function testRemoveApplicable() {
+ public function testRemoveApplicable(): void {
$id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test');
$this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test');
@@ -108,7 +106,7 @@ class DBConfigServiceTest extends TestCase {
$this->assertEquals([], $mount['applicable']);
}
- public function testRemoveApplicableGlobal() {
+ public function testRemoveApplicableGlobal(): void {
$id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
$this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
@@ -120,7 +118,7 @@ class DBConfigServiceTest extends TestCase {
], $mount['applicable']);
}
- public function testSetConfig() {
+ public function testSetConfig(): void {
$id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$this->dbConfig->setConfig($id, 'foo', 'bar');
@@ -133,7 +131,7 @@ class DBConfigServiceTest extends TestCase {
$this->assertEquals(['foo' => 'bar', 'foo2' => 'bar2'], $mount['config']);
}
- public function testSetConfigOverwrite() {
+ public function testSetConfigOverwrite(): void {
$id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$this->dbConfig->setConfig($id, 'foo', 'bar');
$this->dbConfig->setConfig($id, 'asd', '1');
@@ -143,7 +141,7 @@ class DBConfigServiceTest extends TestCase {
$this->assertEquals(['foo' => 'qwerty', 'asd' => '1'], $mount['config']);
}
- public function testSetOption() {
+ public function testSetOption(): void {
$id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$this->dbConfig->setOption($id, 'foo', 'bar');
@@ -156,7 +154,7 @@ class DBConfigServiceTest extends TestCase {
$this->assertEquals(['foo' => 'bar', 'foo2' => 'bar2'], $mount['options']);
}
- public function testSetOptionOverwrite() {
+ public function testSetOptionOverwrite(): void {
$id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$this->dbConfig->setOption($id, 'foo', 'bar');
$this->dbConfig->setOption($id, 'asd', '1');
@@ -166,7 +164,7 @@ class DBConfigServiceTest extends TestCase {
$this->assertEquals(['foo' => 'qwerty', 'asd' => '1'], $mount['options']);
}
- public function testGetMountsFor() {
+ public function testGetMountsFor(): void {
$mounts = $this->dbConfig->getMountsFor(DBConfigService::APPLICABLE_TYPE_USER, 'test');
$this->assertEquals([], $mounts);
@@ -179,7 +177,7 @@ class DBConfigServiceTest extends TestCase {
$this->assertEquals([['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id]], $mounts[0]['applicable']);
}
- public function testGetAdminMounts() {
+ public function testGetAdminMounts(): void {
$id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$this->addMount('/test2', 'foo2', 'bar2', 100, DBConfigService::MOUNT_TYPE_PERSONAL);
@@ -188,7 +186,7 @@ class DBConfigServiceTest extends TestCase {
$this->assertEquals($id1, $mounts[0]['mount_id']);
}
- public function testGetAdminMountsFor() {
+ public function testGetAdminMountsFor(): void {
$id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$this->addMount('/test2', 'foo2', 'bar2', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$id3 = $this->addMount('/test3', 'foo3', 'bar3', 100, DBConfigService::MOUNT_TYPE_PERSONAL);
@@ -202,7 +200,7 @@ class DBConfigServiceTest extends TestCase {
$this->assertEquals([['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id1]], $mounts[0]['applicable']);
}
- public function testGetUserMountsFor() {
+ public function testGetUserMountsFor(): void {
$id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$this->addMount('/test2', 'foo2', 'bar2', 100, DBConfigService::MOUNT_TYPE_PERSONAL);
$id3 = $this->addMount('/test3', 'foo3', 'bar3', 100, DBConfigService::MOUNT_TYPE_PERSONAL);
@@ -216,7 +214,7 @@ class DBConfigServiceTest extends TestCase {
$this->assertEquals([['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id3]], $mounts[0]['applicable']);
}
- public function testGetAdminMountsForGlobal() {
+ public function testGetAdminMountsForGlobal(): void {
$id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$this->dbConfig->addApplicable($id1, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
@@ -227,7 +225,7 @@ class DBConfigServiceTest extends TestCase {
$this->assertEquals([['type' => DBConfigService::APPLICABLE_TYPE_GLOBAL, 'value' => null, 'mount_id' => $id1]], $mounts[0]['applicable']);
}
- public function testSetMountPoint() {
+ public function testSetMountPoint(): void {
$id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$id2 = $this->addMount('/foo', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
@@ -241,7 +239,7 @@ class DBConfigServiceTest extends TestCase {
$this->assertEquals('/foo', $mount['mount_point']);
}
- public function testSetAuthBackend() {
+ public function testSetAuthBackend(): void {
$id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$id2 = $this->addMount('/foo', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
@@ -255,7 +253,7 @@ class DBConfigServiceTest extends TestCase {
$this->assertEquals('bar', $mount['auth_backend']);
}
- public function testGetMountsForDuplicateByGroup() {
+ public function testGetMountsForDuplicateByGroup(): void {
$id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$this->dbConfig->addApplicable($id1, DBConfigService::APPLICABLE_TYPE_GROUP, 'group1');
@@ -266,7 +264,7 @@ class DBConfigServiceTest extends TestCase {
$this->assertEquals($id1, $mounts[0]['mount_id']);
}
- public function testGetAllMounts() {
+ public function testGetAllMounts(): void {
$id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$id2 = $this->addMount('/test2', 'foo2', 'bar2', 100, DBConfigService::MOUNT_TYPE_PERSONAL);
diff --git a/apps/files_external/tests/Service/GlobalStoragesServiceTest.php b/apps/files_external/tests/Service/GlobalStoragesServiceTest.php
index 18fd9d174f2..0a3749981c8 100644
--- a/apps/files_external/tests/Service/GlobalStoragesServiceTest.php
+++ b/apps/files_external/tests/Service/GlobalStoragesServiceTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -7,13 +9,14 @@
namespace OCA\Files_External\Tests\Service;
use OC\Files\Filesystem;
+use OCA\Files_External\MountConfig;
use OCA\Files_External\Service\GlobalStoragesService;
/**
* @group DB
*/
-class GlobalStoragesServiceTest extends StoragesServiceTest {
+class GlobalStoragesServiceTest extends StoragesServiceTestCase {
protected function setUp(): void {
parent::setUp();
$this->service = new GlobalStoragesService($this->backendService, $this->dbConfig, $this->mountCache, $this->eventDispatcher);
@@ -43,7 +46,7 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
]);
}
- public function storageDataProvider() {
+ public static function storageDataProvider(): array {
return [
// all users
[
@@ -112,10 +115,8 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
];
}
- /**
- * @dataProvider storageDataProvider
- */
- public function testAddStorage($storageParams) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('storageDataProvider')]
+ public function testAddStorage($storageParams): void {
$storage = $this->makeStorageConfig($storageParams);
$newStorage = $this->service->addStorage($storage);
@@ -136,10 +137,8 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
$this->assertEquals($baseId + 1, $nextStorage->getId());
}
- /**
- * @dataProvider storageDataProvider
- */
- public function testUpdateStorage($updatedStorageParams) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('storageDataProvider')]
+ public function testUpdateStorage($updatedStorageParams): void {
$updatedStorage = $this->makeStorageConfig($updatedStorageParams);
$storage = $this->makeStorageConfig([
'mountPoint' => 'mountpoint',
@@ -165,13 +164,13 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
$this->assertEquals($updatedStorage->getMountPoint(), $newStorage->getMountPoint());
$this->assertEquals($updatedStorage->getBackendOptions()['password'], $newStorage->getBackendOptions()['password']);
- $this->assertEquals($updatedStorage->getApplicableUsers(), $newStorage->getApplicableUsers());
+ $this->assertEqualsCanonicalizing($updatedStorage->getApplicableUsers(), $newStorage->getApplicableUsers());
$this->assertEquals($updatedStorage->getApplicableGroups(), $newStorage->getApplicableGroups());
$this->assertEquals($updatedStorage->getPriority(), $newStorage->getPriority());
$this->assertEquals(0, $newStorage->getStatus());
}
- public function hooksAddStorageDataProvider() {
+ public static function hooksAddStorageDataProvider(): array {
return [
// applicable all
[
@@ -181,7 +180,7 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
[
[
Filesystem::signal_create_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'all'
],
],
@@ -194,7 +193,7 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
[
[
Filesystem::signal_create_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'user1',
],
],
@@ -207,7 +206,7 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
[
[
Filesystem::signal_create_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
+ MountConfig::MOUNT_TYPE_GROUP,
'group1',
],
],
@@ -219,12 +218,12 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
[
[
Filesystem::signal_create_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'user1',
],
[
Filesystem::signal_create_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'user2',
],
],
@@ -237,12 +236,12 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
[
[
Filesystem::signal_create_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
+ MountConfig::MOUNT_TYPE_GROUP,
'group1'
],
[
Filesystem::signal_create_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
+ MountConfig::MOUNT_TYPE_GROUP,
'group2'
],
],
@@ -255,22 +254,22 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
[
[
Filesystem::signal_create_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'user1',
],
[
Filesystem::signal_create_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'user2',
],
[
Filesystem::signal_create_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
+ MountConfig::MOUNT_TYPE_GROUP,
'group1'
],
[
Filesystem::signal_create_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
+ MountConfig::MOUNT_TYPE_GROUP,
'group2'
],
],
@@ -278,10 +277,8 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
];
}
- /**
- * @dataProvider hooksAddStorageDataProvider
- */
- public function testHooksAddStorage($applicableUsers, $applicableGroups, $expectedCalls) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('hooksAddStorageDataProvider')]
+ public function testHooksAddStorage($applicableUsers, $applicableGroups, $expectedCalls): void {
$storage = $this->makeTestStorageData();
$storage->setApplicableUsers($applicableUsers);
$storage->setApplicableGroups($applicableGroups);
@@ -300,7 +297,7 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
}
}
- public function hooksUpdateStorageDataProvider() {
+ public static function hooksUpdateStorageDataProvider(): array {
return [
[
// nothing to multiple users and groups
@@ -313,27 +310,27 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
// delete the "all entry"
[
Filesystem::signal_delete_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'all',
],
[
Filesystem::signal_create_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'user1',
],
[
Filesystem::signal_create_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'user2',
],
[
Filesystem::signal_create_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
+ MountConfig::MOUNT_TYPE_GROUP,
'group1'
],
[
Filesystem::signal_create_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
+ MountConfig::MOUNT_TYPE_GROUP,
'group2'
],
],
@@ -348,12 +345,12 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
[
[
Filesystem::signal_create_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'user2',
],
[
Filesystem::signal_create_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
+ MountConfig::MOUNT_TYPE_GROUP,
'group2'
],
],
@@ -368,12 +365,12 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
[
[
Filesystem::signal_delete_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'user2',
],
[
Filesystem::signal_delete_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
+ MountConfig::MOUNT_TYPE_GROUP,
'group2'
],
],
@@ -388,18 +385,18 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
[
[
Filesystem::signal_delete_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'user1',
],
[
Filesystem::signal_delete_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
+ MountConfig::MOUNT_TYPE_GROUP,
'group1'
],
// create the "all" entry
[
Filesystem::signal_create_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'all'
],
],
@@ -416,15 +413,14 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
];
}
- /**
- * @dataProvider hooksUpdateStorageDataProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('hooksUpdateStorageDataProvider')]
public function testHooksUpdateStorage(
- $sourceApplicableUsers,
- $sourceApplicableGroups,
- $updatedApplicableUsers,
- $updatedApplicableGroups,
- $expectedCalls) {
+ array $sourceApplicableUsers,
+ array $sourceApplicableGroups,
+ array $updatedApplicableUsers,
+ array $updatedApplicableGroups,
+ array $expectedCalls,
+ ): void {
$storage = $this->makeTestStorageData();
$storage->setApplicableUsers($sourceApplicableUsers);
$storage->setApplicableGroups($sourceApplicableGroups);
@@ -452,7 +448,7 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
}
- public function testHooksRenameMountPoint() {
+ public function testHooksRenameMountPoint(): void {
$storage = $this->makeTestStorageData();
$storage->setApplicableUsers(['user1', 'user2']);
$storage->setApplicableGroups(['group1', 'group2']);
@@ -470,50 +466,50 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
[
Filesystem::signal_delete_mount,
'/mountpoint',
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'user1',
],
[
Filesystem::signal_delete_mount,
'/mountpoint',
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'user2',
],
[
Filesystem::signal_delete_mount,
'/mountpoint',
- \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
+ MountConfig::MOUNT_TYPE_GROUP,
'group1',
],
[
Filesystem::signal_delete_mount,
'/mountpoint',
- \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
+ MountConfig::MOUNT_TYPE_GROUP,
'group2',
],
// creates new one
[
Filesystem::signal_create_mount,
'/renamedMountpoint',
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'user1',
],
[
Filesystem::signal_create_mount,
'/renamedMountpoint',
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'user2',
],
[
Filesystem::signal_create_mount,
'/renamedMountpoint',
- \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
+ MountConfig::MOUNT_TYPE_GROUP,
'group1',
],
[
Filesystem::signal_create_mount,
'/renamedMountpoint',
- \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
+ MountConfig::MOUNT_TYPE_GROUP,
'group2',
],
];
@@ -531,7 +527,7 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
}
}
- public function hooksDeleteStorageDataProvider() {
+ public static function hooksDeleteStorageDataProvider(): array {
return [
[
['user1', 'user2'],
@@ -540,22 +536,22 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
[
[
Filesystem::signal_delete_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'user1',
],
[
Filesystem::signal_delete_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'user2',
],
[
Filesystem::signal_delete_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
+ MountConfig::MOUNT_TYPE_GROUP,
'group1'
],
[
Filesystem::signal_delete_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
+ MountConfig::MOUNT_TYPE_GROUP,
'group2'
],
],
@@ -567,7 +563,7 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
[
[
Filesystem::signal_delete_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'all',
],
],
@@ -575,13 +571,12 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
];
}
- /**
- * @dataProvider hooksDeleteStorageDataProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('hooksDeleteStorageDataProvider')]
public function testHooksDeleteStorage(
- $sourceApplicableUsers,
- $sourceApplicableGroups,
- $expectedCalls) {
+ array $sourceApplicableUsers,
+ array $sourceApplicableGroups,
+ array $expectedCalls,
+ ): void {
$storage = $this->makeTestStorageData();
$storage->setApplicableUsers($sourceApplicableUsers);
$storage->setApplicableGroups($sourceApplicableGroups);
diff --git a/apps/files_external/tests/Service/StoragesServiceTest.php b/apps/files_external/tests/Service/StoragesServiceTestCase.php
index 705d5fa276f..b41eb409468 100644
--- a/apps/files_external/tests/Service/StoragesServiceTest.php
+++ b/apps/files_external/tests/Service/StoragesServiceTestCase.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -6,13 +8,16 @@
*/
namespace OCA\Files_External\Tests\Service;
+use OC\Files\Cache\Storage;
use OC\Files\Filesystem;
-
use OCA\Files_External\Lib\Auth\AuthMechanism;
use OCA\Files_External\Lib\Auth\InvalidAuth;
+use OCA\Files_External\Lib\Auth\NullMechanism;
use OCA\Files_External\Lib\Backend\Backend;
use OCA\Files_External\Lib\Backend\InvalidBackend;
+use OCA\Files_External\Lib\Backend\SMB;
use OCA\Files_External\Lib\StorageConfig;
+use OCA\Files_External\MountConfig;
use OCA\Files_External\NotFoundException;
use OCA\Files_External\Service\BackendService;
use OCA\Files_External\Service\DBConfigService;
@@ -23,12 +28,16 @@ use OCP\Files\Cache\ICache;
use OCP\Files\Config\IUserMountCache;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\Storage\IStorage;
+use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IUser;
+use OCP\Security\ICrypto;
use OCP\Server;
+use OCP\Util;
+use PHPUnit\Framework\MockObject\MockObject;
class CleaningDBConfig extends DBConfigService {
- private $mountIds = [];
+ private array $mountIds = [];
public function addMount($mountPoint, $storageBackend, $authBackend, $priority, $type) {
$id = parent::addMount($mountPoint, $storageBackend, $authBackend, $priority, $type); // TODO: Change the autogenerated stub
@@ -46,61 +55,31 @@ class CleaningDBConfig extends DBConfigService {
/**
* @group DB
*/
-abstract class StoragesServiceTest extends \Test\TestCase {
- /**
- * @var StoragesService
- */
- protected $service;
-
- /** @var BackendService */
- protected $backendService;
-
- /**
- * Data directory
- *
- * @var string
- */
- protected $dataDir;
-
- /** @var CleaningDBConfig */
- protected $dbConfig;
-
- /**
- * Hook calls
- *
- * @var array
- */
- protected static $hookCalls;
-
- /**
- * @var \PHPUnit\Framework\MockObject\MockObject|\OCP\Files\Config\IUserMountCache
- */
- protected $mountCache;
-
- /**
- * @var \PHPUnit\Framework\MockObject\MockObject|IEventDispatcher
- */
- protected IEventDispatcher $eventDispatcher;
+abstract class StoragesServiceTestCase extends \Test\TestCase {
+ protected StoragesService $service;
+ protected BackendService $backendService;
+ protected string $dataDir;
+ protected CleaningDBConfig $dbConfig;
+ protected static array $hookCalls;
+ protected IUserMountCache&MockObject $mountCache;
+ protected IEventDispatcher&MockObject $eventDispatcher;
protected function setUp(): void {
parent::setUp();
- $this->dbConfig = new CleaningDBConfig(\OC::$server->getDatabaseConnection(), \OC::$server->getCrypto());
+ $this->dbConfig = new CleaningDBConfig(Server::get(IDBConnection::class), Server::get(ICrypto::class));
self::$hookCalls = [];
- $config = \OC::$server->getConfig();
+ $config = Server::get(IConfig::class);
$this->dataDir = $config->getSystemValue(
'datadirectory',
\OC::$SERVERROOT . '/data/'
);
- \OCA\Files_External\MountConfig::$skipTest = true;
+ MountConfig::$skipTest = true;
$this->mountCache = $this->createMock(IUserMountCache::class);
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
// prepare BackendService mock
- $this->backendService =
- $this->getMockBuilder('\OCA\Files_External\Service\BackendService')
- ->disableOriginalConstructor()
- ->getMock();
+ $this->backendService = $this->createMock(BackendService::class);
$authMechanisms = [
'identifier:\Auth\Mechanism' => $this->getAuthMechMock('null', '\Auth\Mechanism'),
@@ -143,11 +122,11 @@ abstract class StoragesServiceTest extends \Test\TestCase {
->willReturn($backends);
$this->overwriteService(BackendService::class, $this->backendService);
- \OCP\Util::connectHook(
+ Util::connectHook(
Filesystem::CLASSNAME,
Filesystem::signal_create_mount,
get_class($this), 'createHookCallback');
- \OCP\Util::connectHook(
+ Util::connectHook(
Filesystem::CLASSNAME,
Filesystem::signal_delete_mount,
get_class($this), 'deleteHookCallback');
@@ -162,17 +141,16 @@ abstract class StoragesServiceTest extends \Test\TestCase {
}
protected function tearDown(): void {
- \OCA\Files_External\MountConfig::$skipTest = false;
+ MountConfig::$skipTest = false;
self::$hookCalls = [];
if ($this->dbConfig) {
$this->dbConfig->clean();
}
+ parent::tearDown();
}
- protected function getBackendMock($class = '\OCA\Files_External\Lib\Backend\SMB', $storageClass = '\OCA\Files_External\Lib\Storage\SMB') {
- $backend = $this->getMockBuilder(Backend::class)
- ->disableOriginalConstructor()
- ->getMock();
+ protected function getBackendMock($class = SMB::class, $storageClass = \OCA\Files_External\Lib\Storage\SMB::class) {
+ $backend = $this->createMock(Backend::class);
$backend->method('getStorageClass')
->willReturn($storageClass);
$backend->method('getIdentifier')
@@ -180,10 +158,8 @@ abstract class StoragesServiceTest extends \Test\TestCase {
return $backend;
}
- protected function getAuthMechMock($scheme = 'null', $class = '\OCA\Files_External\Lib\Auth\NullMechanism') {
- $authMech = $this->getMockBuilder(AuthMechanism::class)
- ->disableOriginalConstructor()
- ->getMock();
+ protected function getAuthMechMock($scheme = 'null', $class = NullMechanism::class) {
+ $authMech = $this->createMock(AuthMechanism::class);
$authMech->method('getScheme')
->willReturn($scheme);
$authMech->method('getIdentifier')
@@ -194,12 +170,8 @@ abstract class StoragesServiceTest extends \Test\TestCase {
/**
* Creates a StorageConfig instance based on array data
- *
- * @param array $data
- *
- * @return StorageConfig storage config instance
*/
- protected function makeStorageConfig($data) {
+ protected function makeStorageConfig(array $data): StorageConfig {
$storage = new StorageConfig();
if (isset($data['id'])) {
$storage->setId($data['id']);
@@ -248,13 +220,13 @@ abstract class StoragesServiceTest extends \Test\TestCase {
$this->service->updateStorage($storage);
}
- public function testNonExistingStorage() {
- $this->expectException(\OCA\Files_External\NotFoundException::class);
+ public function testNonExistingStorage(): void {
+ $this->expectException(NotFoundException::class);
$this->ActualNonExistingStorageTest();
}
- public function deleteStorageDataProvider() {
+ public static function deleteStorageDataProvider(): array {
return [
// regular case, can properly delete the oc_storages entry
[
@@ -278,10 +250,8 @@ abstract class StoragesServiceTest extends \Test\TestCase {
];
}
- /**
- * @dataProvider deleteStorageDataProvider
- */
- public function testDeleteStorage($backendOptions, $rustyStorageId) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('deleteStorageDataProvider')]
+ public function testDeleteStorage(array $backendOptions, string $rustyStorageId): void {
$backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\DAV');
$authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism');
$storage = new StorageConfig(255);
@@ -295,10 +265,10 @@ abstract class StoragesServiceTest extends \Test\TestCase {
// manually trigger storage entry because normally it happens on first
// access, which isn't possible within this test
- $storageCache = new \OC\Files\Cache\Storage($rustyStorageId, true, Server::get(IDBConnection::class));
+ $storageCache = new Storage($rustyStorageId, true, Server::get(IDBConnection::class));
/** @var IUserMountCache $mountCache */
- $mountCache = \OC::$server->get(IUserMountCache::class);
+ $mountCache = Server::get(IUserMountCache::class);
$mountCache->clear();
$user = $this->createMock(IUser::class);
$user->method('getUID')->willReturn('test');
@@ -337,7 +307,7 @@ abstract class StoragesServiceTest extends \Test\TestCase {
$this->assertTrue($caught);
// storage id was removed from oc_storages
- $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder();
+ $qb = Server::get(IDBConnection::class)->getQueryBuilder();
$storageCheckQuery = $qb->select('*')
->from('storages')
->where($qb->expr()->eq('numeric_id', $qb->expr()->literal($numericId)));
@@ -345,20 +315,20 @@ abstract class StoragesServiceTest extends \Test\TestCase {
$result = $storageCheckQuery->execute();
$storages = $result->fetchAll();
$result->closeCursor();
- $this->assertCount(0, $storages, "expected 0 storages, got " . json_encode($storages));
+ $this->assertCount(0, $storages, 'expected 0 storages, got ' . json_encode($storages));
}
protected function actualDeletedUnexistingStorageTest() {
$this->service->removeStorage(255);
}
- public function testDeleteUnexistingStorage() {
- $this->expectException(\OCA\Files_External\NotFoundException::class);
+ public function testDeleteUnexistingStorage(): void {
+ $this->expectException(NotFoundException::class);
$this->actualDeletedUnexistingStorageTest();
}
- public function testCreateStorage() {
+ public function testCreateStorage(): void {
$mountPoint = 'mount';
$backendIdentifier = 'identifier:\OCA\Files_External\Lib\Backend\SMB';
$authMechanismIdentifier = 'identifier:\Auth\Mechanism';
@@ -392,7 +362,7 @@ abstract class StoragesServiceTest extends \Test\TestCase {
$this->assertEquals($priority, $storage->getPriority());
}
- public function testCreateStorageInvalidClass() {
+ public function testCreateStorageInvalidClass(): void {
$storage = $this->service->createStorage(
'mount',
'identifier:\OC\Not\A\Backend',
@@ -402,7 +372,7 @@ abstract class StoragesServiceTest extends \Test\TestCase {
$this->assertInstanceOf(InvalidBackend::class, $storage->getBackend());
}
- public function testCreateStorageInvalidAuthMechanismClass() {
+ public function testCreateStorageInvalidAuthMechanismClass(): void {
$storage = $this->service->createStorage(
'mount',
'identifier:\OCA\Files_External\Lib\Backend\SMB',
@@ -412,7 +382,7 @@ abstract class StoragesServiceTest extends \Test\TestCase {
$this->assertInstanceOf(InvalidAuth::class, $storage->getAuthMechanism());
}
- public function testGetStoragesBackendNotVisible() {
+ public function testGetStoragesBackendNotVisible(): void {
$backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB');
$backend->expects($this->once())
->method('isVisibleFor')
@@ -435,7 +405,7 @@ abstract class StoragesServiceTest extends \Test\TestCase {
$this->assertEmpty($this->service->getStorages());
}
- public function testGetStoragesAuthMechanismNotVisible() {
+ public function testGetStoragesAuthMechanismNotVisible(): void {
$backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB');
$backend->method('isVisibleFor')
->with($this->service->getVisibilityType())
@@ -458,14 +428,14 @@ abstract class StoragesServiceTest extends \Test\TestCase {
$this->assertEmpty($this->service->getStorages());
}
- public static function createHookCallback($params) {
+ public static function createHookCallback($params): void {
self::$hookCalls[] = [
'signal' => Filesystem::signal_create_mount,
'params' => $params
];
}
- public static function deleteHookCallback($params) {
+ public static function deleteHookCallback($params): void {
self::$hookCalls[] = [
'signal' => Filesystem::signal_delete_mount,
'params' => $params
@@ -498,7 +468,7 @@ abstract class StoragesServiceTest extends \Test\TestCase {
);
}
- public function testUpdateStorageMountPoint() {
+ public function testUpdateStorageMountPoint(): void {
$backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB');
$authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism');
diff --git a/apps/files_external/tests/Service/UserGlobalStoragesServiceTest.php b/apps/files_external/tests/Service/UserGlobalStoragesServiceTest.php
index e08f3bd4d7d..2a2f4596fda 100644
--- a/apps/files_external/tests/Service/UserGlobalStoragesServiceTest.php
+++ b/apps/files_external/tests/Service/UserGlobalStoragesServiceTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -6,6 +7,7 @@
*/
namespace OCA\Files_External\Tests\Service;
+use OC\User\User;
use OCA\Files_External\Lib\StorageConfig;
use OCA\Files_External\NotFoundException;
use OCA\Files_External\Service\StoragesService;
@@ -14,6 +16,8 @@ use OCP\EventDispatcher\IEventDispatcher;
use OCP\IGroupManager;
use OCP\IUser;
use OCP\IUserSession;
+use OCP\Server;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\Traits\UserTrait;
/**
@@ -22,20 +26,9 @@ use Test\Traits\UserTrait;
class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest {
use UserTrait;
- /** @var \OCP\IGroupManager|\PHPUnit\Framework\MockObject\MockObject groupManager */
- protected $groupManager;
-
- /**
- * @var StoragesService
- */
- protected $globalStoragesService;
-
- /**
- * @var UserGlobalStoragesService
- */
- protected $service;
-
- protected $user;
+ protected IGroupManager&MockObject $groupManager;
+ protected StoragesService $globalStoragesService;
+ protected User $user;
public const USER_ID = 'test_user';
public const GROUP_ID = 'test_group';
@@ -46,8 +39,8 @@ class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest {
$this->globalStoragesService = $this->service;
- $this->user = new \OC\User\User(self::USER_ID, null, \OC::$server->get(IEventDispatcher::class));
- /** @var \OCP\IUserSession|\PHPUnit\Framework\MockObject\MockObject $userSession */
+ $this->user = new User(self::USER_ID, null, Server::get(IEventDispatcher::class));
+ /** @var IUserSession&MockObject $userSession */
$userSession = $this->createMock(IUserSession::class);
$userSession
->expects($this->any())
@@ -85,7 +78,7 @@ class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest {
);
}
- public function applicableStorageProvider() {
+ public static function applicableStorageProvider(): array {
return [
[[], [], true],
@@ -105,10 +98,8 @@ class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest {
];
}
- /**
- * @dataProvider applicableStorageProvider
- */
- public function testGetStorageWithApplicable($applicableUsers, $applicableGroups, $isVisible) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('applicableStorageProvider')]
+ public function testGetStorageWithApplicable($applicableUsers, $applicableGroups, $isVisible): void {
$backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB');
$authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism');
@@ -139,7 +130,7 @@ class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest {
}
- public function testAddStorage($storageParams = null) {
+ public function testAddStorage($storageParams = null): void {
$this->expectException(\DomainException::class);
$backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB');
@@ -155,7 +146,7 @@ class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest {
}
- public function testUpdateStorage($storageParams = null) {
+ public function testUpdateStorage($storageParams = null): void {
$this->expectException(\DomainException::class);
$backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB');
@@ -175,16 +166,14 @@ class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest {
}
- public function testNonExistingStorage() {
+ public function testNonExistingStorage(): void {
$this->expectException(\DomainException::class);
$this->ActualNonExistingStorageTest();
}
- /**
- * @dataProvider deleteStorageDataProvider
- */
- public function testDeleteStorage($backendOptions, $rustyStorageId) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('deleteStorageDataProvider')]
+ public function testDeleteStorage($backendOptions, $rustyStorageId): void {
$this->expectException(\DomainException::class);
$backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB');
@@ -203,13 +192,13 @@ class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest {
}
- public function testDeleteUnexistingStorage() {
+ public function testDeleteUnexistingStorage(): void {
$this->expectException(\DomainException::class);
$this->actualDeletedUnexistingStorageTest();
}
- public function getUniqueStoragesProvider() {
+ public static function getUniqueStoragesProvider(): array {
return [
// 'all' vs group
[100, [], [], 100, [], [self::GROUP_ID], 2],
@@ -237,14 +226,12 @@ class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest {
];
}
- /**
- * @dataProvider getUniqueStoragesProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('getUniqueStoragesProvider')]
public function testGetUniqueStorages(
$priority1, $applicableUsers1, $applicableGroups1,
$priority2, $applicableUsers2, $applicableGroups2,
- $expectedPrecedence
- ) {
+ $expectedPrecedence,
+ ): void {
$backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB');
$backend->method('isVisibleFor')
->willReturn(true);
@@ -284,67 +271,67 @@ class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest {
}
}
- public function testGetStoragesBackendNotVisible() {
+ public function testGetStoragesBackendNotVisible(): void {
// we don't test this here
$this->addToAssertionCount(1);
}
- public function testGetStoragesAuthMechanismNotVisible() {
+ public function testGetStoragesAuthMechanismNotVisible(): void {
// we don't test this here
$this->addToAssertionCount(1);
}
- public function testHooksAddStorage($a = null, $b = null, $c = null) {
+ public function testHooksAddStorage($a = null, $b = null, $c = null): void {
// we don't test this here
$this->addToAssertionCount(1);
}
- public function testHooksUpdateStorage($a = null, $b = null, $c = null, $d = null, $e = null) {
+ public function testHooksUpdateStorage($a = null, $b = null, $c = null, $d = null, $e = null): void {
// we don't test this here
$this->addToAssertionCount(1);
}
- public function testHooksRenameMountPoint() {
+ public function testHooksRenameMountPoint(): void {
// we don't test this here
$this->addToAssertionCount(1);
}
- public function testHooksDeleteStorage($a = null, $b = null, $c = null) {
+ public function testHooksDeleteStorage($a = null, $b = null, $c = null): void {
// we don't test this here
$this->addToAssertionCount(1);
}
- public function testLegacyConfigConversionApplicableAll() {
+ public function testLegacyConfigConversionApplicableAll(): void {
// we don't test this here
$this->addToAssertionCount(1);
}
- public function testLegacyConfigConversionApplicableUserAndGroup() {
+ public function testLegacyConfigConversionApplicableUserAndGroup(): void {
// we don't test this here
$this->addToAssertionCount(1);
}
- public function testReadLegacyConfigAndGenerateConfigId() {
+ public function testReadLegacyConfigAndGenerateConfigId(): void {
// we don't test this here
$this->addToAssertionCount(1);
}
- public function testReadLegacyConfigNoAuthMechanism() {
+ public function testReadLegacyConfigNoAuthMechanism(): void {
// we don't test this here
$this->addToAssertionCount(1);
}
- public function testReadLegacyConfigClass() {
+ public function testReadLegacyConfigClass(): void {
// we don't test this here
$this->addToAssertionCount(1);
}
- public function testReadEmptyMountPoint() {
+ public function testReadEmptyMountPoint(): void {
// we don't test this here
$this->addToAssertionCount(1);
}
- public function testUpdateStorageMountPoint() {
+ public function testUpdateStorageMountPoint(): void {
// we don't test this here
$this->addToAssertionCount(1);
}
diff --git a/apps/files_external/tests/Service/UserStoragesServiceTest.php b/apps/files_external/tests/Service/UserStoragesServiceTest.php
index 370b34245c2..0a2f291f6e4 100644
--- a/apps/files_external/tests/Service/UserStoragesServiceTest.php
+++ b/apps/files_external/tests/Service/UserStoragesServiceTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -7,28 +8,30 @@
namespace OCA\Files_External\Tests\Service;
use OC\Files\Filesystem;
-
+use OC\User\User;
use OCA\Files_External\Lib\StorageConfig;
+use OCA\Files_External\MountConfig;
+use OCA\Files_External\NotFoundException;
use OCA\Files_External\Service\GlobalStoragesService;
+
use OCA\Files_External\Service\StoragesService;
use OCA\Files_External\Service\UserStoragesService;
+use OCP\IUserManager;
use OCP\IUserSession;
+use OCP\Server;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\Traits\UserTrait;
/**
* @group DB
*/
-class UserStoragesServiceTest extends StoragesServiceTest {
+class UserStoragesServiceTest extends StoragesServiceTestCase {
use UserTrait;
- private $user;
-
- private $userId;
+ protected User $user;
- /**
- * @var StoragesService
- */
- protected $globalStoragesService;
+ protected string $userId;
+ protected StoragesService $globalStoragesService;
protected function setUp(): void {
parent::setUp();
@@ -37,9 +40,9 @@ class UserStoragesServiceTest extends StoragesServiceTest {
$this->userId = $this->getUniqueID('user_');
$this->createUser($this->userId, $this->userId);
- $this->user = \OC::$server->getUserManager()->get($this->userId);
+ $this->user = Server::get(IUserManager::class)->get($this->userId);
- /** @var \OCP\IUserSession|\PHPUnit\Framework\MockObject\MockObject $userSession */
+ /** @var IUserSession&MockObject $userSession */
$userSession = $this->createMock(IUserSession::class);
$userSession
->expects($this->any())
@@ -65,7 +68,7 @@ class UserStoragesServiceTest extends StoragesServiceTest {
]);
}
- public function testAddStorage() {
+ public function testAddStorage(): void {
$storage = $this->makeTestStorageData();
$newStorage = $this->service->addStorage($storage);
@@ -85,7 +88,7 @@ class UserStoragesServiceTest extends StoragesServiceTest {
current(self::$hookCalls),
Filesystem::signal_create_mount,
$storage->getMountPoint(),
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
$this->userId
);
@@ -93,7 +96,7 @@ class UserStoragesServiceTest extends StoragesServiceTest {
$this->assertEquals($id + 1, $nextStorage->getId());
}
- public function testUpdateStorage() {
+ public function testUpdateStorage(): void {
$storage = $this->makeStorageConfig([
'mountPoint' => 'mountpoint',
'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
@@ -125,10 +128,8 @@ class UserStoragesServiceTest extends StoragesServiceTest {
$this->assertEmpty(self::$hookCalls);
}
- /**
- * @dataProvider deleteStorageDataProvider
- */
- public function testDeleteStorage($backendOptions, $rustyStorageId) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('deleteStorageDataProvider')]
+ public function testDeleteStorage($backendOptions, $rustyStorageId): void {
parent::testDeleteStorage($backendOptions, $rustyStorageId);
// hook called once for user (first one was during test creation)
@@ -136,12 +137,12 @@ class UserStoragesServiceTest extends StoragesServiceTest {
self::$hookCalls[1],
Filesystem::signal_delete_mount,
'/mountpoint',
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
$this->userId
);
}
- public function testHooksRenameMountPoint() {
+ public function testHooksRenameMountPoint(): void {
$storage = $this->makeTestStorageData();
$storage = $this->service->addStorage($storage);
@@ -157,21 +158,21 @@ class UserStoragesServiceTest extends StoragesServiceTest {
self::$hookCalls[0],
Filesystem::signal_delete_mount,
'/mountpoint',
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
$this->userId
);
$this->assertHookCall(
self::$hookCalls[1],
Filesystem::signal_create_mount,
'/renamedMountpoint',
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
$this->userId
);
}
- public function testGetAdminStorage() {
- $this->expectException(\OCA\Files_External\NotFoundException::class);
+ public function testGetAdminStorage(): void {
+ $this->expectException(NotFoundException::class);
$backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB');
$authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism');
diff --git a/apps/files_external/tests/Settings/AdminTest.php b/apps/files_external/tests/Settings/AdminTest.php
index 1d584814da8..fd4a1949760 100644
--- a/apps/files_external/tests/Settings/AdminTest.php
+++ b/apps/files_external/tests/Settings/AdminTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -6,24 +8,21 @@
namespace OCA\Files_External\Tests\Settings;
use OCA\Files_External\Lib\Auth\Password\GlobalAuth;
+use OCA\Files_External\MountConfig;
use OCA\Files_External\Service\BackendService;
use OCA\Files_External\Service\GlobalStoragesService;
use OCA\Files_External\Settings\Admin;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\Encryption\IManager;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class AdminTest extends TestCase {
- /** @var Admin */
- private $admin;
- /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
- private $encryptionManager;
- /** @var GlobalStoragesService|\PHPUnit\Framework\MockObject\MockObject */
- private $globalStoragesService;
- /** @var BackendService|\PHPUnit\Framework\MockObject\MockObject */
- private $backendService;
- /** @var GlobalAuth|\PHPUnit\Framework\MockObject\MockObject */
- private $globalAuth;
+ private IManager&MockObject $encryptionManager;
+ private GlobalStoragesService&MockObject $globalStoragesService;
+ private BackendService&MockObject $backendService;
+ private GlobalAuth&MockObject $globalAuth;
+ private Admin $admin;
protected function setUp(): void {
parent::setUp();
@@ -40,7 +39,7 @@ class AdminTest extends TestCase {
);
}
- public function testGetForm() {
+ public function testGetForm(): void {
$this->encryptionManager
->expects($this->once())
->method('isEnabled')
@@ -76,7 +75,7 @@ class AdminTest extends TestCase {
'storages' => ['a', 'b', 'c'],
'backends' => ['d', 'e', 'f'],
'authMechanisms' => ['g', 'h', 'i'],
- 'dependencies' => \OCA\Files_External\MountConfig::dependencyMessage($this->backendService->getBackends()),
+ 'dependencies' => MountConfig::dependencyMessage($this->backendService->getBackends()),
'allowUserMounting' => true,
'globalCredentials' => 'asdf:asdf',
'globalCredentialsUid' => '',
@@ -85,11 +84,11 @@ class AdminTest extends TestCase {
$this->assertEquals($expected, $this->admin->getForm());
}
- public function testGetSection() {
+ public function testGetSection(): void {
$this->assertSame('externalstorages', $this->admin->getSection());
}
- public function testGetPriority() {
+ public function testGetPriority(): void {
$this->assertSame(40, $this->admin->getPriority());
}
}
diff --git a/apps/files_external/tests/Settings/SectionTest.php b/apps/files_external/tests/Settings/SectionTest.php
index e9f47cab19d..c64849ff7ba 100644
--- a/apps/files_external/tests/Settings/SectionTest.php
+++ b/apps/files_external/tests/Settings/SectionTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -8,20 +10,18 @@ namespace OCA\Files_External\Tests\Settings;
use OCA\Files_External\Settings\Section;
use OCP\IL10N;
use OCP\IURLGenerator;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class SectionTest extends TestCase {
- /** @var IL10N */
- private $l;
- /** @var IURLGenerator */
- private $urlGenerator;
- /** @var Section */
- private $section;
+ private IL10N&MockObject $l;
+ private IURLGenerator&MockObject $urlGenerator;
+ private Section $section;
protected function setUp(): void {
parent::setUp();
- $this->urlGenerator = $this->getMockBuilder(IURLGenerator::class)->disableOriginalConstructor()->getMock();
- $this->l = $this->getMockBuilder(IL10N::class)->disableOriginalConstructor()->getMock();
+ $this->urlGenerator = $this->createMock(IURLGenerator::class);
+ $this->l = $this->createMock(IL10N::class);
$this->section = new Section(
$this->urlGenerator,
@@ -29,11 +29,11 @@ class SectionTest extends TestCase {
);
}
- public function testGetID() {
+ public function testGetID(): void {
$this->assertSame('externalstorages', $this->section->getID());
}
- public function testGetName() {
+ public function testGetName(): void {
$this->l
->expects($this->once())
->method('t')
@@ -43,7 +43,7 @@ class SectionTest extends TestCase {
$this->assertSame('External storage', $this->section->getName());
}
- public function testGetPriority() {
+ public function testGetPriority(): void {
$this->assertSame(10, $this->section->getPriority());
}
}
diff --git a/apps/files_external/tests/Storage/Amazons3MultiPartTest.php b/apps/files_external/tests/Storage/Amazons3MultiPartTest.php
index 3db468b0fa0..aa3925899f3 100644
--- a/apps/files_external/tests/Storage/Amazons3MultiPartTest.php
+++ b/apps/files_external/tests/Storage/Amazons3MultiPartTest.php
@@ -1,9 +1,11 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
-namespace OCA\files_external\tests\Storage;
+namespace OCA\Files_External\Tests\Storage;
use OCA\Files_External\Lib\Storage\AmazonS3;
@@ -11,6 +13,7 @@ use OCA\Files_External\Lib\Storage\AmazonS3;
* Class Amazons3Test
*
* @group DB
+ * @group S3
*
* @package OCA\Files_External\Tests\Storage
*/
@@ -23,7 +26,7 @@ class Amazons3MultiPartTest extends \Test\Files\Storage\Storage {
parent::setUp();
$this->config = include('files_external/tests/config.amazons3.php');
- if (! is_array($this->config) or ! $this->config['run']) {
+ if (!is_array($this->config) || !$this->config['run']) {
$this->markTestSkipped('AmazonS3 backend not configured');
}
$this->instance = new AmazonS3($this->config + [
@@ -40,11 +43,7 @@ class Amazons3MultiPartTest extends \Test\Files\Storage\Storage {
parent::tearDown();
}
- public function testStat() {
+ public function testStat(): void {
$this->markTestSkipped('S3 doesn\'t update the parents folder mtime');
}
-
- public function testHashInFileName() {
- $this->markTestSkipped('Localstack has a bug with hashes in filename');
- }
}
diff --git a/apps/files_external/tests/Storage/Amazons3Test.php b/apps/files_external/tests/Storage/Amazons3Test.php
index bffe98c3f4d..d02dec0230c 100644
--- a/apps/files_external/tests/Storage/Amazons3Test.php
+++ b/apps/files_external/tests/Storage/Amazons3Test.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -12,11 +14,12 @@ use OCA\Files_External\Lib\Storage\AmazonS3;
* Class Amazons3Test
*
* @group DB
+ * @group S3
*
* @package OCA\Files_External\Tests\Storage
*/
class Amazons3Test extends \Test\Files\Storage\Storage {
- private $config;
+ protected $config;
/** @var AmazonS3 */
protected $instance;
@@ -24,7 +27,7 @@ class Amazons3Test extends \Test\Files\Storage\Storage {
parent::setUp();
$this->config = include('files_external/tests/config.amazons3.php');
- if (! is_array($this->config) or ! $this->config['run']) {
+ if (!is_array($this->config) || !$this->config['run']) {
$this->markTestSkipped('AmazonS3 backend not configured');
}
$this->instance = new AmazonS3($this->config);
@@ -38,11 +41,7 @@ class Amazons3Test extends \Test\Files\Storage\Storage {
parent::tearDown();
}
- public function testStat() {
+ public function testStat(): void {
$this->markTestSkipped('S3 doesn\'t update the parents folder mtime');
}
-
- public function testHashInFileName() {
- $this->markTestSkipped('Localstack has a bug with hashes in filename');
- }
}
diff --git a/apps/files_external/tests/Storage/FtpTest.php b/apps/files_external/tests/Storage/FtpTest.php
index 24f7c511e93..095a5236049 100644
--- a/apps/files_external/tests/Storage/FtpTest.php
+++ b/apps/files_external/tests/Storage/FtpTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -45,7 +47,7 @@ class FtpTest extends \Test\Files\Storage\Storage {
/**
* ftp has no proper way to handle spaces at the end of file names
*/
- public function directoryProvider() {
+ public static function directoryProvider(): array {
return array_filter(parent::directoryProvider(), function ($item) {
return substr($item[0], -1) !== ' ';
});
@@ -55,7 +57,7 @@ class FtpTest extends \Test\Files\Storage\Storage {
/**
* mtime for folders is only with a minute resolution
*/
- public function testStat() {
+ public function testStat(): void {
$textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
$ctimeStart = time();
$this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile));
diff --git a/apps/files_external/tests/Storage/OwncloudTest.php b/apps/files_external/tests/Storage/OwncloudTest.php
index 28041a665f8..ab6cd443dba 100644
--- a/apps/files_external/tests/Storage/OwncloudTest.php
+++ b/apps/files_external/tests/Storage/OwncloudTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
diff --git a/apps/files_external/tests/Storage/SFTP_KeyTest.php b/apps/files_external/tests/Storage/SFTP_KeyTest.php
index c1aaf0b13a3..17e2087f91b 100644
--- a/apps/files_external/tests/Storage/SFTP_KeyTest.php
+++ b/apps/files_external/tests/Storage/SFTP_KeyTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -40,40 +42,40 @@ class SFTP_KeyTest extends \Test\Files\Storage\Storage {
parent::tearDown();
}
-
- public function testInvalidAddressShouldThrowException() {
+
+ public function testInvalidAddressShouldThrowException(): void {
$this->expectException(\InvalidArgumentException::class);
// I'd use example.com for this, but someone decided to break the spec and make it resolve
$this->instance->assertHostAddressValid('notarealaddress...');
}
- public function testValidAddressShouldPass() {
+ public function testValidAddressShouldPass(): void {
$this->assertTrue($this->instance->assertHostAddressValid('localhost'));
}
-
- public function testNegativePortNumberShouldThrowException() {
+
+ public function testNegativePortNumberShouldThrowException(): void {
$this->expectException(\InvalidArgumentException::class);
$this->instance->assertPortNumberValid('-1');
}
-
- public function testNonNumericalPortNumberShouldThrowException() {
+
+ public function testNonNumericalPortNumberShouldThrowException(): void {
$this->expectException(\InvalidArgumentException::class);
$this->instance->assertPortNumberValid('a');
}
-
- public function testHighPortNumberShouldThrowException() {
+
+ public function testHighPortNumberShouldThrowException(): void {
$this->expectException(\InvalidArgumentException::class);
-
+
$this->instance->assertPortNumberValid('65536');
}
- public function testValidPortNumberShouldPass() {
+ public function testValidPortNumberShouldPass(): void {
$this->assertTrue($this->instance->assertPortNumberValid('22222'));
}
}
diff --git a/apps/files_external/tests/Storage/SftpTest.php b/apps/files_external/tests/Storage/SftpTest.php
index ce7d7461ba8..ebfc8ab3c1f 100644
--- a/apps/files_external/tests/Storage/SftpTest.php
+++ b/apps/files_external/tests/Storage/SftpTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -44,15 +46,13 @@ class SftpTest extends \Test\Files\Storage\Storage {
parent::tearDown();
}
- /**
- * @dataProvider configProvider
- */
- public function testStorageId($config, $expectedStorageId) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('configProvider')]
+ public function testStorageId($config, $expectedStorageId): void {
$instance = new SFTP($config);
$this->assertEquals($expectedStorageId, $instance->getId());
}
- public function configProvider() {
+ public static function configProvider(): array {
return [
[
// no root path
diff --git a/apps/files_external/tests/Storage/SmbTest.php b/apps/files_external/tests/Storage/SmbTest.php
index 1040158cf19..afcb5c1034f 100644
--- a/apps/files_external/tests/Storage/SmbTest.php
+++ b/apps/files_external/tests/Storage/SmbTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -49,19 +51,19 @@ class SmbTest extends \Test\Files\Storage\Storage {
parent::tearDown();
}
- public function directoryProvider() {
+ public static function directoryProvider(): array {
// doesn't support leading/trailing spaces
return [['folder']];
}
- public function testRenameWithSpaces() {
+ public function testRenameWithSpaces(): void {
$this->instance->mkdir('with spaces');
$result = $this->instance->rename('with spaces', 'foo bar');
$this->assertTrue($result);
$this->assertTrue($this->instance->is_dir('foo bar'));
}
- public function testStorageId() {
+ public function testStorageId(): void {
$this->instance = new SMB([
'host' => 'testhost',
'user' => 'testuser',
@@ -73,9 +75,9 @@ class SmbTest extends \Test\Files\Storage\Storage {
$this->instance = null;
}
- public function testNotifyGetChanges() {
+ public function testNotifyGetChanges(): void {
$lastError = null;
- for($i = 0; $i < 5; $i++) {
+ for ($i = 0; $i < 5; $i++) {
try {
$this->tryTestNotifyGetChanges();
return;
@@ -130,7 +132,7 @@ class SmbTest extends \Test\Files\Storage\Storage {
}
}
- public function testNotifyListen() {
+ public function testNotifyListen(): void {
$notifyHandler = $this->instance->notify('');
usleep(100 * 1000); //give time for the notify to start
$this->instance->file_put_contents('/newfile.txt', 'test content');
@@ -153,7 +155,7 @@ class SmbTest extends \Test\Files\Storage\Storage {
}
}
- public function testRenameRoot() {
+ public function testRenameRoot(): void {
// root can't be renamed
$this->assertFalse($this->instance->rename('', 'foo1'));
@@ -162,12 +164,12 @@ class SmbTest extends \Test\Files\Storage\Storage {
$this->instance->rmdir('foo2');
}
- public function testUnlinkRoot() {
+ public function testUnlinkRoot(): void {
// root can't be deleted
$this->assertFalse($this->instance->unlink(''));
}
- public function testRmdirRoot() {
+ public function testRmdirRoot(): void {
// root can't be deleted
$this->assertFalse($this->instance->rmdir(''));
}
diff --git a/apps/files_external/tests/Storage/SwiftTest.php b/apps/files_external/tests/Storage/SwiftTest.php
index 53ca499e4eb..17037e76ee3 100644
--- a/apps/files_external/tests/Storage/SwiftTest.php
+++ b/apps/files_external/tests/Storage/SwiftTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -53,7 +55,7 @@ class SwiftTest extends \Test\Files\Storage\Storage {
parent::tearDown();
}
- public function testStat() {
+ public function testStat(): void {
$this->markTestSkipped('Swift doesn\'t update the parents folder mtime');
}
}
diff --git a/apps/files_external/tests/Storage/VersionedAmazonS3Test.php b/apps/files_external/tests/Storage/VersionedAmazonS3Test.php
index 4d9d1e32067..9d413620292 100644
--- a/apps/files_external/tests/Storage/VersionedAmazonS3Test.php
+++ b/apps/files_external/tests/Storage/VersionedAmazonS3Test.php
@@ -10,6 +10,7 @@ namespace OCA\Files_External\Tests\Storage;
/**
* @group DB
+ * @group S3
*/
class VersionedAmazonS3Test extends Amazons3Test {
protected function setUp(): void {
@@ -25,4 +26,12 @@ class VersionedAmazonS3Test extends Amazons3Test {
$this->markTestSkipped("s3 backend doesn't seem to support versioning");
}
}
+
+ public function testCopyOverWriteDirectory(): void {
+ if (isset($this->config['minio'])) {
+ $this->markTestSkipped('MinIO has a bug with batch deletion on versioned storages, see https://github.com/minio/minio/issues/21366');
+ }
+
+ parent::testCopyOverWriteDirectory();
+ }
}
diff --git a/apps/files_external/tests/Storage/WebdavTest.php b/apps/files_external/tests/Storage/WebdavTest.php
index a063ddebb0d..a8de178effd 100644
--- a/apps/files_external/tests/Storage/WebdavTest.php
+++ b/apps/files_external/tests/Storage/WebdavTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -8,6 +10,8 @@ namespace OCA\Files_External\Tests\Storage;
use OC\Files\Storage\DAV;
use OC\Files\Type\Detection;
+use OCP\Files\IMimeTypeDetector;
+use OCP\Server;
/**
* Class WebdavTest
@@ -41,11 +45,11 @@ class WebdavTest extends \Test\Files\Storage\Storage {
parent::tearDown();
}
- public function testMimetypeFallback() {
+ public function testMimetypeFallback(): void {
$this->instance->file_put_contents('foo.bar', 'asd');
/** @var Detection $mimeDetector */
- $mimeDetector = \OC::$server->getMimeTypeDetector();
+ $mimeDetector = Server::get(IMimeTypeDetector::class);
$mimeDetector->registerType('bar', 'application/x-bar');
$this->assertEquals('application/x-bar', $this->instance->getMimeType('foo.bar'));
diff --git a/apps/files_external/tests/StorageConfigTest.php b/apps/files_external/tests/StorageConfigTest.php
index fbbd9de94be..b3024cb228c 100644
--- a/apps/files_external/tests/StorageConfigTest.php
+++ b/apps/files_external/tests/StorageConfigTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -12,13 +14,9 @@ use OCA\Files_External\Lib\DefinitionParameter;
use OCA\Files_External\Lib\StorageConfig;
class StorageConfigTest extends \Test\TestCase {
- public function testJsonSerialization() {
- $backend = $this->getMockBuilder(Backend::class)
- ->disableOriginalConstructor()
- ->getMock();
- $parameter = $this->getMockBuilder(DefinitionParameter::class)
- ->disableOriginalConstructor()
- ->getMock();
+ public function testJsonSerialization(): void {
+ $backend = $this->createMock(Backend::class);
+ $parameter = $this->createMock(DefinitionParameter::class);
$parameter
->expects($this->once())
->method('getType')
@@ -30,9 +28,7 @@ class StorageConfigTest extends \Test\TestCase {
$backend->method('getIdentifier')
->willReturn('storage::identifier');
- $authMech = $this->getMockBuilder(AuthMechanism::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $authMech = $this->createMock(AuthMechanism::class);
$authMech->method('getIdentifier')
->willReturn('auth::identifier');
diff --git a/apps/files_external/tests/appSpec.js b/apps/files_external/tests/appSpec.js
deleted file mode 100644
index 512dc13cc05..00000000000
--- a/apps/files_external/tests/appSpec.js
+++ /dev/null
@@ -1,83 +0,0 @@
-/**
- * SPDX-FileCopyrightText: 2014 Nextcloud GmbH and Nextcloud contributors
- * SPDX-License-Identifier: AGPL-3.0-or-later
- */
-
-describe('OCA.Files_External.App tests', function() {
- const App = OCA.Files_External.App
- let fileList
-
- beforeEach(function() {
- $('#testArea').append(
- '<div id="app-navigation">'
- + '<ul><li data-id="files"><a>Files</a></li>'
- + '<li data-id="sharingin"><a></a></li>'
- + '<li data-id="sharingout"><a></a></li>'
- + '</ul></div>'
- + '<div id="app-content">'
- + '<div id="app-content-files" class="hidden">'
- + '</div>'
- + '<div id="app-content-extstoragemounts" class="hidden">'
- + '</div>'
- + '</div>'
- + '</div>'
- )
- fileList = App.initList($('#app-content-extstoragemounts'))
- })
- afterEach(function() {
- App.fileList = null
- fileList.destroy()
- fileList = null
- })
-
- describe('initialization', function() {
- it('inits external mounts list on show', function() {
- expect(App.fileList).toBeDefined()
- })
- })
- describe('file actions', function() {
- it('provides default file actions', function() {
- const fileActions = fileList.fileActions
-
- expect(fileActions.actions.all).toBeDefined()
- expect(fileActions.actions.all.Delete).toBeDefined()
- expect(fileActions.actions.all.Rename).toBeDefined()
- expect(fileActions.actions.all.Download).toBeDefined()
-
- expect(fileActions.defaults.dir).toEqual('Open')
- })
- it('redirects to files app when opening a directory', function() {
- const oldList = OCA.Files.App.fileList
- // dummy new list to make sure it exists
- OCA.Files.App.fileList = new OCA.Files.FileList($('<table><thead></thead><tbody></tbody></table>'))
-
- const setActiveViewStub = sinon.stub(OCA.Files.App, 'setActiveView')
- // create dummy table so we can click the dom
- const $table = '<table><thead></thead><tbody class="files-fileList"></tbody></table>'
- $('#app-content-extstoragemounts').append($table)
-
- App._inFileList = null
- fileList = App.initList($('#app-content-extstoragemounts'))
-
- fileList.setFiles([{
- name: 'testdir',
- type: 'dir',
- path: '/somewhere/inside/subdir',
- counterParts: ['user2'],
- shareOwner: 'user2',
- }])
-
- fileList.findFileEl('testdir').find('td a.name').click()
-
- expect(OCA.Files.App.fileList.getCurrentDirectory()).toEqual('/somewhere/inside/subdir/testdir')
-
- expect(setActiveViewStub.calledOnce).toEqual(true)
- expect(setActiveViewStub.calledWith('files')).toEqual(true)
-
- setActiveViewStub.restore()
-
- // restore old list
- OCA.Files.App.fileList = oldList
- })
- })
-})
diff --git a/apps/files_external/tests/config.php b/apps/files_external/tests/config.php
index 13fc0c2401e..ec860cf05a4 100644
--- a/apps/files_external/tests/config.php
+++ b/apps/files_external/tests/config.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2012-2016 ownCloud, Inc.
diff --git a/apps/files_external/tests/js/mountsfilelistSpec.js b/apps/files_external/tests/js/mountsfilelistSpec.js
deleted file mode 100644
index fa6de978c81..00000000000
--- a/apps/files_external/tests/js/mountsfilelistSpec.js
+++ /dev/null
@@ -1,148 +0,0 @@
-/**
- * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
- * SPDX-FileCopyrightText: 2014-2016 ownCloud, Inc.
- * SPDX-License-Identifier: AGPL-3.0-or-later
- */
-
-describe('OCA.Files_External.FileList tests', function() {
- var testFiles, alertStub, notificationStub, fileList;
-
- beforeEach(function() {
- alertStub = sinon.stub(OC.dialogs, 'alert');
- notificationStub = sinon.stub(OC.Notification, 'show');
-
- // init parameters and test table elements
- $('#testArea').append(
- '<div id="app-content">' +
- // init horrible parameters
- '<input type="hidden" id="permissions" value="31"></input>' +
- // dummy controls
- '<div class="files-controls">' +
- ' <div class="actions creatable"></div>' +
- ' <div class="notCreatable"></div>' +
- '</div>' +
- // dummy table
- // TODO: at some point this will be rendered by the fileList class itself!
- '<table class="files-filestable">' +
- '<thead><tr>' +
- '<th class="hidden column-name">' +
- ' <div id="column-name-container">' +
- ' <a class="name sort columntitle" data-sort="name"><span>Name</span><span class="sort-indicator"></span></a>' +
- ' </div>' +
- '</th>' +
- '<th id="headerBackend" class="hidden column-backend">' +
- ' <a class="backend sort columntitle" data-sort="backend"><span>Storage type</span><span class="sort-indicator"></span></a>' +
- '</th>' +
- '<th id="headerScope" class="hidden column-scope column-last">' +
- ' <a class="scope sort columntitle" data-sort="scope"><span>Scope</span><span class="sort-indicator"></span></a>' +
- '</th>' +
- '</tr></thead>' +
- '<tbody class="files-fileList"></tbody>' +
- '<tfoot></tfoot>' +
- '</table>' +
- '<div class="emptyfilelist emptycontent">Empty content message</div>' +
- '</div>'
- );
- });
- afterEach(function() {
- testFiles = undefined;
- fileList.destroy();
- fileList = undefined;
-
- notificationStub.restore();
- alertStub.restore();
- });
-
- describe('loading file list for external storage', function() {
- var ocsResponse;
- var reloading;
-
- beforeEach(function() {
- fileList = new OCA.Files_External.FileList(
- $('#app-content')
- );
-
- reloading = fileList.reload();
-
- /* jshint camelcase: false */
- ocsResponse = {
- ocs: {
- meta: {
- status: 'ok',
- statuscode: 100,
- message: null
- },
- data: [{
- name: 'smb mount',
- path: '/mount points',
- type: 'dir',
- backend: 'SMB',
- scope: 'personal',
- permissions: OC.PERMISSION_READ | OC.PERMISSION_DELETE
- }, {
- name: 'sftp mount',
- path: '/another mount points',
- type: 'dir',
- backend: 'SFTP',
- scope: 'system',
- permissions: OC.PERMISSION_READ
- }]
- }
- };
- });
- it('render storage list', function(done) {
- var request;
- var $rows;
- var $tr;
-
- expect(fakeServer.requests.length).toEqual(1);
- request = fakeServer.requests[0];
- expect(request.url).toEqual(
- OC.linkToOCS('apps/files_external/api/v1') + 'mounts?format=json'
- );
-
- fakeServer.requests[0].respond(
- 200,
- { 'Content-Type': 'application/json' },
- JSON.stringify(ocsResponse)
- );
-
- return reloading.then(function() {
- $rows = fileList.$el.find('tbody tr');
- expect($rows.length).toEqual(2);
-
- $tr = $rows.eq(0);
- expect($tr.attr('data-id')).not.toBeDefined();
- expect($tr.attr('data-type')).toEqual('dir');
- expect($tr.attr('data-file')).toEqual('sftp mount');
- expect($tr.attr('data-path')).toEqual('/another mount points');
- expect($tr.attr('data-size')).not.toBeDefined();
- expect($tr.attr('data-permissions')).toEqual('1'); // read only
- expect($tr.find('a.name').attr('href')).toEqual(
- OC.getRootPath() +
- '/index.php/apps/files' +
- '?dir=/another%20mount%20points/sftp%20mount'
- );
- expect($tr.find('.nametext').text().trim()).toEqual('sftp mount');
- expect($tr.find('.column-scope > span').text().trim()).toEqual('System');
- expect($tr.find('.column-backend').text().trim()).toEqual('SFTP');
-
- $tr = $rows.eq(1);
- expect($tr.attr('data-id')).not.toBeDefined();
- expect($tr.attr('data-type')).toEqual('dir');
- expect($tr.attr('data-file')).toEqual('smb mount');
- expect($tr.attr('data-path')).toEqual('/mount points');
- expect($tr.attr('data-size')).not.toBeDefined();
- expect($tr.attr('data-permissions')).toEqual('9'); // read and delete
- expect($tr.find('a.name').attr('href')).toEqual(
- OC.getRootPath() +
- '/index.php/apps/files' +
- '?dir=/mount%20points/smb%20mount'
- );
- expect($tr.find('.nametext').text().trim()).toEqual('smb mount');
- expect($tr.find('.column-scope > span').text().trim()).toEqual('Personal');
- expect($tr.find('.column-backend').text().trim()).toEqual('SMB');
- }).then(done, done);
- });
- });
-});
diff --git a/apps/files_external/tests/js/settingsSpec.js b/apps/files_external/tests/js/settingsSpec.js
deleted file mode 100644
index f79191151d1..00000000000
--- a/apps/files_external/tests/js/settingsSpec.js
+++ /dev/null
@@ -1,447 +0,0 @@
-/**
- * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
- * SPDX-FileCopyrightText: 2015-2016 ownCloud, Inc.
- * SPDX-License-Identifier: AGPL-3.0-or-later
- */
-
-describe('OCA.Files_External.Settings tests', function() {
- var clock;
- var select2Stub;
- var select2ApplicableUsers;
-
- beforeEach(function() {
- clock = sinon.useFakeTimers();
- select2ApplicableUsers = [];
- select2Stub = sinon.stub($.fn, 'select2').callsFake(function(args) {
- if (args === 'val') {
- return select2ApplicableUsers;
- }
- return {
- on: function() { return this; }
- };
- });
-
- // view still requires an existing DOM table
- $('#testArea').append(
- '<table id="externalStorage" data-admin="true">' +
- '<thead></thead>' +
- '<tbody>' +
- '<tr id="addMountPoint" data-id="">' +
- '<td class="status"></td>' +
- '<td class="mountPoint"><input type="text" name="mountPoint"/></td>' +
- '<td class="backend">' +
- '<select class="selectBackend">' +
- '<option disable selected>Add storage</option>' +
- '<option value="\\OC\\TestBackend">Test Backend</option>' +
- '<option value="\\OC\\AnotherTestBackend">Another Test Backend</option>' +
- '<option value="\\OC\\InputsTestBackend">Inputs test backend</option>' +
- '</select>' +
- '</td>' +
- '<td class="authentication"></td>' +
- '<td class="configuration"></td>' +
- '<td class="applicable">' +
- '<input type="checkbox" class="applicableToAllUsers">' +
- '<input type="hidden" class="applicableUsers">' +
- '</td>' +
- '<td class="mountOptionsToggle">'+
- '<div class="icon-more" title="Advanced settings" deluminate_imagetype="unknown"></div>'+
- '<input type="hidden" class="mountOptions"/>'+
- '</td>'+
- '<td class="save">'+
- '<div class="icon-checkmark" title="Save" deluminate_imagetype="unknown"></div>'+
- '</td>'+
- '</tr>' +
- '</tbody>' +
- '</table>'
- );
- // these are usually appended into the data attribute
- // within the DOM by the server template
- $('#externalStorage .selectBackend:first').data('configurations', {
- '\\OC\\TestBackend': {
- 'identifier': '\\OC\\TestBackend',
- 'name': 'Test Backend',
- 'configuration': {
- 'field1': {
- 'value': 'Display Name 1'
- },
- 'field2': {
- 'value': 'Display Name 2',
- 'flags': 1
- }
- },
- 'authSchemes': {
- 'builtin': true,
- },
- 'priority': 11
- },
- '\\OC\\AnotherTestBackend': {
- 'identifier': '\\OC\\AnotherTestBackend',
- 'name': 'Another Test Backend',
- 'configuration': {
- 'field1': {
- 'value': 'Display Name 1'
- },
- 'field2': {
- 'value': 'Display Name 2',
- 'flags': 1
- }
- },
- 'authSchemes': {
- 'builtin': true,
- },
- 'priority': 12
- },
- '\\OC\\InputsTestBackend': {
- 'identifier': '\\OC\\InputsTestBackend',
- 'name': 'Inputs test backend',
- 'configuration': {
- 'field_text': {
- 'value': 'Text field'
- },
- 'field_password': {
- 'value': ',Password field',
- 'type': 2
- },
- 'field_bool': {
- 'value': 'Boolean field',
- 'type': 1
- },
- 'field_hidden': {
- 'value': 'Hidden field',
- 'type': 3
- },
- 'field_text_optional': {
- 'value': 'Text field optional',
- 'flags': 1
- },
- 'field_password_optional': {
- 'value': 'Password field optional',
- 'flags': 1,
- 'type': 2
- }
- },
- 'authSchemes': {
- 'builtin': true,
- },
- 'priority': 13
- }
- }
- );
-
- $('#externalStorage #addMountPoint .authentication:first').data('mechanisms', {
- 'mechanism1': {
- 'identifier': 'mechanism1',
- 'name': 'Mechanism 1',
- 'configuration': {
- },
- 'scheme': 'builtin',
- 'visibility': 3
- },
- });
-
- });
- afterEach(function() {
- select2Stub.restore();
- clock.restore();
- });
-
- describe('storage configuration', function() {
- var view;
-
- function selectBackend(backendName) {
- view.$el.find('.selectBackend:first').val(backendName).trigger('change');
- view.$el.find('.applicableToAllUsers').prop('checked', true).trigger('change');
- }
-
- beforeEach(function() {
- var $el = $('#externalStorage');
- view = new OCA.Files_External.Settings.MountConfigListView($el, {encryptionEnabled: false});
- });
- afterEach(function() {
- view = null;
- });
- describe('selecting backend', function() {
- it('populates the row and creates a new empty one', function() {
- selectBackend('\\OC\\TestBackend');
- var $firstRow = view.$el.find('tr:first');
- expect($firstRow.find('.backend').text()).toEqual('Test Backend');
- expect($firstRow.find('.selectBackend').length).toEqual(0);
-
- // TODO: check "remove" button visibility
-
- // the suggested mount point name
- expect($firstRow.find('[name=mountPoint]').val()).toEqual('TestBackend');
-
- // TODO: check that the options have been created
-
- // TODO: check select2 call on the ".applicableUsers" element
-
- var $emptyRow = $firstRow.next('tr');
- expect($emptyRow.length).toEqual(1);
- expect($emptyRow.find('.selectBackend').length).toEqual(1);
- expect($emptyRow.find('.applicable select').length).toEqual(0);
-
- // TODO: check "remove" button visibility
- });
- it('shows row even if selection row is hidden', function() {
- selectBackend('\\OC\\TestBackend');
- view.$el.find('tr#addMountPoint').hide();
- expect(view.$el.find('tr:first').is(':visible')).toBe(true);
- expect(view.$el.find('tr#addMountPoint').is(':visible')).toBe(false);
- });
- // TODO: test with personal mounts (no applicable fields)
- // TODO: test suggested mount point logic
- });
- describe('saving storages', function() {
- var $tr;
-
- beforeEach(function() {
- selectBackend('\\OC\\TestBackend');
- $tr = view.$el.find('tr:first');
- });
- it('saves storage after clicking the save button', function() {
- var $field1 = $tr.find('input[data-parameter=field1]');
- expect($field1.length).toEqual(1);
- $field1.val('test');
- $field1.trigger(new $.Event('keyup', {keyCode: 97}));
-
- var $mountOptionsField = $tr.find('input.mountOptions');
- expect($mountOptionsField.length).toEqual(1);
- $mountOptionsField.val(JSON.stringify({previews:true}));
-
- var $saveButton = $tr.find('td.save .icon-checkmark');
- $saveButton.click();
-
- expect(fakeServer.requests.length).toEqual(1);
- var request = fakeServer.requests[0];
- expect(request.url).toEqual(OC.getRootPath() + '/index.php/apps/files_external/globalstorages');
- expect(JSON.parse(request.requestBody)).toEqual({
- backend: '\\OC\\TestBackend',
- authMechanism: 'mechanism1',
- backendOptions: {
- 'field1': 'test',
- 'field2': ''
- },
- mountPoint: 'TestBackend',
- priority: 11,
- applicableUsers: [],
- applicableGroups: [],
- mountOptions: {
- 'previews': true
- },
- testOnly: true
- });
-
- // TODO: respond and check data-id
- });
- it('saves storage with applicable users', function() {
- var $field1 = $tr.find('input[data-parameter=field1]');
- expect($field1.length).toEqual(1);
- $field1.val('test');
- $field1.trigger(new $.Event('keyup', {keyCode: 97}));
-
- $tr.find('.applicableToAllUsers').prop('checked', false).trigger('change');
- select2ApplicableUsers = ['user1', 'user2', 'group1(group)', 'group2(group)'];
-
- var $saveButton = $tr.find('td.save .icon-checkmark');
- $saveButton.click();
-
- expect(fakeServer.requests.length).toEqual(1);
- var request = fakeServer.requests[0];
- expect(request.url).toEqual(OC.getRootPath() + '/index.php/apps/files_external/globalstorages');
- expect(JSON.parse(request.requestBody)).toEqual({
- backend: '\\OC\\TestBackend',
- authMechanism: 'mechanism1',
- backendOptions: {
- 'field1': 'test',
- 'field2': ''
- },
- mountPoint: 'TestBackend',
- priority: 11,
- applicableUsers: ['user1', 'user2'],
- applicableGroups: ['group1', 'group2'],
- mountOptions: {
- encrypt: true,
- previews: true,
- enable_sharing: false,
- filesystem_check_changes: 1,
- encoding_compatibility: false,
- readonly: false,
- },
- testOnly: true
- });
-
- // TODO: respond and check data-id
- });
- it('does not saves storage without applicable users and unchecked all users checkbox', function() {
- var $field1 = $tr.find('input[data-parameter=field1]');
- expect($field1.length).toEqual(1);
- $field1.val('test');
- $field1.trigger(new $.Event('keyup', {keyCode: 97}));
-
- $tr.find('.applicableToAllUsers').prop('checked', false).trigger('change');
-
- var $saveButton = $tr.find('td.save .icon-checkmark');
- $saveButton.click();
-
- expect(fakeServer.requests.length).toEqual(0);
- });
-
- it('saves storage after closing mount options popovermenu', function() {
- $tr.find('.mountOptionsToggle .icon-more').click();
- $tr.find('[name=previews]').trigger(new $.Event('keyup', {keyCode: 97}));
- $tr.find('input[data-parameter=field1]').val('test');
-
- // does not save inside the popovermenu
- expect(fakeServer.requests.length).toEqual(0);
-
- $('body').mouseup();
-
- // but after closing the popovermenu
- expect(fakeServer.requests.length).toEqual(1);
- });
- // TODO: status indicator
- });
- describe('validate storage configuration', function() {
- var $tr;
-
- beforeEach(function() {
- selectBackend('\\OC\\InputsTestBackend');
- $tr = view.$el.find('tr:first');
- });
-
- it('lists missing fields in storage errors', function() {
- $tr.find('.applicableToAllUsers').prop('checked', false).trigger('change');
- var storage = view.getStorageConfig($tr);
-
- expect(storage.errors).toEqual({
- backendOptions: ['field_text', 'field_password'],
- requiredApplicable: true,
- });
- });
-
- it('does not list applicable when all users checkbox is ticked', function() {
- var storage = view.getStorageConfig($tr);
-
- expect(storage.errors).toEqual({
- backendOptions: ['field_text', 'field_password']
- });
- });
-
- it('highlights missing non-optional fields', function() {
- _.each([
- 'field_text',
- 'field_password'
- ], function(param) {
- expect($tr.find('input[data-parameter='+param+']').hasClass('warning-input')).toBe(true);
- });
- _.each([
- 'field_bool',
- 'field_hidden',
- 'field_text_optional',
- 'field_password_optional'
- ], function(param) {
- expect($tr.find('input[data-parameter='+param+']').hasClass('warning-input')).toBe(false);
- });
- });
-
- it('validates correct storage', function() {
- $tr.find('[name=mountPoint]').val('mountpoint');
-
- $tr.find('input[data-parameter=field_text]').val('foo');
- $tr.find('input[data-parameter=field_password]').val('bar');
- $tr.find('input[data-parameter=field_text_optional]').val('foobar');
- // don't set field_password_optional
- $tr.find('input[data-parameter=field_hidden]').val('baz');
-
- var storage = view.getStorageConfig($tr);
-
- expect(storage.validate()).toBe(true);
- });
-
- it('checks missing mount point', function() {
- $tr.find('[name=mountPoint]').val('');
-
- $tr.find('input[data-parameter=field_text]').val('foo');
- $tr.find('input[data-parameter=field_password]').val('bar');
-
- var storage = view.getStorageConfig($tr);
-
- expect(storage.validate()).toBe(false);
- });
- });
- describe('update storage', function() {
- // TODO
- });
- describe('delete storage', function() {
- // TODO
- });
- describe('recheck storages', function() {
- // TODO
- });
- describe('mount options popovermenu', function() {
- var $tr;
- var $td;
-
- beforeEach(function() {
- selectBackend('\\OC\\TestBackend');
- $tr = view.$el.find('tr:first');
- $td = $tr.find('.mountOptionsToggle');
- });
-
- it('shows popovermenu when clicking on toggle button, hides when clicking outside', function() {
- $td.find('.icon-more').click();
-
- expect($td.find('.popovermenu.open').length).toEqual(1);
-
- $('body').mouseup();
-
- expect($td.find('.popovermenu.open').length).toEqual(0);
- });
-
- it('doesnt show the encryption option when encryption is disabled', function () {
- view._encryptionEnabled = false;
- $td.find('.icon-more').click();
-
- expect($td.find('.popovermenu [name=encrypt]:visible').length).toEqual(0);
-
- $('body').mouseup();
-
- expect($td.find('.popovermenu.open').length).toEqual(0);
- });
-
- it('reads config from mountOptions field', function() {
- $tr.find('input.mountOptions').val(JSON.stringify({previews:false}));
-
- $td.find('.icon-more').click();
- expect($td.find('.popovermenu [name=previews]').prop('checked')).toEqual(false);
- $('body').mouseup();
-
- $tr.find('input.mountOptions').val(JSON.stringify({previews:true}));
- $td.find('.icon-more').click();
- expect($td.find('.popovermenu [name=previews]').prop('checked')).toEqual(true);
- });
-
- it('writes config into mountOptions field', function() {
- $td.find('.icon-more').click();
- // defaults to true
- var $field = $td.find('.popovermenu [name=previews]');
- expect($field.prop('checked')).toEqual(true);
- $td.find('.popovermenu [name=filesystem_check_changes]').val(0);
- $('body').mouseup();
-
- expect(JSON.parse($tr.find('input.mountOptions').val())).toEqual({
- encrypt: true,
- previews: true,
- enable_sharing: false,
- filesystem_check_changes: 0,
- encoding_compatibility: false,
- readonly: false
- });
- });
- });
- });
- describe('allow user mounts section', function() {
- // TODO: test allowUserMounting section
- });
-});
diff --git a/apps/files_external/tests/sso-setup/apps.config.php b/apps/files_external/tests/sso-setup/apps.config.php
index 71190f44291..b3889956a53 100644
--- a/apps/files_external/tests/sso-setup/apps.config.php
+++ b/apps/files_external/tests/sso-setup/apps.config.php
@@ -5,16 +5,16 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
$CONFIG = [
- "apps_paths" => [
+ 'apps_paths' => [
[
- "path" => "/var/www/html/apps",
- "url" => "/apps",
- "writable" => false,
+ 'path' => '/var/www/html/apps',
+ 'url' => '/apps',
+ 'writable' => false,
],
[
- "path" => "/var/www/html/extra-apps",
- "url" => "/extra-apps",
- "writable" => true,
+ 'path' => '/var/www/html/extra-apps',
+ 'url' => '/extra-apps',
+ 'writable' => true,
],
],
];
diff --git a/apps/files_external/tests/sso-setup/start-apache.sh b/apps/files_external/tests/sso-setup/start-apache.sh
index eb2ff55b0e6..58ad71e3a3a 100755
--- a/apps/files_external/tests/sso-setup/start-apache.sh
+++ b/apps/files_external/tests/sso-setup/start-apache.sh
@@ -15,6 +15,9 @@ APACHE_IP=$(docker inspect apache --format '{{.NetworkSettings.IPAddress}}')
docker exec apache chown 33 /var/www/html/config /var/www/html/data /var/www/html/extra-apps
docker cp "$SCRIPT_DIR/apps.config.php" apache:/var/www/html/config/apps.config.php
+# ensure that samba is started (see https://github.com/icewind1991/samba-krb-test/pull/8)
+docker exec dc service samba-ad-dc status || docker exec dc service samba-ad-dc start
+
# add the dns record for apache
docker exec dc samba-tool dns add krb.domain.test domain.test httpd A $APACHE_IP -U administrator --password=passwOrd1 1>&2
diff --git a/apps/files_external/tests/sso-setup/test-sso-smb.sh b/apps/files_external/tests/sso-setup/test-sso-smb.sh
index d019ce728cd..46955ae0d3c 100755
--- a/apps/files_external/tests/sso-setup/test-sso-smb.sh
+++ b/apps/files_external/tests/sso-setup/test-sso-smb.sh
@@ -16,6 +16,7 @@ if [[ "$LOGIN_CONTENT" =~ "Location: http://localhost/success" ]]; then
echo "✔️"
else
echo "❌"
+ echo "$CONTENT"
exit 1
fi
echo -n "Getting test file: "
@@ -26,5 +27,6 @@ if [[ $CONTENT == "testfile" ]]; then
echo "✔️"
else
echo "❌"
+ echo "$CONTENT"
exit 1
fi