|
|
@@ -66,7 +66,8 @@ class ShareesTest extends TestCase { |
|
|
|
$this->getMockBuilder('OCP\IConfig')->disableOriginalConstructor()->getMock(), |
|
|
|
$this->session, |
|
|
|
$this->getMockBuilder('OCP\IURLGenerator')->disableOriginalConstructor()->getMock(), |
|
|
|
$this->getMockBuilder('OCP\ILogger')->disableOriginalConstructor()->getMock() |
|
|
|
$this->getMockBuilder('OCP\ILogger')->disableOriginalConstructor()->getMock(), |
|
|
|
\OC::$server->getDatabaseConnection() |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
@@ -349,106 +350,106 @@ class ShareesTest extends TestCase { |
|
|
|
$allTypes = [\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_GROUP, \OCP\Share::SHARE_TYPE_REMOTE]; |
|
|
|
|
|
|
|
return [ |
|
|
|
[[], '', true, '', null, [], $allTypes, 1, 200, false], |
|
|
|
[[], '', true, [], '', null, $allTypes, 1, 200, false], |
|
|
|
|
|
|
|
// Test itemType |
|
|
|
[[ |
|
|
|
'search' => '', |
|
|
|
], '', true, '', null, [], $allTypes, 1, 200, false], |
|
|
|
], '', true, [], '', null, $allTypes, 1, 200, false], |
|
|
|
[[ |
|
|
|
'search' => 'foobar', |
|
|
|
], '', true, 'foobar', null, [], $allTypes, 1, 200, false], |
|
|
|
], '', true, [], 'foobar', null, $allTypes, 1, 200, false], |
|
|
|
[[ |
|
|
|
'search' => 0, |
|
|
|
], '', true, '0', null, [], $allTypes, 1, 200, false], |
|
|
|
], '', true, [], '0', null, $allTypes, 1, 200, false], |
|
|
|
|
|
|
|
// Test itemType |
|
|
|
[[ |
|
|
|
'itemType' => '', |
|
|
|
], '', true, '', '', [], $allTypes, 1, 200, false], |
|
|
|
], '', true, [], '', '', $allTypes, 1, 200, false], |
|
|
|
[[ |
|
|
|
'itemType' => 'folder', |
|
|
|
], '', true, '', 'folder', [], $allTypes, 1, 200, false], |
|
|
|
], '', true, [], '', 'folder', $allTypes, 1, 200, false], |
|
|
|
[[ |
|
|
|
'itemType' => 0, |
|
|
|
], '', true, '', '0', [], $allTypes, 1, 200, false], |
|
|
|
], '', true, [], '', '0', $allTypes, 1, 200, false], |
|
|
|
|
|
|
|
// Test existingShares |
|
|
|
[[ |
|
|
|
'existingShares' => [], |
|
|
|
], '', true, '', null, [], $allTypes, 1, 200, false], |
|
|
|
], '', true, [], '', null, $allTypes, 1, 200, false], |
|
|
|
[[ |
|
|
|
'existingShares' => [0 => ['test'], 1 => ['foobar']], |
|
|
|
], '', true, '', null, [0 => ['test'], 1 => ['foobar']], $allTypes, 1, 200, false], |
|
|
|
'existingShares' => [12, 42], |
|
|
|
], '', true, [12, 42], '', null, $allTypes, 1, 200, false], |
|
|
|
|
|
|
|
// Test shareType |
|
|
|
[[ |
|
|
|
], '', true, '', null, [], $allTypes, 1, 200, false], |
|
|
|
], '', true, [], '', null, $allTypes, 1, 200, false], |
|
|
|
[[ |
|
|
|
'shareType' => 0, |
|
|
|
], '', true, '', null, [], [0], 1, 200, false], |
|
|
|
], '', true, [], '', null, [0], 1, 200, false], |
|
|
|
[[ |
|
|
|
'shareType' => '0', |
|
|
|
], '', true, '', null, [], [0], 1, 200, false], |
|
|
|
], '', true, [], '', null, [0], 1, 200, false], |
|
|
|
[[ |
|
|
|
'shareType' => 1, |
|
|
|
], '', true, '', null, [], [1], 1, 200, false], |
|
|
|
], '', true, [], '', null, [1], 1, 200, false], |
|
|
|
[[ |
|
|
|
'shareType' => 12, |
|
|
|
], '', true, '', null, [], [], 1, 200, false], |
|
|
|
], '', true, [], '', null, [], 1, 200, false], |
|
|
|
[[ |
|
|
|
'shareType' => 'foobar', |
|
|
|
], '', true, '', null, [], $allTypes, 1, 200, false], |
|
|
|
], '', true, [], '', null, $allTypes, 1, 200, false], |
|
|
|
[[ |
|
|
|
'shareType' => [0, 1, 2], |
|
|
|
], '', true, '', null, [], [0, 1], 1, 200, false], |
|
|
|
], '', true, [], '', null, [0, 1], 1, 200, false], |
|
|
|
[[ |
|
|
|
'shareType' => [0, 1], |
|
|
|
], '', true, '', null, [], [0, 1], 1, 200, false], |
|
|
|
], '', true, [], '', null, [0, 1], 1, 200, false], |
|
|
|
[[ |
|
|
|
'shareType' => $allTypes, |
|
|
|
], '', true, '', null, [], $allTypes, 1, 200, false], |
|
|
|
], '', true, [], '', null, $allTypes, 1, 200, false], |
|
|
|
[[ |
|
|
|
'shareType' => $allTypes, |
|
|
|
], '', false, '', null, [], [0, 1], 1, 200, false], |
|
|
|
], '', false, [], '', null, [0, 1], 1, 200, false], |
|
|
|
|
|
|
|
// Test pagination |
|
|
|
[[ |
|
|
|
'page' => 0, |
|
|
|
], '', true, '', null, [], $allTypes, 1, 200, false], |
|
|
|
], '', true, [], '', null, $allTypes, 1, 200, false], |
|
|
|
[[ |
|
|
|
'page' => '0', |
|
|
|
], '', true, '', null, [], $allTypes, 1, 200, false], |
|
|
|
], '', true, [], '', null, $allTypes, 1, 200, false], |
|
|
|
[[ |
|
|
|
'page' => -1, |
|
|
|
], '', true, '', null, [], $allTypes, 1, 200, false], |
|
|
|
], '', true, [], '', null, $allTypes, 1, 200, false], |
|
|
|
[[ |
|
|
|
'page' => 1, |
|
|
|
], '', true, '', null, [], $allTypes, 1, 200, false], |
|
|
|
], '', true, [], '', null, $allTypes, 1, 200, false], |
|
|
|
[[ |
|
|
|
'page' => 10, |
|
|
|
], '', true, '', null, [], $allTypes, 10, 200, false], |
|
|
|
], '', true, [], '', null, $allTypes, 10, 200, false], |
|
|
|
|
|
|
|
// Test limit |
|
|
|
[[ |
|
|
|
'limit' => 0, |
|
|
|
], '', true, '', null, [], $allTypes, 1, 200, false], |
|
|
|
], '', true, [], '', null, $allTypes, 1, 200, false], |
|
|
|
[[ |
|
|
|
'limit' => '0', |
|
|
|
], '', true, '', null, [], $allTypes, 1, 200, false], |
|
|
|
], '', true, [], '', null, $allTypes, 1, 200, false], |
|
|
|
[[ |
|
|
|
'limit' => -1, |
|
|
|
], '', true, '', null, [], $allTypes, 1, 1, false], |
|
|
|
], '', true, [], '', null, $allTypes, 1, 1, false], |
|
|
|
[[ |
|
|
|
'limit' => 1, |
|
|
|
], '', true, '', null, [], $allTypes, 1, 1, false], |
|
|
|
], '', true, [], '', null, $allTypes, 1, 1, false], |
|
|
|
[[ |
|
|
|
'limit' => 10, |
|
|
|
], '', true, '', null, [], $allTypes, 1, 10, false], |
|
|
|
], '', true, [], '', null, $allTypes, 1, 10, false], |
|
|
|
|
|
|
|
// Test $shareWithGroupOnly setting |
|
|
|
[[], 'no', true, '', null, [], $allTypes, 1, 200, false], |
|
|
|
[[], 'yes', true, '', null, [], $allTypes, 1, 200, true], |
|
|
|
[[], 'no', true, [], '', null, $allTypes, 1, 200, false], |
|
|
|
[[], 'yes', true, [], '', null, $allTypes, 1, 200, true], |
|
|
|
|
|
|
|
]; |
|
|
|
} |
|
|
@@ -459,15 +460,15 @@ class ShareesTest extends TestCase { |
|
|
|
* @param array $getData |
|
|
|
* @param string $apiSetting |
|
|
|
* @param bool $remoteSharingEnabled |
|
|
|
* @param array $shareIds |
|
|
|
* @param string $search |
|
|
|
* @param string $itemType |
|
|
|
* @param array $existingShares |
|
|
|
* @param array $shareTypes |
|
|
|
* @param int $page |
|
|
|
* @param int $perPage |
|
|
|
* @param bool $shareWithGroupOnly |
|
|
|
*/ |
|
|
|
public function testSearch($getData, $apiSetting, $remoteSharingEnabled, $search, $itemType, $existingShares, $shareTypes, $page, $perPage, $shareWithGroupOnly) { |
|
|
|
public function testSearch($getData, $apiSetting, $remoteSharingEnabled, $shareIds, $search, $itemType, $shareTypes, $page, $perPage, $shareWithGroupOnly) { |
|
|
|
$oldGet = $_GET; |
|
|
|
$_GET = $getData; |
|
|
|
|
|
|
@@ -487,21 +488,22 @@ class ShareesTest extends TestCase { |
|
|
|
$config, |
|
|
|
$this->session, |
|
|
|
$this->getMockBuilder('OCP\IURLGenerator')->disableOriginalConstructor()->getMock(), |
|
|
|
$this->getMockBuilder('OCP\ILogger')->disableOriginalConstructor()->getMock() |
|
|
|
$this->getMockBuilder('OCP\ILogger')->disableOriginalConstructor()->getMock(), |
|
|
|
\OC::$server->getDatabaseConnection() |
|
|
|
]) |
|
|
|
->setMethods(array('searchSharees', 'isRemoteSharingAllowed')) |
|
|
|
->getMock(); |
|
|
|
$sharees->expects($this->once()) |
|
|
|
->method('searchSharees') |
|
|
|
->with($search, $itemType, $existingShares, $shareTypes, $page, $perPage, $shareWithGroupOnly) |
|
|
|
->with($search, $itemType, $shareIds, $shareTypes, $page, $perPage, $shareWithGroupOnly) |
|
|
|
->willReturnCallback(function |
|
|
|
($isearch, $iitemType, $iexistingShares, $ishareTypes, $ipage, $iperPage, $ishareWithGroupOnly) |
|
|
|
use ($search, $itemType, $existingShares, $shareTypes, $page, $perPage, $shareWithGroupOnly) { |
|
|
|
($isearch, $iitemType, $ishareIds, $ishareTypes, $ipage, $iperPage, $ishareWithGroupOnly) |
|
|
|
use ($search, $itemType, $shareIds, $shareTypes, $page, $perPage, $shareWithGroupOnly) { |
|
|
|
|
|
|
|
// We are doing strict comparisons here, so we can differ 0/'' and null on shareType/itemType |
|
|
|
$this->assertSame($search, $isearch); |
|
|
|
$this->assertSame($itemType, $iitemType); |
|
|
|
$this->assertSame($existingShares, $iexistingShares); |
|
|
|
$this->assertSame($shareIds, $ishareIds); |
|
|
|
$this->assertSame($shareTypes, $ishareTypes); |
|
|
|
$this->assertSame($page, $ipage); |
|
|
|
$this->assertSame($perPage, $iperPage); |
|
|
@@ -540,11 +542,11 @@ class ShareesTest extends TestCase { |
|
|
|
|
|
|
|
public function dataSearchSharees() { |
|
|
|
return [ |
|
|
|
['test', 'folder', [], [\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_GROUP, \OCP\Share::SHARE_TYPE_REMOTE], 1, 2, false, [], [], [], [], 0, false], |
|
|
|
['test', 'folder', [0 => ['test1'], 1 => ['test2 group']], [\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_GROUP, \OCP\Share::SHARE_TYPE_REMOTE], 1, 2, false, [], [], [], [], 0, false], |
|
|
|
['test', 'folder', [], [], [\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_GROUP, \OCP\Share::SHARE_TYPE_REMOTE], 1, 2, false, [], [], [], [], 0, false], |
|
|
|
['test', 'folder', [1, 2], [0 => ['test1'], 1 => ['test2 group']], [\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_GROUP, \OCP\Share::SHARE_TYPE_REMOTE], 1, 2, false, [], [], [], [], 0, false], |
|
|
|
// First page with 2 of 3 results |
|
|
|
[ |
|
|
|
'test', 'folder', [], [\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_GROUP, \OCP\Share::SHARE_TYPE_REMOTE], 1, 2, false, [ |
|
|
|
'test', 'folder', [], [], [\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_GROUP, \OCP\Share::SHARE_TYPE_REMOTE], 1, 2, false, [ |
|
|
|
['label' => 'test One', 'value' => ['shareType' => \OCP\Share::SHARE_TYPE_USER, 'shareWith' => 'test1']], |
|
|
|
], [ |
|
|
|
['label' => 'testgroup1', 'value' => ['shareType' => \OCP\Share::SHARE_TYPE_GROUP, 'shareWith' => 'testgroup1']], |
|
|
@@ -557,7 +559,7 @@ class ShareesTest extends TestCase { |
|
|
|
], |
|
|
|
// Second page with the 3rd result |
|
|
|
[ |
|
|
|
'test', 'folder', [], [\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_GROUP, \OCP\Share::SHARE_TYPE_REMOTE], 2, 2, false, [ |
|
|
|
'test', 'folder', [], [], [\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_GROUP, \OCP\Share::SHARE_TYPE_REMOTE], 2, 2, false, [ |
|
|
|
['label' => 'test One', 'value' => ['shareType' => \OCP\Share::SHARE_TYPE_USER, 'shareWith' => 'test1']], |
|
|
|
], [ |
|
|
|
['label' => 'testgroup1', 'value' => ['shareType' => \OCP\Share::SHARE_TYPE_GROUP, 'shareWith' => 'testgroup1']], |
|
|
@@ -569,7 +571,7 @@ class ShareesTest extends TestCase { |
|
|
|
], |
|
|
|
// No groups requested |
|
|
|
[ |
|
|
|
'test', 'folder', [], [\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_REMOTE], 1, 2, false, [ |
|
|
|
'test', 'folder', [], [], [\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_REMOTE], 1, 2, false, [ |
|
|
|
['label' => 'test One', 'value' => ['shareType' => \OCP\Share::SHARE_TYPE_USER, 'shareWith' => 'test1']], |
|
|
|
], null, [ |
|
|
|
['label' => 'testz@remote', 'value' => ['shareType' => \OCP\Share::SHARE_TYPE_REMOTE, 'shareWith' => 'testz@remote']], |
|
|
@@ -580,7 +582,7 @@ class ShareesTest extends TestCase { |
|
|
|
], |
|
|
|
// Ingnoring already shared user |
|
|
|
[ |
|
|
|
'test', 'folder', [\OCP\Share::SHARE_TYPE_USER => ['test1']], [\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_GROUP, \OCP\Share::SHARE_TYPE_REMOTE], 1, 2, false, [ |
|
|
|
'test', 'folder', [1], [\OCP\Share::SHARE_TYPE_USER => ['test1']], [\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_GROUP, \OCP\Share::SHARE_TYPE_REMOTE], 1, 2, false, [ |
|
|
|
['label' => 'test One', 'value' => ['shareType' => \OCP\Share::SHARE_TYPE_USER, 'shareWith' => 'test1']], |
|
|
|
], [ |
|
|
|
['label' => 'testgroup1', 'value' => ['shareType' => \OCP\Share::SHARE_TYPE_GROUP, 'shareWith' => 'testgroup1']], |
|
|
@@ -593,7 +595,7 @@ class ShareesTest extends TestCase { |
|
|
|
], |
|
|
|
// Share type restricted to user - Only one user |
|
|
|
[ |
|
|
|
'test', 'folder', [], [\OCP\Share::SHARE_TYPE_USER], 1, 2, false, [ |
|
|
|
'test', 'folder', [], [], [\OCP\Share::SHARE_TYPE_USER], 1, 2, false, [ |
|
|
|
['label' => 'test One', 'value' => ['shareType' => \OCP\Share::SHARE_TYPE_USER, 'shareWith' => 'test1']], |
|
|
|
], null, null, [ |
|
|
|
['label' => 'test One', 'value' => ['shareType' => \OCP\Share::SHARE_TYPE_USER, 'shareWith' => 'test1']], |
|
|
@@ -601,7 +603,7 @@ class ShareesTest extends TestCase { |
|
|
|
], |
|
|
|
// Share type restricted to user - Multipage result |
|
|
|
[ |
|
|
|
'test', 'folder', [], [\OCP\Share::SHARE_TYPE_USER], 1, 2, false, [ |
|
|
|
'test', 'folder', [], [], [\OCP\Share::SHARE_TYPE_USER], 1, 2, false, [ |
|
|
|
['label' => 'test 1', 'value' => ['shareType' => \OCP\Share::SHARE_TYPE_USER, 'shareWith' => 'test1']], |
|
|
|
['label' => 'test 2', 'value' => ['shareType' => \OCP\Share::SHARE_TYPE_USER, 'shareWith' => 'test2']], |
|
|
|
['label' => 'test 3', 'value' => ['shareType' => \OCP\Share::SHARE_TYPE_USER, 'shareWith' => 'test3']], |
|
|
@@ -612,7 +614,7 @@ class ShareesTest extends TestCase { |
|
|
|
], |
|
|
|
// Share type restricted to user - Only user already shared |
|
|
|
[ |
|
|
|
'test', 'folder', [\OCP\Share::SHARE_TYPE_USER => ['test1']], [\OCP\Share::SHARE_TYPE_USER], 1, 2, false, [ |
|
|
|
'test', 'folder', [1], [\OCP\Share::SHARE_TYPE_USER => ['test1']], [\OCP\Share::SHARE_TYPE_USER], 1, 2, false, [ |
|
|
|
['label' => 'test One', 'value' => ['shareType' => \OCP\Share::SHARE_TYPE_USER, 'shareWith' => 'test1']], |
|
|
|
], null, null, [], 0, false, |
|
|
|
], |
|
|
@@ -624,6 +626,7 @@ class ShareesTest extends TestCase { |
|
|
|
* |
|
|
|
* @param string $searchTerm |
|
|
|
* @param string $itemType |
|
|
|
* @param array $shareIds |
|
|
|
* @param array $existingShares |
|
|
|
* @param array $shareTypes |
|
|
|
* @param int $page |
|
|
@@ -631,7 +634,7 @@ class ShareesTest extends TestCase { |
|
|
|
* @param bool $shareWithGroupOnly |
|
|
|
* @param array $expected |
|
|
|
*/ |
|
|
|
public function testSearchSharees($searchTerm, $itemType, array $existingShares, array $shareTypes, $page, $perPage, $shareWithGroupOnly, |
|
|
|
public function testSearchSharees($searchTerm, $itemType, array $shareIds, array $existingShares, array $shareTypes, $page, $perPage, $shareWithGroupOnly, |
|
|
|
$mockedUserResult, $mockedGroupsResult, $mockedRemotesResult, $expected, $totalItems, $nextLink) { |
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject|\OCA\Files_Sharing\API\Sharees $sharees */ |
|
|
|
$sharees = $this->getMockBuilder('\OCA\Files_Sharing\API\Sharees') |
|
|
@@ -642,10 +645,15 @@ class ShareesTest extends TestCase { |
|
|
|
$this->getMockBuilder('OCP\IConfig')->disableOriginalConstructor()->getMock(), |
|
|
|
$this->session, |
|
|
|
$this->getMockBuilder('OCP\IURLGenerator')->disableOriginalConstructor()->getMock(), |
|
|
|
$this->getMockBuilder('OCP\ILogger')->disableOriginalConstructor()->getMock() |
|
|
|
$this->getMockBuilder('OCP\ILogger')->disableOriginalConstructor()->getMock(), |
|
|
|
\OC::$server->getDatabaseConnection() |
|
|
|
]) |
|
|
|
->setMethods(array('getUsers', 'getGroups', 'getRemote')) |
|
|
|
->setMethods(array('getShareesForShareIds', 'getUsers', 'getGroups', 'getRemote')) |
|
|
|
->getMock(); |
|
|
|
$sharees->expects($this->once()) |
|
|
|
->method('getShareesForShareIds') |
|
|
|
->with($shareIds) |
|
|
|
->willReturn($existingShares); |
|
|
|
$sharees->expects(($mockedUserResult === null) ? $this->never() : $this->once()) |
|
|
|
->method('getUsers') |
|
|
|
->with($searchTerm, $shareWithGroupOnly) |
|
|
@@ -660,7 +668,7 @@ class ShareesTest extends TestCase { |
|
|
|
->willReturn($mockedRemotesResult); |
|
|
|
|
|
|
|
/** @var \OC_OCS_Result $ocs */ |
|
|
|
$ocs = $this->invokePrivate($sharees, 'searchSharees', [$searchTerm, $itemType, $existingShares, $shareTypes, $page, $perPage, $shareWithGroupOnly]); |
|
|
|
$ocs = $this->invokePrivate($sharees, 'searchSharees', [$searchTerm, $itemType, $shareIds, $shareTypes, $page, $perPage, $shareWithGroupOnly]); |
|
|
|
$this->assertInstanceOf('\OC_OCS_Result', $ocs); |
|
|
|
|
|
|
|
$this->assertEquals($expected, $ocs->getData()); |