Files
nextcloud-server-mirror/apps/sharing/tests/CapabilitiesTest.php
skjnldsv d47b1b60ce test(files_sharing): cover the unified sharing sidebar, dialog and API
Unit tests for the share list, its refresh and its delete guards, and a case
pinning the API to off by default.

End to end, 34 tests over opening the sidebar, listing and grouping, the row
actions, and creating and editing shares, including the destructive paths where
a confirmation is declined. On top of those, whole journeys: sharing with a
group and then granting one person more than the group, a link beside an invited
share, abandoning the dialog, and narrowing a single recipient.

The specs turn the API on for their worker, while the share editor specs keep it
off. Recipients cannot list the shares addressed to them through the API yet, so
the tests assert what the share owner sees. The rate limiter is left on so the
specs also stand as the check that its limits are livable.

Signed-off-by: Barthelemy Briand <barthelemy.briand@nextcloud.com>
Assisted-by: ClaudeCode:claude-opus-4-8
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
2026-09-08 08:47:27 +02:00

106 lines
2.8 KiB
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Sharing\Tests;
use NCU\Sharing\ISharingRegistry;
use OCA\Sharing\AppInfo\Application;
use OCA\Sharing\Capabilities;
use OCP\IConfig;
use OCP\Server;
use PHPUnit\Framework\Attributes\Group;
use Test\Sharing\TestSharePermissionPreset1;
use Test\Sharing\TestSharePermissionPreset2;
use Test\Sharing\TestShareSourceType1;
use Test\Sharing\TestShareSourceType2;
use Test\TestCase;
#[Group(name: 'DB')]
final class CapabilitiesTest extends TestCase {
private ISharingRegistry $registry;
private Capabilities $capabilities;
#[\Override]
public function setUp(): void {
parent::setUp();
$this->registry = Server::get(ISharingRegistry::class);
$this->registry->clear();
$this->capabilities = Server::get(Capabilities::class);
}
#[\Override]
protected function tearDown(): void {
$this->registry->clear();
parent::tearDown();
}
public function testGetCapabilities(): void {
$config = Server::get(IConfig::class);
$config->setSystemValue('sharing.unified_api_enable', true);
$this->registry->registerSourceType(new TestShareSourceType1([]));
$this->registry->registerSourceType(new TestShareSourceType2([]));
$this->registry->registerPermissionPreset(new TestSharePermissionPreset1());
$this->registry->registerPermissionPreset(new TestSharePermissionPreset2());
$this->assertEquals(
[
Application::APP_ID => [
'api_versions' => ['v1'],
'source_types' => [
[
'class' => TestShareSourceType1::class,
],
[
'class' => TestShareSourceType2::class,
],
],
'permission_presets' => [
[
'class' => TestSharePermissionPreset1::class,
'display_name' => 'TestSharePermissionPreset1',
'hint' => 'hint TestSharePermissionPreset1',
],
[
'class' => TestSharePermissionPreset2::class,
'display_name' => 'TestSharePermissionPreset2',
'hint' => 'hint TestSharePermissionPreset2',
],
],
],
],
$this->capabilities->getCapabilities(),
);
$config->deleteSystemValue('sharing.unified_api_enable');
}
public function testGetCapabilitiesUnifiedSharingApiDisabledByDefault(): void {
$config = Server::get(IConfig::class);
$config->deleteSystemValue('sharing.unified_api_enable');
$this->registry->registerSourceType(new TestShareSourceType1([]));
$this->assertEquals([], $this->capabilities->getCapabilities());
}
public function testGetCapabilitiesDisableUnifiedSharingApi(): void {
$config = Server::get(IConfig::class);
$config->setSystemValue('sharing.unified_api_enable', false);
$this->assertEquals([], $this->capabilities->getCapabilities());
$config->deleteSystemValue('sharing.unified_api_enable');
}
}