diff options
author | Morris Jobke <hey@morrisjobke.de> | 2014-11-24 11:44:43 +0100 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2014-11-24 11:44:43 +0100 |
commit | 8782b2237c257cf7117ccc441f86e1036b1d2bf3 (patch) | |
tree | 66647fccf50ce26e187344d7c6e87a3a67207ab4 /tests | |
parent | e956bd109467c7ef43fb26ab4883af9802b79eb1 (diff) | |
parent | a7ebfe87c9ef16c698c16c4f72eaf3865825c540 (diff) | |
download | nextcloud-server-8782b2237c257cf7117ccc441f86e1036b1d2bf3.tar.gz nextcloud-server-8782b2237c257cf7117ccc441f86e1036b1d2bf3.zip |
Merge pull request #12084 from owncloud/sharing_fix_shared_with_info
sharing: make sure that we only find the shares from a given owner
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/share/share.php | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php index 7ae458a797d..b5cdab0025b 100644 --- a/tests/lib/share/share.php +++ b/tests/lib/share/share.php @@ -658,6 +658,50 @@ class Test_Share extends \Test\TestCase { return $row; } + public function testGetItemSharedWithUser() { + OC_User::setUserId($this->user1); + + //add dummy values to the share table + $query = \OC_DB::prepare('INSERT INTO `*PREFIX*share` (' + .' `item_type`, `item_source`, `item_target`, `share_type`,' + .' `share_with`, `uid_owner`) VALUES (?,?,?,?,?,?)'); + $args = array('test', 99, 'target1', OCP\Share::SHARE_TYPE_USER, $this->user2, $this->user1); + $query->execute($args); + $args = array('test', 99, 'target2', OCP\Share::SHARE_TYPE_USER, $this->user4, $this->user1); + $query->execute($args); + $args = array('test', 99, 'target3', OCP\Share::SHARE_TYPE_USER, $this->user3, $this->user2); + $query->execute($args); + $args = array('test', 99, 'target4', OCP\Share::SHARE_TYPE_USER, $this->user3, $this->user4); + $query->execute($args); + + + $result1 = \OCP\Share::getItemSharedWithUser('test', 99, $this->user2, $this->user1); + $this->assertSame(1, count($result1)); + $this->verifyResult($result1, array('target1')); + + $result2 = \OCP\Share::getItemSharedWithUser('test', 99, null, $this->user1); + $this->assertSame(2, count($result2)); + $this->verifyResult($result2, array('target1', 'target2')); + + $result3 = \OCP\Share::getItemSharedWithUser('test', 99, $this->user3); + $this->assertSame(2, count($result3)); + $this->verifyResult($result3, array('target3', 'target4')); + + $result4 = \OCP\Share::getItemSharedWithUser('test', 99, null, null); + $this->assertSame(4, count($result4)); + $this->verifyResult($result4, array('target1', 'target2', 'target3', 'target4')); + } + + public function verifyResult($result, $expected) { + foreach ($result as $r) { + if (in_array($r['item_target'], $expected)) { + $key = array_search($r['item_target'], $expected); + unset($expected[$key]); + } + } + $this->assertEmpty($expected, 'did not found all expected values'); + } + public function testShareItemWithLink() { OC_User::setUserId($this->user1); $token = OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_LINK, null, OCP\PERMISSION_READ); |