aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php')
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php118
1 files changed, 46 insertions, 72 deletions
diff --git a/apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php
index a81226ccb5e..33f579eb913 100644
--- a/apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php
@@ -1,72 +1,34 @@
<?php
+
+declare(strict_types=1);
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Daniel Kesselberg <mail@danielkesselberg.de>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Julius Härtl <jus@bitgrid.net>
- * @author Maxence Lange <maxence@nextcloud.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <robin@icewind.nl>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Vincent Petry <vincent@nextcloud.com>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\DAV\Tests\unit\Connector\Sabre;
use OCA\DAV\Connector\Sabre\Directory;
use OCA\DAV\Connector\Sabre\File;
use OCA\DAV\Connector\Sabre\Node;
+use OCA\DAV\Connector\Sabre\SharesPlugin;
use OCA\DAV\Upload\UploadFile;
use OCP\Files\Folder;
use OCP\IUser;
use OCP\IUserSession;
use OCP\Share\IManager;
use OCP\Share\IShare;
+use PHPUnit\Framework\MockObject\MockObject;
use Sabre\DAV\Tree;
class SharesPluginTest extends \Test\TestCase {
- public const SHARETYPES_PROPERTYNAME = \OCA\DAV\Connector\Sabre\SharesPlugin::SHARETYPES_PROPERTYNAME;
-
- /**
- * @var \Sabre\DAV\Server
- */
- private $server;
-
- /**
- * @var \Sabre\DAV\Tree
- */
- private $tree;
+ public const SHARETYPES_PROPERTYNAME = SharesPlugin::SHARETYPES_PROPERTYNAME;
- /**
- * @var \OCP\Share\IManager
- */
- private $shareManager;
-
- /**
- * @var \OCP\Files\Folder
- */
- private $userFolder;
-
- /**
- * @var \OCA\DAV\Connector\Sabre\SharesPlugin
- */
- private $plugin;
+ private \Sabre\DAV\Server $server;
+ private \Sabre\DAV\Tree&MockObject $tree;
+ private \OCP\Share\IManager&MockObject $shareManager;
+ private Folder&MockObject $userFolder;
+ private SharesPlugin $plugin;
protected function setUp(): void {
parent::setUp();
@@ -83,7 +45,7 @@ class SharesPluginTest extends \Test\TestCase {
->willReturn($user);
$this->userFolder = $this->createMock(Folder::class);
- $this->plugin = new \OCA\DAV\Connector\Sabre\SharesPlugin(
+ $this->plugin = new SharesPlugin(
$this->tree,
$userSession,
$this->userFolder,
@@ -92,13 +54,9 @@ class SharesPluginTest extends \Test\TestCase {
$this->plugin->initialize($this->server);
}
- /**
- * @dataProvider sharesGetPropertiesDataProvider
- */
- public function testGetProperties($shareTypes) {
- $sabreNode = $this->getMockBuilder(Node::class)
- ->disableOriginalConstructor()
- ->getMock();
+ #[\PHPUnit\Framework\Attributes\DataProvider('sharesGetPropertiesDataProvider')]
+ public function testGetProperties(array $shareTypes): void {
+ $sabreNode = $this->createMock(Node::class);
$sabreNode->expects($this->any())
->method('getId')
->willReturn(123);
@@ -107,9 +65,7 @@ class SharesPluginTest extends \Test\TestCase {
->willReturn('/subdir');
// node API nodes
- $node = $this->getMockBuilder(Folder::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $node = $this->createMock(Folder::class);
$sabreNode->method('getNode')
->willReturn($node);
@@ -119,7 +75,7 @@ class SharesPluginTest extends \Test\TestCase {
->with(
$this->equalTo('user1'),
$this->anything(),
- $this->anything(),
+ $this->equalTo($node),
$this->equalTo(false),
$this->equalTo(-1)
)
@@ -133,6 +89,16 @@ class SharesPluginTest extends \Test\TestCase {
return [];
});
+ $this->shareManager->expects($this->any())
+ ->method('getSharedWith')
+ ->with(
+ $this->equalTo('user1'),
+ $this->anything(),
+ $this->equalTo($node),
+ $this->equalTo(-1)
+ )
+ ->willReturn([]);
+
$propFind = new \Sabre\DAV\PropFind(
'/dummyPath',
[self::SHARETYPES_PROPERTYNAME],
@@ -151,10 +117,8 @@ class SharesPluginTest extends \Test\TestCase {
$this->assertEquals($shareTypes, $result[200][self::SHARETYPES_PROPERTYNAME]->getShareTypes());
}
- /**
- * @dataProvider sharesGetPropertiesDataProvider
- */
- public function testPreloadThenGetProperties($shareTypes) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('sharesGetPropertiesDataProvider')]
+ public function testPreloadThenGetProperties(array $shareTypes): void {
$sabreNode1 = $this->createMock(File::class);
$sabreNode1->method('getId')
->willReturn(111);
@@ -193,7 +157,7 @@ class SharesPluginTest extends \Test\TestCase {
->willReturn($node2);
$dummyShares = array_map(function ($type) {
- $share = $this->getMockBuilder(IShare::class)->getMock();
+ $share = $this->createMock(IShare::class);
$share->expects($this->any())
->method('getShareType')
->willReturn($type);
@@ -222,6 +186,16 @@ class SharesPluginTest extends \Test\TestCase {
});
$this->shareManager->expects($this->any())
+ ->method('getSharedWith')
+ ->with(
+ $this->equalTo('user1'),
+ $this->anything(),
+ $this->equalTo($node),
+ $this->equalTo(-1)
+ )
+ ->willReturn([]);
+
+ $this->shareManager->expects($this->any())
->method('getSharesInFolder')
->with(
$this->equalTo('user1'),
@@ -249,6 +223,7 @@ class SharesPluginTest extends \Test\TestCase {
0
);
+ $this->server->emit('preloadCollection', [$propFindRoot, $sabreNode]);
$this->plugin->handleGetProperties(
$propFindRoot,
$sabreNode
@@ -269,7 +244,7 @@ class SharesPluginTest extends \Test\TestCase {
$this->assertEquals($shareTypes, $result[200][self::SHARETYPES_PROPERTYNAME]->getShareTypes());
}
- public function sharesGetPropertiesDataProvider() {
+ public static function sharesGetPropertiesDataProvider(): array {
return [
[[]],
[[IShare::TYPE_USER]],
@@ -278,6 +253,7 @@ class SharesPluginTest extends \Test\TestCase {
[[IShare::TYPE_REMOTE]],
[[IShare::TYPE_ROOM]],
[[IShare::TYPE_DECK]],
+ [[IShare::TYPE_SCIENCEMESH]],
[[IShare::TYPE_USER, IShare::TYPE_GROUP]],
[[IShare::TYPE_USER, IShare::TYPE_GROUP, IShare::TYPE_LINK]],
[[IShare::TYPE_USER, IShare::TYPE_LINK]],
@@ -287,9 +263,7 @@ class SharesPluginTest extends \Test\TestCase {
}
public function testGetPropertiesSkipChunks(): void {
- $sabreNode = $this->getMockBuilder(UploadFile::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $sabreNode = $this->createMock(UploadFile::class);
$propFind = new \Sabre\DAV\PropFind(
'/dummyPath',