summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2017-09-13 12:32:47 +0200
committerArthur Schiwon <blizzz@arthur-schiwon.de>2017-09-26 23:10:24 +0200
commit38ff7eaeced5e56786376f7c522fb07c8420c7b3 (patch)
tree056b0f0343b1e23318e3ac7f8d57dd0526420863 /apps/files_sharing
parent3d1d03a51175e0e52b506764bc7d96ddeae4cb65 (diff)
downloadnextcloud-server-38ff7eaeced5e56786376f7c522fb07c8420c7b3.tar.gz
nextcloud-server-38ff7eaeced5e56786376f7c522fb07c8420c7b3.zip
adjust ShareeAPIController search test
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/files_sharing')
-rw-r--r--apps/files_sharing/lib/Controller/ShareesAPIController.php5
-rw-r--r--apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php49
2 files changed, 22 insertions, 32 deletions
diff --git a/apps/files_sharing/lib/Controller/ShareesAPIController.php b/apps/files_sharing/lib/Controller/ShareesAPIController.php
index 45c1b5e6dcf..17d258b3a8f 100644
--- a/apps/files_sharing/lib/Controller/ShareesAPIController.php
+++ b/apps/files_sharing/lib/Controller/ShareesAPIController.php
@@ -199,7 +199,9 @@ class ShareesAPIController extends OCSController {
list($result, $hasMoreResults) = $this->collaboratorSearch->search($search, $shareTypes, $lookup, $this->limit, $this->offset);
// extra treatment for 'exact' subarray, with a single merge expected keys might be lost
- $result['exact'] = array_merge($this->result['exact'], $result['exact']);
+ if(isset($result['exact'])) {
+ $result['exact'] = array_merge($this->result['exact'], $result['exact']);
+ }
$this->result = array_merge($this->result, $result);
$response = new DataResponse($this->result);
@@ -223,6 +225,7 @@ class ShareesAPIController extends OCSController {
*/
protected function isRemoteSharingAllowed($itemType) {
try {
+ // FIXME: static foo makes unit testing unnecessarily difficult
$backend = \OC\Share\Share::getBackend($itemType);
return $backend->isShareTypeAllowed(Share::SHARE_TYPE_REMOTE);
} catch (\Exception $e) {
diff --git a/apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php
index 928a151c420..2586876f88d 100644
--- a/apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php
+++ b/apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php
@@ -250,14 +250,13 @@ class ShareesAPIControllerTest extends TestCase {
*/
public function testSearch($getData, $apiSetting, $enumSetting, $remoteSharingEnabled, $emailSharingEnabled, $shareTypes, $shareWithGroupOnly, $shareeEnumeration, $allowGroupSharing) {
$search = isset($getData['search']) ? $getData['search'] : '';
- $itemType = isset($getData['itemType']) ? $getData['itemType'] : null;
+ $itemType = isset($getData['itemType']) ? $getData['itemType'] : 'irrelevant';
$page = isset($getData['page']) ? $getData['page'] : 1;
$perPage = isset($getData['perPage']) ? $getData['perPage'] : 200;
$shareType = isset($getData['shareType']) ? $getData['shareType'] : null;
- $config = $this->getMockBuilder('OCP\IConfig')
- ->disableOriginalConstructor()
- ->getMock();
+ /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject $config */
+ $config = $this->createMock(IConfig::class);
$config->expects($this->exactly(2))
->method('getAppValue')
->with('core', $this->anything(), $this->anything())
@@ -270,41 +269,29 @@ class ShareesAPIControllerTest extends TestCase {
->method('allowGroupSharing')
->willReturn($allowGroupSharing);
+ /** @var IRequest|\PHPUnit_Framework_MockObject_MockObject $request */
+ $request = $this->createMock(IRequest::class);
+ /** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject $urlGenerator */
+ $urlGenerator = $this->createMock(IURLGenerator::class);
+
/** @var \PHPUnit_Framework_MockObject_MockObject|\OCA\Files_Sharing\Controller\ShareesAPIController $sharees */
$sharees = $this->getMockBuilder('\OCA\Files_Sharing\Controller\ShareesAPIController')
->setConstructorArgs([
'files_sharing',
- $this->getMockBuilder('OCP\IRequest')->disableOriginalConstructor()->getMock(),
- $this->groupManager,
- $this->userManager,
- $this->contactsManager,
+ $request,
$config,
- $this->session,
- $this->getMockBuilder('OCP\IURLGenerator')->disableOriginalConstructor()->getMock(),
- $this->getMockBuilder('OCP\ILogger')->disableOriginalConstructor()->getMock(),
+ $urlGenerator,
$this->shareManager,
- $this->clientService,
- $this->cloudIdManager
+ $this->collaboratorSearch
])
- ->setMethods(array('searchSharees', 'isRemoteSharingAllowed', 'shareProviderExists'))
+ ->setMethods(array('isRemoteSharingAllowed', 'shareProviderExists'))
->getMock();
- $sharees->expects($this->once())
- ->method('searchSharees')
- ->willReturnCallback(function
- ($isearch, $iitemType, $ishareTypes, $ipage, $iperPage)
- use ($search, $itemType, $shareTypes, $page, $perPage) {
-
- // 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(count($shareTypes), count($ishareTypes));
- foreach($shareTypes as $expected) {
- $this->assertTrue(in_array($expected, $ishareTypes));
- }
- $this->assertSame($page, $ipage);
- $this->assertSame($perPage, $iperPage);
- return new Http\DataResponse();
- });
+
+ $this->collaboratorSearch->expects($this->once())
+ ->method('search')
+ ->with($search, $shareTypes, $this->anything(), $perPage, $this->invokePrivate($sharees, 'offset'))
+ ->willReturn([[], false]);
+
$sharees->expects($this->any())
->method('isRemoteSharingAllowed')
->with($itemType)