From f2c7ca45840d20a8b6c40937958f4e5a8953d0dd Mon Sep 17 00:00:00 2001
From: Maxence Lange <maxence@artificial-owl.com>
Date: Mon, 2 Dec 2019 18:16:33 -0100
Subject: [PATCH] fixing tests + avoid duplicate in getFormattedShares()

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
---
 .../lib/Controller/ShareAPIController.php             | 11 +++++++----
 .../tests/Controller/ShareAPIControllerTest.php       | 11 ++++++-----
 2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php
index 208ea79c2ae..1dac86a9514 100644
--- a/apps/files_sharing/lib/Controller/ShareAPIController.php
+++ b/apps/files_sharing/lib/Controller/ShareAPIController.php
@@ -759,15 +759,18 @@ class ShareAPIController extends OCSController {
 
 		$shares = $this->getSharesFromNode($viewer, $node, $reShares);
 
-		$formatted = $miniFormatted = [];
+		$known = $formatted = $miniFormatted = [];
 		$resharingRight = false;
 		foreach ($shares as $share) {
+			if (in_array($share->getId(), $known) || $share->getSharedWith() === $this->currentUser) {
+				continue;
+			}
+
+			$known[] = $share->getId();
 			try {
 				/** @var IShare $share */
 				$format = $this->formatShare($share, $node);
-				if ($share->getSharedWith() !== $this->currentUser) {
-					$formatted[] = $format;
-				}
+				$formatted[] = $format;
 
 				// let's also build a list of shares created
 				// by the current user only, in case
diff --git a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
index ae7fc54599c..90238d64274 100644
--- a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
+++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
@@ -106,6 +106,9 @@ class ShareAPIControllerTest extends TestCase {
 			->expects($this->any())
 			->method('shareApiEnabled')
 			->willReturn(true);
+		$this->shareManager
+			->expects($this->any())
+		->method('shareProviderExists')->willReturn(true);
 		$this->groupManager = $this->createMock(IGroupManager::class);
 		$this->userManager = $this->createMock(IUserManager::class);
 		$this->request = $this->createMock(IRequest::class);
@@ -170,10 +173,10 @@ class ShareAPIControllerTest extends TestCase {
 		$this->expectExceptionMessage('Wrong share ID, share doesn\'t exist');
 
 		$this->shareManager
-			->expects($this->exactly(3))
+			->expects($this->exactly(5))
 			->method('getShareById')
 			->will($this->returnCallback(function($id) {
-				if ($id === 'ocinternal:42' || $id === 'ocRoomShare:42' || $id === 'ocFederatedSharing:42') {
+				if ($id === 'ocinternal:42' || $id === 'ocRoomShare:42' || $id === 'ocFederatedSharing:42' || $id === 'ocCircleShare:42' || $id === 'ocMailShare:42') {
 					throw new \OCP\Share\Exceptions\ShareNotFound();
 				} else {
 					throw new \Exception();
@@ -1008,9 +1011,7 @@ class ShareAPIControllerTest extends TestCase {
 				[
 				],
 				[
-					$file1UserShareOwnerExpected,
-					$file1UserShareOwnerExpected,
-					$file1UserShareOwnerExpected,
+					$file1UserShareOwnerExpected
 				]
 			],
 			[
-- 
GitLab