summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2014-09-29 20:26:41 +0200
committerLukas Reschke <lukas@owncloud.com>2014-09-29 20:26:41 +0200
commit8c8e5c168eefbf1460d5456dde6d09562de8902e (patch)
tree71d80acf82bb9e2c6188ff8f6cc495876bad0ebc /tests
parent9489852e9490c6182e3d900c5fba2ca37d281dd1 (diff)
parent6e7acb8ae083c158fb412fa3e035e64a83063911 (diff)
downloadnextcloud-server-8c8e5c168eefbf1460d5456dde6d09562de8902e.tar.gz
nextcloud-server-8c8e5c168eefbf1460d5456dde6d09562de8902e.zip
Merge pull request #10107 from owncloud/sharing_group_shares
[sharing] group shares
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/share/backend.php23
-rw-r--r--tests/lib/share/share.php96
2 files changed, 102 insertions, 17 deletions
diff --git a/tests/lib/share/backend.php b/tests/lib/share/backend.php
index 420bd9d88b3..50ce24e07b6 100644
--- a/tests/lib/share/backend.php
+++ b/tests/lib/share/backend.php
@@ -38,19 +38,36 @@ class Test_Share_Backend implements OCP\Share_Backend {
public function generateTarget($itemSource, $shareWith, $exclude = null) {
// Always make target be test.txt to cause conflicts
- $target = 'test.txt';
- if (isset($exclude)) {
+
+ if (substr($itemSource, 0, strlen('test')) !== 'test') {
+ $target = "test.txt";
+ } else {
+ $target = $itemSource;
+ }
+
+
+ $shares = \OCP\Share::getItemsSharedWithUser('test', $shareWith);
+
+ $knownTargets = array();
+ foreach ($shares as $share) {
+ $knownTargets[] = $share['item_target'];
+ }
+
+
+ if (in_array($target, $knownTargets)) {
$pos = strrpos($target, '.');
$name = substr($target, 0, $pos);
$ext = substr($target, $pos);
$append = '';
$i = 1;
- while (in_array($name.$append.$ext, $exclude)) {
+ while (in_array($name.$append.$ext, $knownTargets)) {
$append = $i;
$i++;
}
$target = $name.$append.$ext;
+
}
+
return $target;
}
diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php
index 0a8d7856915..3d99883f2de 100644
--- a/tests/lib/share/share.php
+++ b/tests/lib/share/share.php
@@ -48,8 +48,8 @@ class Test_Share extends PHPUnit_Framework_TestCase {
OC_User::setUserId($this->user1);
OC_Group::clearBackends();
OC_Group::useBackend(new OC_Group_Dummy);
- $this->group1 = uniqid('group_');
- $this->group2 = uniqid('group_');
+ $this->group1 = uniqid('group1_');
+ $this->group2 = uniqid('group2_');
OC_Group::createGroup($this->group1);
OC_Group::createGroup($this->group2);
OC_Group::addToGroup($this->user1, $this->group1);
@@ -541,7 +541,7 @@ class Test_Share extends PHPUnit_Framework_TestCase {
OC_User::setUserId($this->user2);
$this->assertEquals(array(OCP\PERMISSION_READ | OCP\PERMISSION_UPDATE), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS));
OC_User::setUserId($this->user4);
- $this->assertEquals(array(), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET));
+ $this->assertEquals(array('test.txt'), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET));
// Valid share with same person - group then user
OC_User::setUserId($this->user1);
@@ -757,20 +757,88 @@ class Test_Share extends PHPUnit_Framework_TestCase {
array(false, array('share_with' => '1234567890', 'share_type' => '3', 'id' => 101)),
array(false, array('share_with' => '1234567890', 'share_type' => 3, 'id' => 101)),
);
+ }
- /*
- if (!isset($linkItem['share_with'])) {
- return true;
- }
+ /**
+ * @dataProvider dataProviderTestGroupItems
+ * @param type $ungrouped
+ * @param type $grouped
+ */
+ function testGroupItems($ungrouped, $grouped) {
- if ($linkItem['share_type'] != \OCP\Share::SHARE_TYPE_LINK) {
- return true;
- }
+ $result = DummyShareClass::groupItemsTest($ungrouped);
- if ( \OC::$server->getSession()->exists('public_link_authenticated')
- && \OC::$server->getSession()->get('public_link_authenticated') === $linkItem['id'] ) {
- return true;
+ $this->compareArrays($grouped, $result);
+
+ }
+
+ function compareArrays($result, $expectedResult) {
+ foreach ($expectedResult as $key => $value) {
+ if (is_array($value)) {
+ $this->compareArrays($result[$key], $value);
+ } else {
+ $this->assertSame($value, $result[$key]);
+ }
}
- * */
+ }
+
+ function dataProviderTestGroupItems() {
+ return array(
+ // one array with one share
+ array(
+ array( // input
+ array('item_source' => 1, 'permissions' => \OCP\PERMISSION_ALL, 'item_target' => 't1')),
+ array( // expected result
+ array('item_source' => 1, 'permissions' => \OCP\PERMISSION_ALL, 'item_target' => 't1'))),
+ // two shares both point to the same source
+ array(
+ array( // input
+ array('item_source' => 1, 'permissions' => \OCP\PERMISSION_READ, 'item_target' => 't1'),
+ array('item_source' => 1, 'permissions' => \OCP\PERMISSION_UPDATE, 'item_target' => 't1'),
+ ),
+ array( // expected result
+ array('item_source' => 1, 'permissions' => \OCP\PERMISSION_READ | \OCP\PERMISSION_UPDATE, 'item_target' => 't1',
+ 'grouped' => array(
+ array('item_source' => 1, 'permissions' => \OCP\PERMISSION_READ, 'item_target' => 't1'),
+ array('item_source' => 1, 'permissions' => \OCP\PERMISSION_UPDATE, 'item_target' => 't1'),
+ )
+ ),
+ )
+ ),
+ // two shares both point to the same source but with different targets
+ array(
+ array( // input
+ array('item_source' => 1, 'permissions' => \OCP\PERMISSION_READ, 'item_target' => 't1'),
+ array('item_source' => 1, 'permissions' => \OCP\PERMISSION_UPDATE, 'item_target' => 't2'),
+ ),
+ array( // expected result
+ array('item_source' => 1, 'permissions' => \OCP\PERMISSION_READ, 'item_target' => 't1'),
+ array('item_source' => 1, 'permissions' => \OCP\PERMISSION_UPDATE, 'item_target' => 't2'),
+ )
+ ),
+ // three shares two point to the same source
+ array(
+ array( // input
+ array('item_source' => 1, 'permissions' => \OCP\PERMISSION_READ, 'item_target' => 't1'),
+ array('item_source' => 2, 'permissions' => \OCP\PERMISSION_CREATE, 'item_target' => 't2'),
+ array('item_source' => 1, 'permissions' => \OCP\PERMISSION_UPDATE, 'item_target' => 't1'),
+ ),
+ array( // expected result
+ array('item_source' => 1, 'permissions' => \OCP\PERMISSION_READ | \OCP\PERMISSION_UPDATE, 'item_target' => 't1',
+ 'grouped' => array(
+ array('item_source' => 1, 'permissions' => \OCP\PERMISSION_READ, 'item_target' => 't1'),
+ array('item_source' => 1, 'permissions' => \OCP\PERMISSION_UPDATE, 'item_target' => 't1'),
+ )
+ ),
+ array('item_source' => 2, 'permissions' => \OCP\PERMISSION_CREATE, 'item_target' => 't2'),
+ )
+ ),
+ );
+ }
+}
+
+class DummyShareClass extends \OC\Share\Share {
+ public static function groupItemsTest($items) {
+ return parent::groupItems($items, 'test');
}
}