aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/tests/Collaboration
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_sharing/tests/Collaboration')
-rw-r--r--apps/files_sharing/tests/Collaboration/ShareRecipientSorterTest.php174
1 files changed, 75 insertions, 99 deletions
diff --git a/apps/files_sharing/tests/Collaboration/ShareRecipientSorterTest.php b/apps/files_sharing/tests/Collaboration/ShareRecipientSorterTest.php
index ed35c81fb7d..572463a9ebc 100644
--- a/apps/files_sharing/tests/Collaboration/ShareRecipientSorterTest.php
+++ b/apps/files_sharing/tests/Collaboration/ShareRecipientSorterTest.php
@@ -1,26 +1,8 @@
<?php
+
/**
- * @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * 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
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files_Sharing\Tests\Collaboration;
@@ -34,13 +16,13 @@ use OCP\Share\IManager;
use Test\TestCase;
class ShareRecipientSorterTest extends TestCase {
- /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
protected $shareManager;
- /** @var IRootFolder|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IRootFolder|\PHPUnit\Framework\MockObject\MockObject */
protected $rootFolder;
- /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
protected $userSession;
- /** @var ShareRecipientSorter */
+ /** @var ShareRecipientSorter */
protected $sorter;
protected function setUp(): void {
@@ -54,10 +36,10 @@ class ShareRecipientSorterTest extends TestCase {
}
/**
- * @dataProvider sortDataProvider
* @param $data
*/
- public function testSort($data) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('sortDataProvider')]
+ public function testSort($data): void {
$node = $this->createMock(Node::class);
/** @var Folder|\PHPUnit\Framework\MockObject\MockObject $folder */
@@ -77,9 +59,9 @@ class ShareRecipientSorterTest extends TestCase {
if ($data['context']['itemType'] === 'files') {
$folder->expects($this->once())
- ->method('getById')
+ ->method('getFirstNodeById')
->with($data['context']['itemId'])
- ->willReturn([$node]);
+ ->willReturn($node);
$this->shareManager->expects($this->once())
->method('getAccessList')
@@ -87,7 +69,7 @@ class ShareRecipientSorterTest extends TestCase {
->willReturn($data['accessList']);
} else {
$folder->expects($this->never())
- ->method('getById');
+ ->method('getFirstNodeById');
$this->shareManager->expects($this->never())
->method('getAccessList');
}
@@ -98,7 +80,7 @@ class ShareRecipientSorterTest extends TestCase {
$this->assertEquals($data['expected'], $workArray);
}
- public function testSortNoNodes() {
+ public function testSortNoNodes(): void {
/** @var Folder|\PHPUnit\Framework\MockObject\MockObject $folder */
$folder = $this->createMock(Folder::class);
$this->rootFolder->expects($this->any())
@@ -106,8 +88,8 @@ class ShareRecipientSorterTest extends TestCase {
->willReturn($folder);
$folder->expects($this->once())
- ->method('getById')
- ->willReturn([]);
+ ->method('getFirstNodeById')
+ ->willReturn(null);
$user = $this->createMock(IUser::class);
$user->expects($this->any())
@@ -128,44 +110,42 @@ class ShareRecipientSorterTest extends TestCase {
]
];
$workArray = $originalArray;
- $this->sorter->sort($workArray, ['itemType' => 'files', 'itemId' => 404]);
+ $this->sorter->sort($workArray, ['itemType' => 'files', 'itemId' => '404']);
$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],
+ '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']],
@@ -174,35 +154,33 @@ class ShareRecipientSorterTest extends TestCase {
],
[
#1 – no recipients
- 'context' => ['itemType' => 'files', 'itemId' => 42],
+ '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']],
@@ -211,35 +189,33 @@ class ShareRecipientSorterTest extends TestCase {
],
[
#2 – unsupported item type
- 'context' => ['itemType' => 'announcements', 'itemId' => 42],
+ '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']],
@@ -248,7 +224,7 @@ class ShareRecipientSorterTest extends TestCase {
],
[
#3 – no nothing
- 'context' => ['itemType' => 'files', 'itemId' => 42],
+ 'context' => ['itemType' => 'files', 'itemId' => '42'],
'accessList' => [],
'input' => [],
'expected' => [],