diff --git a/tests/lib/Share/GetUsersSharingFileTest.php b/tests/lib/Share/GetUsersSharingFileTest.php index 86e7be483bb9..60768b738ba8 100644 --- a/tests/lib/Share/GetUsersSharingFileTest.php +++ b/tests/lib/Share/GetUsersSharingFileTest.php @@ -1,8 +1,9 @@ getShareManager(); $share = $sm->newShare(); $share->setSharedBy($owner->getUID()); @@ -54,6 +56,20 @@ private static function shareWithUser(File $file, IUser $user, IUser $owner): IS return $sm->createShare($share); } + /** + * @throws GenericShareException + */ + private static function shareByLink(File $file, IUser $owner): IShare { + $sm = OC::$server->getShareManager(); + $share = $sm->newShare(); + $share->setSharedBy($owner->getUID()); + $share->setNode($file); + $share->setShareType(Constants::SHARE_TYPE_LINK); + $share->setPermissions(OCConstants::PERMISSION_READ); + + return $sm->createShare($share); + } + /** * @see https://github.com/owncloud/activity/issues/1143 * @throws NotPermittedException @@ -69,15 +85,17 @@ public function testGroupShare() : void { self::loginAsUser($alice->getUID()); $aliceFolder = OC::$server->getUserFolder($alice->getUID()); $file = self::createFileWithContent($aliceFolder, 'welcome.txt', 'loram ipsum'); - $share = self::shareWithGroup($file, $group, $alice); + self::shareWithGroup($file, $group, $alice); # test + self::trackQueries(); $result = Share::getUsersSharingFile('welcome.txt', $alice->getUID()); assertEquals([ 'users' => ['alice', 'bob'], 'public' => false, 'remote' => false ], $result); + #$this->assertQueryCountLessThan(9); } /** @@ -96,16 +114,18 @@ public function testRejected() : void { $share = self::shareWithUser($file, $bob, $alice); # test accepted + self::trackQueries(); $result = Share::getUsersSharingFile('welcome.txt', $alice->getUID()); assertEquals([ 'users' => ['bob'], 'public' => false, 'remote' => false ], $result); + #$this->assertQueryCountMatches(7); - # tst rejected + # test rejected $share->setState(Constants::STATE_REJECTED); - \OC::$server->getShareManager()->updateShare($share); + OC::$server->getShareManager()->updateShare($share); $result = Share::getUsersSharingFile('welcome.txt', $alice->getUID()); assertEquals([ @@ -114,4 +134,101 @@ public function testRejected() : void { 'remote' => false ], $result); } + + /** + * @throws NotPermittedException + * @throws NoUserException + * @throws GenericShareException + */ + public function testPublicLink(): void { + # setup + $alice = $this->createUser('alice'); + + self::loginAsUser($alice->getUID()); + $aliceFolder = OC::$server->getUserFolder($alice->getUID()); + $file = self::createFileWithContent($aliceFolder, 'welcome.txt', 'loram ipsum'); + self::shareByLink($file, $alice); + + # test + self::trackQueries(); + $result = Share::getUsersSharingFile('welcome.txt', $alice->getUID()); + assertEquals([ + 'users' => [], + 'public' => true, + 'remote' => false + ], $result); + #$this->assertQueryCountMatches(7); + } + + /** + * @throws NotPermittedException + * @throws NoUserException + * @throws GenericShareException + */ + public function testRecursive() : void { + # setup + $alice = $this->createUser('alice'); + $bob = $this->createUser('bob'); + + self::loginAsUser($alice->getUID()); + $aliceFolder = OC::$server->getUserFolder($alice->getUID()); + $fooFolder = $aliceFolder->newFolder('foo'); + self::createFileWithContent($fooFolder, 'welcome.txt', 'loram ipsum'); + self::shareWithUser($fooFolder, $bob, $alice); + + # test recursive + $result = Share::getUsersSharingFile('foo/welcome.txt', $alice->getUID()); + assertEquals([ + 'users' => ['bob'], + 'public' => false, + 'remote' => false + ], $result); + + # test recursive + self::trackQueries(); + $result = Share::getUsersSharingFile('foo/welcome.txt', $alice->getUID(), false, false, false); + assertEquals([ + 'users' => [], + 'public' => false, + 'remote' => false + ], $result); + #$this->assertQueryCountMatches(4); + } + + /** + * @throws NotPermittedException + * @throws NoUserException + * @throws GenericShareException + */ + public function testIncludeOwner() : void { + self::assertTrue(Share::isEnabled()); + # setup + $alice = $this->createUser('alice'); + $bob = $this->createUser('bob'); + + self::loginAsUser($alice->getUID()); + $aliceFolder = OC::$server->getUserFolder($alice->getUID()); + $fooFolder = $aliceFolder->newFolder('foo'); + self::createFileWithContent($fooFolder, 'welcome.txt', 'loram ipsum'); + self::shareWithUser($fooFolder, $bob, $alice); + + self::trackQueries(); + $result = Share::getUsersSharingFile('foo/welcome.txt', $alice->getUID(), true, true); + assertEquals([ + 'bob' => '/foo/welcome.txt', + 'alice' => '/foo/welcome.txt', + ], $result); + # in some cases there is an additional query required because Cache::$path_cache is not holding the path in question + #$this->assertQueryCountLessThan(11); + + # let's see how bob is doing .... + self::loginAsUser($bob->getUID()); + self::trackQueries(); + $result = Share::getUsersSharingFile('foo/welcome.txt', $bob->getUID(), true, true); + assertEquals([ + 'bob' => '/foo/welcome.txt', + ], $result); + # in some cases there is an additional query required because Cache::$path_cache is not holding the path in question + #$this->assertQueryCountLessThan(11); + } }