diff options
author | Vincent Petry <pvince81@owncloud.com> | 2015-04-30 12:22:57 +0200 |
---|---|---|
committer | Joas Schilling <nickvergessen@owncloud.com> | 2015-07-15 10:12:29 +0200 |
commit | 60939ebd2c38ebb372b6ed4b0546c46be7d2d5d1 (patch) | |
tree | 106b255ea523fbb64077b2b584d3c7916600c466 | |
parent | c73f938ff4d844d2a444835eb2c131b266fe1eb5 (diff) | |
download | nextcloud-server-60939ebd2c38ebb372b6ed4b0546c46be7d2d5d1.tar.gz nextcloud-server-60939ebd2c38ebb372b6ed4b0546c46be7d2d5d1.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
-rw-r--r-- | apps/files_sharing/tests/share.php | 127 |
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', + ], + ], + ]; + } + } |