summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2015-01-16 18:11:13 +0100
committerVincent Petry <pvince81@owncloud.com>2015-01-16 18:11:13 +0100
commit40931a8b0d5d10c0f711756a4e8a423ff055621e (patch)
treebac0e1f21d9f3761e7a384928dbd2ab36e9b2a97 /tests
parenta65f666834742f8df25493a11e10063e1e5ff98a (diff)
downloadnextcloud-server-40931a8b0d5d10c0f711756a4e8a423ff055621e.tar.gz
nextcloud-server-40931a8b0d5d10c0f711756a4e8a423ff055621e.zip
Fix getItemSharedWithUser for groups
Fixed SQL query for whenever a user has more than one group. Added missing $owner where clause for group lookup. Added unit tests for the group cases.
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/share/share.php35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php
index b8abfa29a81..b1261b0afbd 100644
--- a/tests/lib/share/share.php
+++ b/tests/lib/share/share.php
@@ -692,6 +692,41 @@ class Test_Share extends \Test\TestCase {
$this->verifyResult($result4, array('target1', 'target2', 'target3', 'target4'));
}
+ public function testGetItemSharedWithUserFromGroupShare() {
+ 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_GROUP, $this->group1, $this->user1);
+ $query->execute($args);
+ $args = array('test', 99, 'target2', OCP\Share::SHARE_TYPE_GROUP, $this->group2, $this->user1);
+ $query->execute($args);
+ $args = array('test', 99, 'target3', OCP\Share::SHARE_TYPE_GROUP, $this->group1, $this->user2);
+ $query->execute($args);
+ $args = array('test', 99, 'target4', OCP\Share::SHARE_TYPE_GROUP, $this->group1, $this->user4);
+ $query->execute($args);
+
+ // user2 is in group1 and group2
+ $result1 = \OCP\Share::getItemSharedWithUser('test', 99, $this->user2, $this->user1);
+ $this->assertSame(2, count($result1));
+ $this->verifyResult($result1, array('target1', 'target2'));
+
+ $result2 = \OCP\Share::getItemSharedWithUser('test', 99, null, $this->user1);
+ $this->assertSame(2, count($result2));
+ $this->verifyResult($result2, array('target1', 'target2'));
+
+ // user3 is in group1 and group2
+ $result3 = \OCP\Share::getItemSharedWithUser('test', 99, $this->user3);
+ $this->assertSame(3, count($result3));
+ $this->verifyResult($result3, array('target1', '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)) {