diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2014-08-01 16:24:19 +0200 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2014-09-22 17:54:47 +0200 |
commit | 9105e17307b3e6a80ac32f2b06df12df82ccedd9 (patch) | |
tree | ec17d847151d378e85456206bec42b8cdf014e7b /tests/lib/share | |
parent | 89c3b650e6c47899ceea105713b389fe8af78bfa (diff) | |
download | nextcloud-server-9105e17307b3e6a80ac32f2b06df12df82ccedd9.tar.gz nextcloud-server-9105e17307b3e6a80ac32f2b06df12df82ccedd9.zip |
unit tests for grouping of shares pointing to the same source
Diffstat (limited to 'tests/lib/share')
-rw-r--r-- | tests/lib/share/share.php | 92 |
1 files changed, 80 insertions, 12 deletions
diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php index 0a8d7856915..1fc2cecd1ed 100644 --- a/tests/lib/share/share.php +++ b/tests/lib/share/share.php @@ -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'); } } |