|
|
|
|
@ -21,10 +21,9 @@ |
|
|
|
|
|
|
|
|
|
namespace OCA\Files_Sharing\Tests\API; |
|
|
|
|
|
|
|
|
|
use Doctrine\DBAL\Connection; |
|
|
|
|
use OC\Share\Constants; |
|
|
|
|
use OCA\Files_Sharing\API\Sharees; |
|
|
|
|
use OCA\Files_sharing\Tests\TestCase; |
|
|
|
|
use OCP\AppFramework\Http; |
|
|
|
|
use OCP\Share; |
|
|
|
|
|
|
|
|
|
class ShareesTest extends TestCase { |
|
|
|
|
@ -652,15 +651,6 @@ class ShareesTest extends TestCase { |
|
|
|
|
], '', false, '', null, [0, 1], 1, 200, false], |
|
|
|
|
|
|
|
|
|
// Test pagination |
|
|
|
|
[[ |
|
|
|
|
'page' => 0, |
|
|
|
|
], '', true, '', null, $allTypes, 1, 200, false], |
|
|
|
|
[[ |
|
|
|
|
'page' => '0', |
|
|
|
|
], '', true, '', null, $allTypes, 1, 200, false], |
|
|
|
|
[[ |
|
|
|
|
'page' => -1, |
|
|
|
|
], '', true, '', null, $allTypes, 1, 200, false], |
|
|
|
|
[[ |
|
|
|
|
'page' => 1, |
|
|
|
|
], '', true, '', null, $allTypes, 1, 200, false], |
|
|
|
|
@ -669,15 +659,6 @@ class ShareesTest extends TestCase { |
|
|
|
|
], '', true, '', null, $allTypes, 10, 200, false], |
|
|
|
|
|
|
|
|
|
// Test perPage |
|
|
|
|
[[ |
|
|
|
|
'perPage' => 0, |
|
|
|
|
], '', true, '', null, $allTypes, 1, 200, false], |
|
|
|
|
[[ |
|
|
|
|
'perPage' => '0', |
|
|
|
|
], '', true, '', null, $allTypes, 1, 200, false], |
|
|
|
|
[[ |
|
|
|
|
'perPage' => -1, |
|
|
|
|
], '', true, '', null, $allTypes, 1, 1, false], |
|
|
|
|
[[ |
|
|
|
|
'perPage' => 1, |
|
|
|
|
], '', true, '', null, $allTypes, 1, 1, false], |
|
|
|
|
@ -758,6 +739,75 @@ class ShareesTest extends TestCase { |
|
|
|
|
$_GET = $oldGet; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function dataSearchInvalid() { |
|
|
|
|
return [ |
|
|
|
|
// Test invalid pagination |
|
|
|
|
[[ |
|
|
|
|
'page' => 0, |
|
|
|
|
], 'Invalid page'], |
|
|
|
|
[[ |
|
|
|
|
'page' => '0', |
|
|
|
|
], 'Invalid page'], |
|
|
|
|
[[ |
|
|
|
|
'page' => -1, |
|
|
|
|
], 'Invalid page'], |
|
|
|
|
|
|
|
|
|
// Test invalid perPage |
|
|
|
|
[[ |
|
|
|
|
'perPage' => 0, |
|
|
|
|
], 'Invalid perPage argument'], |
|
|
|
|
[[ |
|
|
|
|
'perPage' => '0', |
|
|
|
|
], 'Invalid perPage argument'], |
|
|
|
|
[[ |
|
|
|
|
'perPage' => -1, |
|
|
|
|
], 'Invalid perPage argument'], |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @dataProvider dataSearchInvalid |
|
|
|
|
* |
|
|
|
|
* @param array $getData |
|
|
|
|
* @param string $message |
|
|
|
|
*/ |
|
|
|
|
public function testSearchInvalid($getData, $message) { |
|
|
|
|
$oldGet = $_GET; |
|
|
|
|
$_GET = $getData; |
|
|
|
|
|
|
|
|
|
$config = $this->getMockBuilder('OCP\IConfig') |
|
|
|
|
->disableOriginalConstructor() |
|
|
|
|
->getMock(); |
|
|
|
|
$config->expects($this->never()) |
|
|
|
|
->method('getAppValue'); |
|
|
|
|
|
|
|
|
|
$sharees = $this->getMockBuilder('\OCA\Files_Sharing\API\Sharees') |
|
|
|
|
->setConstructorArgs([ |
|
|
|
|
$this->groupManager, |
|
|
|
|
$this->userManager, |
|
|
|
|
$this->contactsManager, |
|
|
|
|
$config, |
|
|
|
|
$this->session, |
|
|
|
|
$this->getMockBuilder('OCP\IURLGenerator')->disableOriginalConstructor()->getMock(), |
|
|
|
|
$this->getMockBuilder('OCP\IRequest')->disableOriginalConstructor()->getMock(), |
|
|
|
|
$this->getMockBuilder('OCP\ILogger')->disableOriginalConstructor()->getMock() |
|
|
|
|
]) |
|
|
|
|
->setMethods(array('searchSharees', 'isRemoteSharingAllowed')) |
|
|
|
|
->getMock(); |
|
|
|
|
$sharees->expects($this->never()) |
|
|
|
|
->method('searchSharees'); |
|
|
|
|
$sharees->expects($this->never()) |
|
|
|
|
->method('isRemoteSharingAllowed'); |
|
|
|
|
|
|
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject|\OCA\Files_Sharing\API\Sharees $sharees */ |
|
|
|
|
$ocs = $sharees->search(); |
|
|
|
|
$this->assertInstanceOf('\OC_OCS_Result', $ocs); |
|
|
|
|
|
|
|
|
|
$this->assertOCSError($ocs, $message); |
|
|
|
|
|
|
|
|
|
$_GET = $oldGet; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function dataIsRemoteSharingAllowed() { |
|
|
|
|
return [ |
|
|
|
|
['file', true], |
|
|
|
|
@ -940,13 +990,7 @@ class ShareesTest extends TestCase { |
|
|
|
|
$ocs = $this->invokePrivate($this->sharees, 'searchSharees', ['', null, [], [], 0, 0, false]); |
|
|
|
|
$this->assertInstanceOf('\OC_OCS_Result', $ocs); |
|
|
|
|
|
|
|
|
|
$this->assertSame(400, $ocs->getStatusCode(), 'Expected status code 400'); |
|
|
|
|
$this->assertSame([], $ocs->getData(), 'Expected that no data is send'); |
|
|
|
|
|
|
|
|
|
$meta = $ocs->getMeta(); |
|
|
|
|
$this->assertNotEmpty($meta); |
|
|
|
|
$this->assertArrayHasKey('message', $meta); |
|
|
|
|
$this->assertSame('missing itemType', $meta['message']); |
|
|
|
|
$this->assertOCSError($ocs, 'Missing itemType'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function dataGetPaginationLink() { |
|
|
|
|
@ -992,4 +1036,18 @@ class ShareesTest extends TestCase { |
|
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $this->invokePrivate($this->sharees, 'isV2')); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param \OC_OCS_Result $ocs |
|
|
|
|
* @param string $message |
|
|
|
|
*/ |
|
|
|
|
protected function assertOCSError(\OC_OCS_Result $ocs, $message) { |
|
|
|
|
$this->assertSame(Http::STATUS_BAD_REQUEST, $ocs->getStatusCode(), 'Expected status code 400'); |
|
|
|
|
$this->assertSame([], $ocs->getData(), 'Expected that no data is send'); |
|
|
|
|
|
|
|
|
|
$meta = $ocs->getMeta(); |
|
|
|
|
$this->assertNotEmpty($meta); |
|
|
|
|
$this->assertArrayHasKey('message', $meta); |
|
|
|
|
$this->assertSame($message, $meta['message']); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|