]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add defaultShareProvider & federatedshareprovider tests 339/head
authorRoeland Jago Douma <roeland@famdouma.nl>
Tue, 1 Nov 2016 12:22:52 +0000 (13:22 +0100)
committerRoeland Jago Douma <roeland@famdouma.nl>
Tue, 1 Nov 2016 12:52:37 +0000 (13:52 +0100)
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
apps/federatedfilesharing/tests/FederatedShareProviderTest.php
tests/lib/Share20/DefaultShareProviderTest.php

index e4c234fd03819264a9c93faf513c911d3d85b59b..92f6ac5e99679ba87792fd4291e93fcade84e517 100644 (file)
@@ -702,4 +702,49 @@ class FederatedShareProviderTest extends \Test\TestCase {
                        ['no', false]
                ];
        }
+
+       public function testGetSharesInFolder() {
+               $userManager = \OC::$server->getUserManager();
+               $rootFolder = \OC::$server->getRootFolder();
+
+               $u1 = $userManager->createUser('testFed', 'test');
+               $u2 = $userManager->createUser('testFed2', 'test');
+
+               $folder1 = $rootFolder->getUserFolder($u1->getUID())->newFolder('foo');
+               $file1 = $folder1->newFile('bar1');
+               $file2 = $folder1->newFile('bar2');
+
+               $this->tokenHandler->method('generateToken')->willReturn('token');
+               $this->notifications
+                       ->method('sendRemoteShare')
+                       ->willReturn(true);
+
+               $share1 = $this->shareManager->newShare();
+               $share1->setSharedWith('user@server.com')
+                       ->setSharedBy($u1->getUID())
+                       ->setShareOwner($u1->getUID())
+                       ->setPermissions(\OCP\Constants::PERMISSION_READ)
+                       ->setNode($file1);
+               $this->provider->create($share1);
+
+               $share2 = $this->shareManager->newShare();
+               $share2->setSharedWith('user@server.com')
+                       ->setSharedBy($u2->getUID())
+                       ->setShareOwner($u1->getUID())
+                       ->setPermissions(\OCP\Constants::PERMISSION_READ)
+                       ->setNode($file2);
+               $this->provider->create($share2);
+
+               $result = $this->provider->getSharesInFolder($u1->getUID(), $folder1, false);
+               $this->assertCount(1, $result);
+               $this->assertCount(1, $result[$file1->getId()]);
+
+               $result = $this->provider->getSharesInFolder($u1->getUID(), $folder1, true);
+               $this->assertCount(2, $result);
+               $this->assertCount(1, $result[$file1->getId()]);
+               $this->assertCount(1, $result[$file2->getId()]);
+
+               $u1->delete();
+               $u2->delete();
+       }
 }
index 778c1cb5722c8fe9c8715a3ac3d412f0590b45fa..5870da8d2188f924f497c5306b362e665ff974fb 100644 (file)
@@ -2298,4 +2298,95 @@ 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();
+
+               $provider = new DefaultShareProvider(
+                       $this->dbConn,
+                       $userManager,
+                       $groupManager,
+                       $rootFolder
+               );
+
+               $u1 = $userManager->createUser('testShare1', 'test');
+               $u2 = $userManager->createUser('testShare2', 'test');
+               $u3 = $userManager->createUser('testShare3', 'test');
+
+               $g1 = $groupManager->createGroup('group1');
+
+               $u1Folder = $rootFolder->getUserFolder($u1->getUID());
+               $folder1 = $u1Folder->newFolder('foo');
+               $file1 = $folder1->newFile('bar');
+               $folder2 = $folder1->newFolder('baz');
+
+               $shareManager = \OC::$server->getShareManager();
+               $share1 = $shareManager->newShare();
+               $share1->setNode($folder1)
+                       ->setSharedBy($u1->getUID())
+                       ->setSharedWith($u2->getUID())
+                       ->setShareOwner($u1->getUID())
+                       ->setShareType(\OCP\Share::SHARE_TYPE_USER)
+                       ->setPermissions(\OCP\Constants::PERMISSION_ALL);
+               $share1 = $this->provider->create($share1);
+
+               $share2 = $shareManager->newShare();
+               $share2->setNode($file1)
+                       ->setSharedBy($u2->getUID())
+                       ->setSharedWith($u3->getUID())
+                       ->setShareOwner($u1->getUID())
+                       ->setShareType(\OCP\Share::SHARE_TYPE_USER)
+                       ->setPermissions(\OCP\Constants::PERMISSION_READ);
+               $share2 = $this->provider->create($share2);
+
+               $share3 = $shareManager->newShare();
+               $share3->setNode($folder2)
+                       ->setSharedBy($u2->getUID())
+                       ->setShareOwner($u1->getUID())
+                       ->setShareType(\OCP\Share::SHARE_TYPE_LINK)
+                       ->setPermissions(\OCP\Constants::PERMISSION_READ);
+               $share3 = $this->provider->create($share3);
+
+               $share4 = $shareManager->newShare();
+               $share4->setNode($folder2)
+                       ->setSharedBy($u1->getUID())
+                       ->setSharedWith($g1->getGID())
+                       ->setShareOwner($u1->getUID())
+                       ->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
+                       ->setPermissions(\OCP\Constants::PERMISSION_READ);
+               $share4 = $this->provider->create($share4);
+
+               $result = $provider->getSharesInFolder($u1->getUID(), $folder1, false);
+               $this->assertCount(1, $result);
+               $shares = array_pop($result);
+               $this->assertCount(1, $shares);
+               $this->assertSame($folder2->getId(), $shares[0]->getNodeId());
+
+               $result = $provider->getSharesInFolder($u1->getUID(), $folder1, true);
+               $this->assertCount(2, $result);
+
+               $file_shares = $result[$file1->getId()];
+               $this->assertCount(1, $file_shares);
+               $this->assertSame($file1->getId(), $file_shares[0]->getNodeId());
+               $this->assertSame(\OCP\Share::SHARE_TYPE_USER, $file_shares[0]->getShareType());
+
+               $folder_shares = $result[$folder2->getId()];
+               $this->assertCount(2, $folder_shares);
+               $this->assertSame($folder2->getId(), $folder_shares[0]->getNodeId());
+               $this->assertSame($folder2->getId(), $folder_shares[1]->getNodeId());
+               $this->assertSame(\OCP\Share::SHARE_TYPE_LINK, $folder_shares[0]->getShareType());
+               $this->assertSame(\OCP\Share::SHARE_TYPE_GROUP, $folder_shares[1]->getShareType());
+
+               $provider->delete($share1);
+               $provider->delete($share2);
+               $provider->delete($share3);
+               $provider->delete($share4);
+
+               $u1->delete();
+               $u2->delete();
+               $u3->delete();
+               $g1->delete();
+       }
 }