summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2015-04-30 12:22:57 +0200
committerJoas Schilling <nickvergessen@owncloud.com>2015-07-07 11:06:11 +0200
commit547c4b9a9f48d82f4b8905b13afbda5f923b25e0 (patch)
treedf1738227560e23ee9e3b100fc7182773a894538 /apps/files_sharing
parent8294ad71fcbf69960b7d6009f077ceb3c6d00168 (diff)
downloadnextcloud-server-547c4b9a9f48d82f4b8905b13afbda5f923b25e0.tar.gz
nextcloud-server-547c4b9a9f48d82f4b8905b13afbda5f923b25e0.zip
Add unit test for getUsersSharingFile
This is to test if the user list and paths are correct, even when a recipient renamed the received shared folder
Diffstat (limited to 'apps/files_sharing')
-rw-r--r--apps/files_sharing/tests/share.php127
1 files changed, 127 insertions, 0 deletions
diff --git a/apps/files_sharing/tests/share.php b/apps/files_sharing/tests/share.php
index 0759d0015bd..ec0e21fbf80 100644
--- a/apps/files_sharing/tests/share.php
+++ b/apps/files_sharing/tests/share.php
@@ -321,4 +321,131 @@ class Test_Files_Sharing extends OCA\Files_sharing\Tests\TestCase {
);
}
+ /**
+ * @dataProvider dataProviderGetUsersSharingFile
+ *
+ * @param string $groupName name of group to share with
+ * @param bool $includeOwner whether to include the owner in the result
+ * @param bool $includePaths whether to include paths in the result
+ * @param array $expectedResult expected result of the API call
+ */
+ function testGetUsersSharingFile($groupName, $includeOwner, $includePaths, $expectedResult) {
+
+ $fileinfo = $this->view->getFileInfo($this->folder);
+
+ $result = \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP,
+ $groupName, \OCP\Constants::PERMISSION_READ);
+ $this->assertTrue($result);
+
+ // public share
+ $result = \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_LINK,
+ null, \OCP\Constants::PERMISSION_READ);
+ $this->assertNotNull($result); // returns the token!
+
+ self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
+
+ $user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
+ $user2View->rename($this->folder, $this->folder . '_renamed');
+
+ $ownerPath = $this->folder;
+ $owner = self::TEST_FILES_SHARING_API_USER1;
+
+ $result = \OCP\Share::getUsersSharingFile($ownerPath, $owner, $includeOwner, $includePaths);
+
+ // sort users to make sure it matches
+ if ($includePaths) {
+ ksort($result);
+ } else {
+ sort($result['users']);
+ }
+
+ $this->assertEquals(
+ $expectedResult,
+ $result
+ );
+ }
+
+ function dataProviderGetUsersSharingFile() {
+ // note: "group" contains user1 (the owner), user2 and user3
+ // and self::TEST_FILES_SHARING_API_GROUP1 contains only user2
+ return [
+ // share with group that contains owner
+ [
+ 'group',
+ false,
+ false,
+ [
+ 'users' =>
+ [
+ // because user1 was in group
+ self::TEST_FILES_SHARING_API_USER1,
+ self::TEST_FILES_SHARING_API_USER2,
+ self::TEST_FILES_SHARING_API_USER3,
+ ],
+ 'public' => true,
+ 'remote' => false,
+ ],
+ ],
+ // share with group that does not contain owner
+ [
+ self::TEST_FILES_SHARING_API_GROUP1,
+ false,
+ false,
+ [
+ 'users' =>
+ [
+ self::TEST_FILES_SHARING_API_USER2,
+ ],
+ 'public' => true,
+ 'remote' => false,
+ ],
+ ],
+ // share with group that does not contain owner, include owner
+ [
+ self::TEST_FILES_SHARING_API_GROUP1,
+ true,
+ false,
+ [
+ 'users' =>
+ [
+ self::TEST_FILES_SHARING_API_USER1,
+ self::TEST_FILES_SHARING_API_USER2,
+ ],
+ 'public' => true,
+ 'remote' => false,
+ ],
+ ],
+ // include paths, with owner
+ [
+ 'group',
+ true,
+ true,
+ [
+ self::TEST_FILES_SHARING_API_USER1 => self::TEST_FOLDER_NAME,
+ self::TEST_FILES_SHARING_API_USER2 => self::TEST_FOLDER_NAME. '_renamed',
+ self::TEST_FILES_SHARING_API_USER3 => self::TEST_FOLDER_NAME,
+ ],
+ ],
+ // include paths, group without owner
+ [
+ self::TEST_FILES_SHARING_API_GROUP1,
+ false,
+ true,
+ [
+ self::TEST_FILES_SHARING_API_USER2 => self::TEST_FOLDER_NAME. '_renamed',
+ ],
+ ],
+ // include paths, include owner, group without owner
+ [
+ self::TEST_FILES_SHARING_API_GROUP1,
+ true,
+ true,
+ [
+ self::TEST_FILES_SHARING_API_USER1 => self::TEST_FOLDER_NAME,
+ self::TEST_FILES_SHARING_API_USER2 => self::TEST_FOLDER_NAME. '_renamed',
+ ],
+ ],
+ ];
+ }
+
}