aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/tests/CapabilitiesTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_sharing/tests/CapabilitiesTest.php')
-rw-r--r--apps/files_sharing/tests/CapabilitiesTest.php117
1 files changed, 66 insertions, 51 deletions
diff --git a/apps/files_sharing/tests/CapabilitiesTest.php b/apps/files_sharing/tests/CapabilitiesTest.php
index 100c7759900..9a076d7a171 100644
--- a/apps/files_sharing/tests/CapabilitiesTest.php
+++ b/apps/files_sharing/tests/CapabilitiesTest.php
@@ -1,30 +1,9 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Bjoern Schiessle <bjoern@schiessle.org>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <robin@icewind.nl>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- * @author Vincent Petry <vincent@nextcloud.com>
- *
- * @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_Sharing\Tests;
@@ -32,9 +11,11 @@ use OC\KnownUser\KnownUserService;
use OC\Share20\Manager;
use OC\Share20\ShareDisableChecker;
use OCA\Files_Sharing\Capabilities;
+use OCP\App\IAppManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\IRootFolder;
use OCP\Files\Mount\IMountManager;
+use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IDateTimeZone;
use OCP\IGroupManager;
@@ -75,9 +56,30 @@ class CapabilitiesTest extends \Test\TestCase {
* @param (string[])[] $map Map of arguments to return types for the getAppValue function in the mock
* @return string[]
*/
- private function getResults(array $map) {
+ private function getResults(array $map, array $typedMap = [], bool $federationEnabled = true) {
$config = $this->getMockBuilder(IConfig::class)->disableOriginalConstructor()->getMock();
+ $appManager = $this->getMockBuilder(IAppManager::class)->disableOriginalConstructor()->getMock();
$config->method('getAppValue')->willReturnMap($map);
+ $appManager->method('isEnabledForAnyone')->with('federation')->willReturn($federationEnabled);
+
+ if (empty($typedMap)) {
+ $appConfig = $this->createMock(IAppConfig::class);
+ } else {
+ // hack to help transition from old IConfig to new IAppConfig
+ $appConfig = $this->getMockBuilder(IAppConfig::class)->disableOriginalConstructor()->getMock();
+ $appConfig->expects($this->any())->method('getValueBool')->willReturnCallback(function (...$args) use ($typedMap): bool {
+ foreach ($typedMap as $entry) {
+ if ($entry[0] !== $args[0] || $entry[1] !== $args[1]) {
+ continue;
+ }
+
+ return $entry[2];
+ }
+
+ return false;
+ });
+ }
+
$shareManager = new Manager(
$this->createMock(LoggerInterface::class),
$config,
@@ -97,13 +99,15 @@ class CapabilitiesTest extends \Test\TestCase {
$this->createMock(KnownUserService::class),
$this->createMock(ShareDisableChecker::class),
$this->createMock(IDateTimeZone::class),
+ $appConfig,
);
- $cap = new Capabilities($config, $shareManager);
+
+ $cap = new Capabilities($config, $appConfig, $shareManager, $appManager);
$result = $this->getFilesSharingPart($cap->getCapabilities());
return $result;
}
- public function testEnabledSharingAPI() {
+ public function testEnabledSharingAPI(): void {
$map = [
['core', 'shareapi_enabled', 'yes', 'yes'],
];
@@ -114,7 +118,7 @@ class CapabilitiesTest extends \Test\TestCase {
$this->assertArrayHasKey('resharing', $result);
}
- public function testDisabledSharingAPI() {
+ public function testDisabledSharingAPI(): void {
$map = [
['core', 'shareapi_enabled', 'yes', 'no'],
];
@@ -125,7 +129,7 @@ class CapabilitiesTest extends \Test\TestCase {
$this->assertFalse($result['resharing']);
}
- public function testNoLinkSharing() {
+ public function testNoLinkSharing(): void {
$map = [
['core', 'shareapi_enabled', 'yes', 'yes'],
['core', 'shareapi_allow_links', 'yes', 'no'],
@@ -135,7 +139,7 @@ class CapabilitiesTest extends \Test\TestCase {
$this->assertFalse($result['public']['enabled']);
}
- public function testOnlyLinkSharing() {
+ public function testOnlyLinkSharing(): void {
$map = [
['core', 'shareapi_enabled', 'yes', 'yes'],
['core', 'shareapi_allow_links', 'yes', 'yes'],
@@ -146,20 +150,22 @@ class CapabilitiesTest extends \Test\TestCase {
$this->assertTrue($result['public']['enabled']);
}
- public function testLinkPassword() {
+ public function testLinkPassword(): void {
$map = [
['core', 'shareapi_enabled', 'yes', 'yes'],
['core', 'shareapi_allow_links', 'yes', 'yes'],
['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
- ['core', 'shareapi_enforce_links_password', 'no', 'yes'],
];
- $result = $this->getResults($map);
+ $typedMap = [
+ ['core', 'shareapi_enforce_links_password', true],
+ ];
+ $result = $this->getResults($map, $typedMap);
$this->assertArrayHasKey('password', $result['public']);
$this->assertArrayHasKey('enforced', $result['public']['password']);
$this->assertTrue($result['public']['password']['enforced']);
}
- public function testLinkNoPassword() {
+ public function testLinkNoPassword(): void {
$map = [
['core', 'shareapi_enabled', 'yes', 'yes'],
['core', 'shareapi_allow_links', 'yes', 'yes'],
@@ -172,7 +178,7 @@ class CapabilitiesTest extends \Test\TestCase {
$this->assertFalse($result['public']['password']['enforced']);
}
- public function testLinkNoExpireDate() {
+ public function testLinkNoExpireDate(): void {
$map = [
['core', 'shareapi_enabled', 'yes', 'yes'],
['core', 'shareapi_allow_links', 'yes', 'yes'],
@@ -185,7 +191,7 @@ class CapabilitiesTest extends \Test\TestCase {
$this->assertFalse($result['public']['expire_date']['enabled']);
}
- public function testLinkExpireDate() {
+ public function testLinkExpireDate(): void {
$map = [
['core', 'shareapi_enabled', 'yes', 'yes'],
['core', 'shareapi_allow_links', 'yes', 'yes'],
@@ -202,7 +208,7 @@ class CapabilitiesTest extends \Test\TestCase {
$this->assertFalse($result['public']['expire_date']['enforced']);
}
- public function testLinkExpireDateEnforced() {
+ public function testLinkExpireDateEnforced(): void {
$map = [
['core', 'shareapi_enabled', 'yes', 'yes'],
['core', 'shareapi_allow_links', 'yes', 'yes'],
@@ -216,7 +222,7 @@ class CapabilitiesTest extends \Test\TestCase {
$this->assertTrue($result['public']['expire_date']['enforced']);
}
- public function testLinkSendMail() {
+ public function testLinkSendMail(): void {
$map = [
['core', 'shareapi_enabled', 'yes', 'yes'],
['core', 'shareapi_allow_links', 'yes', 'yes'],
@@ -227,7 +233,7 @@ class CapabilitiesTest extends \Test\TestCase {
$this->assertTrue($result['public']['send_mail']);
}
- public function testLinkNoSendMail() {
+ public function testLinkNoSendMail(): void {
$map = [
['core', 'shareapi_enabled', 'yes', 'yes'],
['core', 'shareapi_allow_links', 'yes', 'yes'],
@@ -238,7 +244,7 @@ class CapabilitiesTest extends \Test\TestCase {
$this->assertFalse($result['public']['send_mail']);
}
- public function testResharing() {
+ public function testResharing(): void {
$map = [
['core', 'shareapi_enabled', 'yes', 'yes'],
['core', 'shareapi_allow_resharing', 'yes', 'yes'],
@@ -248,7 +254,7 @@ class CapabilitiesTest extends \Test\TestCase {
$this->assertTrue($result['resharing']);
}
- public function testNoResharing() {
+ public function testNoResharing(): void {
$map = [
['core', 'shareapi_enabled', 'yes', 'yes'],
['core', 'shareapi_allow_resharing', 'yes', 'no'],
@@ -258,7 +264,7 @@ class CapabilitiesTest extends \Test\TestCase {
$this->assertFalse($result['resharing']);
}
- public function testLinkPublicUpload() {
+ public function testLinkPublicUpload(): void {
$map = [
['core', 'shareapi_enabled', 'yes', 'yes'],
['core', 'shareapi_allow_links', 'yes', 'yes'],
@@ -270,7 +276,7 @@ class CapabilitiesTest extends \Test\TestCase {
$this->assertTrue($result['public']['upload_files_drop']);
}
- public function testLinkNoPublicUpload() {
+ public function testLinkNoPublicUpload(): void {
$map = [
['core', 'shareapi_enabled', 'yes', 'yes'],
['core', 'shareapi_allow_links', 'yes', 'yes'],
@@ -282,7 +288,7 @@ class CapabilitiesTest extends \Test\TestCase {
$this->assertFalse($result['public']['upload_files_drop']);
}
- public function testNoGroupSharing() {
+ public function testNoGroupSharing(): void {
$map = [
['core', 'shareapi_enabled', 'yes', 'yes'],
['core', 'shareapi_allow_group_sharing', 'yes', 'no'],
@@ -291,7 +297,7 @@ class CapabilitiesTest extends \Test\TestCase {
$this->assertFalse($result['group_sharing']);
}
- public function testGroupSharing() {
+ public function testGroupSharing(): void {
$map = [
['core', 'shareapi_enabled', 'yes', 'yes'],
['core', 'shareapi_allow_group_sharing', 'yes', 'yes'],
@@ -300,7 +306,7 @@ class CapabilitiesTest extends \Test\TestCase {
$this->assertTrue($result['group_sharing']);
}
- public function testFederatedSharingIncoming() {
+ public function testFederatedSharingIncoming(): void {
$map = [
['files_sharing', 'incoming_server2server_share_enabled', 'yes', 'yes'],
];
@@ -309,7 +315,7 @@ class CapabilitiesTest extends \Test\TestCase {
$this->assertTrue($result['federation']['incoming']);
}
- public function testFederatedSharingNoIncoming() {
+ public function testFederatedSharingNoIncoming(): void {
$map = [
['files_sharing', 'incoming_server2server_share_enabled', 'yes', 'no'],
];
@@ -318,7 +324,7 @@ class CapabilitiesTest extends \Test\TestCase {
$this->assertFalse($result['federation']['incoming']);
}
- public function testFederatedSharingOutgoing() {
+ public function testFederatedSharingOutgoing(): void {
$map = [
['files_sharing', 'outgoing_server2server_share_enabled', 'yes', 'yes'],
];
@@ -327,7 +333,7 @@ class CapabilitiesTest extends \Test\TestCase {
$this->assertTrue($result['federation']['outgoing']);
}
- public function testFederatedSharingNoOutgoing() {
+ public function testFederatedSharingNoOutgoing(): void {
$map = [
['files_sharing', 'outgoing_server2server_share_enabled', 'yes', 'no'],
];
@@ -336,10 +342,19 @@ class CapabilitiesTest extends \Test\TestCase {
$this->assertFalse($result['federation']['outgoing']);
}
- public function testFederatedSharingExpirationDate() {
+ public function testFederatedSharingExpirationDate(): void {
$result = $this->getResults([]);
$this->assertArrayHasKey('federation', $result);
$this->assertEquals(['enabled' => true], $result['federation']['expire_date']);
$this->assertEquals(['enabled' => true], $result['federation']['expire_date_supported']);
}
+
+ public function testFederatedSharingDisabled(): void {
+ $result = $this->getResults([], federationEnabled: false);
+ $this->assertArrayHasKey('federation', $result);
+ $this->assertFalse($result['federation']['incoming']);
+ $this->assertFalse($result['federation']['outgoing']);
+ $this->assertEquals(['enabled' => false], $result['federation']['expire_date']);
+ $this->assertEquals(['enabled' => false], $result['federation']['expire_date_supported']);
+ }
}