aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_external/tests/Auth
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_external/tests/Auth')
-rw-r--r--apps/files_external/tests/Auth/AuthMechanismTest.php49
-rw-r--r--apps/files_external/tests/Auth/Password/GlobalAuthTest.php (renamed from apps/files_external/tests/Auth/Password/GlobalAuth.php)87
2 files changed, 44 insertions, 92 deletions
diff --git a/apps/files_external/tests/Auth/AuthMechanismTest.php b/apps/files_external/tests/Auth/AuthMechanismTest.php
index ed3b52c1dbb..e999cecf181 100644
--- a/apps/files_external/tests/Auth/AuthMechanismTest.php
+++ b/apps/files_external/tests/Auth/AuthMechanismTest.php
@@ -1,26 +1,11 @@
<?php
+
+declare(strict_types=1);
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin McCorkell <robin@mccorkell.me.uk>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2020-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
-
namespace OCA\Files_External\Tests\Auth;
use OCA\Files_External\Lib\Auth\AuthMechanism;
@@ -28,10 +13,9 @@ use OCA\Files_External\Lib\Backend\Backend;
use OCA\Files_External\Lib\StorageConfig;
class AuthMechanismTest extends \Test\TestCase {
-
- public function testJsonSerialization() {
+ public function testJsonSerialization(): void {
$mechanism = $this->getMockBuilder(AuthMechanism::class)
- ->setMethods(['jsonSerializeDefinition'])
+ ->onlyMethods(['jsonSerializeDefinition'])
->getMock();
$mechanism->expects($this->once())
->method('jsonSerializeDefinition')
@@ -44,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],
@@ -53,12 +37,10 @@ class AuthMechanismTest extends \Test\TestCase {
];
}
- /**
- * @dataProvider validateStorageProvider
- */
- public function testValidateStorage($expectedSuccess, $scheme, $definitionSuccess) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('validateStorageProvider')]
+ public function testValidateStorage(bool $expectedSuccess, string $scheme, bool $definitionSuccess): void {
$mechanism = $this->getMockBuilder(AuthMechanism::class)
- ->setMethods(['validateStorageDefinition'])
+ ->onlyMethods(['validateStorageDefinition'])
->getMock();
$mechanism->expects($this->atMost(1))
->method('validateStorageDefinition')
@@ -66,21 +48,16 @@ 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);
$this->assertEquals($expectedSuccess, $mechanism->validateStorage($storageConfig));
}
-
}
diff --git a/apps/files_external/tests/Auth/Password/GlobalAuth.php b/apps/files_external/tests/Auth/Password/GlobalAuthTest.php
index c447be7a669..6d83655403e 100644
--- a/apps/files_external/tests/Auth/Password/GlobalAuth.php
+++ b/apps/files_external/tests/Auth/Password/GlobalAuthTest.php
@@ -1,51 +1,27 @@
<?php
+
+declare(strict_types=1);
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Robin Appelman <robin@icewind.nl>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
-
namespace OCA\Files_External\Tests\Auth\Password;
use OCA\Files_External\Lib\Auth\Password\GlobalAuth;
-use OCA\Files_external\Lib\StorageConfig;
+use OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException;
+use OCA\Files_External\Lib\StorageConfig;
use OCP\IL10N;
use OCP\Security\ICredentialsManager;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class GlobalAuthTest extends TestCase {
- /**
- * @var \OCP\IL10N|\PHPUnit_Framework_MockObject_MockObject
- */
- private $l10n;
-
- /**
- * @var \OCP\Security\ICredentialsManager|\PHPUnit_Framework_MockObject_MockObject
- */
- private $credentialsManager;
-
- /**
- * @var GlobalAuth
- */
- private $instance;
-
- protected function setUp() {
+ private IL10N&MockObject $l10n;
+ private ICredentialsManager&MockObject $credentialsManager;
+ private GlobalAuth $instance;
+
+ protected function setUp(): void {
parent::setUp();
$this->l10n = $this->createMock(IL10N::class);
$this->credentialsManager = $this->createMock(ICredentialsManager::class);
@@ -53,34 +29,34 @@ class GlobalAuthTest extends TestCase {
}
private function getStorageConfig($type, $config = []) {
- /** @var \OCA\Files_External\Lib\StorageConfig|\PHPUnit_Framework_MockObject_MockObject $storageConfig */
+ /** @var StorageConfig&MockObject $storageConfig */
$storageConfig = $this->createMock(StorageConfig::class);
$storageConfig->expects($this->any())
->method('getType')
- ->will($this->returnValue($type));
+ ->willReturn($type);
$storageConfig->expects($this->any())
->method('getBackendOptions')
- ->will($this->returnCallback(function () use (&$config) {
+ ->willReturnCallback(function () use (&$config) {
return $config;
- }));
+ });
$storageConfig->expects($this->any())
->method('getBackendOption')
- ->will($this->returnCallback(function ($key) use (&$config) {
+ ->willReturnCallback(function ($key) use (&$config) {
return $config[$key];
- }));
+ });
$storageConfig->expects($this->any())
->method('setBackendOption')
- ->will($this->returnCallback(function ($key, $value) use (&$config) {
+ ->willReturnCallback(function ($key, $value) use (&$config): void {
$config[$key] = $value;
- }));
+ });
return $storageConfig;
}
- public function testNoCredentials() {
+ public function testNoCredentials(): void {
$this->credentialsManager->expects($this->once())
->method('retrieve')
- ->will($this->returnValue(null));
+ ->willReturn(null);
$storage = $this->getStorageConfig(StorageConfig::MOUNT_TYPE_ADMIN);
@@ -88,13 +64,13 @@ class GlobalAuthTest extends TestCase {
$this->assertEquals([], $storage->getBackendOptions());
}
- public function testSavedCredentials() {
+ public function testSavedCredentials(): void {
$this->credentialsManager->expects($this->once())
->method('retrieve')
- ->will($this->returnValue([
+ ->willReturn([
'user' => 'a',
'password' => 'b'
- ]));
+ ]);
$storage = $this->getStorageConfig(StorageConfig::MOUNT_TYPE_ADMIN);
@@ -105,17 +81,16 @@ class GlobalAuthTest extends TestCase {
], $storage->getBackendOptions());
}
- /**
- * @expectedException \OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException
- */
- public function testNoCredentialsPersonal() {
+
+ public function testNoCredentialsPersonal(): void {
+ $this->expectException(InsufficientDataForMeaningfulAnswerException::class);
+
$this->credentialsManager->expects($this->never())
->method('retrieve');
- $storage = $this->getStorageConfig(StorageConfig::MOUNT_TYPE_PERSONAl);
+ $storage = $this->getStorageConfig(StorageConfig::MOUNT_TYPE_PERSONAL);
$this->instance->manipulateStorageConfig($storage);
$this->assertEquals([], $storage->getBackendOptions());
}
-
}