]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add unit tests for getting shares of a file
authorDaniel Calviño Sánchez <danxuliu@gmail.com>
Fri, 25 Oct 2019 08:02:06 +0000 (10:02 +0200)
committerDaniel Calviño Sánchez <danxuliu@gmail.com>
Fri, 25 Oct 2019 19:39:45 +0000 (21:39 +0200)
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
apps/files_sharing/tests/Controller/ShareAPIControllerTest.php

index 5fd5e7c4a46774b4e1b09b32b55fa25b8fb79241..4fda1aa41566121efc60ce9a5c9d027348281110 100644 (file)
@@ -833,6 +833,11 @@ class ShareAPIControllerTest extends TestCase {
                        ->setNode($file1)
                        ->setId(15);
 
+               $file1UserShareRecipientExpected = [
+                       'id' => 15,
+                       'share_type' => IShare::TYPE_USER,
+               ];
+
                $file1UserShareOther = \OC::$server->getShareManager()->newShare();
                $file1UserShareOther->setShareType(IShare::TYPE_USER)
                        ->setSharedWith('recipient')
@@ -912,6 +917,20 @@ class ShareAPIControllerTest extends TestCase {
                        'share_type' => IShare::TYPE_EMAIL,
                ];
 
+               $file1CircleShareOwner = \OC::$server->getShareManager()->newShare();
+               $file1CircleShareOwner->setShareType(IShare::TYPE_CIRCLE)
+                       ->setSharedWith('recipient')
+                       ->setSharedBy('initiator')
+                       ->setShareOwner('currentUser')
+                       ->setPermissions(\OCP\Constants::PERMISSION_READ)
+                       ->setNode($file1)
+                       ->setId(423);
+
+               $file1CircleShareOwnerExpected = [
+                       'id' => 423,
+                       'share_type' => IShare::TYPE_CIRCLE,
+               ];
+
                $file1RoomShareOwner = \OC::$server->getShareManager()->newShare();
                $file1RoomShareOwner->setShareType(IShare::TYPE_ROOM)
                        ->setSharedWith('recipient')
@@ -919,10 +938,10 @@ class ShareAPIControllerTest extends TestCase {
                        ->setShareOwner('currentUser')
                        ->setPermissions(\OCP\Constants::PERMISSION_READ)
                        ->setNode($file1)
-                       ->setId(423);
+                       ->setId(442);
 
                $file1RoomShareOwnerExpected = [
-                       'id' => 423,
+                       'id' => 442,
                        'share_type' => IShare::TYPE_ROOM,
                ];
 
@@ -933,13 +952,27 @@ class ShareAPIControllerTest extends TestCase {
                        ->setShareOwner('currentUser')
                        ->setPermissions(\OCP\Constants::PERMISSION_READ)
                        ->setNode($file1)
-                       ->setId(442);
+                       ->setId(815);
 
                $file1RemoteShareOwnerExpected = [
-                       'id' => 442,
+                       'id' => 815,
                        'share_type' => IShare::TYPE_REMOTE,
                ];
 
+               $file1RemoteGroupShareOwner = \OC::$server->getShareManager()->newShare();
+               $file1RemoteGroupShareOwner->setShareType(IShare::TYPE_REMOTE_GROUP)
+                       ->setSharedWith('recipient')
+                       ->setSharedBy('initiator')
+                       ->setShareOwner('currentUser')
+                       ->setPermissions(\OCP\Constants::PERMISSION_READ)
+                       ->setNode($file1)
+                       ->setId(816);
+
+               $file1RemoteGroupShareOwnerExpected = [
+                       'id' => 816,
+                       'share_type' => IShare::TYPE_REMOTE_GROUP,
+               ];
+
                $file2UserShareOwner = \OC::$server->getShareManager()->newShare();
                $file2UserShareOwner->setShareType(IShare::TYPE_USER)
                        ->setSharedWith('recipient')
@@ -947,14 +980,155 @@ class ShareAPIControllerTest extends TestCase {
                        ->setShareOwner('currentUser')
                        ->setPermissions(\OCP\Constants::PERMISSION_READ)
                        ->setNode($file2)
-                       ->setId(815);
+                       ->setId(823);
 
                $file2UserShareOwnerExpected = [
-                       'id' => 815,
+                       'id' => 823,
                        'share_type' => IShare::TYPE_USER,
                ];
 
                $data = [
+                       [
+                               [
+                                       'path' => $file1,
+                               ],
+                               [
+                                       'file1' => [
+                                               IShare::TYPE_USER => [$file1UserShareOwner, $file1UserShareOwner, $file1UserShareOwner],
+                                       ],
+                               ],
+                               [
+                               ],
+                               [
+                                       $file1UserShareOwnerExpected,
+                                       $file1UserShareOwnerExpected,
+                                       $file1UserShareOwnerExpected,
+                               ]
+                       ],
+                       [
+                               [
+                                       'path' => $file1,
+                               ],
+                               [
+                                       'file1' => [
+                                               IShare::TYPE_USER => [$file1UserShareOwner, $file1UserShareRecipient],
+                                       ],
+                               ],
+                               [
+                               ],
+                               [
+                                       $file1UserShareOwnerExpected,
+                                       $file1UserShareRecipientExpected,
+                               ]
+                       ],
+                       [
+                               [
+                                       'path' => $file1,
+                               ],
+                               [
+                                       'file1' => [
+                                               IShare::TYPE_USER => [$file1UserShareOwner, $file1UserShareRecipient, $file1UserShareInitiator, $file1UserShareOther],
+                                       ],
+                               ],
+                               [
+                               ],
+                               [
+                                       $file1UserShareOwnerExpected,
+                                       $file1UserShareRecipientExpected,
+                                       $file1UserShareInitiatorExpected,
+                                       $file1UserShareOtherExpected,
+                               ]
+                       ],
+                       [
+                               [
+                                       'path' => $file1,
+                               ],
+                               [
+                                       'file1' => [
+                                               IShare::TYPE_USER => [$file1UserShareRecipient, $file1UserShareInitiator, $file1UserShareOther],
+                                       ],
+                               ],
+                               [
+                               ],
+                               [
+                                       $file1UserShareInitiatorExpected,
+                               ]
+                       ],
+                       [
+                               [
+                                       'path' => $file1,
+                               ],
+                               [
+                                       'file1' => [
+                                               IShare::TYPE_USER => [$file1UserShareOwner],
+                                               IShare::TYPE_GROUP => [$file1GroupShareRecipient],
+                                       ],
+                               ],
+                               [
+                               ],
+                               [
+                                       $file1UserShareOwnerExpected,
+                                       $file1GroupShareRecipientExpected,
+                               ]
+                       ],
+                       [
+                               [
+                                       'path' => $file1,
+                               ],
+                               [
+                                       'file1' => [
+                                               IShare::TYPE_USER => [$file1UserShareOwner],
+                                               IShare::TYPE_GROUP => [$file1GroupShareOwner],
+                                               IShare::TYPE_LINK => [$file1LinkShareOwner],
+                                               IShare::TYPE_EMAIL => [$file1EmailShareOwner],
+                                               IShare::TYPE_CIRCLE => [$file1CircleShareOwner],
+                                               IShare::TYPE_ROOM => [$file1RoomShareOwner],
+                                               IShare::TYPE_REMOTE => [$file1RemoteShareOwner],
+                                               IShare::TYPE_REMOTE_GROUP => [$file1RemoteGroupShareOwner],
+                                       ],
+                               ],
+                               [
+                               ],
+                               [
+                                       $file1UserShareOwnerExpected,
+                                       $file1GroupShareOwnerExpected,
+                                       $file1LinkShareOwnerExpected,
+                                       $file1RoomShareOwnerExpected,
+                               ]
+                       ],
+                       [
+                               [
+                                       'path' => $file1,
+                               ],
+                               [
+                                       'file1' => [
+                                               IShare::TYPE_USER => [$file1UserShareOwner],
+                                               IShare::TYPE_GROUP => [$file1GroupShareOwner],
+                                               IShare::TYPE_LINK => [$file1LinkShareOwner],
+                                               IShare::TYPE_EMAIL => [$file1EmailShareOwner],
+                                               IShare::TYPE_CIRCLE => [$file1CircleShareOwner],
+                                               IShare::TYPE_ROOM => [$file1RoomShareOwner],
+                                               IShare::TYPE_REMOTE => [$file1RemoteShareOwner],
+                                               IShare::TYPE_REMOTE_GROUP => [$file1RemoteGroupShareOwner],
+                                       ],
+                               ],
+                               [
+                                       IShare::TYPE_EMAIL => true,
+                                       IShare::TYPE_CIRCLE => true,
+                                       IShare::TYPE_REMOTE => true,
+                                       IShare::TYPE_REMOTE_GROUP => true,
+                               ],
+                               [
+                                       $file1UserShareOwnerExpected,
+                                       $file1GroupShareOwnerExpected,
+                                       $file1LinkShareOwnerExpected,
+                                       $file1EmailShareOwnerExpected,
+                                       $file1CircleShareOwnerExpected,
+                                       $file1RoomShareOwnerExpected,
+                                       $file1RemoteShareOwnerExpected,
+                                       $file1RemoteGroupShareOwnerExpected,
+                               ]
+                       ],
                        [
                                [
                                        'path' => $folder,
@@ -1177,6 +1351,7 @@ class ShareAPIControllerTest extends TestCase {
 
                $shareProviderExistsMap = [
                        [IShare::TYPE_EMAIL, $extraShareTypes[IShare::TYPE_EMAIL] ?? false],
+                       [IShare::TYPE_CIRCLE, $extraShareTypes[IShare::TYPE_CIRCLE] ?? false],
                ];
 
                $this->shareManager
@@ -1187,6 +1362,10 @@ class ShareAPIControllerTest extends TestCase {
                        ->method('outgoingServer2ServerSharesAllowed')
                        ->willReturn($extraShareTypes[ISHARE::TYPE_REMOTE] ?? false);
 
+               $this->shareManager
+                       ->method('outgoingServer2ServerGroupSharesAllowed')
+                       ->willReturn($extraShareTypes[ISHARE::TYPE_REMOTE_GROUP] ?? false);
+
                $this->groupManager
                        ->method('isInGroup')
                        ->will($this->returnCallback(