diff options
author | Joas Schilling <nickvergessen@owncloud.com> | 2015-08-17 12:43:20 +0200 |
---|---|---|
committer | Joas Schilling <nickvergessen@owncloud.com> | 2015-08-26 11:54:25 +0200 |
commit | 6b69e7b1dae71601db8486df4c30ab9d73419694 (patch) | |
tree | 6fdd1dc4367fd97f6e631e127e21ccef6bfc8ebc /apps/files_sharing | |
parent | 83b88c9a264a46f393df95e6c57793f0300495da (diff) | |
download | nextcloud-server-6b69e7b1dae71601db8486df4c30ab9d73419694.tar.gz nextcloud-server-6b69e7b1dae71601db8486df4c30ab9d73419694.zip |
Add tests for "getShareesForShareIds()"
Diffstat (limited to 'apps/files_sharing')
-rw-r--r-- | apps/files_sharing/tests/api/sharees.php | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/apps/files_sharing/tests/api/sharees.php b/apps/files_sharing/tests/api/sharees.php index 9b7a21b0635..675cc7bede0 100644 --- a/apps/files_sharing/tests/api/sharees.php +++ b/apps/files_sharing/tests/api/sharees.php @@ -21,6 +21,8 @@ namespace OCA\Files_Sharing\Tests\API; +use Doctrine\DBAL\Connection; +use OC\Share\Constants; use OCA\Files_Sharing\API\Sharees; use OCA\Files_sharing\Tests\TestCase; @@ -781,6 +783,97 @@ class ShareesTest extends TestCase { $this->assertEquals($expectedSharees, $this->invokePrivate($this->sharees, 'filterSharees', [$potentialSharees, $existingSharees])); } + public function dataGetShareesForShareIds() { + return [ + [[], []], + [[1, 2, 3], [Constants::SHARE_TYPE_USER => ['user1'], Constants::SHARE_TYPE_GROUP => ['group1']]], + ]; + } + + /** + * @dataProvider dataGetShareesForShareIds + * + * @param array $shareIds + * @param array $expectedSharees + */ + public function testGetShareesForShareIds(array $shareIds, array $expectedSharees) { + $owner = $this->getUniqueID('test'); + $shares2delete = []; + + if (!empty($shareIds)) { + $userShare = $this->createShare(Constants::SHARE_TYPE_USER, 'user1', $owner, null); + $shares2delete[] = $userShare; + $shares2delete[] = $this->createShare(Constants::SHARE_TYPE_USER, 'user3', $owner . '2', null); + + $groupShare = $this->createShare(Constants::SHARE_TYPE_GROUP, 'group1', $owner, null); + $shares2delete[] = $groupShare; + $groupShare2 = $this->createShare(Constants::SHARE_TYPE_GROUP, 'group2', $owner . '2', null); + $shares2delete[] = $groupShare2; + + $shares2delete[] = $this->createShare($this->invokePrivate(new Constants(), 'shareTypeGroupUserUnique'), 'user2', $owner, $groupShare); + $shares2delete[] = $this->createShare($this->invokePrivate(new Constants(), 'shareTypeGroupUserUnique'), 'user4', $owner, $groupShare2); + } + + $user = $this->getUserMock($owner, 'Sharee OCS test user'); + $this->session->expects($this->any()) + ->method('getUser') + ->willReturn($user); + $this->assertEquals($expectedSharees, $this->invokePrivate($this->sharees, 'getShareesForShareIds', [$shares2delete])); + + $this->deleteShares($shares2delete); + } + + /** + * @param int $type + * @param string $with + * @param string $owner + * @param int $parent + * @return int + */ + protected function createShare($type, $with, $owner, $parent) { + $connection = \OC::$server->getDatabaseConnection(); + $queryBuilder = $connection->getQueryBuilder(); + $queryBuilder->insert('share') + ->values([ + 'share_type' => $queryBuilder->createParameter('share_type'), + 'share_with' => $queryBuilder->createParameter('share_with'), + 'uid_owner' => $queryBuilder->createParameter('uid_owner'), + 'parent' => $queryBuilder->createParameter('parent'), + 'item_type' => $queryBuilder->expr()->literal('fake'), + 'item_source' => $queryBuilder->expr()->literal(''), + 'item_target' => $queryBuilder->expr()->literal(''), + 'file_source' => $queryBuilder->expr()->literal(0), + 'file_target' => $queryBuilder->expr()->literal(''), + 'permissions' => $queryBuilder->expr()->literal(0), + 'stime' => $queryBuilder->expr()->literal(0), + 'accepted' => $queryBuilder->expr()->literal(0), + 'expiration' => $queryBuilder->expr()->literal(''), + 'token' => $queryBuilder->expr()->literal(''), + 'mail_send' => $queryBuilder->expr()->literal(0), + ]) + ->setParameters([ + 'share_type' => $type, + 'share_with' => $with, + 'uid_owner' => $owner, + 'parent' => $parent, + ]) + ->execute(); + return $connection->lastInsertId('share'); + } + + /** + * @param int[] $shareIds + * @return null + */ + protected function deleteShares(array $shareIds) { + $connection = \OC::$server->getDatabaseConnection(); + $queryBuilder = $connection->getQueryBuilder(); + $queryBuilder->delete('share') + ->where($queryBuilder->expr()->in('id', $queryBuilder->createParameter('ids'))) + ->setParameter('ids', $shareIds, Connection::PARAM_INT_ARRAY) + ->execute(); + } + public function dataGetPaginationLinks() { return [ [1, 1, ['limit' => 2], []], |