aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Share20/DefaultShareProviderTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Share20/DefaultShareProviderTest.php')
-rw-r--r--tests/lib/Share20/DefaultShareProviderTest.php683
1 files changed, 434 insertions, 249 deletions
diff --git a/tests/lib/Share20/DefaultShareProviderTest.php b/tests/lib/Share20/DefaultShareProviderTest.php
index 03e1bdb4346..bacf2b61ee3 100644
--- a/tests/lib/Share20/DefaultShareProviderTest.php
+++ b/tests/lib/Share20/DefaultShareProviderTest.php
@@ -1,28 +1,20 @@
<?php
+
/**
- * @author Roeland Jago Douma <rullzer@owncloud.com>
- *
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- * @copyright Copyright (c) 2016, Roeland Jago Douma <roeland@famdouma.nl>
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace Test\Share20;
+use OC\Files\Node\Node;
use OC\Share20\DefaultShareProvider;
+use OC\Share20\Exception\ProviderException;
+use OC\Share20\Share;
+use OC\Share20\ShareAttributes;
+use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\Constants;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Defaults;
use OCP\Files\File;
@@ -38,8 +30,12 @@ use OCP\IUser;
use OCP\IUserManager;
use OCP\L10N\IFactory;
use OCP\Mail\IMailer;
+use OCP\Server;
+use OCP\Share\Exceptions\ShareNotFound;
+use OCP\Share\IManager as IShareManager;
use OCP\Share\IShare;
use PHPUnit\Framework\MockObject\MockObject;
+use Psr\Log\LoggerInterface;
/**
* Class DefaultShareProviderTest
@@ -48,42 +44,48 @@ use PHPUnit\Framework\MockObject\MockObject;
* @group DB
*/
class DefaultShareProviderTest extends \Test\TestCase {
-
/** @var IDBConnection */
protected $dbConn;
- /** @var IUserManager | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var IUserManager | MockObject */
protected $userManager;
- /** @var IGroupManager | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var IGroupManager | MockObject */
protected $groupManager;
- /** @var IRootFolder | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var IRootFolder | MockObject */
protected $rootFolder;
/** @var DefaultShareProvider */
protected $provider;
- /** @var \PHPUnit\Framework\MockObject\MockObject|IMailer */
+ /** @var MockObject|IMailer */
protected $mailer;
/** @var IFactory|MockObject */
protected $l10nFactory;
- /** @var \PHPUnit\Framework\MockObject\MockObject|IL10N */
+ /** @var MockObject|IL10N */
protected $l10n;
- /** @var \PHPUnit\Framework\MockObject\MockObject|Defaults */
+ /** @var MockObject|Defaults */
protected $defaults;
- /** @var \PHPUnit\Framework\MockObject\MockObject|IURLGenerator */
+ /** @var MockObject|IURLGenerator */
protected $urlGenerator;
- /** @var IConfig|MockObject */
- protected $config;
+ /** @var ITimeFactory|MockObject */
+ protected $timeFactory;
+
+ /** @var LoggerInterface|MockObject */
+ protected $logger;
+
+ protected IConfig&MockObject $config;
+
+ protected IShareManager&MockObject $shareManager;
protected function setUp(): void {
- $this->dbConn = \OC::$server->getDatabaseConnection();
+ $this->dbConn = Server::get(IDBConnection::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->groupManager = $this->createMock(IGroupManager::class);
$this->rootFolder = $this->createMock(IRootFolder::class);
@@ -92,9 +94,13 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->l10n = $this->createMock(IL10N::class);
$this->defaults = $this->getMockBuilder(Defaults::class)->disableOriginalConstructor()->getMock();
$this->urlGenerator = $this->createMock(IURLGenerator::class);
+ $this->timeFactory = $this->createMock(ITimeFactory::class);
+ $this->logger = $this->createMock(LoggerInterface::class);
+ $this->shareManager = $this->createMock(IShareManager::class);
$this->config = $this->createMock(IConfig::class);
$this->userManager->expects($this->any())->method('userExists')->willReturn(true);
+ $this->timeFactory->expects($this->any())->method('now')->willReturn(new \DateTimeImmutable('2023-05-04 00:00 Europe/Berlin'));
//Empty share table
$this->dbConn->getQueryBuilder()->delete('share')->execute();
@@ -108,13 +114,16 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->defaults,
$this->l10nFactory,
$this->urlGenerator,
- $this->config
+ $this->timeFactory,
+ $this->logger,
+ $this->shareManager,
+ $this->config,
);
}
protected function tearDown(): void {
$this->dbConn->getQueryBuilder()->delete('share')->execute();
- $this->dbConn->getQueryBuilder()->delete('filecache')->execute();
+ $this->dbConn->getQueryBuilder()->delete('filecache')->runAcrossAllShards()->execute();
$this->dbConn->getQueryBuilder()->delete('storages')->execute();
}
@@ -132,8 +141,8 @@ class DefaultShareProviderTest extends \Test\TestCase {
* @return int
*/
private function addShareToDB($shareType, $sharedWith, $sharedBy, $shareOwner,
- $itemType, $fileSource, $fileTarget, $permissions, $token, $expiration,
- $parent = null) {
+ $itemType, $fileSource, $fileTarget, $permissions, $token, $expiration,
+ $parent = null) {
$qb = $this->dbConn->getQueryBuilder();
$qb->insert('share');
@@ -165,7 +174,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$qb->setValue('token', $qb->expr()->literal($token));
}
if ($expiration) {
- $qb->setValue('expiration', $qb->createNamedParameter($expiration, IQueryBuilder::PARAM_DATE));
+ $qb->setValue('expiration', $qb->createNamedParameter($expiration, IQueryBuilder::PARAM_DATETIME_MUTABLE));
}
if ($parent) {
$qb->setValue('parent', $qb->expr()->literal($parent));
@@ -178,13 +187,13 @@ class DefaultShareProviderTest extends \Test\TestCase {
- public function testGetShareByIdNotExist() {
- $this->expectException(\OCP\Share\Exceptions\ShareNotFound::class);
+ public function testGetShareByIdNotExist(): void {
+ $this->expectException(ShareNotFound::class);
$this->provider->getShareById(1);
}
- public function testGetShareByIdUserShare() {
+ public function testGetShareByIdUserShare(): void {
$qb = $this->dbConn->getQueryBuilder();
$qb->insert('share')
@@ -209,7 +218,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$ownerPath = $this->createMock(File::class);
$shareOwnerFolder = $this->createMock(Folder::class);
- $shareOwnerFolder->method('getById')->with(42)->willReturn([$ownerPath]);
+ $shareOwnerFolder->method('getFirstNodeById')->with(42)->willReturn($ownerPath);
$this->rootFolder
->method('getUserFolder')
@@ -231,7 +240,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals('myTarget', $share->getTarget());
}
- public function testGetShareByIdLazy() {
+ public function testGetShareByIdLazy(): void {
$qb = $this->dbConn->getQueryBuilder();
$qb->insert('share')
@@ -266,7 +275,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals('myTarget', $share->getTarget());
}
- public function testGetShareByIdLazy2() {
+ public function testGetShareByIdLazy2(): void {
$qb = $this->dbConn->getQueryBuilder();
$qb->insert('share')
@@ -287,7 +296,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$ownerPath = $this->createMock(File::class);
$shareOwnerFolder = $this->createMock(Folder::class);
- $shareOwnerFolder->method('getById')->with(42)->willReturn([$ownerPath]);
+ $shareOwnerFolder->method('getFirstNodeById')->with(42)->willReturn($ownerPath);
$this->rootFolder
->method('getUserFolder')
@@ -310,7 +319,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals('myTarget', $share->getTarget());
}
- public function testGetShareByIdGroupShare() {
+ public function testGetShareByIdGroupShare(): void {
$qb = $this->dbConn->getQueryBuilder();
$qb->insert('share')
@@ -331,13 +340,13 @@ class DefaultShareProviderTest extends \Test\TestCase {
$ownerPath = $this->createMock(Folder::class);
$shareOwnerFolder = $this->createMock(Folder::class);
- $shareOwnerFolder->method('getById')->with(42)->willReturn([$ownerPath]);
+ $shareOwnerFolder->method('getFirstNodeById')->with(42)->willReturn($ownerPath);
$this->rootFolder
- ->method('getUserFolder')
- ->willReturnMap([
- ['shareOwner', $shareOwnerFolder],
- ]);
+ ->method('getUserFolder')
+ ->willReturnMap([
+ ['shareOwner', $shareOwnerFolder],
+ ]);
$share = $this->provider->getShareById($id);
@@ -353,7 +362,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals('myTarget', $share->getTarget());
}
- public function testGetShareByIdUserGroupShare() {
+ public function testGetShareByIdUserGroupShare(): void {
$id = $this->addShareToDB(IShare::TYPE_GROUP, 'group0', 'user0', 'user0', 'file', 42, 'myTarget', 31, null, null);
$this->addShareToDB(2, 'user1', 'user0', 'user0', 'file', 42, 'userTarget', 0, null, null, $id);
@@ -364,12 +373,14 @@ class DefaultShareProviderTest extends \Test\TestCase {
$group0 = $this->createMock(IGroup::class);
$group0->method('inGroup')->with($user1)->willReturn(true);
+ $group0->method('getDisplayName')->willReturn('g0-displayname');
$node = $this->createMock(Folder::class);
$node->method('getId')->willReturn(42);
+ $node->method('getName')->willReturn('myTarget');
$this->rootFolder->method('getUserFolder')->with('user0')->willReturnSelf();
- $this->rootFolder->method('getById')->willReturn([$node]);
+ $this->rootFolder->method('getFirstNodeById')->willReturn($node);
$this->userManager->method('get')->willReturnMap([
['user0', $user0],
@@ -391,7 +402,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals('userTarget', $share->getTarget());
}
- public function testGetShareByIdLinkShare() {
+ public function testGetShareByIdLinkShare(): void {
$qb = $this->dbConn->getQueryBuilder();
$qb->insert('share')
@@ -414,13 +425,13 @@ class DefaultShareProviderTest extends \Test\TestCase {
$ownerPath = $this->createMock(Folder::class);
$shareOwnerFolder = $this->createMock(Folder::class);
- $shareOwnerFolder->method('getById')->with(42)->willReturn([$ownerPath]);
+ $shareOwnerFolder->method('getFirstNodeById')->with(42)->willReturn($ownerPath);
$this->rootFolder
- ->method('getUserFolder')
- ->willReturnMap([
- ['shareOwner', $shareOwnerFolder],
- ]);
+ ->method('getUserFolder')
+ ->willReturnMap([
+ ['shareOwner', $shareOwnerFolder],
+ ]);
$share = $this->provider->getShareById($id);
@@ -438,7 +449,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals('myTarget', $share->getTarget());
}
- public function testDeleteSingleShare() {
+ public function testDeleteSingleShare(): void {
$qb = $this->dbConn->getQueryBuilder();
$qb->insert('share')
->values([
@@ -468,9 +479,12 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->defaults,
$this->l10nFactory,
$this->urlGenerator,
- $this->config
+ $this->timeFactory,
+ $this->logger,
+ $this->shareManager,
+ $this->config,
])
- ->setMethods(['getShareById'])
+ ->onlyMethods(['getShareById'])
->getMock();
$provider->delete($share);
@@ -486,7 +500,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEmpty($result);
}
- public function testDeleteSingleShareLazy() {
+ public function testDeleteSingleShareLazy(): void {
$qb = $this->dbConn->getQueryBuilder();
$qb->insert('share')
->values([
@@ -519,7 +533,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEmpty($result);
}
- public function testDeleteGroupShareWithUserGroupShares() {
+ public function testDeleteGroupShareWithUserGroupShares(): void {
$qb = $this->dbConn->getQueryBuilder();
$qb->insert('share')
->values([
@@ -563,9 +577,12 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->defaults,
$this->l10nFactory,
$this->urlGenerator,
- $this->config
+ $this->timeFactory,
+ $this->logger,
+ $this->shareManager,
+ $this->config,
])
- ->setMethods(['getShareById'])
+ ->onlyMethods(['getShareById'])
->getMock();
$provider->delete($share);
@@ -581,7 +598,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEmpty($result);
}
- public function testGetChildren() {
+ public function testGetChildren(): void {
$qb = $this->dbConn->getQueryBuilder();
$qb->insert('share')
->values([
@@ -631,7 +648,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$ownerPath = $this->createMock(Folder::class);
$ownerFolder = $this->createMock(Folder::class);
- $ownerFolder->method('getById')->willReturn([$ownerPath]);
+ $ownerFolder->method('getFirstNodeById')->willReturn($ownerPath);
$this->rootFolder
->method('getUserFolder')
@@ -669,8 +686,8 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals('myTarget2', $children[1]->getTarget());
}
- public function testCreateUserShare() {
- $share = new \OC\Share20\Share($this->rootFolder, $this->userManager);
+ public function testCreateUserShare(): void {
+ $share = new Share($this->rootFolder, $this->userManager);
$shareOwner = $this->createMock(IUser::class);
$shareOwner->method('getUID')->willReturn('shareOwner');
@@ -688,12 +705,12 @@ class DefaultShareProviderTest extends \Test\TestCase {
['shareOwner', $ownerFolder],
]);
- $userFolder->method('getById')
+ $userFolder->method('getFirstNodeById')
->with(100)
- ->willReturn([$path]);
- $ownerFolder->method('getById')
+ ->willReturn($path);
+ $ownerFolder->method('getFirstNodeById')
->with(100)
- ->willReturn([$path]);
+ ->willReturn($path);
$share->setShareType(IShare::TYPE_USER);
$share->setSharedWith('sharedWith');
@@ -703,12 +720,17 @@ class DefaultShareProviderTest extends \Test\TestCase {
$share->setSharedWithDisplayName('Displayed Name');
$share->setSharedWithAvatar('/path/to/image.svg');
$share->setPermissions(1);
+
+ $attrs = new ShareAttributes();
+ $attrs->setAttribute('permissions', 'download', true);
+ $share->setAttributes($attrs);
+
$share->setTarget('/target');
$share2 = $this->provider->create($share);
$this->assertNotNull($share2->getId());
- $this->assertSame('ocinternal:'.$share2->getId(), $share2->getFullId());
+ $this->assertSame('ocinternal:' . $share2->getId(), $share2->getFullId());
$this->assertSame(IShare::TYPE_USER, $share2->getShareType());
$this->assertSame('sharedWith', $share2->getSharedWith());
$this->assertSame('sharedBy', $share2->getSharedBy());
@@ -718,15 +740,26 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertLessThanOrEqual(new \DateTime(), $share2->getShareTime());
$this->assertSame($path, $share2->getNode());
- // nothing from setSharedWithDisplayName/setSharedWithAvatar is saved in DB
+ // Data is kept after creation
$this->assertSame('Displayed Name', $share->getSharedWithDisplayName());
$this->assertSame('/path/to/image.svg', $share->getSharedWithAvatar());
- $this->assertSame(null, $share2->getSharedWithDisplayName());
- $this->assertSame(null, $share2->getSharedWithAvatar());
+ $this->assertSame('Displayed Name', $share2->getSharedWithDisplayName());
+ $this->assertSame('/path/to/image.svg', $share2->getSharedWithAvatar());
+
+ $this->assertSame(
+ [
+ [
+ 'scope' => 'permissions',
+ 'key' => 'download',
+ 'value' => true
+ ]
+ ],
+ $share->getAttributes()->toArray()
+ );
}
- public function testCreateGroupShare() {
- $share = new \OC\Share20\Share($this->rootFolder, $this->userManager);
+ public function testCreateGroupShare(): void {
+ $share = new Share($this->rootFolder, $this->userManager);
$shareOwner = $this->createMock(IUser::class);
$shareOwner->method('getUID')->willReturn('shareOwner');
@@ -744,12 +777,12 @@ class DefaultShareProviderTest extends \Test\TestCase {
['shareOwner', $ownerFolder],
]);
- $userFolder->method('getById')
+ $userFolder->method('getFirstNodeById')
->with(100)
- ->willReturn([$path]);
- $ownerFolder->method('getById')
+ ->willReturn($path);
+ $ownerFolder->method('getFirstNodeById')
->with(100)
- ->willReturn([$path]);
+ ->willReturn($path);
$share->setShareType(IShare::TYPE_GROUP);
$share->setSharedWith('sharedWith');
@@ -760,11 +793,14 @@ class DefaultShareProviderTest extends \Test\TestCase {
$share->setSharedWithDisplayName('Displayed Name');
$share->setSharedWithAvatar('/path/to/image.svg');
$share->setTarget('/target');
+ $attrs = new ShareAttributes();
+ $attrs->setAttribute('permissions', 'download', true);
+ $share->setAttributes($attrs);
$share2 = $this->provider->create($share);
$this->assertNotNull($share2->getId());
- $this->assertSame('ocinternal:'.$share2->getId(), $share2->getFullId());
+ $this->assertSame('ocinternal:' . $share2->getId(), $share2->getFullId());
$this->assertSame(IShare::TYPE_GROUP, $share2->getShareType());
$this->assertSame('sharedWith', $share2->getSharedWith());
$this->assertSame('sharedBy', $share2->getSharedBy());
@@ -774,15 +810,26 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertLessThanOrEqual(new \DateTime(), $share2->getShareTime());
$this->assertSame($path, $share2->getNode());
- // nothing from setSharedWithDisplayName/setSharedWithAvatar is saved in DB
+ // Data is kept after creation
$this->assertSame('Displayed Name', $share->getSharedWithDisplayName());
$this->assertSame('/path/to/image.svg', $share->getSharedWithAvatar());
- $this->assertSame(null, $share2->getSharedWithDisplayName());
- $this->assertSame(null, $share2->getSharedWithAvatar());
+ $this->assertSame('Displayed Name', $share2->getSharedWithDisplayName());
+ $this->assertSame('/path/to/image.svg', $share2->getSharedWithAvatar());
+
+ $this->assertSame(
+ [
+ [
+ 'scope' => 'permissions',
+ 'key' => 'download',
+ 'value' => true
+ ]
+ ],
+ $share->getAttributes()->toArray()
+ );
}
- public function testCreateLinkShare() {
- $share = new \OC\Share20\Share($this->rootFolder, $this->userManager);
+ public function testCreateLinkShare(): void {
+ $share = new Share($this->rootFolder, $this->userManager);
$shareOwner = $this->createMock(IUser::class);
$shareOwner->method('getUID')->willReturn('shareOwner');
@@ -794,18 +841,18 @@ class DefaultShareProviderTest extends \Test\TestCase {
$ownerFolder = $this->createMock(Folder::class);
$userFolder = $this->createMock(Folder::class);
$this->rootFolder
- ->method('getUserFolder')
- ->willReturnMap([
- ['sharedBy', $userFolder],
- ['shareOwner', $ownerFolder],
- ]);
-
- $userFolder->method('getById')
- ->with(100)
- ->willReturn([$path]);
- $ownerFolder->method('getById')
- ->with(100)
- ->willReturn([$path]);
+ ->method('getUserFolder')
+ ->willReturnMap([
+ ['sharedBy', $userFolder],
+ ['shareOwner', $ownerFolder],
+ ]);
+
+ $userFolder->method('getFirstNodeById')
+ ->with(100)
+ ->willReturn($path);
+ $ownerFolder->method('getFirstNodeById')
+ ->with(100)
+ ->willReturn($path);
$share->setShareType(IShare::TYPE_LINK);
$share->setSharedBy('sharedBy');
@@ -822,7 +869,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$share2 = $this->provider->create($share);
$this->assertNotNull($share2->getId());
- $this->assertSame('ocinternal:'.$share2->getId(), $share2->getFullId());
+ $this->assertSame('ocinternal:' . $share2->getId(), $share2->getFullId());
$this->assertSame(IShare::TYPE_LINK, $share2->getShareType());
$this->assertSame('sharedBy', $share2->getSharedBy());
$this->assertSame('shareOwner', $share2->getShareOwner());
@@ -836,7 +883,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals($expireDate->getTimestamp(), $share2->getExpirationDate()->getTimestamp());
}
- public function testGetShareByToken() {
+ public function testGetShareByToken(): void {
$qb = $this->dbConn->getQueryBuilder();
$qb->insert('share')
@@ -851,6 +898,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
'file_target' => $qb->expr()->literal('myTarget'),
'permissions' => $qb->expr()->literal(13),
'token' => $qb->expr()->literal('secrettoken'),
+ 'label' => $qb->expr()->literal('the label'),
]);
$qb->execute();
$id = $qb->getLastInsertId();
@@ -858,7 +906,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$file = $this->createMock(File::class);
$this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf();
- $this->rootFolder->method('getById')->with(42)->willReturn([$file]);
+ $this->rootFolder->method('getFirstNodeById')->with(42)->willReturn($file);
$share = $this->provider->getShareByToken('secrettoken');
$this->assertEquals($id, $share->getId());
@@ -866,13 +914,46 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertSame('sharedBy', $share->getSharedBy());
$this->assertSame('secrettoken', $share->getToken());
$this->assertSame('password', $share->getPassword());
+ $this->assertSame('the label', $share->getLabel());
$this->assertSame(true, $share->getSendPasswordByTalk());
$this->assertSame(null, $share->getSharedWith());
}
+ /**
+ * Assert that if no label is provided the label is correctly,
+ * as types on IShare, a string and not null
+ */
+ public function testGetShareByTokenNullLabel(): void {
+ $qb = $this->dbConn->getQueryBuilder();
+
+ $qb->insert('share')
+ ->values([
+ 'share_type' => $qb->expr()->literal(IShare::TYPE_LINK),
+ 'password' => $qb->expr()->literal('password'),
+ 'password_by_talk' => $qb->expr()->literal(true),
+ 'uid_owner' => $qb->expr()->literal('shareOwner'),
+ 'uid_initiator' => $qb->expr()->literal('sharedBy'),
+ 'item_type' => $qb->expr()->literal('file'),
+ 'file_source' => $qb->expr()->literal(42),
+ 'file_target' => $qb->expr()->literal('myTarget'),
+ 'permissions' => $qb->expr()->literal(13),
+ 'token' => $qb->expr()->literal('secrettoken'),
+ ]);
+ $qb->executeStatement();
+ $id = $qb->getLastInsertId();
+
+ $file = $this->createMock(File::class);
+
+ $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf();
+ $this->rootFolder->method('getFirstNodeById')->with(42)->willReturn($file);
+
+ $share = $this->provider->getShareByToken('secrettoken');
+ $this->assertEquals($id, $share->getId());
+ $this->assertSame('', $share->getLabel());
+ }
- public function testGetShareByTokenNotFound() {
- $this->expectException(\OCP\Share\Exceptions\ShareNotFound::class);
+ public function testGetShareByTokenNotFound(): void {
+ $this->expectException(ShareNotFound::class);
$this->provider->getShareByToken('invalidtoken');
}
@@ -891,16 +972,16 @@ class DefaultShareProviderTest extends \Test\TestCase {
$qb = $this->dbConn->getQueryBuilder();
$qb->insert('filecache')
->values([
- 'storage' => $qb->expr()->literal($storage),
- 'path' => $qb->expr()->literal($path),
- 'path_hash' => $qb->expr()->literal(md5($path)),
- 'name' => $qb->expr()->literal(basename($path)),
+ 'storage' => $qb->createNamedParameter($storage, IQueryBuilder::PARAM_INT),
+ 'path' => $qb->createNamedParameter($path),
+ 'path_hash' => $qb->createNamedParameter(md5($path)),
+ 'name' => $qb->createNamedParameter(basename($path)),
]);
$this->assertEquals(1, $qb->execute());
return $qb->getLastInsertId();
}
- public function storageAndFileNameProvider() {
+ public static function storageAndFileNameProvider(): array {
return [
// regular file on regular storage
['home::shareOwner', 'files/test.txt', 'files/test2.txt'],
@@ -911,10 +992,8 @@ class DefaultShareProviderTest extends \Test\TestCase {
];
}
- /**
- * @dataProvider storageAndFileNameProvider
- */
- public function testGetSharedWithUser($storageStringId, $fileName1, $fileName2) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('storageAndFileNameProvider')]
+ public function testGetSharedWithUser($storageStringId, $fileName1, $fileName2): void {
$storageId = $this->createTestStorageEntry($storageStringId);
$fileId = $this->createTestFileEntry($fileName1, $storageId);
$fileId2 = $this->createTestFileEntry($fileName2, $storageId);
@@ -949,7 +1028,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$file = $this->createMock(File::class);
$this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf();
- $this->rootFolder->method('getById')->with($fileId)->willReturn([$file]);
+ $this->rootFolder->method('getFirstNodeById')->with($fileId)->willReturn($file);
$share = $this->provider->getSharedWith('sharedWith', IShare::TYPE_USER, null, 1, 0);
$this->assertCount(1, $share);
@@ -962,10 +1041,8 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals(IShare::TYPE_USER, $share->getShareType());
}
- /**
- * @dataProvider storageAndFileNameProvider
- */
- public function testGetSharedWithGroup($storageStringId, $fileName1, $fileName2) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('storageAndFileNameProvider')]
+ public function testGetSharedWithGroup($storageStringId, $fileName1, $fileName2): void {
$storageId = $this->createTestStorageEntry($storageStringId);
$fileId = $this->createTestFileEntry($fileName1, $storageId);
$fileId2 = $this->createTestFileEntry($fileName2, $storageId);
@@ -1000,7 +1077,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$groups = [];
foreach (range(0, 100) as $i) {
- $groups[] = 'group'.$i;
+ $groups[] = 'group' . $i;
}
$groups[] = 'sharedWith';
@@ -1017,11 +1094,13 @@ class DefaultShareProviderTest extends \Test\TestCase {
['shareOwner', $owner],
['sharedBy', $initiator],
]);
- $this->groupManager->method('getUserGroupIds')->with($user)->willReturn($groups);
+ $this->groupManager
+ ->method('getUserGroupIds')
+ ->willReturnCallback(fn (IUser $user) => ($user->getUID() === 'sharedWith' ? $groups : []));
$file = $this->createMock(File::class);
$this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf();
- $this->rootFolder->method('getById')->with($fileId)->willReturn([$file]);
+ $this->rootFolder->method('getFirstNodeById')->with($fileId)->willReturn($file);
$share = $this->provider->getSharedWith('sharedWith', IShare::TYPE_GROUP, null, 20, 1);
$this->assertCount(1, $share);
@@ -1034,10 +1113,8 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals(IShare::TYPE_GROUP, $share->getShareType());
}
- /**
- * @dataProvider storageAndFileNameProvider
- */
- public function testGetSharedWithGroupUserModified($storageStringId, $fileName1, $fileName2) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('storageAndFileNameProvider')]
+ public function testGetSharedWithGroupUserModified($storageStringId, $fileName1, $fileName2): void {
$storageId = $this->createTestStorageEntry($storageStringId);
$fileId = $this->createTestFileEntry($fileName1, $storageId);
$qb = $this->dbConn->getQueryBuilder();
@@ -1105,11 +1182,13 @@ class DefaultShareProviderTest extends \Test\TestCase {
['shareOwner', $owner],
['sharedBy', $initiator],
]);
- $this->groupManager->method('getUserGroupIds')->with($user)->willReturn($groups);
+ $this->groupManager
+ ->method('getUserGroupIds')
+ ->willReturnCallback(fn (IUser $user) => ($user->getUID() === 'user' ? $groups : []));
$file = $this->createMock(File::class);
$this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf();
- $this->rootFolder->method('getById')->with($fileId)->willReturn([$file]);
+ $this->rootFolder->method('getFirstNodeById')->with($fileId)->willReturn($file);
$share = $this->provider->getSharedWith('user', IShare::TYPE_GROUP, null, -1, 0);
$this->assertCount(1, $share);
@@ -1124,10 +1203,8 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertSame('userTarget', $share->getTarget());
}
- /**
- * @dataProvider storageAndFileNameProvider
- */
- public function testGetSharedWithUserWithNode($storageStringId, $fileName1, $fileName2) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('storageAndFileNameProvider')]
+ public function testGetSharedWithUserWithNode($storageStringId, $fileName1, $fileName2): void {
$storageId = $this->createTestStorageEntry($storageStringId);
$fileId = $this->createTestFileEntry($fileName1, $storageId);
$fileId2 = $this->createTestFileEntry($fileName2, $storageId);
@@ -1152,7 +1229,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$file->method('getId')->willReturn($fileId2);
$this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf();
- $this->rootFolder->method('getById')->with($fileId2)->willReturn([$file]);
+ $this->rootFolder->method('getFirstNodeById')->with($fileId2)->willReturn($file);
$share = $this->provider->getSharedWith('user0', IShare::TYPE_USER, $file, -1, 0);
$this->assertCount(1, $share);
@@ -1166,10 +1243,8 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals(IShare::TYPE_USER, $share->getShareType());
}
- /**
- * @dataProvider storageAndFileNameProvider
- */
- public function testGetSharedWithGroupWithNode($storageStringId, $fileName1, $fileName2) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('storageAndFileNameProvider')]
+ public function testGetSharedWithGroupWithNode($storageStringId, $fileName1, $fileName2): void {
$storageId = $this->createTestStorageEntry($storageStringId);
$fileId = $this->createTestFileEntry($fileName1, $storageId);
$fileId2 = $this->createTestFileEntry($fileName2, $storageId);
@@ -1188,12 +1263,14 @@ class DefaultShareProviderTest extends \Test\TestCase {
['user1', $user1],
]);
- $this->groupManager->method('getUserGroupIds')->with($user0)->willReturn(['group0']);
+ $this->groupManager
+ ->method('getUserGroupIds')
+ ->willReturnCallback(fn (IUser $user) => ($user->getUID() === 'user0' ? ['group0'] : []));
$node = $this->createMock(Folder::class);
$node->method('getId')->willReturn($fileId2);
$this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf();
- $this->rootFolder->method('getById')->with($fileId2)->willReturn([$node]);
+ $this->rootFolder->method('getFirstNodeById')->with($fileId2)->willReturn($node);
$share = $this->provider->getSharedWith('user0', IShare::TYPE_GROUP, $node, -1, 0);
$this->assertCount(1, $share);
@@ -1207,7 +1284,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals(IShare::TYPE_GROUP, $share->getShareType());
}
- public function shareTypesProvider() {
+ public static function shareTypesProvider(): array {
return [
[IShare::TYPE_USER, false],
[IShare::TYPE_GROUP, false],
@@ -1216,10 +1293,8 @@ class DefaultShareProviderTest extends \Test\TestCase {
];
}
- /**
- * @dataProvider shareTypesProvider
- */
- public function testGetSharedWithWithDeletedFile($shareType, $trashed) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('shareTypesProvider')]
+ public function testGetSharedWithWithDeletedFile($shareType, $trashed): void {
if ($trashed) {
// exists in database but is in trash
$storageId = $this->createTestStorageEntry('home::shareOwner');
@@ -1244,11 +1319,11 @@ class DefaultShareProviderTest extends \Test\TestCase {
$file = $this->createMock(File::class);
$this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf();
- $this->rootFolder->method('getById')->with($deletedFileId)->willReturn([$file]);
+ $this->rootFolder->method('getFirstNodeById')->with($deletedFileId)->willReturn($file);
$groups = [];
foreach (range(0, 100) as $i) {
- $groups[] = 'group'.$i;
+ $groups[] = 'group' . $i;
}
$groups[] = 'sharedWith';
@@ -1265,13 +1340,15 @@ class DefaultShareProviderTest extends \Test\TestCase {
['shareOwner', $owner],
['sharedBy', $initiator],
]);
- $this->groupManager->method('getUserGroupIds')->with($user)->willReturn($groups);
+ $this->groupManager
+ ->method('getUserGroupIds')
+ ->willReturnCallback(fn (IUser $user) => ($user->getUID() === 'sharedWith' ? $groups : []));
$share = $this->provider->getSharedWith('sharedWith', $shareType, null, 1, 0);
$this->assertCount(0, $share);
}
- public function testGetSharesBy() {
+ public function testGetSharesBy(): void {
$qb = $this->dbConn->getQueryBuilder();
$qb->insert('share')
->values([
@@ -1304,7 +1381,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$file = $this->createMock(File::class);
$this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf();
- $this->rootFolder->method('getById')->with(42)->willReturn([$file]);
+ $this->rootFolder->method('getFirstNodeById')->with(42)->willReturn($file);
$share = $this->provider->getSharesBy('sharedBy', IShare::TYPE_USER, null, false, 1, 0);
$this->assertCount(1, $share);
@@ -1320,7 +1397,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals('myTarget', $share->getTarget());
}
- public function testGetSharesNode() {
+ public function testGetSharesNode(): void {
$qb = $this->dbConn->getQueryBuilder();
$qb->insert('share')
->values([
@@ -1354,7 +1431,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$file = $this->createMock(File::class);
$file->method('getId')->willReturn(42);
$this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf();
- $this->rootFolder->method('getById')->with(42)->willReturn([$file]);
+ $this->rootFolder->method('getFirstNodeById')->with(42)->willReturn($file);
$share = $this->provider->getSharesBy('sharedBy', IShare::TYPE_USER, $file, false, 1, 0);
$this->assertCount(1, $share);
@@ -1370,7 +1447,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals('myTarget', $share->getTarget());
}
- public function testGetSharesReshare() {
+ public function testGetSharesReshare(): void {
$qb = $this->dbConn->getQueryBuilder();
$qb->insert('share')
->values([
@@ -1404,7 +1481,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$file = $this->createMock(File::class);
$file->method('getId')->willReturn(42);
$this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf();
- $this->rootFolder->method('getById')->with(42)->willReturn([$file]);
+ $this->rootFolder->method('getFirstNodeById')->with(42)->willReturn($file);
$shares = $this->provider->getSharesBy('shareOwner', IShare::TYPE_USER, null, true, -1, 0);
$this->assertCount(2, $shares);
@@ -1429,7 +1506,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals('userTarget', $share->getTarget());
}
- public function testDeleteFromSelfGroupNoCustomShare() {
+ public function testDeleteFromSelfGroupNoCustomShare(): void {
$qb = $this->dbConn->getQueryBuilder();
$stmt = $qb->insert('share')
->values([
@@ -1457,13 +1534,14 @@ class DefaultShareProviderTest extends \Test\TestCase {
$group = $this->createMock(IGroup::class);
$group->method('getGID')->willReturn('group');
$group->method('inGroup')->with($user2)->willReturn(true);
+ $group->method('getDisplayName')->willReturn('group-displayname');
$this->groupManager->method('get')->with('group')->willReturn($group);
$file = $this->createMock(File::class);
$file->method('getId')->willReturn(1);
$this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf();
- $this->rootFolder->method('getById')->with(1)->willReturn([$file]);
+ $this->rootFolder->method('getFirstNodeById')->with(1)->willReturn($file);
$share = $this->provider->getShareById($id);
@@ -1485,7 +1563,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals('user2', $share2['share_with']);
}
- public function testDeleteFromSelfGroupAlreadyCustomShare() {
+ public function testDeleteFromSelfGroupAlreadyCustomShare(): void {
$qb = $this->dbConn->getQueryBuilder();
$stmt = $qb->insert('share')
->values([
@@ -1528,13 +1606,14 @@ class DefaultShareProviderTest extends \Test\TestCase {
$group = $this->createMock(IGroup::class);
$group->method('getGID')->willReturn('group');
$group->method('inGroup')->with($user2)->willReturn(true);
+ $group->method('getDisplayName')->willReturn('group-displayname');
$this->groupManager->method('get')->with('group')->willReturn($group);
$file = $this->createMock(File::class);
$file->method('getId')->willReturn(1);
$this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf();
- $this->rootFolder->method('getById')->with(1)->willReturn([$file]);
+ $this->rootFolder->method('getFirstNodeById')->with(1)->willReturn($file);
$share = $this->provider->getShareById($id);
@@ -1557,7 +1636,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
}
- public function testDeleteFromSelfGroupUserNotInGroup() {
+ public function testDeleteFromSelfGroupUserNotInGroup(): void {
$qb = $this->dbConn->getQueryBuilder();
$stmt = $qb->insert('share')
->values([
@@ -1585,13 +1664,14 @@ class DefaultShareProviderTest extends \Test\TestCase {
$group = $this->createMock(IGroup::class);
$group->method('getGID')->willReturn('group');
$group->method('inGroup')->with($user2)->willReturn(false);
+ $group->method('getDisplayName')->willReturn('group-displayname');
$this->groupManager->method('get')->with('group')->willReturn($group);
$file = $this->createMock(File::class);
$file->method('getId')->willReturn(1);
$this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf();
- $this->rootFolder->method('getById')->with(1)->willReturn([$file]);
+ $this->rootFolder->method('getFirstNodeById')->with(1)->willReturn($file);
$share = $this->provider->getShareById($id);
@@ -1599,8 +1679,8 @@ class DefaultShareProviderTest extends \Test\TestCase {
}
- public function testDeleteFromSelfGroupDoesNotExist() {
- $this->expectException(\OC\Share20\Exception\ProviderException::class);
+ public function testDeleteFromSelfGroupDoesNotExist(): void {
+ $this->expectException(ProviderException::class);
$this->expectExceptionMessage('Group "group" does not exist');
$qb = $this->dbConn->getQueryBuilder();
@@ -1633,14 +1713,14 @@ class DefaultShareProviderTest extends \Test\TestCase {
$file->method('getId')->willReturn(1);
$this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf();
- $this->rootFolder->method('getById')->with(1)->willReturn([$file]);
+ $this->rootFolder->method('getFirstNodeById')->with(1)->willReturn($file);
$share = $this->provider->getShareById($id);
$this->provider->deleteFromSelf($share, 'user2');
}
- public function testDeleteFromSelfUser() {
+ public function testDeleteFromSelfUser(): void {
$qb = $this->dbConn->getQueryBuilder();
$stmt = $qb->insert('share')
->values([
@@ -1671,7 +1751,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$file->method('getId')->willReturn(1);
$this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf();
- $this->rootFolder->method('getById')->with(1)->willReturn([$file]);
+ $this->rootFolder->method('getFirstNodeById')->with(1)->willReturn($file);
$share = $this->provider->getShareById($id);
@@ -1690,8 +1770,8 @@ class DefaultShareProviderTest extends \Test\TestCase {
}
- public function testDeleteFromSelfUserNotRecipient() {
- $this->expectException(\OC\Share20\Exception\ProviderException::class);
+ public function testDeleteFromSelfUserNotRecipient(): void {
+ $this->expectException(ProviderException::class);
$this->expectExceptionMessage('Recipient does not match');
$qb = $this->dbConn->getQueryBuilder();
@@ -1725,7 +1805,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$file->method('getId')->willReturn(1);
$this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf();
- $this->rootFolder->method('getById')->with(1)->willReturn([$file]);
+ $this->rootFolder->method('getFirstNodeById')->with(1)->willReturn($file);
$share = $this->provider->getShareById($id);
@@ -1733,8 +1813,8 @@ class DefaultShareProviderTest extends \Test\TestCase {
}
- public function testDeleteFromSelfLink() {
- $this->expectException(\OC\Share20\Exception\ProviderException::class);
+ public function testDeleteFromSelfLink(): void {
+ $this->expectException(ProviderException::class);
$this->expectExceptionMessage('Invalid shareType');
$qb = $this->dbConn->getQueryBuilder();
@@ -1762,23 +1842,23 @@ class DefaultShareProviderTest extends \Test\TestCase {
$file->method('getId')->willReturn(1);
$this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf();
- $this->rootFolder->method('getById')->with(1)->willReturn([$file]);
+ $this->rootFolder->method('getFirstNodeById')->with(1)->willReturn($file);
$share = $this->provider->getShareById($id);
$this->provider->deleteFromSelf($share, $user1);
}
- public function testUpdateUser() {
+ public function testUpdateUser(): void {
$id = $this->addShareToDB(IShare::TYPE_USER, 'user0', 'user1', 'user2',
'file', 42, 'target', 31, null, null);
$users = [];
for ($i = 0; $i < 6; $i++) {
$user = $this->createMock(IUser::class);
- $user->method('getUID')->willReturn('user'.$i);
+ $user->method('getUID')->willReturn('user' . $i);
$user->method('getDisplayName')->willReturn('user' . $i);
- $users['user'.$i] = $user;
+ $users['user' . $i] = $user;
}
$this->userManager->method('get')->willReturnCallback(
@@ -1793,9 +1873,9 @@ class DefaultShareProviderTest extends \Test\TestCase {
$file2->method('getId')->willReturn(43);
$folder1 = $this->createMock(Folder::class);
- $folder1->method('getById')->with(42)->willReturn([$file1]);
+ $folder1->method('getFirstNodeById')->with(42)->willReturn($file1);
$folder2 = $this->createMock(Folder::class);
- $folder2->method('getById')->with(43)->willReturn([$file2]);
+ $folder2->method('getFirstNodeById')->with(43)->willReturn($file2);
$this->rootFolder->method('getUserFolder')->willReturnMap([
['user2', $folder1],
@@ -1827,15 +1907,15 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertSame(1, $share2->getPermissions());
}
- public function testUpdateLink() {
+ public function testUpdateLink(): void {
$id = $this->addShareToDB(IShare::TYPE_LINK, null, 'user1', 'user2',
'file', 42, 'target', 31, null, null);
$users = [];
for ($i = 0; $i < 6; $i++) {
$user = $this->createMock(IUser::class);
- $user->method('getUID')->willReturn('user'.$i);
- $users['user'.$i] = $user;
+ $user->method('getUID')->willReturn('user' . $i);
+ $users['user' . $i] = $user;
}
$this->userManager->method('get')->willReturnCallback(
@@ -1850,9 +1930,9 @@ class DefaultShareProviderTest extends \Test\TestCase {
$file2->method('getId')->willReturn(43);
$folder1 = $this->createMock(Folder::class);
- $folder1->method('getById')->with(42)->willReturn([$file1]);
+ $folder1->method('getFirstNodeById')->with(42)->willReturn($file1);
$folder2 = $this->createMock(Folder::class);
- $folder2->method('getById')->with(43)->willReturn([$file2]);
+ $folder2->method('getFirstNodeById')->with(43)->willReturn($file2);
$this->rootFolder->method('getUserFolder')->willReturnMap([
['user2', $folder1],
@@ -1887,7 +1967,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertSame(1, $share2->getPermissions());
}
- public function testUpdateLinkRemovePassword() {
+ public function testUpdateLinkRemovePassword(): void {
$id = $this->addShareToDB(IShare::TYPE_LINK, 'foo', 'user1', 'user2',
'file', 42, 'target', 31, null, null);
@@ -1900,8 +1980,8 @@ class DefaultShareProviderTest extends \Test\TestCase {
$users = [];
for ($i = 0; $i < 6; $i++) {
$user = $this->createMock(IUser::class);
- $user->method('getUID')->willReturn('user'.$i);
- $users['user'.$i] = $user;
+ $user->method('getUID')->willReturn('user' . $i);
+ $users['user' . $i] = $user;
}
$this->userManager->method('get')->willReturnCallback(
@@ -1916,9 +1996,9 @@ class DefaultShareProviderTest extends \Test\TestCase {
$file2->method('getId')->willReturn(43);
$folder1 = $this->createMock(Folder::class);
- $folder1->method('getById')->with(42)->willReturn([$file1]);
+ $folder1->method('getFirstNodeById')->with(42)->willReturn($file1);
$folder2 = $this->createMock(Folder::class);
- $folder2->method('getById')->with(43)->willReturn([$file2]);
+ $folder2->method('getFirstNodeById')->with(43)->willReturn($file2);
$this->rootFolder->method('getUserFolder')->willReturnMap([
['user2', $folder1],
@@ -1950,15 +2030,15 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertSame(1, $share2->getPermissions());
}
- public function testUpdateGroupNoSub() {
+ public function testUpdateGroupNoSub(): void {
$id = $this->addShareToDB(IShare::TYPE_GROUP, 'group0', 'user1', 'user2',
'file', 42, 'target', 31, null, null);
$users = [];
for ($i = 0; $i < 6; $i++) {
$user = $this->createMock(IUser::class);
- $user->method('getUID')->willReturn('user'.$i);
- $users['user'.$i] = $user;
+ $user->method('getUID')->willReturn('user' . $i);
+ $users['user' . $i] = $user;
}
$this->userManager->method('get')->willReturnCallback(
@@ -1970,8 +2050,9 @@ class DefaultShareProviderTest extends \Test\TestCase {
$groups = [];
for ($i = 0; $i < 2; $i++) {
$group = $this->createMock(IGroup::class);
- $group->method('getGID')->willReturn('group'.$i);
- $groups['group'.$i] = $group;
+ $group->method('getGID')->willReturn('group' . $i);
+ $group->method('getDisplayName')->willReturn('group-displayname' . $i);
+ $groups['group' . $i] = $group;
}
$this->groupManager->method('get')->willReturnCallback(
@@ -1986,9 +2067,9 @@ class DefaultShareProviderTest extends \Test\TestCase {
$file2->method('getId')->willReturn(43);
$folder1 = $this->createMock(Folder::class);
- $folder1->method('getById')->with(42)->willReturn([$file1]);
+ $folder1->method('getFirstNodeById')->with(42)->willReturn($file1);
$folder2 = $this->createMock(Folder::class);
- $folder2->method('getById')->with(43)->willReturn([$file2]);
+ $folder2->method('getFirstNodeById')->with(43)->willReturn($file2);
$this->rootFolder->method('getUserFolder')->willReturnMap([
['user2', $folder1],
@@ -2022,7 +2103,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertSame(1, $share2->getPermissions());
}
- public function testUpdateGroupSubShares() {
+ public function testUpdateGroupSubShares(): void {
$id = $this->addShareToDB(IShare::TYPE_GROUP, 'group0', 'user1', 'user2',
'file', 42, 'target', 31, null, null);
@@ -2035,8 +2116,8 @@ class DefaultShareProviderTest extends \Test\TestCase {
$users = [];
for ($i = 0; $i < 6; $i++) {
$user = $this->createMock(IUser::class);
- $user->method('getUID')->willReturn('user'.$i);
- $users['user'.$i] = $user;
+ $user->method('getUID')->willReturn('user' . $i);
+ $users['user' . $i] = $user;
}
$this->userManager->method('get')->willReturnCallback(
@@ -2048,8 +2129,9 @@ class DefaultShareProviderTest extends \Test\TestCase {
$groups = [];
for ($i = 0; $i < 2; $i++) {
$group = $this->createMock(IGroup::class);
- $group->method('getGID')->willReturn('group'.$i);
- $groups['group'.$i] = $group;
+ $group->method('getGID')->willReturn('group' . $i);
+ $group->method('getDisplayName')->willReturn('group-displayname' . $i);
+ $groups['group' . $i] = $group;
}
$this->groupManager->method('get')->willReturnCallback(
@@ -2064,9 +2146,9 @@ class DefaultShareProviderTest extends \Test\TestCase {
$file2->method('getId')->willReturn(43);
$folder1 = $this->createMock(Folder::class);
- $folder1->method('getById')->with(42)->willReturn([$file1]);
+ $folder1->method('getFirstNodeById')->with(42)->willReturn($file1);
$folder2 = $this->createMock(Folder::class);
- $folder2->method('getById')->with(43)->willReturn([$file2]);
+ $folder2->method('getFirstNodeById')->with(43)->willReturn($file2);
$this->rootFolder->method('getUserFolder')->willReturnMap([
['user2', $folder1],
@@ -2122,7 +2204,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$stmt->closeCursor();
}
- public function testMoveUserShare() {
+ public function testMoveUserShare(): void {
$id = $this->addShareToDB(IShare::TYPE_USER, 'user0', 'user1', 'user1', 'file',
42, 'mytaret', 31, null, null);
@@ -2142,7 +2224,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$file->method('getId')->willReturn(42);
$this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf();
- $this->rootFolder->method('getById')->willReturn([$file]);
+ $this->rootFolder->method('getFirstNodeById')->willReturn($file);
$share = $this->provider->getShareById($id, null);
@@ -2153,7 +2235,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertSame('/newTarget', $share->getTarget());
}
- public function testMoveGroupShare() {
+ public function testMoveGroupShare(): void {
$id = $this->addShareToDB(IShare::TYPE_GROUP, 'group0', 'user1', 'user1', 'file',
42, 'mytaret', 31, null, null);
@@ -2165,6 +2247,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$group0 = $this->createMock(IGroup::class);
$group0->method('getGID')->willReturn('group0');
$group0->method('inGroup')->with($user0)->willReturn(true);
+ $group0->method('getDisplayName')->willReturn('group0-displayname');
$this->groupManager->method('get')->with('group0')->willReturn($group0);
@@ -2177,7 +2260,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$folder->method('getId')->willReturn(42);
$this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf();
- $this->rootFolder->method('getById')->willReturn([$folder]);
+ $this->rootFolder->method('getFirstNodeById')->willReturn($folder);
$share = $this->provider->getShareById($id, 'user0');
@@ -2194,7 +2277,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertSame('/ultraNewTarget', $share->getTarget());
}
- public function dataDeleteUser() {
+ public static function dataDeleteUser(): array {
return [
[IShare::TYPE_USER, 'a', 'b', 'c', 'a', true],
[IShare::TYPE_USER, 'a', 'b', 'c', 'b', false],
@@ -2214,7 +2297,6 @@ class DefaultShareProviderTest extends \Test\TestCase {
}
/**
- * @dataProvider dataDeleteUser
*
* @param int $type The shareType (user/group/link)
* @param string $owner The owner of the share (uid)
@@ -2223,7 +2305,8 @@ class DefaultShareProviderTest extends \Test\TestCase {
* @param string $deletedUser The user that is deleted
* @param bool $rowDeleted Is the row deleted in this setup
*/
- public function testDeleteUser($type, $owner, $initiator, $recipient, $deletedUser, $rowDeleted) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataDeleteUser')]
+ public function testDeleteUser($type, $owner, $initiator, $recipient, $deletedUser, $rowDeleted): void {
$qb = $this->dbConn->getQueryBuilder();
$qb->insert('share')
->setValue('share_type', $qb->createNamedParameter($type))
@@ -2252,7 +2335,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertCount($rowDeleted ? 0 : 1, $data);
}
- public function dataDeleteUserGroup() {
+ public static function dataDeleteUserGroup(): array {
return [
['a', 'b', 'c', 'a', true, true],
['a', 'b', 'c', 'b', false, false],
@@ -2262,7 +2345,6 @@ class DefaultShareProviderTest extends \Test\TestCase {
}
/**
- * @dataProvider dataDeleteUserGroup
*
* @param string $owner The owner of the share (uid)
* @param string $initiator The initiator of the share (uid)
@@ -2271,7 +2353,8 @@ class DefaultShareProviderTest extends \Test\TestCase {
* @param bool $groupShareDeleted
* @param bool $userGroupShareDeleted
*/
- public function testDeleteUserGroup($owner, $initiator, $recipient, $deletedUser, $groupShareDeleted, $userGroupShareDeleted) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataDeleteUserGroup')]
+ public function testDeleteUserGroup($owner, $initiator, $recipient, $deletedUser, $groupShareDeleted, $userGroupShareDeleted): void {
$qb = $this->dbConn->getQueryBuilder();
$qb->insert('share')
->setValue('share_type', $qb->createNamedParameter(IShare::TYPE_GROUP))
@@ -2321,7 +2404,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertCount($groupShareDeleted ? 0 : 1, $data);
}
- public function dataGroupDeleted() {
+ public static function dataGroupDeleted(): array {
return [
[
[
@@ -2368,13 +2451,13 @@ class DefaultShareProviderTest extends \Test\TestCase {
}
/**
- * @dataProvider dataGroupDeleted
*
* @param $shares
* @param $groupToDelete
* @param $shouldBeDeleted
*/
- public function testGroupDeleted($shares, $groupToDelete, $shouldBeDeleted) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGroupDeleted')]
+ public function testGroupDeleted($shares, $groupToDelete, $shouldBeDeleted): void {
$qb = $this->dbConn->getQueryBuilder();
$qb->insert('share')
->setValue('share_type', $qb->createNamedParameter($shares['type']))
@@ -2415,7 +2498,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertCount($shouldBeDeleted ? 0 : count($ids), $data);
}
- public function dataUserDeletedFromGroup() {
+ public static function dataUserDeletedFromGroup(): array {
return [
['group1', 'user1', true],
['group1', 'user2', false],
@@ -2428,13 +2511,13 @@ class DefaultShareProviderTest extends \Test\TestCase {
* And a user specific group share with 'user1'.
* User $user is deleted from group $gid.
*
- * @dataProvider dataUserDeletedFromGroup
*
* @param string $group
* @param string $user
* @param bool $toDelete
*/
- public function testUserDeletedFromGroup($group, $user, $toDelete) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataUserDeletedFromGroup')]
+ public function testUserDeletedFromGroup($group, $user, $toDelete): void {
$qb = $this->dbConn->getQueryBuilder();
$qb->insert('share')
->setValue('share_type', $qb->createNamedParameter(IShare::TYPE_GROUP))
@@ -2473,10 +2556,10 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertCount($toDelete ? 0 : 1, $data);
}
- public function testGetSharesInFolder() {
- $userManager = \OC::$server->getUserManager();
- $groupManager = \OC::$server->getGroupManager();
- $rootFolder = \OC::$server->getRootFolder();
+ public function testGetSharesInFolder(): void {
+ $userManager = Server::get(IUserManager::class);
+ $groupManager = Server::get(IGroupManager::class);
+ $rootFolder = Server::get(IRootFolder::class);
$provider = new DefaultShareProvider(
$this->dbConn,
@@ -2487,7 +2570,10 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->defaults,
$this->l10nFactory,
$this->urlGenerator,
- $this->config
+ $this->timeFactory,
+ $this->logger,
+ $this->shareManager,
+ $this->config,
);
$password = md5(time());
@@ -2503,14 +2589,14 @@ class DefaultShareProviderTest extends \Test\TestCase {
$file1 = $folder1->newFile('bar');
$folder2 = $folder1->newFolder('baz');
- $shareManager = \OC::$server->getShareManager();
+ $shareManager = Server::get(IShareManager::class);
$share1 = $shareManager->newShare();
$share1->setNode($folder1)
->setSharedBy($u1->getUID())
->setSharedWith($u2->getUID())
->setShareOwner($u1->getUID())
->setShareType(IShare::TYPE_USER)
- ->setPermissions(\OCP\Constants::PERMISSION_ALL);
+ ->setPermissions(Constants::PERMISSION_ALL);
$share1 = $this->provider->create($share1);
$share2 = $shareManager->newShare();
@@ -2519,7 +2605,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
->setSharedWith($u3->getUID())
->setShareOwner($u1->getUID())
->setShareType(IShare::TYPE_USER)
- ->setPermissions(\OCP\Constants::PERMISSION_READ);
+ ->setPermissions(Constants::PERMISSION_READ);
$share2 = $this->provider->create($share2);
$share3 = $shareManager->newShare();
@@ -2527,7 +2613,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
->setSharedBy($u2->getUID())
->setShareOwner($u1->getUID())
->setShareType(IShare::TYPE_LINK)
- ->setPermissions(\OCP\Constants::PERMISSION_READ);
+ ->setPermissions(Constants::PERMISSION_READ);
$share3 = $this->provider->create($share3);
$share4 = $shareManager->newShare();
@@ -2536,7 +2622,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
->setSharedWith($g1->getGID())
->setShareOwner($u1->getUID())
->setShareType(IShare::TYPE_GROUP)
- ->setPermissions(\OCP\Constants::PERMISSION_READ);
+ ->setPermissions(Constants::PERMISSION_READ);
$share4 = $this->provider->create($share4);
$result = $provider->getSharesInFolder($u1->getUID(), $folder1, false);
@@ -2571,10 +2657,10 @@ class DefaultShareProviderTest extends \Test\TestCase {
$g1->delete();
}
- public function testGetAccessListNoCurrentAccessRequired() {
- $userManager = \OC::$server->getUserManager();
- $groupManager = \OC::$server->getGroupManager();
- $rootFolder = \OC::$server->getRootFolder();
+ public function testGetAccessListNoCurrentAccessRequired(): void {
+ $userManager = Server::get(IUserManager::class);
+ $groupManager = Server::get(IGroupManager::class);
+ $rootFolder = Server::get(IRootFolder::class);
$provider = new DefaultShareProvider(
$this->dbConn,
@@ -2585,7 +2671,10 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->defaults,
$this->l10nFactory,
$this->urlGenerator,
- $this->config
+ $this->timeFactory,
+ $this->logger,
+ $this->shareManager,
+ $this->config,
);
$u1 = $userManager->createUser('testShare1', 'test');
@@ -2607,15 +2696,16 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertCount(0, $result['users']);
$this->assertFalse($result['public']);
- $shareManager = \OC::$server->getShareManager();
+ $shareManager = Server::get(IShareManager::class);
$share1 = $shareManager->newShare();
$share1->setNode($folder1)
->setSharedBy($u1->getUID())
->setSharedWith($u2->getUID())
->setShareOwner($u1->getUID())
->setShareType(IShare::TYPE_USER)
- ->setPermissions(\OCP\Constants::PERMISSION_ALL);
+ ->setPermissions(Constants::PERMISSION_ALL);
$share1 = $this->provider->create($share1);
+ $share1 = $provider->acceptShare($share1, $u2->getUid());
$share2 = $shareManager->newShare();
$share2->setNode($folder2)
@@ -2623,17 +2713,20 @@ class DefaultShareProviderTest extends \Test\TestCase {
->setSharedWith($g1->getGID())
->setShareOwner($u1->getUID())
->setShareType(IShare::TYPE_GROUP)
- ->setPermissions(\OCP\Constants::PERMISSION_ALL);
+ ->setPermissions(Constants::PERMISSION_ALL);
$share2 = $this->provider->create($share2);
$shareManager->deleteFromSelf($share2, $u4->getUID());
+ $share2 = $provider->acceptShare($share2, $u3->getUid());
+ $share2 = $provider->acceptShare($share2, $u4->getUid());
+
$share3 = $shareManager->newShare();
$share3->setNode($file1)
->setSharedBy($u3->getUID())
->setShareOwner($u1->getUID())
->setShareType(IShare::TYPE_LINK)
- ->setPermissions(\OCP\Constants::PERMISSION_READ);
+ ->setPermissions(Constants::PERMISSION_READ);
$share3 = $this->provider->create($share3);
$share4 = $shareManager->newShare();
@@ -2642,8 +2735,9 @@ class DefaultShareProviderTest extends \Test\TestCase {
->setSharedWith($u5->getUID())
->setShareOwner($u1->getUID())
->setShareType(IShare::TYPE_USER)
- ->setPermissions(\OCP\Constants::PERMISSION_READ);
+ ->setPermissions(Constants::PERMISSION_READ);
$share4 = $this->provider->create($share4);
+ $share4 = $provider->acceptShare($share4, $u5->getUid());
$result = $provider->getAccessList([$folder1, $folder2, $file1], false);
@@ -2667,10 +2761,10 @@ class DefaultShareProviderTest extends \Test\TestCase {
$g1->delete();
}
- public function testGetAccessListCurrentAccessRequired() {
- $userManager = \OC::$server->getUserManager();
- $groupManager = \OC::$server->getGroupManager();
- $rootFolder = \OC::$server->getRootFolder();
+ public function testGetAccessListCurrentAccessRequired(): void {
+ $userManager = Server::get(IUserManager::class);
+ $groupManager = Server::get(IGroupManager::class);
+ $rootFolder = Server::get(IRootFolder::class);
$provider = new DefaultShareProvider(
$this->dbConn,
@@ -2681,7 +2775,10 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->defaults,
$this->l10nFactory,
$this->urlGenerator,
- $this->config
+ $this->timeFactory,
+ $this->logger,
+ $this->shareManager,
+ $this->config,
);
$u1 = $userManager->createUser('testShare1', 'test');
@@ -2703,15 +2800,16 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertCount(0, $result['users']);
$this->assertFalse($result['public']);
- $shareManager = \OC::$server->getShareManager();
+ $shareManager = Server::get(IShareManager::class);
$share1 = $shareManager->newShare();
$share1->setNode($folder1)
->setSharedBy($u1->getUID())
->setSharedWith($u2->getUID())
->setShareOwner($u1->getUID())
->setShareType(IShare::TYPE_USER)
- ->setPermissions(\OCP\Constants::PERMISSION_ALL);
+ ->setPermissions(Constants::PERMISSION_ALL);
$share1 = $this->provider->create($share1);
+ $share1 = $provider->acceptShare($share1, $u2->getUid());
$share2 = $shareManager->newShare();
$share2->setNode($folder2)
@@ -2719,8 +2817,10 @@ class DefaultShareProviderTest extends \Test\TestCase {
->setSharedWith($g1->getGID())
->setShareOwner($u1->getUID())
->setShareType(IShare::TYPE_GROUP)
- ->setPermissions(\OCP\Constants::PERMISSION_ALL);
+ ->setPermissions(Constants::PERMISSION_ALL);
$share2 = $this->provider->create($share2);
+ $share2 = $provider->acceptShare($share2, $u3->getUid());
+ $share2 = $provider->acceptShare($share2, $u4->getUid());
$shareManager->deleteFromSelf($share2, $u4->getUID());
@@ -2729,7 +2829,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
->setSharedBy($u3->getUID())
->setShareOwner($u1->getUID())
->setShareType(IShare::TYPE_LINK)
- ->setPermissions(\OCP\Constants::PERMISSION_READ);
+ ->setPermissions(Constants::PERMISSION_READ);
$share3 = $this->provider->create($share3);
$share4 = $shareManager->newShare();
@@ -2738,8 +2838,9 @@ class DefaultShareProviderTest extends \Test\TestCase {
->setSharedWith($u5->getUID())
->setShareOwner($u1->getUID())
->setShareType(IShare::TYPE_USER)
- ->setPermissions(\OCP\Constants::PERMISSION_READ);
+ ->setPermissions(Constants::PERMISSION_READ);
$share4 = $this->provider->create($share4);
+ $share4 = $provider->acceptShare($share4, $u5->getUid());
$result = $provider->getAccessList([$folder1, $folder2, $file1], true);
@@ -2762,7 +2863,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$g1->delete();
}
- public function testGetAllShares() {
+ public function testGetAllShares(): void {
$qb = $this->dbConn->getQueryBuilder();
$qb->insert('share')
@@ -2843,23 +2944,23 @@ class DefaultShareProviderTest extends \Test\TestCase {
$ownerPath1 = $this->createMock(File::class);
$shareOwner1Folder = $this->createMock(Folder::class);
- $shareOwner1Folder->method('getById')->willReturn([$ownerPath1]);
+ $shareOwner1Folder->method('getFirstNodeById')->willReturn($ownerPath1);
$ownerPath2 = $this->createMock(File::class);
$shareOwner2Folder = $this->createMock(Folder::class);
- $shareOwner2Folder->method('getById')->willReturn([$ownerPath2]);
+ $shareOwner2Folder->method('getFirstNodeById')->willReturn($ownerPath2);
$ownerPath3 = $this->createMock(File::class);
$shareOwner3Folder = $this->createMock(Folder::class);
- $shareOwner3Folder->method('getById')->willReturn([$ownerPath3]);
+ $shareOwner3Folder->method('getFirstNodeById')->willReturn($ownerPath3);
$ownerPath4 = $this->createMock(File::class);
$shareOwner4Folder = $this->createMock(Folder::class);
- $shareOwner4Folder->method('getById')->willReturn([$ownerPath4]);
+ $shareOwner4Folder->method('getFirstNodeById')->willReturn($ownerPath4);
$ownerPath5 = $this->createMock(File::class);
$shareOwner5Folder = $this->createMock(Folder::class);
- $shareOwner5Folder->method('getById')->willReturn([$ownerPath5]);
+ $shareOwner5Folder->method('getFirstNodeById')->willReturn($ownerPath5);
$this->rootFolder
->method('getUserFolder')
@@ -2926,4 +3027,88 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals('token5', $share->getToken());
$this->assertEquals('myTarget5', $share->getTarget());
}
+
+
+ public function testGetSharesByPath(): void {
+ $qb = $this->dbConn->getQueryBuilder();
+
+ $qb->insert('share')
+ ->values([
+ 'share_type' => $qb->expr()->literal(IShare::TYPE_USER),
+ 'uid_owner' => $qb->expr()->literal('user1'),
+ 'uid_initiator' => $qb->expr()->literal('user1'),
+ 'share_with' => $qb->expr()->literal('user2'),
+ 'item_type' => $qb->expr()->literal('file'),
+ 'file_source' => $qb->expr()->literal(1),
+ ]);
+ $qb->execute();
+
+ $id1 = $qb->getLastInsertId();
+
+ $qb->insert('share')
+ ->values([
+ 'share_type' => $qb->expr()->literal(IShare::TYPE_GROUP),
+ 'uid_owner' => $qb->expr()->literal('user1'),
+ 'uid_initiator' => $qb->expr()->literal('user1'),
+ 'share_with' => $qb->expr()->literal('user2'),
+ 'item_type' => $qb->expr()->literal('file'),
+ 'file_source' => $qb->expr()->literal(1),
+ ]);
+ $qb->execute();
+
+ $id2 = $qb->getLastInsertId();
+
+ $qb->insert('share')
+ ->values([
+ 'share_type' => $qb->expr()->literal(IShare::TYPE_LINK),
+ 'uid_owner' => $qb->expr()->literal('user1'),
+ 'uid_initiator' => $qb->expr()->literal('user1'),
+ 'share_with' => $qb->expr()->literal('user2'),
+ 'item_type' => $qb->expr()->literal('file'),
+ 'file_source' => $qb->expr()->literal(1),
+ ]);
+ $qb->execute();
+
+ $id3 = $qb->getLastInsertId();
+
+ $ownerPath1 = $this->createMock(File::class);
+ $shareOwner1Folder = $this->createMock(Folder::class);
+ $shareOwner1Folder->method('getFirstNodeById')->willReturn($ownerPath1);
+
+ $ownerPath2 = $this->createMock(File::class);
+ $shareOwner2Folder = $this->createMock(Folder::class);
+ $shareOwner2Folder->method('getFirstNodeById')->willReturn($ownerPath2);
+
+ $ownerPath3 = $this->createMock(File::class);
+ $shareOwner3Folder = $this->createMock(Folder::class);
+ $shareOwner3Folder->method('getFirstNodeById')->willReturn($ownerPath3);
+
+ $this->rootFolder
+ ->method('getUserFolder')
+ ->willReturnMap(
+ [
+ ['shareOwner1', $shareOwner1Folder],
+ ['shareOwner2', $shareOwner2Folder],
+ ['shareOwner3', $shareOwner3Folder],
+ ]
+ );
+
+ $node = $this->createMock(Node::class);
+ $node
+ ->expects($this->once())
+ ->method('getId')
+ ->willReturn(1);
+
+ $shares = $this->provider->getSharesByPath($node);
+ $this->assertCount(3, $shares);
+
+ $this->assertEquals($id1, $shares[0]->getId());
+ $this->assertEquals(IShare::TYPE_USER, $shares[0]->getShareType());
+
+ $this->assertEquals($id2, $shares[1]->getId());
+ $this->assertEquals(IShare::TYPE_GROUP, $shares[1]->getShareType());
+
+ $this->assertEquals($id3, $shares[2]->getId());
+ $this->assertEquals(IShare::TYPE_LINK, $shares[2]->getShareType());
+ }
}