aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/tests
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_sharing/tests')
-rw-r--r--apps/files_sharing/tests/ApiTest.php28
-rw-r--r--apps/files_sharing/tests/ApplicationTest.php9
-rw-r--r--apps/files_sharing/tests/CacheTest.php1
-rw-r--r--apps/files_sharing/tests/CapabilitiesTest.php1
-rw-r--r--apps/files_sharing/tests/Collaboration/ShareRecipientSorterTest.php119
-rw-r--r--apps/files_sharing/tests/Command/CleanupRemoteStoragesTest.php43
-rw-r--r--apps/files_sharing/tests/Command/FixShareOwnersTest.php1
-rw-r--r--apps/files_sharing/tests/Controller/ExternalShareControllerTest.php1
-rw-r--r--apps/files_sharing/tests/Controller/PublicPreviewControllerTest.php37
-rw-r--r--apps/files_sharing/tests/Controller/ShareAPIControllerTest.php494
-rw-r--r--apps/files_sharing/tests/Controller/ShareControllerTest.php33
-rw-r--r--apps/files_sharing/tests/Controller/ShareInfoControllerTest.php22
-rw-r--r--apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php21
-rw-r--r--apps/files_sharing/tests/DeleteOrphanedSharesJobTest.php1
-rw-r--r--apps/files_sharing/tests/EncryptedSizePropagationTest.php21
-rw-r--r--apps/files_sharing/tests/EtagPropagationTest.php1
-rw-r--r--apps/files_sharing/tests/ExpireSharesJobTest.php5
-rw-r--r--apps/files_sharing/tests/External/CacheTest.php1
-rw-r--r--apps/files_sharing/tests/External/ManagerTest.php71
-rw-r--r--apps/files_sharing/tests/External/ScannerTest.php1
-rw-r--r--apps/files_sharing/tests/ExternalStorageTest.php7
-rw-r--r--apps/files_sharing/tests/GroupEtagPropagationTest.php1
-rw-r--r--apps/files_sharing/tests/HelperTest.php1
-rw-r--r--apps/files_sharing/tests/Listener/LoadAdditionalListenerTest.php120
-rw-r--r--apps/files_sharing/tests/LockingTest.php1
-rw-r--r--apps/files_sharing/tests/Middleware/OCSShareAPIMiddlewareTest.php5
-rw-r--r--apps/files_sharing/tests/Middleware/ShareInfoMiddlewareTest.php1
-rw-r--r--apps/files_sharing/tests/Middleware/SharingCheckMiddlewareTest.php11
-rw-r--r--apps/files_sharing/tests/Migration/SetPasswordColumnTest.php1
-rw-r--r--apps/files_sharing/tests/MountProviderTest.php93
-rw-r--r--apps/files_sharing/tests/PropagationTestCase.php1
-rw-r--r--apps/files_sharing/tests/ShareTest.php5
-rw-r--r--apps/files_sharing/tests/SharedMountTest.php5
-rw-r--r--apps/files_sharing/tests/SharedStorageTest.php3
-rw-r--r--apps/files_sharing/tests/SharesReminderJobTest.php4
-rw-r--r--apps/files_sharing/tests/SizePropagationTest.php1
-rw-r--r--apps/files_sharing/tests/TestCase.php5
-rw-r--r--apps/files_sharing/tests/UnshareChildrenTest.php1
-rw-r--r--apps/files_sharing/tests/UpdaterTest.php5
-rw-r--r--apps/files_sharing/tests/WatcherTest.php1
40 files changed, 690 insertions, 493 deletions
diff --git a/apps/files_sharing/tests/ApiTest.php b/apps/files_sharing/tests/ApiTest.php
index 4ef9f536cb9..bb686c1ea8c 100644
--- a/apps/files_sharing/tests/ApiTest.php
+++ b/apps/files_sharing/tests/ApiTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -26,6 +27,7 @@ use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IPreview;
use OCP\IRequest;
+use OCP\ITagManager;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\Mail\IMailer;
@@ -111,6 +113,7 @@ class ApiTest extends TestCase {
$logger = $this->createMock(LoggerInterface::class);
$providerFactory = $this->createMock(IProviderFactory::class);
$mailer = $this->createMock(IMailer::class);
+ $tagManager = $this->createMock(ITagManager::class);
$dateTimeZone->method('getTimeZone')->willReturn(new \DateTimeZone(date_default_timezone_get()));
return new ShareAPIController(
@@ -131,6 +134,7 @@ class ApiTest extends TestCase {
$logger,
$providerFactory,
$mailer,
+ $tagManager,
$userId,
);
}
@@ -237,11 +241,11 @@ class ApiTest extends TestCase {
$data = $result->getData();
$this->assertEquals(
- Constants::PERMISSION_READ |
- Constants::PERMISSION_CREATE |
- Constants::PERMISSION_UPDATE |
- Constants::PERMISSION_DELETE |
- Constants::PERMISSION_SHARE,
+ Constants::PERMISSION_READ
+ | Constants::PERMISSION_CREATE
+ | Constants::PERMISSION_UPDATE
+ | Constants::PERMISSION_DELETE
+ | Constants::PERMISSION_SHARE,
$data['permissions']
);
$this->assertEmpty($data['expiration']);
@@ -1018,11 +1022,11 @@ class ApiTest extends TestCase {
$share1 = $this->shareManager->getShareById($share1->getFullId());
$this->assertEquals(
- Constants::PERMISSION_READ |
- Constants::PERMISSION_CREATE |
- Constants::PERMISSION_UPDATE |
- Constants::PERMISSION_DELETE |
- Constants::PERMISSION_SHARE,
+ Constants::PERMISSION_READ
+ | Constants::PERMISSION_CREATE
+ | Constants::PERMISSION_UPDATE
+ | Constants::PERMISSION_DELETE
+ | Constants::PERMISSION_SHARE,
$share1->getPermissions()
);
@@ -1277,7 +1281,7 @@ class ApiTest extends TestCase {
\OC_Hook::clear('\OCA\Files_Sharing\Tests\ApiTest', 'initTestMountPointsHook');
}
- public function datesProvider() {
+ public static function datesProvider() {
$date = new \DateTime();
$date->setTime(0, 0);
$date->add(new \DateInterval('P5D'));
@@ -1293,9 +1297,9 @@ class ApiTest extends TestCase {
/**
* Make sure only ISO 8601 dates are accepted
*
- * @dataProvider datesProvider
* @group RoutingWeirdness
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('datesProvider')]
public function testPublicLinkExpireDate($date, $valid): void {
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
diff --git a/apps/files_sharing/tests/ApplicationTest.php b/apps/files_sharing/tests/ApplicationTest.php
index b1a635406b2..84a3f4b372b 100644
--- a/apps/files_sharing/tests/ApplicationTest.php
+++ b/apps/files_sharing/tests/ApplicationTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -86,9 +87,7 @@ class ApplicationTest extends TestCase {
return $result;
}
- /**
- * @dataProvider providesDataForCanGet
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providesDataForCanGet')]
public function testCheckDirectCanBeDownloaded(string $path, Folder $userFolder, bool $run): void {
$user = $this->createMock(IUser::class);
$user->method('getUID')->willReturn('test');
@@ -167,9 +166,7 @@ class ApplicationTest extends TestCase {
return $return;
}
- /**
- * @dataProvider providesDataForCanZip
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providesDataForCanZip')]
public function testCheckZipCanBeDownloaded(string $dir, array $files, Folder $userFolder, bool $run): void {
$user = $this->createMock(IUser::class);
$user->method('getUID')->willReturn('test');
diff --git a/apps/files_sharing/tests/CacheTest.php b/apps/files_sharing/tests/CacheTest.php
index 53e9efd5d9e..e95d3d4f91a 100644
--- a/apps/files_sharing/tests/CacheTest.php
+++ b/apps/files_sharing/tests/CacheTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
diff --git a/apps/files_sharing/tests/CapabilitiesTest.php b/apps/files_sharing/tests/CapabilitiesTest.php
index 737362e2195..2600bd9d925 100644
--- a/apps/files_sharing/tests/CapabilitiesTest.php
+++ b/apps/files_sharing/tests/CapabilitiesTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
diff --git a/apps/files_sharing/tests/Collaboration/ShareRecipientSorterTest.php b/apps/files_sharing/tests/Collaboration/ShareRecipientSorterTest.php
index 2bef0b0e922..572463a9ebc 100644
--- a/apps/files_sharing/tests/Collaboration/ShareRecipientSorterTest.php
+++ b/apps/files_sharing/tests/Collaboration/ShareRecipientSorterTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -35,9 +36,9 @@ class ShareRecipientSorterTest extends TestCase {
}
/**
- * @dataProvider sortDataProvider
* @param $data
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('sortDataProvider')]
public function testSort($data): void {
$node = $this->createMock(Node::class);
@@ -114,39 +115,37 @@ class ShareRecipientSorterTest extends TestCase {
$this->assertEquals($originalArray, $workArray);
}
- public function sortDataProvider() {
+ public static function sortDataProvider() {
return [[
[
#0 – sort properly and otherwise keep existing order
'context' => ['itemType' => 'files', 'itemId' => '42'],
'accessList' => ['users' => ['celia', 'darius', 'faruk', 'gail'], 'bots' => ['r2-d2']],
'input' => [
- 'users' =>
- [
- ['value' => ['shareWith' => 'alice']],
- ['value' => ['shareWith' => 'bob']],
- ['value' => ['shareWith' => 'celia']],
- ['value' => ['shareWith' => 'darius']],
- ['value' => ['shareWith' => 'elena']],
- ['value' => ['shareWith' => 'faruk']],
- ['value' => ['shareWith' => 'gail']],
- ],
+ 'users' => [
+ ['value' => ['shareWith' => 'alice']],
+ ['value' => ['shareWith' => 'bob']],
+ ['value' => ['shareWith' => 'celia']],
+ ['value' => ['shareWith' => 'darius']],
+ ['value' => ['shareWith' => 'elena']],
+ ['value' => ['shareWith' => 'faruk']],
+ ['value' => ['shareWith' => 'gail']],
+ ],
'bots' => [
['value' => ['shareWith' => 'c-3po']],
['value' => ['shareWith' => 'r2-d2']],
]
],
'expected' => [
- 'users' =>
- [
- ['value' => ['shareWith' => 'celia']],
- ['value' => ['shareWith' => 'darius']],
- ['value' => ['shareWith' => 'faruk']],
- ['value' => ['shareWith' => 'gail']],
- ['value' => ['shareWith' => 'alice']],
- ['value' => ['shareWith' => 'bob']],
- ['value' => ['shareWith' => 'elena']],
- ],
+ 'users' => [
+ ['value' => ['shareWith' => 'celia']],
+ ['value' => ['shareWith' => 'darius']],
+ ['value' => ['shareWith' => 'faruk']],
+ ['value' => ['shareWith' => 'gail']],
+ ['value' => ['shareWith' => 'alice']],
+ ['value' => ['shareWith' => 'bob']],
+ ['value' => ['shareWith' => 'elena']],
+ ],
'bots' => [
['value' => ['shareWith' => 'r2-d2']],
['value' => ['shareWith' => 'c-3po']],
@@ -158,32 +157,30 @@ class ShareRecipientSorterTest extends TestCase {
'context' => ['itemType' => 'files', 'itemId' => '42'],
'accessList' => ['users' => false],
'input' => [
- 'users' =>
- [
- ['value' => ['shareWith' => 'alice']],
- ['value' => ['shareWith' => 'bob']],
- ['value' => ['shareWith' => 'celia']],
- ['value' => ['shareWith' => 'darius']],
- ['value' => ['shareWith' => 'elena']],
- ['value' => ['shareWith' => 'faruk']],
- ['value' => ['shareWith' => 'gail']],
- ],
+ 'users' => [
+ ['value' => ['shareWith' => 'alice']],
+ ['value' => ['shareWith' => 'bob']],
+ ['value' => ['shareWith' => 'celia']],
+ ['value' => ['shareWith' => 'darius']],
+ ['value' => ['shareWith' => 'elena']],
+ ['value' => ['shareWith' => 'faruk']],
+ ['value' => ['shareWith' => 'gail']],
+ ],
'bots' => [
['value' => ['shareWith' => 'c-3po']],
['value' => ['shareWith' => 'r2-d2']],
]
],
'expected' => [
- 'users' =>
- [
- ['value' => ['shareWith' => 'alice']],
- ['value' => ['shareWith' => 'bob']],
- ['value' => ['shareWith' => 'celia']],
- ['value' => ['shareWith' => 'darius']],
- ['value' => ['shareWith' => 'elena']],
- ['value' => ['shareWith' => 'faruk']],
- ['value' => ['shareWith' => 'gail']],
- ],
+ 'users' => [
+ ['value' => ['shareWith' => 'alice']],
+ ['value' => ['shareWith' => 'bob']],
+ ['value' => ['shareWith' => 'celia']],
+ ['value' => ['shareWith' => 'darius']],
+ ['value' => ['shareWith' => 'elena']],
+ ['value' => ['shareWith' => 'faruk']],
+ ['value' => ['shareWith' => 'gail']],
+ ],
'bots' => [
['value' => ['shareWith' => 'c-3po']],
['value' => ['shareWith' => 'r2-d2']],
@@ -195,32 +192,30 @@ class ShareRecipientSorterTest extends TestCase {
'context' => ['itemType' => 'announcements', 'itemId' => '42'],
'accessList' => null, // not needed
'input' => [
- 'users' =>
- [
- ['value' => ['shareWith' => 'alice']],
- ['value' => ['shareWith' => 'bob']],
- ['value' => ['shareWith' => 'celia']],
- ['value' => ['shareWith' => 'darius']],
- ['value' => ['shareWith' => 'elena']],
- ['value' => ['shareWith' => 'faruk']],
- ['value' => ['shareWith' => 'gail']],
- ],
+ 'users' => [
+ ['value' => ['shareWith' => 'alice']],
+ ['value' => ['shareWith' => 'bob']],
+ ['value' => ['shareWith' => 'celia']],
+ ['value' => ['shareWith' => 'darius']],
+ ['value' => ['shareWith' => 'elena']],
+ ['value' => ['shareWith' => 'faruk']],
+ ['value' => ['shareWith' => 'gail']],
+ ],
'bots' => [
['value' => ['shareWith' => 'c-3po']],
['value' => ['shareWith' => 'r2-d2']],
]
],
'expected' => [
- 'users' =>
- [
- ['value' => ['shareWith' => 'alice']],
- ['value' => ['shareWith' => 'bob']],
- ['value' => ['shareWith' => 'celia']],
- ['value' => ['shareWith' => 'darius']],
- ['value' => ['shareWith' => 'elena']],
- ['value' => ['shareWith' => 'faruk']],
- ['value' => ['shareWith' => 'gail']],
- ],
+ 'users' => [
+ ['value' => ['shareWith' => 'alice']],
+ ['value' => ['shareWith' => 'bob']],
+ ['value' => ['shareWith' => 'celia']],
+ ['value' => ['shareWith' => 'darius']],
+ ['value' => ['shareWith' => 'elena']],
+ ['value' => ['shareWith' => 'faruk']],
+ ['value' => ['shareWith' => 'gail']],
+ ],
'bots' => [
['value' => ['shareWith' => 'c-3po']],
['value' => ['shareWith' => 'r2-d2']],
diff --git a/apps/files_sharing/tests/Command/CleanupRemoteStoragesTest.php b/apps/files_sharing/tests/Command/CleanupRemoteStoragesTest.php
index 888b2cdd596..6f0960bf46c 100644
--- a/apps/files_sharing/tests/Command/CleanupRemoteStoragesTest.php
+++ b/apps/files_sharing/tests/Command/CleanupRemoteStoragesTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud GmbH.
@@ -11,6 +12,7 @@ use OCP\Federation\ICloudId;
use OCP\Federation\ICloudIdManager;
use OCP\IDBConnection;
use OCP\Server;
+use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Test\TestCase;
@@ -24,20 +26,9 @@ use Test\TestCase;
*/
class CleanupRemoteStoragesTest extends TestCase {
- /**
- * @var CleanupRemoteStorages
- */
- private $command;
-
- /**
- * @var IDBConnection
- */
- private $connection;
-
- /**
- * @var ICloudIdManager|\PHPUnit\Framework\MockObject\MockObject
- */
- private $cloudIdManager;
+ protected IDBConnection $connection;
+ protected CleanupRemoteStorages $command;
+ private ICloudIdManager&MockObject $cloudIdManager;
private $storages = [
['id' => 'shared::7b4a322b22f9d0047c38d77d471ce3cf', 'share_token' => 'f2c69dad1dc0649f26976fd210fc62e1', 'remote' => 'https://hostname.tld/owncloud1', 'user' => 'user1'],
@@ -77,7 +68,7 @@ class CleanupRemoteStoragesTest extends TestCase {
foreach ($this->storages as &$storage) {
if (isset($storage['id'])) {
$storageQuery->setParameter('id', $storage['id']);
- $storageQuery->execute();
+ $storageQuery->executeStatement();
$storage['numeric_id'] = $storageQuery->getLastInsertId();
}
@@ -121,13 +112,13 @@ class CleanupRemoteStoragesTest extends TestCase {
foreach ($this->storages as $storage) {
if (isset($storage['id'])) {
$storageQuery->setParameter('id', $storage['id']);
- $storageQuery->execute();
+ $storageQuery->executeStatement();
}
if (isset($storage['share_token'])) {
$shareExternalQuery->setParameter('share_token', $storage['share_token']);
$shareExternalQuery->setParameter('remote', $storage['remote']);
- $shareExternalQuery->execute();
+ $shareExternalQuery->executeStatement();
}
}
@@ -174,19 +165,18 @@ class CleanupRemoteStoragesTest extends TestCase {
->getMock();
// parent folder, `files`, ´test` and `welcome.txt` => 4 elements
-
+ $outputCalls = [];
$output
->expects($this->any())
->method('writeln')
- ->withConsecutive(
- ['5 remote storage(s) need(s) to be checked'],
- ['5 remote share(s) exist'],
- );
+ ->willReturnCallback(function (string $text) use (&$outputCalls): void {
+ $outputCalls[] = $text;
+ });
$this->cloudIdManager
->expects($this->any())
->method('getCloudId')
- ->will($this->returnCallback(function (string $user, string $remote) {
+ ->willReturnCallback(function (string $user, string $remote) {
$cloudIdMock = $this->createMock(ICloudId::class);
// The remotes are already sanitized in the original data, so
@@ -197,7 +187,7 @@ class CleanupRemoteStoragesTest extends TestCase {
->willReturn($remote);
return $cloudIdMock;
- }));
+ });
$this->command->execute($input, $output);
@@ -206,5 +196,10 @@ class CleanupRemoteStoragesTest extends TestCase {
$this->assertFalse($this->doesStorageExist($this->storages[3]['numeric_id']));
$this->assertTrue($this->doesStorageExist($this->storages[4]['numeric_id']));
$this->assertFalse($this->doesStorageExist($this->storages[5]['numeric_id']));
+
+ $this->assertEquals([
+ '5 remote storage(s) need(s) to be checked',
+ '5 remote share(s) exist',
+ ], array_slice($outputCalls, 0, 2));
}
}
diff --git a/apps/files_sharing/tests/Command/FixShareOwnersTest.php b/apps/files_sharing/tests/Command/FixShareOwnersTest.php
index 939fad03d7c..0fde61895b1 100644
--- a/apps/files_sharing/tests/Command/FixShareOwnersTest.php
+++ b/apps/files_sharing/tests/Command/FixShareOwnersTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-only
diff --git a/apps/files_sharing/tests/Controller/ExternalShareControllerTest.php b/apps/files_sharing/tests/Controller/ExternalShareControllerTest.php
index 5e8e32c06d8..7e054d9a6dc 100644
--- a/apps/files_sharing/tests/Controller/ExternalShareControllerTest.php
+++ b/apps/files_sharing/tests/Controller/ExternalShareControllerTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
diff --git a/apps/files_sharing/tests/Controller/PublicPreviewControllerTest.php b/apps/files_sharing/tests/Controller/PublicPreviewControllerTest.php
index bd64cfc60b4..f49d839e8d4 100644
--- a/apps/files_sharing/tests/Controller/PublicPreviewControllerTest.php
+++ b/apps/files_sharing/tests/Controller/PublicPreviewControllerTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -18,8 +19,8 @@ use OCP\Files\SimpleFS\ISimpleFile;
use OCP\IPreview;
use OCP\IRequest;
use OCP\ISession;
+use OCP\Preview\IMimeIconProvider;
use OCP\Share\Exceptions\ShareNotFound;
-use OCP\Share\IAttributes;
use OCP\Share\IManager;
use OCP\Share\IShare;
use PHPUnit\Framework\MockObject\MockObject;
@@ -52,7 +53,8 @@ class PublicPreviewControllerTest extends TestCase {
$this->request,
$this->shareManager,
$this->createMock(ISession::class),
- $this->previewManager
+ $this->previewManager,
+ $this->createMock(IMimeIconProvider::class),
);
}
@@ -112,12 +114,8 @@ class PublicPreviewControllerTest extends TestCase {
$share->method('getPermissions')
->willReturn(Constants::PERMISSION_READ);
- $attributes = $this->createMock(IAttributes::class);
- $attributes->method('getAttribute')
- ->with('permissions', 'download')
+ $share->method('canSeeContent')
->willReturn(false);
- $share->method('getAttributes')
- ->willReturn($attributes);
$res = $this->controller->getPreview('token', 'file', 10, 10);
$expected = new DataResponse([], Http::STATUS_FORBIDDEN);
@@ -134,15 +132,11 @@ class PublicPreviewControllerTest extends TestCase {
$share->method('getPermissions')
->willReturn(Constants::PERMISSION_READ);
- $attributes = $this->createMock(IAttributes::class);
- $attributes->method('getAttribute')
- ->with('permissions', 'download')
+ $share->method('canSeeContent')
->willReturn(false);
- $share->method('getAttributes')
- ->willReturn($attributes);
$this->request->method('getHeader')
- ->with('X-NC-Preview')
+ ->with('x-nc-preview')
->willReturn('true');
$file = $this->createMock(File::class);
@@ -174,15 +168,11 @@ class PublicPreviewControllerTest extends TestCase {
$share->method('getPermissions')
->willReturn(Constants::PERMISSION_READ);
- $attributes = $this->createMock(IAttributes::class);
- $attributes->method('getAttribute')
- ->with('permissions', 'download')
+ $share->method('canSeeContent')
->willReturn(true);
- $share->method('getAttributes')
- ->willReturn($attributes);
$this->request->method('getHeader')
- ->with('X-NC-Preview')
+ ->with('x-nc-preview')
->willReturn('true');
$file = $this->createMock(File::class);
@@ -218,6 +208,9 @@ class PublicPreviewControllerTest extends TestCase {
$share->method('getNode')
->willReturn($file);
+ $share->method('canSeeContent')
+ ->willReturn(true);
+
$preview = $this->createMock(ISimpleFile::class);
$preview->method('getName')->willReturn('name');
$preview->method('getMTime')->willReturn(42);
@@ -247,6 +240,9 @@ class PublicPreviewControllerTest extends TestCase {
$share->method('getNode')
->willReturn($folder);
+ $share->method('canSeeContent')
+ ->willReturn(true);
+
$folder->method('get')
->with($this->equalTo('file'))
->willThrowException(new NotFoundException());
@@ -270,6 +266,9 @@ class PublicPreviewControllerTest extends TestCase {
$share->method('getNode')
->willReturn($folder);
+ $share->method('canSeeContent')
+ ->willReturn(true);
+
$file = $this->createMock(File::class);
$folder->method('get')
->with($this->equalTo('file'))
diff --git a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
index 29eae2dc581..8bb220d684b 100644
--- a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
+++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -28,6 +29,8 @@ use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IPreview;
use OCP\IRequest;
+use OCP\ITagManager;
+use OCP\ITags;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
@@ -76,6 +79,7 @@ class ShareAPIControllerTest extends TestCase {
private LoggerInterface&MockObject $logger;
private IProviderFactory&MockObject $factory;
private IMailer&MockObject $mailer;
+ private ITagManager&MockObject $tagManager;
protected function setUp(): void {
$this->shareManager = $this->createMock(IManager::class);
@@ -111,6 +115,7 @@ class ShareAPIControllerTest extends TestCase {
$this->logger = $this->createMock(LoggerInterface::class);
$this->factory = $this->createMock(IProviderFactory::class);
$this->mailer = $this->createMock(IMailer::class);
+ $this->tagManager = $this->createMock(ITagManager::class);
$this->ocs = new ShareAPIController(
$this->appName,
@@ -130,6 +135,7 @@ class ShareAPIControllerTest extends TestCase {
$this->logger,
$this->factory,
$this->mailer,
+ $this->tagManager,
$this->currentUser,
);
}
@@ -157,6 +163,7 @@ class ShareAPIControllerTest extends TestCase {
$this->logger,
$this->factory,
$this->mailer,
+ $this->tagManager,
$this->currentUser,
])->onlyMethods(['formatShare'])
->getMock();
@@ -265,7 +272,7 @@ class ShareAPIControllerTest extends TestCase {
$node->expects($this->once())
->method('lock')
->with(ILockingProvider::LOCK_SHARED)
- ->will($this->throwException(new LockedException('mypath')));
+ ->willThrowException(new LockedException('mypath'));
$this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteFromSelf', [$share]));
$this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteShare', [$share]));
@@ -586,9 +593,9 @@ class ShareAPIControllerTest extends TestCase {
$share->method('getToken')->willReturn($token);
$share->method('getPassword')->willReturn($password);
- if ($shareType === IShare::TYPE_USER ||
- $shareType === IShare::TYPE_GROUP ||
- $shareType === IShare::TYPE_LINK) {
+ if ($shareType === IShare::TYPE_USER
+ || $shareType === IShare::TYPE_GROUP
+ || $shareType === IShare::TYPE_LINK) {
$share->method('getFullId')->willReturn('ocinternal:' . $id);
}
@@ -817,9 +824,7 @@ class ShareAPIControllerTest extends TestCase {
return $data;
}
- /**
- * @dataProvider dataGetShare
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetShare')]
public function testGetShare(IShare $share, array $result): void {
/** @var ShareAPIController&MockObject $ocs */
$ocs = $this->getMockBuilder(ShareAPIController::class)
@@ -841,8 +846,8 @@ class ShareAPIControllerTest extends TestCase {
$this->logger,
$this->factory,
$this->mailer,
+ $this->tagManager,
$this->currentUser,
-
])
->onlyMethods(['canAccessShare'])
->getMock();
@@ -1450,9 +1455,7 @@ class ShareAPIControllerTest extends TestCase {
return $data;
}
- /**
- * @dataProvider dataGetShares
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetShares')]
public function testGetShares(array $getSharesParameters, array $shares, array $extraShareTypes, array $expected): void {
/** @var ShareAPIController&MockObject $ocs */
$ocs = $this->getMockBuilder(ShareAPIController::class)
@@ -1474,6 +1477,7 @@ class ShareAPIControllerTest extends TestCase {
$this->logger,
$this->factory,
$this->mailer,
+ $this->tagManager,
$this->currentUser,
])
->onlyMethods(['formatShare'])
@@ -1535,84 +1539,125 @@ class ShareAPIControllerTest extends TestCase {
$this->assertEquals($expected, $result->getData());
}
- public function testCanAccessShare(): void {
- $share = $this->getMockBuilder(IShare::class)->getMock();
+ public function testCanAccessShareAsOwner(): void {
+ $share = $this->createMock(IShare::class);
$share->method('getShareOwner')->willReturn($this->currentUser);
$this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
+ }
- $share = $this->getMockBuilder(IShare::class)->getMock();
+ public function testCanAccessShareAsSharer(): void {
+ $share = $this->createMock(IShare::class);
$share->method('getSharedBy')->willReturn($this->currentUser);
$this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
+ }
- $share = $this->getMockBuilder(IShare::class)->getMock();
+ public function testCanAccessShareAsSharee(): void {
+ $share = $this->createMock(IShare::class);
$share->method('getShareType')->willReturn(IShare::TYPE_USER);
$share->method('getSharedWith')->willReturn($this->currentUser);
$this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
+ }
- $file = $this->getMockBuilder(File::class)->getMock();
+ public function testCannotAccessLinkShare(): void {
+ $share = $this->createMock(IShare::class);
+ $share->method('getShareType')->willReturn(IShare::TYPE_LINK);
+ $share->method('getNodeId')->willReturn(42);
- $userFolder = $this->getMockBuilder(Folder::class)->getMock();
+ $userFolder = $this->createMock(Folder::class);
$this->rootFolder->method('getUserFolder')
->with($this->currentUser)
->willReturn($userFolder);
+ $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataCanAccessShareWithPermissions')]
+ public function testCanAccessShareWithPermissions(int $permissions, bool $expected): void {
+ $share = $this->createMock(IShare::class);
+ $share->method('getShareType')->willReturn(IShare::TYPE_USER);
+ $share->method('getSharedWith')->willReturn($this->createMock(IUser::class));
+ $share->method('getNodeId')->willReturn(42);
+
+ $file = $this->createMock(File::class);
+
+ $userFolder = $this->getMockBuilder(Folder::class)->getMock();
$userFolder->method('getFirstNodeById')
->with($share->getNodeId())
->willReturn($file);
$userFolder->method('getById')
->with($share->getNodeId())
->willReturn([$file]);
+ $this->rootFolder->method('getUserFolder')
+ ->with($this->currentUser)
+ ->willReturn($userFolder);
$file->method('getPermissions')
- ->will($this->onConsecutiveCalls(Constants::PERMISSION_SHARE, Constants::PERMISSION_READ));
+ ->willReturn($permissions);
- // getPermissions -> share
- $share = $this->getMockBuilder(IShare::class)->getMock();
- $share->method('getShareType')->willReturn(IShare::TYPE_USER);
- $share->method('getSharedWith')->willReturn($this->getMockBuilder(IUser::class)->getMock());
- $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
+ if ($expected) {
+ $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
+ } else {
+ $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
+ }
+ }
- // getPermissions -> read
- $share = $this->getMockBuilder(IShare::class)->getMock();
- $share->method('getShareType')->willReturn(IShare::TYPE_USER);
- $share->method('getSharedWith')->willReturn($this->getMockBuilder(IUser::class)->getMock());
- $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
+ public static function dataCanAccessShareWithPermissions(): array {
+ return [
+ [Constants::PERMISSION_SHARE, true],
+ [Constants::PERMISSION_READ, false],
+ [Constants::PERMISSION_READ | Constants::PERMISSION_SHARE, true],
+ ];
+ }
- $share = $this->getMockBuilder(IShare::class)->getMock();
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataCanAccessShareAsGroupMember')]
+ public function testCanAccessShareAsGroupMember(string $group, bool $expected): void {
+ $share = $this->createMock(IShare::class);
$share->method('getShareType')->willReturn(IShare::TYPE_GROUP);
- $share->method('getSharedWith')->willReturn('group');
+ $share->method('getSharedWith')->willReturn($group);
+ $share->method('getNodeId')->willReturn(42);
+
+ $file = $this->createMock(File::class);
+
+ $userFolder = $this->createMock(Folder::class);
+ $userFolder->method('getFirstNodeById')
+ ->with($share->getNodeId())
+ ->willReturn($file);
+ $userFolder->method('getById')
+ ->with($share->getNodeId())
+ ->willReturn([$file]);
+ $this->rootFolder->method('getUserFolder')
+ ->with($this->currentUser)
+ ->willReturn($userFolder);
$user = $this->createMock(IUser::class);
$this->userManager->method('get')
->with($this->currentUser)
->willReturn($user);
- $group = $this->getMockBuilder(IGroup::class)->getMock();
+ $group = $this->createMock(IGroup::class);
$group->method('inGroup')->with($user)->willReturn(true);
- $group2 = $this->getMockBuilder(IGroup::class)->getMock();
+ $group2 = $this->createMock(IGroup::class);
$group2->method('inGroup')->with($user)->willReturn(false);
$this->groupManager->method('get')->willReturnMap([
['group', $group],
['group2', $group2],
- ['groupnull', null],
+ ['group-null', null],
]);
- $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
- $share = $this->createMock(IShare::class);
- $share->method('getShareType')->willReturn(IShare::TYPE_GROUP);
- $share->method('getSharedWith')->willReturn('group2');
- $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
-
- // null group
- $share = $this->createMock(IShare::class);
- $share->method('getShareType')->willReturn(IShare::TYPE_GROUP);
- $share->method('getSharedWith')->willReturn('groupnull');
- $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
+ if ($expected) {
+ $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
+ } else {
+ $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
+ }
+ }
- $share = $this->createMock(IShare::class);
- $share->method('getShareType')->willReturn(IShare::TYPE_LINK);
- $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
+ public static function dataCanAccessShareAsGroupMember(): array {
+ return [
+ ['group', true],
+ ['group2', false],
+ ['group-null', false],
+ ];
}
public function dataCanAccessRoomShare() {
@@ -1642,13 +1687,13 @@ class ShareAPIControllerTest extends TestCase {
}
/**
- * @dataProvider dataCanAccessRoomShare
*
* @param bool $expects
* @param IShare $share
* @param bool helperAvailable
* @param bool canAccessShareByHelper
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataCanAccessRoomShare')]
public function testCanAccessRoomShare(bool $expected, IShare $share, bool $helperAvailable, bool $canAccessShareByHelper): void {
$userFolder = $this->getMockBuilder(Folder::class)->getMock();
$this->rootFolder->method('getUserFolder')
@@ -1668,8 +1713,11 @@ class ShareAPIControllerTest extends TestCase {
->with('spreed')
->willReturn(true);
- $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
- ->setMethods(['canAccessShare'])
+ // This is not possible anymore with PHPUnit 10+
+ // as `setMethods` was removed and now real reflection is used, thus the class needs to exist.
+ // $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
+ $helper = $this->getMockBuilder(\stdClass::class)
+ ->addMethods(['canAccessShare'])
->getMock();
$helper->method('canAccessShare')
->with($share, $this->currentUser)
@@ -1705,7 +1753,7 @@ class ShareAPIControllerTest extends TestCase {
$userFolder->expects($this->once())
->method('get')
->with('invalid-path')
- ->will($this->throwException(new NotFoundException()));
+ ->willThrowException(new NotFoundException());
$this->ocs->createShare('invalid-path');
}
@@ -1816,8 +1864,9 @@ class ShareAPIControllerTest extends TestCase {
$this->logger,
$this->factory,
$this->mailer,
+ $this->tagManager,
$this->currentUser,
- ])->setMethods(['formatShare'])
+ ])->onlyMethods(['formatShare'])
->getMock();
[$userFolder, $path] = $this->getNonSharedUserFile();
@@ -1841,15 +1890,15 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->method('createShare')
->with($this->callback(function (IShare $share) use ($path) {
- return $share->getNode() === $path &&
- $share->getPermissions() === (
- Constants::PERMISSION_ALL &
- ~Constants::PERMISSION_DELETE &
- ~Constants::PERMISSION_CREATE
- ) &&
- $share->getShareType() === IShare::TYPE_USER &&
- $share->getSharedWith() === 'validUser' &&
- $share->getSharedBy() === 'currentUser';
+ return $share->getNode() === $path
+ && $share->getPermissions() === (
+ Constants::PERMISSION_ALL
+ & ~Constants::PERMISSION_DELETE
+ & ~Constants::PERMISSION_CREATE
+ )
+ && $share->getShareType() === IShare::TYPE_USER
+ && $share->getSharedWith() === 'validUser'
+ && $share->getSharedBy() === 'currentUser';
}))
->willReturnArgument(0);
@@ -1913,8 +1962,9 @@ class ShareAPIControllerTest extends TestCase {
$this->logger,
$this->factory,
$this->mailer,
+ $this->tagManager,
$this->currentUser,
- ])->setMethods(['formatShare'])
+ ])->onlyMethods(['formatShare'])
->getMock();
$this->request
@@ -1951,11 +2001,11 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->method('createShare')
->with($this->callback(function (IShare $share) use ($path) {
- return $share->getNode() === $path &&
- $share->getPermissions() === Constants::PERMISSION_ALL &&
- $share->getShareType() === IShare::TYPE_GROUP &&
- $share->getSharedWith() === 'validGroup' &&
- $share->getSharedBy() === 'currentUser';
+ return $share->getNode() === $path
+ && $share->getPermissions() === Constants::PERMISSION_ALL
+ && $share->getShareType() === IShare::TYPE_GROUP
+ && $share->getSharedWith() === 'validGroup'
+ && $share->getSharedBy() === 'currentUser';
}))
->willReturnArgument(0);
@@ -2068,7 +2118,7 @@ class ShareAPIControllerTest extends TestCase {
$file = $this->createMock(File::class);
$file->method('getId')->willReturn(42);
$file->method('getStorage')->willReturn($storage);
-
+
$this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf();
$this->rootFolder->method('get')->with('valid-path')->willReturn($file);
$this->rootFolder->method('getById')
@@ -2104,12 +2154,12 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->expects($this->once())->method('createShare')->with(
$this->callback(function (IShare $share) use ($path) {
- return $share->getNode() === $path &&
- $share->getShareType() === IShare::TYPE_LINK &&
- $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE) &&
- $share->getSharedBy() === 'currentUser' &&
- $share->getPassword() === null &&
- $share->getExpirationDate() === null;
+ return $share->getNode() === $path
+ && $share->getShareType() === IShare::TYPE_LINK
+ && $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE)
+ && $share->getSharedBy() === 'currentUser'
+ && $share->getPassword() === null
+ && $share->getExpirationDate() === null;
})
)->willReturnArgument(0);
@@ -2184,13 +2234,13 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->expects($this->once())->method('createShare')->with(
$this->callback(function (IShare $share) use ($path) {
- return $share->getNode() === $path &&
- $share->getShareType() === IShare::TYPE_LINK &&
- $share->getPermissions() === (Constants::PERMISSION_ALL & ~(Constants::PERMISSION_SHARE)) &&
- $share->getSharedBy() === 'currentUser' &&
- $share->getPassword() === 'password' &&
- $share->getSendPasswordByTalk() === true &&
- $share->getExpirationDate() === null;
+ return $share->getNode() === $path
+ && $share->getShareType() === IShare::TYPE_LINK
+ && $share->getPermissions() === (Constants::PERMISSION_ALL & ~(Constants::PERMISSION_SHARE))
+ && $share->getSharedBy() === 'currentUser'
+ && $share->getPassword() === 'password'
+ && $share->getSendPasswordByTalk() === true
+ && $share->getExpirationDate() === null;
})
)->willReturnArgument(0);
@@ -2270,12 +2320,12 @@ class ShareAPIControllerTest extends TestCase {
$date = new \DateTime('2000-01-01');
$date->setTime(0, 0, 0);
- return $share->getNode() === $path &&
- $share->getShareType() === IShare::TYPE_LINK &&
- $share->getPermissions() === Constants::PERMISSION_READ | Constants::PERMISSION_SHARE &&
- $share->getSharedBy() === 'currentUser' &&
- $share->getPassword() === null &&
- $share->getExpirationDate() == $date;
+ return $share->getNode() === $path
+ && $share->getShareType() === IShare::TYPE_LINK
+ && $share->getPermissions() === Constants::PERMISSION_READ | Constants::PERMISSION_SHARE
+ && $share->getSharedBy() === 'currentUser'
+ && $share->getPassword() === null
+ && $share->getExpirationDate() == $date;
})
)->willReturnArgument(0);
@@ -2338,8 +2388,9 @@ class ShareAPIControllerTest extends TestCase {
$this->logger,
$this->factory,
$this->mailer,
+ $this->tagManager,
$this->currentUser,
- ])->setMethods(['formatShare'])
+ ])->onlyMethods(['formatShare'])
->getMock();
[$userFolder, $path] = $this->getNonSharedUserFile();
@@ -2363,15 +2414,15 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->method('createShare')
->with($this->callback(function (IShare $share) use ($path) {
- return $share->getNode() === $path &&
- $share->getPermissions() === (
- Constants::PERMISSION_ALL &
- ~Constants::PERMISSION_DELETE &
- ~Constants::PERMISSION_CREATE
- ) &&
- $share->getShareType() === IShare::TYPE_REMOTE &&
- $share->getSharedWith() === 'user@example.org' &&
- $share->getSharedBy() === 'currentUser';
+ return $share->getNode() === $path
+ && $share->getPermissions() === (
+ Constants::PERMISSION_ALL
+ & ~Constants::PERMISSION_DELETE
+ & ~Constants::PERMISSION_CREATE
+ )
+ && $share->getShareType() === IShare::TYPE_REMOTE
+ && $share->getSharedWith() === 'user@example.org'
+ && $share->getSharedBy() === 'currentUser';
}))
->willReturnArgument(0);
@@ -2408,8 +2459,9 @@ class ShareAPIControllerTest extends TestCase {
$this->logger,
$this->factory,
$this->mailer,
+ $this->tagManager,
$this->currentUser,
- ])->setMethods(['formatShare'])
+ ])->onlyMethods(['formatShare'])
->getMock();
[$userFolder, $path] = $this->getNonSharedUserFile();
@@ -2433,15 +2485,15 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->method('createShare')
->with($this->callback(function (IShare $share) use ($path) {
- return $share->getNode() === $path &&
- $share->getPermissions() === (
- Constants::PERMISSION_ALL &
- ~Constants::PERMISSION_DELETE &
- ~Constants::PERMISSION_CREATE
- ) &&
- $share->getShareType() === IShare::TYPE_REMOTE_GROUP &&
- $share->getSharedWith() === 'group@example.org' &&
- $share->getSharedBy() === 'currentUser';
+ return $share->getNode() === $path
+ && $share->getPermissions() === (
+ Constants::PERMISSION_ALL
+ & ~Constants::PERMISSION_DELETE
+ & ~Constants::PERMISSION_CREATE
+ )
+ && $share->getShareType() === IShare::TYPE_REMOTE_GROUP
+ && $share->getSharedWith() === 'group@example.org'
+ && $share->getSharedBy() === 'currentUser';
}))
->willReturnArgument(0);
@@ -2481,16 +2533,19 @@ class ShareAPIControllerTest extends TestCase {
->with('spreed')
->willReturn(true);
- $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
- ->setMethods(['createShare'])
+ // This is not possible anymore with PHPUnit 10+
+ // as `setMethods` was removed and now real reflection is used, thus the class needs to exist.
+ // $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
+ $helper = $this->getMockBuilder(\stdClass::class)
+ ->addMethods(['createShare'])
->getMock();
$helper->method('createShare')
->with(
$share,
'recipientRoom',
- Constants::PERMISSION_ALL &
- ~Constants::PERMISSION_DELETE &
- ~Constants::PERMISSION_CREATE,
+ Constants::PERMISSION_ALL
+ & ~Constants::PERMISSION_DELETE
+ & ~Constants::PERMISSION_CREATE,
''
)->willReturnCallback(
function ($share): void {
@@ -2587,7 +2642,10 @@ class ShareAPIControllerTest extends TestCase {
->with('spreed')
->willReturn(true);
- $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
+ // This is not possible anymore with PHPUnit 10+
+ // as `setMethods` was removed and now real reflection is used, thus the class needs to exist.
+ // $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
+ $helper = $this->getMockBuilder(\stdClass::class)
->addMethods(['createShare'])
->getMock();
$helper->method('createShare')
@@ -2639,8 +2697,9 @@ class ShareAPIControllerTest extends TestCase {
$this->logger,
$this->factory,
$this->mailer,
+ $this->tagManager,
$this->currentUser,
- ])->setMethods(['formatShare'])
+ ])->onlyMethods(['formatShare'])
->getMock();
$userFolder = $this->getMockBuilder(Folder::class)->getMock();
@@ -2776,14 +2835,14 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->expects($this->once())->method('updateShare')->with(
$this->callback(function (IShare $share) {
- return $share->getPermissions() === Constants::PERMISSION_READ &&
- $share->getPassword() === null &&
- $share->getExpirationDate() === null &&
+ return $share->getPermissions() === Constants::PERMISSION_READ
+ && $share->getPassword() === null
+ && $share->getExpirationDate() === null
// Once set a note or a label are never back to null, only to an
// empty string.
- $share->getNote() === '' &&
- $share->getLabel() === '' &&
- $share->getHideDownload() === false;
+ && $share->getNote() === ''
+ && $share->getLabel() === ''
+ && $share->getHideDownload() === false;
})
)->willReturnArgument(0);
@@ -2835,12 +2894,12 @@ class ShareAPIControllerTest extends TestCase {
$date = new \DateTime('2000-01-01');
$date->setTime(0, 0, 0);
- return $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE) &&
- $share->getPassword() === 'password' &&
- $share->getExpirationDate() == $date &&
- $share->getNote() === 'note' &&
- $share->getLabel() === 'label' &&
- $share->getHideDownload() === true;
+ return $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE)
+ && $share->getPassword() === 'password'
+ && $share->getExpirationDate() == $date
+ && $share->getNote() === 'note'
+ && $share->getLabel() === 'label'
+ && $share->getHideDownload() === true;
})
)->willReturnArgument(0);
@@ -2868,9 +2927,7 @@ class ShareAPIControllerTest extends TestCase {
$this->assertEquals($expected->getData(), $result->getData());
}
- /**
- * @dataProvider publicUploadParamsProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('publicUploadParamsProvider')]
public function testUpdateLinkShareEnablePublicUpload($permissions, $publicUpload, $expireDate, $password): void {
$ocs = $this->mockFormatShare();
@@ -2891,9 +2948,9 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->expects($this->once())->method('updateShare')->with(
$this->callback(function (IShare $share) {
- return $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE) &&
- $share->getPassword() === 'password' &&
- $share->getExpirationDate() === null;
+ return $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE)
+ && $share->getPassword() === 'password'
+ && $share->getExpirationDate() === null;
})
)->willReturnArgument(0);
@@ -2919,7 +2976,7 @@ class ShareAPIControllerTest extends TestCase {
}
- public function publicLinkValidPermissionsProvider() {
+ public static function publicLinkValidPermissionsProvider() {
return [
[Constants::PERMISSION_CREATE],
[Constants::PERMISSION_READ],
@@ -2929,9 +2986,7 @@ class ShareAPIControllerTest extends TestCase {
];
}
- /**
- * @dataProvider publicLinkValidPermissionsProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('publicLinkValidPermissionsProvider')]
public function testUpdateLinkShareSetCRUDPermissions($permissions): void {
$ocs = $this->mockFormatShare();
@@ -2976,7 +3031,7 @@ class ShareAPIControllerTest extends TestCase {
$this->assertEquals($expected->getData(), $result->getData());
}
- public function publicLinkInvalidPermissionsProvider1() {
+ public static function publicLinkInvalidPermissionsProvider1() {
return [
[Constants::PERMISSION_DELETE],
[Constants::PERMISSION_UPDATE],
@@ -2984,9 +3039,7 @@ class ShareAPIControllerTest extends TestCase {
];
}
- /**
- * @dataProvider publicLinkInvalidPermissionsProvider1
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('publicLinkInvalidPermissionsProvider1')]
public function testUpdateLinkShareSetInvalidCRUDPermissions1($permissions): void {
$this->expectException(OCSBadRequestException::class);
$this->expectExceptionMessage('Share must at least have READ or CREATE permissions');
@@ -2994,16 +3047,14 @@ class ShareAPIControllerTest extends TestCase {
$this->testUpdateLinkShareSetCRUDPermissions($permissions, null);
}
- public function publicLinkInvalidPermissionsProvider2() {
+ public static function publicLinkInvalidPermissionsProvider2() {
return [
[Constants::PERMISSION_CREATE | Constants::PERMISSION_DELETE],
[Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE],
];
}
- /**
- * @dataProvider publicLinkInvalidPermissionsProvider2
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('publicLinkInvalidPermissionsProvider2')]
public function testUpdateLinkShareSetInvalidCRUDPermissions2($permissions): void {
$this->expectException(OCSBadRequestException::class);
$this->expectExceptionMessage('Share must have READ permission if UPDATE or DELETE permission is set');
@@ -3039,7 +3090,7 @@ class ShareAPIControllerTest extends TestCase {
$ocs->updateShare(42, null, 'password', null, 'true', '2000-01-a');
}
- public function publicUploadParamsProvider() {
+ public static function publicUploadParamsProvider() {
return [
[null, 'true', null, 'password'],
// legacy had no delete
@@ -3055,9 +3106,7 @@ class ShareAPIControllerTest extends TestCase {
];
}
- /**
- * @dataProvider publicUploadParamsProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('publicUploadParamsProvider')]
public function testUpdateLinkSharePublicUploadNotAllowed($permissions, $publicUpload, $expireDate, $password): void {
$this->expectException(OCSForbiddenException::class);
$this->expectExceptionMessage('Public upload disabled by the administrator');
@@ -3159,13 +3208,13 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->expects($this->once())->method('updateShare')->with(
$this->callback(function (IShare $share) use ($date) {
- return $share->getPermissions() === Constants::PERMISSION_ALL &&
- $share->getPassword() === 'newpassword' &&
- $share->getSendPasswordByTalk() === true &&
- $share->getExpirationDate() === $date &&
- $share->getNote() === 'note' &&
- $share->getLabel() === 'label' &&
- $share->getHideDownload() === true;
+ return $share->getPermissions() === Constants::PERMISSION_ALL
+ && $share->getPassword() === 'newpassword'
+ && $share->getSendPasswordByTalk() === true
+ && $share->getExpirationDate() === $date
+ && $share->getNote() === 'note'
+ && $share->getLabel() === 'label'
+ && $share->getHideDownload() === true;
})
)->willReturnArgument(0);
@@ -3213,13 +3262,13 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->expects($this->once())->method('updateShare')->with(
$this->callback(function (IShare $share) use ($date) {
- return $share->getPermissions() === Constants::PERMISSION_ALL &&
- $share->getPassword() === 'password' &&
- $share->getSendPasswordByTalk() === true &&
- $share->getExpirationDate() === $date &&
- $share->getNote() === 'note' &&
- $share->getLabel() === 'label' &&
- $share->getHideDownload() === true;
+ return $share->getPermissions() === Constants::PERMISSION_ALL
+ && $share->getPassword() === 'password'
+ && $share->getSendPasswordByTalk() === true
+ && $share->getExpirationDate() === $date
+ && $share->getNote() === 'note'
+ && $share->getLabel() === 'label'
+ && $share->getHideDownload() === true;
})
)->willReturnArgument(0);
@@ -3311,13 +3360,13 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->expects($this->once())->method('updateShare')->with(
$this->callback(function (IShare $share) use ($date) {
- return $share->getPermissions() === Constants::PERMISSION_ALL &&
- $share->getPassword() === 'password' &&
- $share->getSendPasswordByTalk() === false &&
- $share->getExpirationDate() === $date &&
- $share->getNote() === 'note' &&
- $share->getLabel() === 'label' &&
- $share->getHideDownload() === true;
+ return $share->getPermissions() === Constants::PERMISSION_ALL
+ && $share->getPassword() === 'password'
+ && $share->getSendPasswordByTalk() === false
+ && $share->getExpirationDate() === $date
+ && $share->getNote() === 'note'
+ && $share->getLabel() === 'label'
+ && $share->getHideDownload() === true;
})
)->willReturnArgument(0);
@@ -3361,13 +3410,13 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->expects($this->once())->method('updateShare')->with(
$this->callback(function (IShare $share) use ($date) {
- return $share->getPermissions() === Constants::PERMISSION_ALL &&
- $share->getPassword() === 'password' &&
- $share->getSendPasswordByTalk() === false &&
- $share->getExpirationDate() === $date &&
- $share->getNote() === 'note' &&
- $share->getLabel() === 'label' &&
- $share->getHideDownload() === true;
+ return $share->getPermissions() === Constants::PERMISSION_ALL
+ && $share->getPassword() === 'password'
+ && $share->getSendPasswordByTalk() === false
+ && $share->getExpirationDate() === $date
+ && $share->getNote() === 'note'
+ && $share->getLabel() === 'label'
+ && $share->getHideDownload() === true;
})
)->willReturnArgument(0);
@@ -3429,13 +3478,13 @@ class ShareAPIControllerTest extends TestCase {
$date = new \DateTime('2010-12-23');
$date->setTime(0, 0, 0);
- return $share->getPermissions() === Constants::PERMISSION_ALL &&
- $share->getPassword() === 'password' &&
- $share->getSendPasswordByTalk() === true &&
- $share->getExpirationDate() == $date &&
- $share->getNote() === 'note' &&
- $share->getLabel() === 'label' &&
- $share->getHideDownload() === true;
+ return $share->getPermissions() === Constants::PERMISSION_ALL
+ && $share->getPassword() === 'password'
+ && $share->getSendPasswordByTalk() === true
+ && $share->getExpirationDate() == $date
+ && $share->getNote() === 'note'
+ && $share->getLabel() === 'label'
+ && $share->getHideDownload() === true;
})
)->willReturnArgument(0);
@@ -3487,13 +3536,13 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->expects($this->once())->method('updateShare')->with(
$this->callback(function (IShare $share) use ($date) {
- return $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE) &&
- $share->getPassword() === 'password' &&
- $share->getSendPasswordByTalk() === true &&
- $share->getExpirationDate() === $date &&
- $share->getNote() === 'note' &&
- $share->getLabel() === 'label' &&
- $share->getHideDownload() === true;
+ return $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE)
+ && $share->getPassword() === 'password'
+ && $share->getSendPasswordByTalk() === true
+ && $share->getExpirationDate() === $date
+ && $share->getNote() === 'note'
+ && $share->getLabel() === 'label'
+ && $share->getHideDownload() === true;
})
)->willReturnArgument(0);
@@ -3548,13 +3597,13 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->expects($this->once())->method('updateShare')->with(
$this->callback(function (IShare $share) use ($date): bool {
- return $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE) &&
- $share->getPassword() === 'password' &&
- $share->getSendPasswordByTalk() === true &&
- $share->getExpirationDate() === $date &&
- $share->getNote() === 'note' &&
- $share->getLabel() === 'label' &&
- $share->getHideDownload() === true;
+ return $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE)
+ && $share->getPassword() === 'password'
+ && $share->getSendPasswordByTalk() === true
+ && $share->getExpirationDate() === $date
+ && $share->getNote() === 'note'
+ && $share->getLabel() === 'label'
+ && $share->getHideDownload() === true;
})
)->willReturnArgument(0);
@@ -3610,13 +3659,13 @@ class ShareAPIControllerTest extends TestCase {
->method('updateShare')
->with(
$this->callback(function (IShare $share) use ($date) {
- return $share->getPermissions() === Constants::PERMISSION_ALL &&
- $share->getPassword() === 'password' &&
- $share->getSendPasswordByTalk() === true &&
- $share->getExpirationDate() === $date &&
- $share->getNote() === 'note' &&
- $share->getLabel() === 'label' &&
- $share->getHideDownload() === true;
+ return $share->getPermissions() === Constants::PERMISSION_ALL
+ && $share->getPassword() === 'password'
+ && $share->getSendPasswordByTalk() === true
+ && $share->getExpirationDate() === $date
+ && $share->getNote() === 'note'
+ && $share->getLabel() === 'label'
+ && $share->getHideDownload() === true;
})
)->willReturnArgument(0);
@@ -4833,13 +4882,13 @@ class ShareAPIControllerTest extends TestCase {
}
/**
- * @dataProvider dataFormatShare
*
* @param array $expects
* @param IShare $share
* @param array $users
* @param $exception
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataFormatShare')]
public function testFormatShare(array $expects, IShare $share, array $users, $exception): void {
$this->userManager->method('get')->willReturnMap($users);
@@ -5052,13 +5101,13 @@ class ShareAPIControllerTest extends TestCase {
}
/**
- * @dataProvider dataFormatRoomShare
*
* @param array $expects
* @param IShare $share
* @param bool $helperAvailable
* @param array $formatShareByHelper
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataFormatRoomShare')]
public function testFormatRoomShare(array $expects, IShare $share, bool $helperAvailable, array $formatShareByHelper): void {
$this->rootFolder->method('getUserFolder')
->with($this->currentUser)
@@ -5081,8 +5130,11 @@ class ShareAPIControllerTest extends TestCase {
->with('spreed')
->willReturn(true);
- $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
- ->setMethods(['formatShare', 'canAccessShare'])
+ // This is not possible anymore with PHPUnit 10+
+ // as `setMethods` was removed and now real reflection is used, thus the class needs to exist.
+ // $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
+ $helper = $this->getMockBuilder(\stdClass::class)
+ ->addMethods(['formatShare', 'canAccessShare'])
->getMock();
$helper->method('formatShare')
->with($share)
@@ -5138,4 +5190,30 @@ class ShareAPIControllerTest extends TestCase {
$node->method('getId')->willReturn(42);
return [$userFolder, $node];
}
+
+ public function testPopulateTags(): void {
+ $tagger = $this->createMock(ITags::class);
+ $this->tagManager->method('load')
+ ->with('files')
+ ->willReturn($tagger);
+ $data = [
+ ['file_source' => 10],
+ ['file_source' => 22, 'foo' => 'bar'],
+ ['file_source' => 42, 'x' => 'y'],
+ ];
+ $tags = [
+ 10 => ['tag3'],
+ 42 => ['tag1', 'tag2'],
+ ];
+ $tagger->method('getTagsForObjects')
+ ->with([10, 22, 42])
+ ->willReturn($tags);
+
+ $result = self::invokePrivate($this->ocs, 'populateTags', [$data]);
+ $this->assertSame([
+ ['file_source' => 10, 'tags' => ['tag3']],
+ ['file_source' => 22, 'foo' => 'bar', 'tags' => []],
+ ['file_source' => 42, 'x' => 'y', 'tags' => ['tag1', 'tag2']],
+ ], $result);
+ }
}
diff --git a/apps/files_sharing/tests/Controller/ShareControllerTest.php b/apps/files_sharing/tests/Controller/ShareControllerTest.php
index 58cbb4e0b82..011210aff42 100644
--- a/apps/files_sharing/tests/Controller/ShareControllerTest.php
+++ b/apps/files_sharing/tests/Controller/ShareControllerTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -175,7 +176,7 @@ class ShareControllerTest extends \Test\TestCase {
->expects($this->once())
->method('getShareByToken')
->with('invalidtoken')
- ->will($this->throwException(new ShareNotFound()));
+ ->willThrowException(new ShareNotFound());
$this->expectException(NotFoundException::class);
@@ -261,8 +262,12 @@ class ShareControllerTest extends \Test\TestCase {
['files_sharing.sharecontroller.showShare', ['token' => 'token'], 'shareUrl'],
// this share is not an image to the default preview is used
['files_sharing.PublicPreview.getPreview', ['x' => 256, 'y' => 256, 'file' => $share->getTarget(), 'token' => 'token'], 'previewUrl'],
- // for the direct link
- ['files_sharing.sharecontroller.downloadShare', ['token' => 'token', 'filename' => $filename ], 'downloadUrl'],
+ ]);
+
+ $this->urlGenerator->expects($this->once())
+ ->method('getAbsoluteURL')
+ ->willReturnMap([
+ ['/public.php/dav/files/token/?accept=zip', 'downloadUrl'],
]);
$this->previewManager->method('isMimeSupported')->with('text/plain')->willReturn(true);
@@ -332,6 +337,7 @@ class ShareControllerTest extends \Test\TestCase {
'fileId' => 111,
'owner' => 'ownerUID',
'ownerDisplayName' => 'ownerDisplay',
+ 'isFileRequest' => false,
];
$response = $this->shareController->showShare();
@@ -395,6 +401,8 @@ class ShareControllerTest extends \Test\TestCase {
->setPassword('password')
->setShareOwner('ownerUID')
->setSharedBy('initiatorUID')
+ ->setNote('The note')
+ ->setLabel('A label')
->setNode($file)
->setTarget("/$filename")
->setToken('token');
@@ -474,6 +482,9 @@ class ShareControllerTest extends \Test\TestCase {
'disclaimer' => 'My disclaimer text',
'owner' => 'ownerUID',
'ownerDisplayName' => 'ownerDisplay',
+ 'isFileRequest' => false,
+ 'note' => 'The note',
+ 'label' => 'A label',
];
$response = $this->shareController->showShare();
@@ -483,9 +494,9 @@ class ShareControllerTest extends \Test\TestCase {
$csp = new ContentSecurityPolicy();
$csp->addAllowedFrameDomain('\'self\'');
$expectedResponse = new PublicTemplateResponse('files', 'index');
- $expectedResponse->setParams(['pageTitle' => $filename]);
+ $expectedResponse->setParams(['pageTitle' => 'A label']);
$expectedResponse->setContentSecurityPolicy($csp);
- $expectedResponse->setHeaderTitle($filename);
+ $expectedResponse->setHeaderTitle('A label');
$expectedResponse->setHeaderDetails('shared by ownerDisplay');
$expectedResponse->setHeaderActions([
new LinkMenuAction($this->l10n->t('Direct link'), 'icon-public', 'shareUrl'),
@@ -552,8 +563,12 @@ class ShareControllerTest extends \Test\TestCase {
['files_sharing.sharecontroller.showShare', ['token' => 'token'], 'shareUrl'],
// this share is not an image to the default preview is used
['files_sharing.PublicPreview.getPreview', ['x' => 256, 'y' => 256, 'file' => $share->getTarget(), 'token' => 'token'], 'previewUrl'],
- // for the direct link
- ['files_sharing.sharecontroller.downloadShare', ['token' => 'token', 'filename' => $filename ], 'downloadUrl'],
+ ]);
+
+ $this->urlGenerator->expects($this->once())
+ ->method('getAbsoluteURL')
+ ->willReturnMap([
+ ['/public.php/dav/files/token/?accept=zip', 'downloadUrl'],
]);
$this->previewManager->method('isMimeSupported')->with('text/plain')->willReturn(true);
@@ -598,9 +613,9 @@ class ShareControllerTest extends \Test\TestCase {
$this->l10n->expects($this->any())
->method('t')
- ->will($this->returnCallback(function ($text, $parameters) {
+ ->willReturnCallback(function ($text, $parameters) {
return vsprintf($text, $parameters);
- }));
+ });
$this->defaults->expects(self::any())
->method('getProductName')
diff --git a/apps/files_sharing/tests/Controller/ShareInfoControllerTest.php b/apps/files_sharing/tests/Controller/ShareInfoControllerTest.php
index f2df74fd01b..1a678610805 100644
--- a/apps/files_sharing/tests/Controller/ShareInfoControllerTest.php
+++ b/apps/files_sharing/tests/Controller/ShareInfoControllerTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -15,15 +16,13 @@ use OCP\IRequest;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager as ShareManager;
use OCP\Share\IShare;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class ShareInfoControllerTest extends TestCase {
- /** @var ShareInfoController */
- private $controller;
-
- /** @var ShareManager|\PHPUnit\Framework\MockObject\MockObject */
- private $shareManager;
+ protected ShareInfoController $controller;
+ protected ShareManager&MockObject $shareManager;
protected function setUp(): void {
@@ -31,14 +30,11 @@ class ShareInfoControllerTest extends TestCase {
$this->shareManager = $this->createMock(ShareManager::class);
- $this->controller = $this->getMockBuilder(ShareInfoController::class)
- ->setConstructorArgs([
- 'files_sharing',
- $this->createMock(IRequest::class),
- $this->shareManager
- ])
- ->setMethods(['addROWrapper'])
- ->getMock();
+ $this->controller = new ShareInfoController(
+ 'files_sharing',
+ $this->createMock(IRequest::class),
+ $this->shareManager
+ );
}
public function testNoShare(): void {
diff --git a/apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php
index c8113558f6c..18e1bf0347b 100644
--- a/apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php
+++ b/apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -69,7 +70,7 @@ class ShareesAPIControllerTest extends TestCase {
);
}
- public function dataSearch(): array {
+ public static function dataSearch(): array {
$noRemote = [IShare::TYPE_USER, IShare::TYPE_GROUP, IShare::TYPE_EMAIL];
$allTypes = [IShare::TYPE_USER, IShare::TYPE_GROUP, IShare::TYPE_REMOTE, IShare::TYPE_REMOTE_GROUP, IShare::TYPE_EMAIL];
@@ -197,7 +198,6 @@ class ShareesAPIControllerTest extends TestCase {
}
/**
- * @dataProvider dataSearch
*
* @param array $getData
* @param string $apiSetting
@@ -211,6 +211,7 @@ class ShareesAPIControllerTest extends TestCase {
* @param bool $allowGroupSharing
* @throws OCSBadRequestException
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataSearch')]
public function testSearch(
array $getData,
string $apiSetting,
@@ -301,7 +302,7 @@ class ShareesAPIControllerTest extends TestCase {
$this->assertInstanceOf(DataResponse::class, $sharees->search($search, $itemType, $page, $perPage, $shareType));
}
- public function dataSearchInvalid(): array {
+ public static function dataSearchInvalid(): array {
return [
// Test invalid pagination
[[
@@ -328,11 +329,11 @@ class ShareesAPIControllerTest extends TestCase {
}
/**
- * @dataProvider dataSearchInvalid
*
* @param array $getData
* @param string $message
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataSearchInvalid')]
public function testSearchInvalid($getData, $message): void {
$page = $getData['page'] ?? 1;
$perPage = $getData['perPage'] ?? 200;
@@ -376,7 +377,7 @@ class ShareesAPIControllerTest extends TestCase {
}
}
- public function dataIsRemoteSharingAllowed() {
+ public static function dataIsRemoteSharingAllowed() {
return [
['file', true],
['folder', true],
@@ -386,11 +387,11 @@ class ShareesAPIControllerTest extends TestCase {
}
/**
- * @dataProvider dataIsRemoteSharingAllowed
*
* @param string $itemType
* @param bool $expected
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataIsRemoteSharingAllowed')]
public function testIsRemoteSharingAllowed($itemType, $expected): void {
$this->assertSame($expected, $this->invokePrivate($this->sharees, 'isRemoteSharingAllowed', [$itemType]));
}
@@ -419,7 +420,7 @@ class ShareesAPIControllerTest extends TestCase {
$this->sharees->search('', null, 1, 10, [], false);
}
- public function dataGetPaginationLink() {
+ public static function dataGetPaginationLink() {
return [
[1, '/ocs/v1.php', ['perPage' => 2], '<?perPage=2&page=2>; rel="next"'],
[10, '/ocs/v2.php', ['perPage' => 2], '<?perPage=2&page=11>; rel="next"'],
@@ -427,13 +428,13 @@ class ShareesAPIControllerTest extends TestCase {
}
/**
- * @dataProvider dataGetPaginationLink
*
* @param int $page
* @param string $scriptName
* @param array $params
* @param array $expected
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetPaginationLink')]
public function testGetPaginationLink($page, $scriptName, $params, $expected): void {
$this->request->expects($this->once())
->method('getScriptName')
@@ -442,7 +443,7 @@ class ShareesAPIControllerTest extends TestCase {
$this->assertEquals($expected, $this->invokePrivate($this->sharees, 'getPaginationLink', [$page, $params]));
}
- public function dataIsV2() {
+ public static function dataIsV2() {
return [
['/ocs/v1.php', false],
['/ocs/v2.php', true],
@@ -450,11 +451,11 @@ class ShareesAPIControllerTest extends TestCase {
}
/**
- * @dataProvider dataIsV2
*
* @param string $scriptName
* @param bool $expected
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataIsV2')]
public function testIsV2($scriptName, $expected): void {
$this->request->expects($this->once())
->method('getScriptName')
diff --git a/apps/files_sharing/tests/DeleteOrphanedSharesJobTest.php b/apps/files_sharing/tests/DeleteOrphanedSharesJobTest.php
index 727b0a16cc5..c245d157151 100644
--- a/apps/files_sharing/tests/DeleteOrphanedSharesJobTest.php
+++ b/apps/files_sharing/tests/DeleteOrphanedSharesJobTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
diff --git a/apps/files_sharing/tests/EncryptedSizePropagationTest.php b/apps/files_sharing/tests/EncryptedSizePropagationTest.php
index 1430e5f17ac..1be17df3957 100644
--- a/apps/files_sharing/tests/EncryptedSizePropagationTest.php
+++ b/apps/files_sharing/tests/EncryptedSizePropagationTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -17,13 +18,27 @@ use Test\Traits\EncryptionTrait;
class EncryptedSizePropagationTest extends SizePropagationTest {
use EncryptionTrait;
+ protected function setUp(): void {
+ parent::setUp();
+ $this->config->setAppValue('encryption', 'useMasterKey', '0');
+ }
+
protected function setupUser($name, $password = '') {
$this->createUser($name, $password);
- $tmpFolder = Server::get(ITempManager::class)->getTemporaryFolder();
- $this->registerMount($name, '\OC\Files\Storage\Local', '/' . $name, ['datadir' => $tmpFolder]);
- $this->config->setAppValue('encryption', 'useMasterKey', '0');
+ $this->registerMountForUser($name);
$this->setupForUser($name, $password);
$this->loginWithEncryption($name);
return new View('/' . $name . '/files');
}
+
+ private function registerMountForUser($user): void {
+ $tmpFolder = Server::get(ITempManager::class)->getTemporaryFolder();
+ $this->registerMount($user, '\OC\Files\Storage\Local', '/' . $user, ['datadir' => $tmpFolder]);
+ }
+
+ protected function loginHelper($user, $create = false, $password = false) {
+ $this->registerMountForUser($user);
+ $this->setupForUser($user, $password);
+ parent::loginHelper($user, $create, $password);
+ }
}
diff --git a/apps/files_sharing/tests/EtagPropagationTest.php b/apps/files_sharing/tests/EtagPropagationTest.php
index 930279a531c..d8580ea92d5 100644
--- a/apps/files_sharing/tests/EtagPropagationTest.php
+++ b/apps/files_sharing/tests/EtagPropagationTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
diff --git a/apps/files_sharing/tests/ExpireSharesJobTest.php b/apps/files_sharing/tests/ExpireSharesJobTest.php
index e636a52c05c..42bc5a4b659 100644
--- a/apps/files_sharing/tests/ExpireSharesJobTest.php
+++ b/apps/files_sharing/tests/ExpireSharesJobTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -89,7 +90,7 @@ class ExpireSharesJobTest extends \Test\TestCase {
return $shares;
}
- public function dataExpireLinkShare() {
+ public static function dataExpireLinkShare() {
return [
[false, '', false, false],
[false, '', true, false],
@@ -105,13 +106,13 @@ class ExpireSharesJobTest extends \Test\TestCase {
}
/**
- * @dataProvider dataExpireLinkShare
*
* @param bool addExpiration Should we add an expire date
* @param string $interval The dateInterval
* @param bool $addInterval If true add to the current time if false subtract
* @param bool $shouldExpire Should this share be expired
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataExpireLinkShare')]
public function testExpireLinkShare($addExpiration, $interval, $addInterval, $shouldExpire): void {
$this->loginAsUser($this->user1);
diff --git a/apps/files_sharing/tests/External/CacheTest.php b/apps/files_sharing/tests/External/CacheTest.php
index 5a862d8ddc0..60820013f11 100644
--- a/apps/files_sharing/tests/External/CacheTest.php
+++ b/apps/files_sharing/tests/External/CacheTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
diff --git a/apps/files_sharing/tests/External/ManagerTest.php b/apps/files_sharing/tests/External/ManagerTest.php
index 611392c286e..fbe6eb1e85b 100644
--- a/apps/files_sharing/tests/External/ManagerTest.php
+++ b/apps/files_sharing/tests/External/ManagerTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -33,6 +34,7 @@ use OCP\IUserSession;
use OCP\OCS\IDiscoveryService;
use OCP\Server;
use OCP\Share\IShare;
+use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\Traits\UserTrait;
@@ -46,42 +48,19 @@ use Test\Traits\UserTrait;
class ManagerTest extends TestCase {
use UserTrait;
- /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
- protected $contactsManager;
-
- /** @var Manager|\PHPUnit\Framework\MockObject\MockObject * */
- private $manager;
-
- /** @var \OC\Files\Mount\Manager */
- private $mountManager;
-
- /** @var IClientService|\PHPUnit\Framework\MockObject\MockObject */
- private $clientService;
-
- /** @var ICloudFederationProviderManager|\PHPUnit\Framework\MockObject\MockObject */
- private $cloudFederationProviderManager;
-
- /** @var ICloudFederationFactory|\PHPUnit\Framework\MockObject\MockObject */
- private $cloudFederationFactory;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject|IGroupManager */
- private $groupManager;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject|IUserManager */
- private $userManager;
-
- /** @var LoggerInterface */
- private $logger;
-
- private $uid;
-
- /**
- * @var IUser
- */
- private $user;
- private $testMountProvider;
- /** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */
- private $eventDispatcher;
+ protected string $uid;
+ protected IUser $user;
+ protected MountProvider $testMountProvider;
+ protected IEventDispatcher&MockObject $eventDispatcher;
+ protected LoggerInterface&MockObject $logger;
+ protected \OC\Files\Mount\Manager $mountManager;
+ protected IManager&MockObject $contactsManager;
+ protected Manager&MockObject $manager;
+ protected IClientService&MockObject $clientService;
+ protected ICloudFederationProviderManager&MockObject $cloudFederationProviderManager;
+ protected ICloudFederationFactory&MockObject $cloudFederationFactory;
+ protected IGroupManager&MockObject $groupManager;
+ protected IUserManager&MockObject $userManager;
protected function setUp(): void {
parent::setUp();
@@ -129,10 +108,10 @@ class ManagerTest extends TestCase {
$this->userManager->expects($this->any())->method('get')->willReturn($this->user);
$this->groupManager->expects($this->any())->method(('getUserGroups'))->willReturn([$group1, $group2]);
$this->groupManager->expects($this->any())->method(('get'))
- ->will($this->returnValueMap([
+ ->willReturnMap([
['group1', $group1],
['group2', $group2],
- ]));
+ ]);
}
protected function tearDown(): void {
@@ -169,7 +148,7 @@ class ManagerTest extends TestCase {
$this->eventDispatcher,
$this->logger,
]
- )->setMethods(['tryOCMEndPoint'])->getMock();
+ )->onlyMethods(['tryOCMEndPoint'])->getMock();
}
private function setupMounts() {
@@ -222,14 +201,12 @@ class ManagerTest extends TestCase {
if ($isGroup) {
$this->manager->expects($this->never())->method('tryOCMEndPoint');
} else {
- $this->manager->method('tryOCMEndPoint')
- ->withConsecutive(
- ['http://localhost', 'token1', '2342', 'accept'],
- ['http://localhost', 'token3', '2342', 'decline'],
- )->willReturnOnConsecutiveCalls(
- false,
- false,
- );
+ $this->manager->expects(self::atLeast(2))
+ ->method('tryOCMEndPoint')
+ ->willReturnMap([
+ ['http://localhost', 'token1', '2342', 'accept', false],
+ ['http://localhost', 'token3', '2342', 'decline', false],
+ ]);
}
// Add a share for "user"
diff --git a/apps/files_sharing/tests/External/ScannerTest.php b/apps/files_sharing/tests/External/ScannerTest.php
index 6241174fb28..8b44d47f2b1 100644
--- a/apps/files_sharing/tests/External/ScannerTest.php
+++ b/apps/files_sharing/tests/External/ScannerTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
diff --git a/apps/files_sharing/tests/ExternalStorageTest.php b/apps/files_sharing/tests/ExternalStorageTest.php
index ef69e85d71b..1d9d2eed7bd 100644
--- a/apps/files_sharing/tests/ExternalStorageTest.php
+++ b/apps/files_sharing/tests/ExternalStorageTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -19,7 +20,7 @@ use OCP\Http\Client\IResponse;
* @group DB
*/
class ExternalStorageTest extends \Test\TestCase {
- public function optionsProvider() {
+ public static function optionsProvider() {
return [
[
'http://remoteserver:8080/owncloud',
@@ -87,9 +88,7 @@ class ExternalStorageTest extends \Test\TestCase {
);
}
- /**
- * @dataProvider optionsProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('optionsProvider')]
public function testStorageMountOptions($inputUri, $baseUri): void {
$storage = $this->getTestStorage($inputUri);
$this->assertEquals($baseUri, $storage->getBaseUri());
diff --git a/apps/files_sharing/tests/GroupEtagPropagationTest.php b/apps/files_sharing/tests/GroupEtagPropagationTest.php
index f2c74789697..da9c7c6bd07 100644
--- a/apps/files_sharing/tests/GroupEtagPropagationTest.php
+++ b/apps/files_sharing/tests/GroupEtagPropagationTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
diff --git a/apps/files_sharing/tests/HelperTest.php b/apps/files_sharing/tests/HelperTest.php
index d8b5b9a6f3f..4d0d747b3e4 100644
--- a/apps/files_sharing/tests/HelperTest.php
+++ b/apps/files_sharing/tests/HelperTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
diff --git a/apps/files_sharing/tests/Listener/LoadAdditionalListenerTest.php b/apps/files_sharing/tests/Listener/LoadAdditionalListenerTest.php
new file mode 100644
index 00000000000..75bee35d58a
--- /dev/null
+++ b/apps/files_sharing/tests/Listener/LoadAdditionalListenerTest.php
@@ -0,0 +1,120 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace OCA\Files_Sharing\Tests\Listener;
+
+use OC\InitialStateService;
+use OCA\Files\Event\LoadAdditionalScriptsEvent;
+use OCA\Files_Sharing\Listener\LoadAdditionalListener;
+use OCP\EventDispatcher\Event;
+use OCP\IConfig;
+use OCP\L10N\IFactory;
+use OCP\Share\IManager;
+use OCP\Util;
+use PHPUnit\Framework\MockObject\MockObject;
+use Psr\Log\LoggerInterface;
+use Test\TestCase;
+
+class LoadAdditionalListenerTest extends TestCase {
+ protected LoggerInterface&MockObject $logger;
+ protected LoadAdditionalScriptsEvent&MockObject $event;
+ protected IManager&MockObject $shareManager;
+ protected IFactory&MockObject $factory;
+ protected InitialStateService&MockObject $initialStateService;
+ protected IConfig&MockObject $config;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->logger = $this->createMock(LoggerInterface::class);
+ $this->event = $this->createMock(LoadAdditionalScriptsEvent::class);
+ $this->shareManager = $this->createMock(IManager::class);
+ $this->factory = $this->createMock(IFactory::class);
+ $this->initialStateService = $this->createMock(InitialStateService::class);
+ $this->config = $this->createMock(IConfig::class);
+
+ /* Empty static array to avoid inter-test conflicts */
+ \OC_Util::$styles = [];
+ self::invokePrivate(Util::class, 'scripts', [[]]);
+ self::invokePrivate(Util::class, 'scriptDeps', [[]]);
+ self::invokePrivate(Util::class, 'scriptsInit', [[]]);
+ }
+
+ protected function tearDown(): void {
+ parent::tearDown();
+
+ \OC_Util::$styles = [];
+ self::invokePrivate(Util::class, 'scripts', [[]]);
+ self::invokePrivate(Util::class, 'scriptDeps', [[]]);
+ self::invokePrivate(Util::class, 'scriptsInit', [[]]);
+ }
+
+ public function testHandleIgnoresNonMatchingEvent(): void {
+ $listener = new LoadAdditionalListener();
+ $event = $this->createMock(Event::class);
+
+ // Should not throw or call anything
+ $listener->handle($event);
+
+ $this->assertTrue(true); // No exception means pass
+ }
+
+ public function testHandleWithLoadAdditionalScriptsEvent(): void {
+ $listener = new LoadAdditionalListener();
+
+ $this->shareManager->method('shareApiEnabled')->willReturn(false);
+ $this->factory->method('findLanguage')->willReturn('language_mock');
+ $this->config->method('getSystemValueBool')->willReturn(true);
+
+ $this->overwriteService(IManager::class, $this->shareManager);
+ $this->overwriteService(IFactory::class, $this->factory);
+ $this->overwriteService(InitialStateService::class, $this->initialStateService);
+ $this->overwriteService(IConfig::class, $this->config);
+
+ $scriptsBefore = Util::getScripts();
+ $this->assertNotContains('files_sharing/l10n/language_mock', $scriptsBefore);
+ $this->assertNotContains('files_sharing/js/additionalScripts', $scriptsBefore);
+ $this->assertNotContains('files_sharing/js/init', $scriptsBefore);
+ $this->assertNotContains('files_sharing/css/icons', \OC_Util::$styles);
+
+ // Util static methods can't be easily mocked, so just ensure no exceptions
+ $listener->handle($this->event);
+
+ // assert array $scripts contains the expected scripts
+ $scriptsAfter = Util::getScripts();
+ $this->assertContains('files_sharing/l10n/language_mock', $scriptsAfter);
+ $this->assertContains('files_sharing/js/additionalScripts', $scriptsAfter);
+ $this->assertNotContains('files_sharing/js/init', $scriptsAfter);
+
+ $this->assertContains('files_sharing/css/icons', \OC_Util::$styles);
+ }
+
+ public function testHandleWithLoadAdditionalScriptsEventWithShareApiEnabled(): void {
+ $listener = new LoadAdditionalListener();
+
+ $this->shareManager->method('shareApiEnabled')->willReturn(true);
+ $this->config->method('getSystemValueBool')->willReturn(true);
+
+ $this->overwriteService(IManager::class, $this->shareManager);
+ $this->overwriteService(InitialStateService::class, $this->initialStateService);
+ $this->overwriteService(IConfig::class, $this->config);
+ $this->overwriteService(IFactory::class, $this->factory);
+
+ $scriptsBefore = Util::getScripts();
+ $this->assertNotContains('files_sharing/js/init', $scriptsBefore);
+
+ // Util static methods can't be easily mocked, so just ensure no exceptions
+ $listener->handle($this->event);
+
+ $scriptsAfter = Util::getScripts();
+
+ // assert array $scripts contains the expected scripts
+ $this->assertContains('files_sharing/js/init', $scriptsAfter);
+ }
+}
diff --git a/apps/files_sharing/tests/LockingTest.php b/apps/files_sharing/tests/LockingTest.php
index eba1e662907..280c364a136 100644
--- a/apps/files_sharing/tests/LockingTest.php
+++ b/apps/files_sharing/tests/LockingTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
diff --git a/apps/files_sharing/tests/Middleware/OCSShareAPIMiddlewareTest.php b/apps/files_sharing/tests/Middleware/OCSShareAPIMiddlewareTest.php
index 30bae45f520..efc6b3f7f7f 100644
--- a/apps/files_sharing/tests/Middleware/OCSShareAPIMiddlewareTest.php
+++ b/apps/files_sharing/tests/Middleware/OCSShareAPIMiddlewareTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -72,12 +73,12 @@ class OCSShareAPIMiddlewareTest extends \Test\TestCase {
}
/**
- * @dataProvider dataBeforeController
*
* @param Controller $controller
* @param bool $enabled
* @param bool $exception
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataBeforeController')]
public function testBeforeController(Controller $controller, $enabled, $exception): void {
$this->shareManager->method('shareApiEnabled')->willReturn($enabled);
@@ -104,11 +105,11 @@ class OCSShareAPIMiddlewareTest extends \Test\TestCase {
}
/**
- * @dataProvider dataAfterController
*
* @param Controller $controller
* @param bool $called
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataAfterController')]
public function testAfterController(Controller $controller): void {
if ($controller instanceof ShareAPIController) {
$controller->expects($this->once())->method('cleanup');
diff --git a/apps/files_sharing/tests/Middleware/ShareInfoMiddlewareTest.php b/apps/files_sharing/tests/Middleware/ShareInfoMiddlewareTest.php
index 44ef3bebdc8..631b6a0f51c 100644
--- a/apps/files_sharing/tests/Middleware/ShareInfoMiddlewareTest.php
+++ b/apps/files_sharing/tests/Middleware/ShareInfoMiddlewareTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
diff --git a/apps/files_sharing/tests/Middleware/SharingCheckMiddlewareTest.php b/apps/files_sharing/tests/Middleware/SharingCheckMiddlewareTest.php
index 5b4f4de33d7..3d86007a54c 100644
--- a/apps/files_sharing/tests/Middleware/SharingCheckMiddlewareTest.php
+++ b/apps/files_sharing/tests/Middleware/SharingCheckMiddlewareTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -79,7 +80,7 @@ class SharingCheckMiddlewareTest extends \Test\TestCase {
$this->assertFalse(self::invokePrivate($this->sharingCheckMiddleware, 'isSharingEnabled'));
}
- public function externalSharesChecksDataProvider() {
+ public static function externalSharesChecksDataProvider() {
$data = [];
foreach ([false, true] as $annIn) {
@@ -114,9 +115,7 @@ class SharingCheckMiddlewareTest extends \Test\TestCase {
return $data;
}
- /**
- * @dataProvider externalSharesChecksDataProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('externalSharesChecksDataProvider')]
public function testExternalSharesChecks($annotations, $config, $expectedResult): void {
$this->reflector
->expects($this->atLeastOnce())
@@ -130,9 +129,7 @@ class SharingCheckMiddlewareTest extends \Test\TestCase {
$this->assertEquals($expectedResult, self::invokePrivate($this->sharingCheckMiddleware, 'externalSharesChecks'));
}
- /**
- * @dataProvider externalSharesChecksDataProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('externalSharesChecksDataProvider')]
public function testBeforeControllerWithExternalShareControllerWithSharingEnabled($annotations, $config, $noException): void {
$this->appManager
->expects($this->once())
diff --git a/apps/files_sharing/tests/Migration/SetPasswordColumnTest.php b/apps/files_sharing/tests/Migration/SetPasswordColumnTest.php
index 9dccfd80025..3cbbad0f8bc 100644
--- a/apps/files_sharing/tests/Migration/SetPasswordColumnTest.php
+++ b/apps/files_sharing/tests/Migration/SetPasswordColumnTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2017 ownCloud, Inc.
diff --git a/apps/files_sharing/tests/MountProviderTest.php b/apps/files_sharing/tests/MountProviderTest.php
index 285af51f022..e043a1cb1ef 100644
--- a/apps/files_sharing/tests/MountProviderTest.php
+++ b/apps/files_sharing/tests/MountProviderTest.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_Sharing\Tests;
use OC\Memcache\NullCache;
use OC\Share20\Share;
use OCA\Files_Sharing\MountProvider;
+use OCA\Files_Sharing\SharedMount;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\IRootFolder;
use OCP\Files\Mount\IMountManager;
@@ -20,29 +22,21 @@ use OCP\IUserManager;
use OCP\Share\IAttributes as IShareAttributes;
use OCP\Share\IManager;
use OCP\Share\IShare;
+use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
/**
* @group DB
*/
class MountProviderTest extends \Test\TestCase {
- /** @var MountProvider */
- private $provider;
-
- /** @var IConfig|MockObject */
- private $config;
-
- /** @var IUser|MockObject */
- private $user;
- /** @var IStorageFactory|MockObject */
- private $loader;
+ protected MountProvider $provider;
- /** @var IManager|MockObject */
- private $shareManager;
-
- /** @var LoggerInterface|MockObject */
- private $logger;
+ protected IUser&MockObject $user;
+ protected IConfig&MockObject $config;
+ protected IManager&MockObject $shareManager;
+ protected IStorageFactory&MockObject $loader;
+ protected LoggerInterface&MockObject $logger;
protected function setUp(): void {
parent::setUp();
@@ -68,8 +62,8 @@ class MountProviderTest extends \Test\TestCase {
$shareAttributes = $this->createMock(IShareAttributes::class);
$shareAttributes->method('toArray')->willReturn($attrs);
- $shareAttributes->method('getAttribute')->will(
- $this->returnCallback(function ($scope, $key) use ($attrs) {
+ $shareAttributes->method('getAttribute')->willReturnCallback(
+ function ($scope, $key) use ($attrs) {
$result = null;
foreach ($attrs as $attr) {
if ($attr['key'] === $key && $attr['scope'] === $scope) {
@@ -77,7 +71,7 @@ class MountProviderTest extends \Test\TestCase {
}
}
return $result;
- })
+ }
);
return $shareAttributes;
}
@@ -89,7 +83,7 @@ class MountProviderTest extends \Test\TestCase {
->willReturn($permissions);
$share->expects($this->any())
->method('getAttributes')
- ->will($this->returnValue($this->makeMockShareAttributes($attributes)));
+ ->willReturn($this->makeMockShareAttributes($attributes));
$share->expects($this->any())
->method('getShareOwner')
->willReturn($owner);
@@ -144,38 +138,34 @@ class MountProviderTest extends \Test\TestCase {
];
// tests regarding circles and sciencemesh are made in the apps themselves.
$circleShares = [];
- $sciencemeshShares = [];
+ $scienceMeshShares = [];
$this->user->expects($this->any())
->method('getUID')
->willReturn('user1');
$this->shareManager->expects($this->exactly(6))
->method('getSharedWith')
- ->withConsecutive(
- ['user1', IShare::TYPE_USER],
- ['user1', IShare::TYPE_GROUP, null, -1],
- ['user1', IShare::TYPE_CIRCLE, null, -1],
- ['user1', IShare::TYPE_ROOM, null, -1],
- ['user1', IShare::TYPE_DECK, null, -1],
- ['user1', IShare::TYPE_SCIENCEMESH, null, -1],
- )->willReturnOnConsecutiveCalls(
- $userShares,
- $groupShares,
- $circleShares,
- $roomShares,
- $deckShares,
- $sciencemeshShares
- );
+ ->willReturnMap([
+ ['user1', IShare::TYPE_USER, null, -1, 0, $userShares],
+ ['user1', IShare::TYPE_GROUP, null, -1, 0, $groupShares],
+ ['user1', IShare::TYPE_CIRCLE, null, -1, 0, $circleShares],
+ ['user1', IShare::TYPE_ROOM, null, -1, 0, $roomShares],
+ ['user1', IShare::TYPE_DECK, null, -1, 0, $deckShares],
+ ['user1', IShare::TYPE_SCIENCEMESH, null, -1, 0, $scienceMeshShares],
+ ]);
+
$this->shareManager->expects($this->any())
->method('newShare')
->willReturnCallback(function () use ($rootFolder, $userManager) {
return new Share($rootFolder, $userManager);
});
+
$mounts = $this->provider->getMountsForUser($this->user, $this->loader);
$this->assertCount(4, $mounts);
$this->assertInstanceOf('OCA\Files_Sharing\SharedMount', $mounts[0]);
$this->assertInstanceOf('OCA\Files_Sharing\SharedMount', $mounts[1]);
$this->assertInstanceOf('OCA\Files_Sharing\SharedMount', $mounts[2]);
$this->assertInstanceOf('OCA\Files_Sharing\SharedMount', $mounts[3]);
+ /** @var SharedMount[] $mounts */
$mountedShare1 = $mounts[0]->getShare();
$this->assertEquals('2', $mountedShare1->getId());
$this->assertEquals('user2', $mountedShare1->getShareOwner());
@@ -204,7 +194,7 @@ class MountProviderTest extends \Test\TestCase {
$this->assertEquals(31, $mountedShare4->getPermissions());
}
- public function mergeSharesDataProvider() {
+ public static function mergeSharesDataProvider(): array {
// note: the user in the specs here is the shareOwner not recipient
// the recipient is always "user1"
return [
@@ -343,12 +333,12 @@ class MountProviderTest extends \Test\TestCase {
* Happens when sharing the same entry to a user through multiple ways,
* like several groups and also direct shares at the same time.
*
- * @dataProvider mergeSharesDataProvider
*
* @param array $userShares array of user share specs
* @param array $groupShares array of group share specs
* @param array $expectedShares array of expected supershare specs
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('mergeSharesDataProvider')]
public function testMergeShares($userShares, $groupShares, $expectedShares, $moveFails = false): void {
$rootFolder = $this->createMock(IRootFolder::class);
$userManager = $this->createMock(IUserManager::class);
@@ -368,24 +358,18 @@ class MountProviderTest extends \Test\TestCase {
$circleShares = [];
$roomShares = [];
$deckShares = [];
- $sciencemeshShares = [];
+ $scienceMeshShares = [];
$this->shareManager->expects($this->exactly(6))
->method('getSharedWith')
- ->withConsecutive(
- ['user1', IShare::TYPE_USER],
- ['user1', IShare::TYPE_GROUP, null, -1],
- ['user1', IShare::TYPE_CIRCLE, null, -1],
- ['user1', IShare::TYPE_ROOM, null, -1],
- ['user1', IShare::TYPE_DECK, null, -1],
- ['user1', IShare::TYPE_SCIENCEMESH, null, -1],
- )->willReturnOnConsecutiveCalls(
- $userShares,
- $groupShares,
- $circleShares,
- $roomShares,
- $deckShares,
- $sciencemeshShares
- );
+ ->willReturnMap([
+ ['user1', IShare::TYPE_USER, null, -1, 0, $userShares],
+ ['user1', IShare::TYPE_GROUP, null, -1, 0, $groupShares],
+ ['user1', IShare::TYPE_CIRCLE, null, -1, 0, $circleShares],
+ ['user1', IShare::TYPE_ROOM, null, -1, 0, $roomShares],
+ ['user1', IShare::TYPE_DECK, null, -1, 0, $deckShares],
+ ['user1', IShare::TYPE_SCIENCEMESH, null, -1, 0, $scienceMeshShares],
+ ]);
+
$this->shareManager->expects($this->any())
->method('newShare')
->willReturnCallback(function () use ($rootFolder, $userManager) {
@@ -395,7 +379,7 @@ class MountProviderTest extends \Test\TestCase {
if ($moveFails) {
$this->shareManager->expects($this->any())
->method('moveShare')
- ->will($this->throwException(new \InvalidArgumentException()));
+ ->willThrowException(new \InvalidArgumentException());
}
$mounts = $this->provider->getMountsForUser($this->user, $this->loader);
@@ -407,6 +391,7 @@ class MountProviderTest extends \Test\TestCase {
$this->assertInstanceOf('OCA\Files_Sharing\SharedMount', $mount);
// supershare
+ /** @var SharedMount $mount */
$share = $mount->getShare();
$this->assertEquals($expectedShare[0], $share->getId());
diff --git a/apps/files_sharing/tests/PropagationTestCase.php b/apps/files_sharing/tests/PropagationTestCase.php
index 1c67b1b9337..98bf5ad92fd 100644
--- a/apps/files_sharing/tests/PropagationTestCase.php
+++ b/apps/files_sharing/tests/PropagationTestCase.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
diff --git a/apps/files_sharing/tests/ShareTest.php b/apps/files_sharing/tests/ShareTest.php
index a0458ab0ffb..737ad6dcb4e 100644
--- a/apps/files_sharing/tests/ShareTest.php
+++ b/apps/files_sharing/tests/ShareTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -188,8 +189,8 @@ class ShareTest extends TestCase {
/**
* shared files should never have delete permissions
- * @dataProvider dataProviderTestFileSharePermissions
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataProviderTestFileSharePermissions')]
public function testFileSharePermissions($permission, $expectedvalid): void {
$pass = true;
try {
@@ -207,7 +208,7 @@ class ShareTest extends TestCase {
$this->assertEquals($expectedvalid, $pass);
}
- public function dataProviderTestFileSharePermissions() {
+ public static function dataProviderTestFileSharePermissions() {
$permission1 = Constants::PERMISSION_ALL;
$permission3 = Constants::PERMISSION_READ;
$permission4 = Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE;
diff --git a/apps/files_sharing/tests/SharedMountTest.php b/apps/files_sharing/tests/SharedMountTest.php
index 56accb88db6..cc9c70a241f 100644
--- a/apps/files_sharing/tests/SharedMountTest.php
+++ b/apps/files_sharing/tests/SharedMountTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -224,11 +225,11 @@ class SharedMountTest extends TestCase {
}
/**
- * @dataProvider dataProviderTestStripUserFilesPath
* @param string $path
* @param string $expectedResult
* @param bool $exception if a exception is expected
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataProviderTestStripUserFilesPath')]
public function testStripUserFilesPath($path, $expectedResult, $exception): void {
$testClass = new DummyTestClassSharedMount(null, null);
try {
@@ -243,7 +244,7 @@ class SharedMountTest extends TestCase {
}
}
- public function dataProviderTestStripUserFilesPath() {
+ public static function dataProviderTestStripUserFilesPath() {
return [
['/user/files/foo.txt', '/foo.txt', false],
['/user/files/folder/foo.txt', '/folder/foo.txt', false],
diff --git a/apps/files_sharing/tests/SharedStorageTest.php b/apps/files_sharing/tests/SharedStorageTest.php
index 55c16c2ebb3..1c1f0a7b71d 100644
--- a/apps/files_sharing/tests/SharedStorageTest.php
+++ b/apps/files_sharing/tests/SharedStorageTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -570,7 +571,7 @@ class SharedStorageTest extends TestCase {
$share->method('getShareOwner')->willReturn(self::TEST_FILES_SHARING_API_USER1);
$share->method('getNodeId')->willReturn(1);
$ownerView = $this->createMock(View::class);
- $ownerView->method('getPath')->will($this->throwException(new NotFoundException()));
+ $ownerView->method('getPath')->willThrowException(new NotFoundException());
$storage = new SharedStorage([
'ownerView' => $ownerView,
'superShare' => $share,
diff --git a/apps/files_sharing/tests/SharesReminderJobTest.php b/apps/files_sharing/tests/SharesReminderJobTest.php
index 7a480fccb23..ce468e279ec 100644
--- a/apps/files_sharing/tests/SharesReminderJobTest.php
+++ b/apps/files_sharing/tests/SharesReminderJobTest.php
@@ -95,7 +95,7 @@ class SharesReminderJobTest extends \Test\TestCase {
parent::tearDown();
}
- public function dataSharesReminder() {
+ public static function dataSharesReminder() {
$someMail = 'test@test.com';
$noExpirationDate = null;
$today = new \DateTime();
@@ -144,7 +144,6 @@ class SharesReminderJobTest extends \Test\TestCase {
}
/**
- * @dataProvider dataSharesReminder
*
* @param \DateTime|null $expirationDate Share expiration date
* @param string $email Share with this email. If empty, the share is of type TYPE_USER and the sharee is user2
@@ -152,6 +151,7 @@ class SharesReminderJobTest extends \Test\TestCase {
* @param int $permissions
* @param bool $shouldBeReminded
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataSharesReminder')]
public function testSharesReminder(
?\DateTime $expirationDate, string $email, bool $isEmpty, int $permissions, bool $shouldBeReminded,
): void {
diff --git a/apps/files_sharing/tests/SizePropagationTest.php b/apps/files_sharing/tests/SizePropagationTest.php
index 082348c31a0..e1b67abca90 100644
--- a/apps/files_sharing/tests/SizePropagationTest.php
+++ b/apps/files_sharing/tests/SizePropagationTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
diff --git a/apps/files_sharing/tests/TestCase.php b/apps/files_sharing/tests/TestCase.php
index 647a591db8d..9a6935e46b6 100644
--- a/apps/files_sharing/tests/TestCase.php
+++ b/apps/files_sharing/tests/TestCase.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -108,7 +109,7 @@ abstract class TestCase extends \Test\TestCase {
Server::get(DisplayNameCache::class)->clear();
//login as user1
- self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
+ $this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
$this->data = 'foobar';
$this->view = new View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files');
@@ -173,7 +174,7 @@ abstract class TestCase extends \Test\TestCase {
* @param bool $create
* @param bool $password
*/
- protected static function loginHelper($user, $create = false, $password = false) {
+ protected function loginHelper($user, $create = false, $password = false) {
if ($password === false) {
$password = $user;
}
diff --git a/apps/files_sharing/tests/UnshareChildrenTest.php b/apps/files_sharing/tests/UnshareChildrenTest.php
index 61c4aa94213..ac870212c99 100644
--- a/apps/files_sharing/tests/UnshareChildrenTest.php
+++ b/apps/files_sharing/tests/UnshareChildrenTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
diff --git a/apps/files_sharing/tests/UpdaterTest.php b/apps/files_sharing/tests/UpdaterTest.php
index efdbeebdf3f..23044e0b2f3 100644
--- a/apps/files_sharing/tests/UpdaterTest.php
+++ b/apps/files_sharing/tests/UpdaterTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -123,7 +124,7 @@ class UpdaterTest extends TestCase {
Filesystem::getLoader()->removeStorageWrapper('oc_trashbin');
}
- public function shareFolderProvider() {
+ public static function shareFolderProvider() {
return [
['/'],
['/my_shares'],
@@ -133,10 +134,10 @@ class UpdaterTest extends TestCase {
/**
* if a file gets shared the etag for the recipients root should change
*
- * @dataProvider shareFolderProvider
*
* @param string $shareFolder share folder to use
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('shareFolderProvider')]
public function testShareFile($shareFolder): void {
$config = Server::get(IConfig::class);
$oldShareFolder = $config->getSystemValue('share_folder');
diff --git a/apps/files_sharing/tests/WatcherTest.php b/apps/files_sharing/tests/WatcherTest.php
index 2d1568e6a31..15676836915 100644
--- a/apps/files_sharing/tests/WatcherTest.php
+++ b/apps/files_sharing/tests/WatcherTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.