diff options
Diffstat (limited to 'apps/files_external/tests')
41 files changed, 321 insertions, 1067 deletions
diff --git a/apps/files_external/tests/Auth/AuthMechanismTest.php b/apps/files_external/tests/Auth/AuthMechanismTest.php index 682d2e1326f..d6279ea4f1f 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. @@ -13,7 +15,7 @@ use OCA\Files_External\Lib\StorageConfig; class AuthMechanismTest extends \Test\TestCase { 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], @@ -38,9 +40,9 @@ class AuthMechanismTest extends \Test\TestCase { /** * @dataProvider validateStorageProvider */ - public function testValidateStorage($expectedSuccess, $scheme, $definitionSuccess): void { + 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 +50,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 998db198b53..02f15cb76c4 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. @@ -8,26 +10,16 @@ namespace OCA\Files_External\Tests\Auth\Password; use OCA\Files_External\Lib\Auth\Password\GlobalAuth; use OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException; -use OCA\Files_external\Lib\StorageConfig; +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 IL10N|\PHPUnit\Framework\MockObject\MockObject - */ - private $l10n; - - /** - * @var 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(); @@ -37,7 +29,7 @@ class GlobalAuthTest extends TestCase { } private function getStorageConfig($type, $config = []) { - /** @var \OCA\Files_External\Lib\StorageConfig|\PHPUnit\Framework\MockObject\MockObject $storageConfig */ + /** @var \OCA\Files_External\Lib\StorageConfig&MockObject $storageConfig */ $storageConfig = $this->createMock(StorageConfig::class); $storageConfig->expects($this->any()) ->method('getType') diff --git a/apps/files_external/tests/Backend/BackendTest.php b/apps/files_external/tests/Backend/BackendTest.php index 26aa5ebe6af..1e158654595 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. @@ -12,7 +14,7 @@ use OCA\Files_External\Lib\StorageConfig; class BackendTest extends \Test\TestCase { public function testJsonSerialization(): void { $backend = $this->getMockBuilder(Backend::class) - ->setMethods(['jsonSerializeDefinition']) + ->onlyMethods(['jsonSerializeDefinition']) ->getMock(); $backend->expects($this->once()) ->method('jsonSerializeDefinition') @@ -32,7 +34,7 @@ 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], @@ -42,9 +44,9 @@ class BackendTest extends \Test\TestCase { /** * @dataProvider validateStorageProvider */ - public function testValidateStorage($expectedSuccess, $definitionSuccess): void { + 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') diff --git a/apps/files_external/tests/Backend/LegacyBackendTest.php b/apps/files_external/tests/Backend/LegacyBackendTest.php index 303700c6611..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(): void { - $auth = $this->getMockBuilder('\OCA\Files_External\Lib\Auth\Builtin') - ->disableOriginalConstructor() - ->getMock(); + $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()); @@ -78,11 +74,9 @@ class LegacyBackendTest extends \Test\TestCase { } public function testNoDependencies(): void { - $auth = $this->getMockBuilder('\OCA\Files_External\Lib\Auth\Builtin') - ->disableOriginalConstructor() - ->getMock(); + $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 8854e4ad485..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 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 IGroupManager|\PHPUnit\Framework\MockObject\MockObject $groupManager */ + /** @var IGroupManager&MockObject $groupManager */ $groupManager = $this->createMock(IGroupManager::class); $userManager->expects($this->any()) diff --git a/apps/files_external/tests/Command/CommandTest.php b/apps/files_external/tests/Command/CommandTestCase.php index ed991fd784d..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. @@ -9,21 +10,20 @@ 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 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); @@ -31,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) { @@ -70,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) { @@ -82,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 bd4430b4116..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,24 +18,20 @@ 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); @@ -41,8 +39,6 @@ class ListCommandTest extends CommandTest { 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 b3c7db9306f..b40e9461287 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']], @@ -64,7 +56,7 @@ class UserPlaceholderHandlerTest extends \Test\TestCase { /** * @dataProvider optionProvider */ - public function testHandle($option, $expected): void { + public function testHandle(string|array $option, string|array $expected): void { $this->setUser(); $this->assertSame($expected, $this->handler->handle($option)); } @@ -72,7 +64,7 @@ class UserPlaceholderHandlerTest extends \Test\TestCase { /** * @dataProvider optionProvider */ - public function testHandleNoUser($option): void { + 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 005e6e9714c..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 @@ -14,32 +16,22 @@ 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; - /** @var IL10N */ - private $l10n; + 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); diff --git a/apps/files_external/tests/Controller/GlobalStoragesControllerTest.php b/apps/files_external/tests/Controller/GlobalStoragesControllerTest.php index 4c318951d1b..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))); diff --git a/apps/files_external/tests/Controller/StoragesControllerTest.php b/apps/files_external/tests/Controller/StoragesControllerTestCase.php index 0d604ff2d47..bb29904ab0d 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,10 +9,12 @@ 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; @@ -18,33 +22,25 @@ 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 { + parent::setUp(); MountConfig::$skipTest = true; } protected function tearDown(): void { 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') @@ -57,10 +53,8 @@ abstract class StoragesControllerTest extends \Test\TestCase { /** * @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') @@ -98,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, [], [], [], @@ -130,7 +124,7 @@ abstract class StoragesControllerTest extends \Test\TestCase { $response = $this->controller->create( 'mount', 'local', - '\OCA\Files_External\Lib\Auth\NullMechanism', + NullMechanism::class, [], [], [], @@ -170,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, [], [], [], @@ -184,7 +178,7 @@ abstract class StoragesControllerTest extends \Test\TestCase { $this->assertEquals($storageConfig->jsonSerialize(), $data); } - public function mountPointNamesProvider() { + public static function mountPointNamesProvider(): array { return [ [''], ['/'], @@ -212,8 +206,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, [], [], [], @@ -226,8 +220,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, [], [], [], @@ -250,7 +244,7 @@ abstract class StoragesControllerTest extends \Test\TestCase { $response = $this->controller->create( 'mount', '\OC\Files\Storage\InvalidStorage', - '\OCA\Files_External\Lib\Auth\NullMechanism', + NullMechanism::class, [], [], [], @@ -264,7 +258,7 @@ abstract class StoragesControllerTest extends \Test\TestCase { 1, 'mount', '\OC\Files\Storage\InvalidStorage', - '\OCA\Files_External\Lib\Auth\NullMechanism', + NullMechanism::class, [], [], [], @@ -303,8 +297,8 @@ abstract class StoragesControllerTest extends \Test\TestCase { $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, [], [], [], @@ -354,7 +348,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], @@ -366,7 +360,7 @@ abstract class StoragesControllerTest extends \Test\TestCase { /** * @dataProvider validateStorageProvider */ - public function testValidateStorage($backendValidate, $authMechValidate, $expectSuccess): void { + public function testValidateStorage(bool $backendValidate, bool $authMechValidate, bool $expectSuccess): void { $backend = $this->getBackendMock(); $backend->method('validateStorage') ->willReturn($backendValidate); @@ -401,8 +395,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 c15ded48ea7..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))); @@ -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 0b1d11bbf0c..f39ba90c871 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. @@ -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,8 +65,6 @@ 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] ]; } diff --git a/apps/files_external/tests/FrontendDefinitionTraitTest.php b/apps/files_external/tests/FrontendDefinitionTraitTest.php index bc5d88ff3f0..5319920e61a 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. @@ -16,7 +17,7 @@ class FrontendDefinitionTraitTest extends \Test\TestCase { ->getMock(); $param->method('getName')->willReturn('foo'); - $trait = $this->getMockForTrait('\OCA\Files_External\Lib\FrontendDefinitionTrait'); + $trait = $this->getMockForTrait(\OCA\Files_External\Lib\FrontendDefinitionTrait::class); $trait->setText('test'); $trait->addParameters([$param]); $trait->addCustomJs('foo/bar.js'); @@ -32,7 +33,7 @@ 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]] @@ -42,7 +43,7 @@ class FrontendDefinitionTraitTest extends \Test\TestCase { /** * @dataProvider validateStorageProvider */ - public function testValidateStorage($expectedSuccess, $params): void { + public function testValidateStorage(bool $expectedSuccess, array $params): void { $backendParams = []; foreach ($params as $name => $valid) { $param = $this->getMockBuilder(DefinitionParameter::class) @@ -67,7 +68,7 @@ class FrontendDefinitionTraitTest extends \Test\TestCase { $storageConfig->expects($this->any()) ->method('setBackendOption'); - $trait = $this->getMockForTrait('\OCA\Files_External\Lib\FrontendDefinitionTrait'); + $trait = $this->getMockForTrait(\OCA\Files_External\Lib\FrontendDefinitionTrait::class); $trait->setText('test'); $trait->addParameters($backendParams); @@ -98,7 +99,7 @@ class FrontendDefinitionTraitTest extends \Test\TestCase { ->method('setBackendOption') ->with('param', 'foobar'); - $trait = $this->getMockForTrait('\OCA\Files_External\Lib\FrontendDefinitionTrait'); + $trait = $this->getMockForTrait(\OCA\Files_External\Lib\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 5fcfe1dd1e6..b6a351d44c0 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. @@ -13,7 +15,7 @@ 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'), @@ -21,10 +23,10 @@ class LegacyDependencyCheckPolyfillTest extends \Test\TestCase { } public function testCheckDependencies(): void { - $trait = $this->getMockForTrait('\OCA\Files_External\Lib\LegacyDependencyCheckPolyfill'); + $trait = $this->getMockForTrait(\OCA\Files_External\Lib\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 ec278f84331..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'); } diff --git a/apps/files_external/tests/OwnCloudFunctionsTest.php b/apps/files_external/tests/OwnCloudFunctionsTest.php index 3488195d3e8..2890cad3ac1 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. @@ -16,7 +18,7 @@ use OCA\Files_External\Lib\Storage\OwnCloud; * @package OCA\Files_External\Tests */ class OwnCloudFunctionsTest extends \Test\TestCase { - public function configUrlProvider() { + public static function configUrlProvider(): array { return [ [ [ @@ -88,7 +90,7 @@ class OwnCloudFunctionsTest extends \Test\TestCase { /** * @dataProvider configUrlProvider */ - public function testConfig($config, $expectedUri): void { + public function testConfig(array $config, string $expectedUri): void { $config['user'] = 'someuser'; $config['password'] = 'somepassword'; $instance = new OwnCloud($config); diff --git a/apps/files_external/tests/PersonalMountTest.php b/apps/files_external/tests/PersonalMountTest.php index b268d3b5142..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,6 +10,7 @@ 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; @@ -17,13 +20,9 @@ class PersonalMountTest extends TestCase { public function testFindByStorageId(): void { $storageConfig = $this->createMock(StorageConfig::class); /** @var UserStoragesService $storageService */ - $storageService = $this->getMockBuilder('\OCA\Files_External\Service\UserStoragesService') - ->disableOriginalConstructor() - ->getMock(); + $storageService = $this->createMock(UserStoragesService::class); - $storage = $this->getMockBuilder('\OC\Files\Storage\Storage') - ->disableOriginalConstructor() - ->getMock(); + $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 e7644d8e523..a0426df10c8 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,26 +13,21 @@ 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 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(); + protected function getBackendMock(string $class) { + $backend = $this->createMock(Backend::class); $backend->method('getIdentifier')->willReturn('identifier:' . $class); $backend->method('getIdentifierAliases')->willReturn(['identifier:' . $class]); return $backend; @@ -40,26 +36,22 @@ class BackendServiceTest extends \Test\TestCase { /** * @param string $class * - * @return AuthMechanism|\PHPUnit\Framework\MockObject\MockObject + * @return AuthMechanism&MockObject */ protected function getAuthMechanismMock($class) { - $backend = $this->getMockBuilder(AuthMechanism::class) - ->disableOriginalConstructor() - ->getMock(); + $backend = $this->createMock(AuthMechanism::class); $backend->method('getIdentifier')->willReturn('identifier:' . $class); $backend->method('getIdentifierAliases')->willReturn(['identifier:' . $class]); return $backend; } public function testRegisterBackend(): void { - $service = new BackendService($this->config); + $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') @@ -80,12 +72,12 @@ class BackendServiceTest extends \Test\TestCase { } public function testBackendProvider(): void { - $service = new BackendService($this->config); + $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') @@ -99,12 +91,12 @@ class BackendServiceTest extends \Test\TestCase { } public function testAuthMechanismProvider(): void { - $service = new BackendService($this->config); + $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') @@ -118,20 +110,20 @@ class BackendServiceTest extends \Test\TestCase { } public function testMultipleBackendProviders(): void { - $service = new BackendService($this->config); + $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') @@ -146,14 +138,16 @@ class BackendServiceTest extends \Test\TestCase { } public function testUserMountingBackends(): void { - $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'] - ]); + $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()) @@ -177,7 +171,7 @@ class BackendServiceTest extends \Test\TestCase { } public function testGetAvailableBackends(): void { - $service = new BackendService($this->config); + $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']], @@ -220,7 +214,7 @@ class BackendServiceTest extends \Test\TestCase { 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; @@ -231,7 +225,7 @@ class BackendServiceTest extends \Test\TestCase { } public function testConfigHandlers(): void { - $service = new BackendService($this->config); + $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 51051d6c9f2..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. @@ -16,17 +18,10 @@ 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(); @@ -39,9 +34,10 @@ 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; @@ -74,7 +70,7 @@ 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] diff --git a/apps/files_external/tests/Service/GlobalStoragesServiceTest.php b/apps/files_external/tests/Service/GlobalStoragesServiceTest.php index b4907f7f00f..47be54a02d4 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. @@ -14,7 +16,7 @@ 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); @@ -44,7 +46,7 @@ class GlobalStoragesServiceTest extends StoragesServiceTest { ]); } - public function storageDataProvider() { + public static function storageDataProvider(): array { return [ // all users [ @@ -166,13 +168,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 [ @@ -301,7 +303,7 @@ class GlobalStoragesServiceTest extends StoragesServiceTest { } } - public function hooksUpdateStorageDataProvider() { + public static function hooksUpdateStorageDataProvider(): array { return [ [ // nothing to multiple users and groups @@ -421,11 +423,12 @@ class GlobalStoragesServiceTest extends StoragesServiceTest { * @dataProvider hooksUpdateStorageDataProvider */ public function testHooksUpdateStorage( - $sourceApplicableUsers, - $sourceApplicableGroups, - $updatedApplicableUsers, - $updatedApplicableGroups, - $expectedCalls): void { + array $sourceApplicableUsers, + array $sourceApplicableGroups, + array $updatedApplicableUsers, + array $updatedApplicableGroups, + array $expectedCalls, + ): void { $storage = $this->makeTestStorageData(); $storage->setApplicableUsers($sourceApplicableUsers); $storage->setApplicableGroups($sourceApplicableGroups); @@ -532,7 +535,7 @@ class GlobalStoragesServiceTest extends StoragesServiceTest { } } - public function hooksDeleteStorageDataProvider() { + public static function hooksDeleteStorageDataProvider(): array { return [ [ ['user1', 'user2'], @@ -580,9 +583,10 @@ class GlobalStoragesServiceTest extends StoragesServiceTest { * @dataProvider hooksDeleteStorageDataProvider */ public function testHooksDeleteStorage( - $sourceApplicableUsers, - $sourceApplicableGroups, - $expectedCalls): void { + 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 8d24b98d6af..a5cffd45ec2 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. @@ -10,9 +12,10 @@ 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; @@ -31,9 +34,10 @@ 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 @@ -51,41 +55,14 @@ 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|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(); @@ -102,10 +79,7 @@ abstract class StoragesServiceTest extends \Test\TestCase { $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'), @@ -172,12 +146,11 @@ abstract class StoragesServiceTest extends \Test\TestCase { 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') @@ -185,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') @@ -199,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']); @@ -259,7 +226,7 @@ abstract class StoragesServiceTest extends \Test\TestCase { $this->ActualNonExistingStorageTest(); } - public function deleteStorageDataProvider() { + public static function deleteStorageDataProvider(): array { return [ // regular case, can properly delete the oc_storages entry [ @@ -286,7 +253,7 @@ abstract class StoragesServiceTest extends \Test\TestCase { /** * @dataProvider deleteStorageDataProvider */ - public function testDeleteStorage($backendOptions, $rustyStorageId): void { + 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); @@ -463,14 +430,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 diff --git a/apps/files_external/tests/Service/UserGlobalStoragesServiceTest.php b/apps/files_external/tests/Service/UserGlobalStoragesServiceTest.php index e3c5cd486e9..6948d9d31bf 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. @@ -16,6 +17,7 @@ use OCP\IGroupManager; use OCP\IUser; use OCP\IUserSession; use OCP\Server; +use PHPUnit\Framework\MockObject\MockObject; use Test\Traits\UserTrait; /** @@ -24,20 +26,9 @@ use Test\Traits\UserTrait; class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest { use UserTrait; - /** @var 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'; @@ -49,7 +40,7 @@ class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest { $this->globalStoragesService = $this->service; $this->user = new User(self::USER_ID, null, Server::get(IEventDispatcher::class)); - /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject $userSession */ + /** @var IUserSession&MockObject $userSession */ $userSession = $this->createMock(IUserSession::class); $userSession ->expects($this->any()) @@ -87,7 +78,7 @@ class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest { ); } - public function applicableStorageProvider() { + public static function applicableStorageProvider(): array { return [ [[], [], true], @@ -211,7 +202,7 @@ class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest { $this->actualDeletedUnexistingStorageTest(); } - public function getUniqueStoragesProvider() { + public static function getUniqueStoragesProvider(): array { return [ // 'all' vs group [100, [], [], 100, [], [self::GROUP_ID], 2], diff --git a/apps/files_external/tests/Service/UserStoragesServiceTest.php b/apps/files_external/tests/Service/UserStoragesServiceTest.php index a7b9f200417..9dca0397f94 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. @@ -17,22 +18,19 @@ 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 \OC\User\User $user; - /** - * @var StoragesService - */ - protected $globalStoragesService; + protected string $userId; + protected StoragesService $globalStoragesService; protected function setUp(): void { parent::setUp(); @@ -43,7 +41,7 @@ class UserStoragesServiceTest extends StoragesServiceTest { $this->createUser($this->userId, $this->userId); $this->user = Server::get(IUserManager::class)->get($this->userId); - /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject $userSession */ + /** @var IUserSession&MockObject $userSession */ $userSession = $this->createMock(IUserSession::class); $userSession ->expects($this->any()) diff --git a/apps/files_external/tests/Settings/AdminTest.php b/apps/files_external/tests/Settings/AdminTest.php index aceb8d2e915..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 @@ -12,19 +14,15 @@ 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(); diff --git a/apps/files_external/tests/Settings/SectionTest.php b/apps/files_external/tests/Settings/SectionTest.php index 9154106ff8a..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, diff --git a/apps/files_external/tests/Storage/Amazons3MultiPartTest.php b/apps/files_external/tests/Storage/Amazons3MultiPartTest.php index 1ac18406d24..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 + [ @@ -43,8 +46,4 @@ class Amazons3MultiPartTest extends \Test\Files\Storage\Storage { public function testStat(): void { $this->markTestSkipped('S3 doesn\'t update the parents folder mtime'); } - - public function testHashInFileName(): void { - $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 fd7fd9225c9..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); @@ -41,8 +44,4 @@ class Amazons3Test extends \Test\Files\Storage\Storage { public function testStat(): void { $this->markTestSkipped('S3 doesn\'t update the parents folder mtime'); } - - public function testHashInFileName(): void { - $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 c6a1d8f77ba..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) !== ' '; }); 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 9be3cb7d3e8..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,7 +42,7 @@ class SFTP_KeyTest extends \Test\Files\Storage\Storage { parent::tearDown(); } - + public function testInvalidAddressShouldThrowException(): void { $this->expectException(\InvalidArgumentException::class); @@ -52,24 +54,24 @@ class SFTP_KeyTest extends \Test\Files\Storage\Storage { $this->assertTrue($this->instance->assertHostAddressValid('localhost')); } - + public function testNegativePortNumberShouldThrowException(): void { $this->expectException(\InvalidArgumentException::class); $this->instance->assertPortNumberValid('-1'); } - + public function testNonNumericalPortNumberShouldThrowException(): void { $this->expectException(\InvalidArgumentException::class); $this->instance->assertPortNumberValid('a'); } - + public function testHighPortNumberShouldThrowException(): void { $this->expectException(\InvalidArgumentException::class); - + $this->instance->assertPortNumberValid('65536'); } diff --git a/apps/files_external/tests/Storage/SftpTest.php b/apps/files_external/tests/Storage/SftpTest.php index cc29486f426..082f0d7c502 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. @@ -52,7 +54,7 @@ class SftpTest extends \Test\Files\Storage\Storage { $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 d5a83905112..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,7 +51,7 @@ 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']]; } diff --git a/apps/files_external/tests/Storage/SwiftTest.php b/apps/files_external/tests/Storage/SwiftTest.php index c21c8c6f506..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. 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 f1d3415e91e..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. diff --git a/apps/files_external/tests/StorageConfigTest.php b/apps/files_external/tests/StorageConfigTest.php index b67d69a3ce7..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. @@ -13,12 +15,8 @@ use OCA\Files_External\Lib\StorageConfig; class StorageConfigTest extends \Test\TestCase { public function testJsonSerialization(): void { - $backend = $this->getMockBuilder(Backend::class) - ->disableOriginalConstructor() - ->getMock(); - $parameter = $this->getMockBuilder(DefinitionParameter::class) - ->disableOriginalConstructor() - ->getMock(); + $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 4d150cd36bb..00000000000 --- a/apps/files_external/tests/appSpec.js +++ /dev/null @@ -1,84 +0,0 @@ -/** - * SPDX-FileCopyrightText: 2014 Nextcloud GmbH and Nextcloud contributors - * SPDX-License-Identifier: AGPL-3.0-or-later - */ -import $ from 'jquery' - -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 - }); -}); |