summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/tests/API/Share20OCSTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_sharing/tests/API/Share20OCSTest.php')
-rw-r--r--apps/files_sharing/tests/API/Share20OCSTest.php409
1 files changed, 166 insertions, 243 deletions
diff --git a/apps/files_sharing/tests/API/Share20OCSTest.php b/apps/files_sharing/tests/API/Share20OCSTest.php
index 5486a83c159..b32684ef547 100644
--- a/apps/files_sharing/tests/API/Share20OCSTest.php
+++ b/apps/files_sharing/tests/API/Share20OCSTest.php
@@ -23,6 +23,8 @@
*/
namespace OCA\Files_Sharing\Tests\API;
+use OCP\AppFramework\Http\DataResponse;
+use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\IL10N;
use OCA\Files_Sharing\API\Share20OCS;
use OCP\Files\NotFoundException;
@@ -33,6 +35,7 @@ use OCP\IURLGenerator;
use OCP\IUser;
use OCP\Files\IRootFolder;
use OCP\Lock\LockedException;
+use Punic\Data;
/**
* Class Share20OCSTest
@@ -42,6 +45,9 @@ use OCP\Lock\LockedException;
*/
class Share20OCSTest extends \Test\TestCase {
+ /** @var string */
+ private $appName = 'files_sharing';
+
/** @var \OC\Share20\Manager | \PHPUnit_Framework_MockObject_MockObject */
private $shareManager;
@@ -94,10 +100,11 @@ class Share20OCSTest extends \Test\TestCase {
}));
$this->ocs = new Share20OCS(
+ $this->appName,
+ $this->request,
$this->shareManager,
$this->groupManager,
$this->userManager,
- $this->request,
$this->rootFolder,
$this->urlGenerator,
$this->currentUser,
@@ -108,10 +115,11 @@ class Share20OCSTest extends \Test\TestCase {
private function mockFormatShare() {
return $this->getMockBuilder('OCA\Files_Sharing\API\Share20OCS')
->setConstructorArgs([
+ $this->appName,
+ $this->request,
$this->shareManager,
$this->groupManager,
$this->userManager,
- $this->request,
$this->rootFolder,
$this->urlGenerator,
$this->currentUser,
@@ -124,6 +132,10 @@ class Share20OCSTest extends \Test\TestCase {
return \OC::$server->getShareManager()->newShare();
}
+ /**
+ * @expectedException \OCP\AppFramework\OCS\OCSNotFoundException
+ * @expectedExceptionMessage Wrong share ID, share doesn't exist
+ */
public function testDeleteShareShareNotFound() {
$this->shareManager
->expects($this->exactly(2))
@@ -138,8 +150,7 @@ class Share20OCSTest extends \Test\TestCase {
$this->shareManager->method('outgoingServer2ServerSharesAllowed')->willReturn(true);
- $expected = new \OC_OCS_Result(null, 404, 'Wrong share ID, share doesn\'t exist');
- $this->assertEquals($expected, $this->ocs->deleteShare(42));
+ $this->ocs->deleteShare(42);
}
public function testDeleteShare() {
@@ -161,14 +172,18 @@ class Share20OCSTest extends \Test\TestCase {
$node->expects($this->once())
->method('lock')
->with(\OCP\Lock\ILockingProvider::LOCK_SHARED);
- $node->expects($this->once())
- ->method('unlock')
- ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED);
- $expected = new \OC_OCS_Result();
- $this->assertEquals($expected, $this->ocs->deleteShare(42));
+ $expected = new DataResponse();
+ $result = $this->ocs->deleteShare(42);
+
+ $this->assertInstanceOf(get_class($expected), $result);
+ $this->assertEquals($expected->getData(), $result->getData());
}
+ /**
+ * @expectedException \OCP\AppFramework\OCS\OCSNotFoundException
+ * @expectedExceptionMessage could not delete share
+ */
public function testDeleteShareLocked() {
$node = $this->getMockBuilder('\OCP\Files\File')->getMock();
@@ -189,12 +204,8 @@ class Share20OCSTest extends \Test\TestCase {
->method('lock')
->with(\OCP\Lock\ILockingProvider::LOCK_SHARED)
->will($this->throwException(new LockedException('mypath')));
- $node->expects($this->never())
- ->method('unlock')
- ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED);
- $expected = new \OC_OCS_Result(null, 404, 'could not delete share');
- $this->assertEquals($expected, $this->ocs->deleteShare(42));
+ $this->ocs->deleteShare(42);
}
/*
@@ -411,10 +422,11 @@ class Share20OCSTest extends \Test\TestCase {
public function testGetShare(\OCP\Share\IShare $share, array $result) {
$ocs = $this->getMockBuilder('OCA\Files_Sharing\API\Share20OCS')
->setConstructorArgs([
+ $this->appName,
+ $this->request,
$this->shareManager,
$this->groupManager,
$this->userManager,
- $this->request,
$this->rootFolder,
$this->urlGenerator,
$this->currentUser,
@@ -422,7 +434,9 @@ class Share20OCSTest extends \Test\TestCase {
])->setMethods(['canAccessShare'])
->getMock();
- $ocs->method('canAccessShare')->willReturn(true);
+ $ocs->expects($this->any())
+ ->method('canAccessShare')
+ ->willReturn(true);
$this->shareManager
->expects($this->once())
@@ -471,10 +485,13 @@ class Share20OCSTest extends \Test\TestCase {
['group', $group],
]));
- $expected = new \OC_OCS_Result([$result]);
- $this->assertEquals($expected->getData(), $ocs->getShare($share->getId())->getData());
+ $this->assertEquals($result, $ocs->getShare($share->getId())->getData()['data'][0]);
}
+ /**
+ * @expectedException \OCP\AppFramework\OCS\OCSNotFoundException
+ * @expectedExceptionMessage Wrong share ID, share doesn't exist
+ */
public function testGetShareInvalidNode() {
$share = \OC::$server->getShareManager()->newShare();
$share->setSharedBy('initiator')
@@ -487,8 +504,7 @@ class Share20OCSTest extends \Test\TestCase {
->with('ocinternal:42')
->willReturn($share);
- $expected = new \OC_OCS_Result(null, 404, 'Wrong share ID, share doesn\'t exist');
- $this->assertEquals($expected->getMeta(), $this->ocs->getShare(42)->getMeta());
+ $this->ocs->getShare(42);
}
public function testCanAccessShare() {
@@ -538,15 +554,18 @@ class Share20OCSTest extends \Test\TestCase {
$this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
}
+ /**
+ * @expectedException \OCP\AppFramework\OCS\OCSNotFoundException
+ * @expectedExceptionMessage Please specify a file or folder path
+ */
public function testCreateShareNoPath() {
- $expected = new \OC_OCS_Result(null, 404, 'Please specify a file or folder path');
-
- $result = $this->ocs->createShare();
-
- $this->assertEquals($expected->getMeta(), $result->getMeta());
- $this->assertEquals($expected->getData(), $result->getData());
+ $this->ocs->createShare();
}
+ /**
+ * @expectedException \OCP\AppFramework\OCS\OCSNotFoundException
+ * @expectedExceptionMessage Wrong path, file/folder doesn't exist
+ */
public function testCreateShareInvalidPath() {
$this->request
->method('getParam')
@@ -565,14 +584,13 @@ class Share20OCSTest extends \Test\TestCase {
->with('invalid-path')
->will($this->throwException(new \OCP\Files\NotFoundException()));
- $expected = new \OC_OCS_Result(null, 404, 'Wrong path, file/folder doesn\'t exist');
-
- $result = $this->ocs->createShare();
-
- $this->assertEquals($expected->getMeta(), $result->getMeta());
- $this->assertEquals($expected->getData(), $result->getData());
+ $this->ocs->createShare();
}
+ /**
+ * @expectedException \OCP\AppFramework\OCS\OCSNotFoundException
+ * @expectedExceptionMessage invalid permissions
+ */
public function testCreateShareInvalidPermissions() {
$share = $this->newShare();
$this->shareManager->method('newShare')->willReturn($share);
@@ -600,14 +618,13 @@ class Share20OCSTest extends \Test\TestCase {
->method('lock')
->with(\OCP\Lock\ILockingProvider::LOCK_SHARED);
- $expected = new \OC_OCS_Result(null, 404, 'invalid permissions');
-
- $result = $this->ocs->createShare();
-
- $this->assertEquals($expected->getMeta(), $result->getMeta());
- $this->assertEquals($expected->getData(), $result->getData());
+ $this->ocs->createShare();
}
+ /**
+ * @expectedException \OCP\AppFramework\OCS\OCSNotFoundException
+ * @expectedExceptionMessage Please specify a valid user
+ */
public function testCreateShareUserNoShareWith() {
$share = $this->newShare();
$this->shareManager->method('newShare')->willReturn($share);
@@ -641,14 +658,13 @@ class Share20OCSTest extends \Test\TestCase {
->method('lock')
->with(\OCP\Lock\ILockingProvider::LOCK_SHARED);
- $expected = new \OC_OCS_Result(null, 404, 'Please specify a valid user');
-
- $result = $this->ocs->createShare();
-
- $this->assertEquals($expected->getMeta(), $result->getMeta());
- $this->assertEquals($expected->getData(), $result->getData());
+ $this->ocs->createShare();
}
+ /**
+ * @expectedException \OCP\AppFramework\OCS\OCSNotFoundException
+ * @expectedExceptionMessage Please specify a valid user
+ */
public function testCreateShareUserNoValidShareWith() {
$share = $this->newShare();
$this->shareManager->method('newShare')->willReturn($share);
@@ -679,16 +695,11 @@ class Share20OCSTest extends \Test\TestCase {
->with('valid-path')
->willReturn($path);
- $expected = new \OC_OCS_Result(null, 404, 'Please specify a valid user');
-
$path->expects($this->once())
->method('lock')
->with(\OCP\Lock\ILockingProvider::LOCK_SHARED);
- $result = $this->ocs->createShare();
-
- $this->assertEquals($expected->getMeta(), $result->getMeta());
- $this->assertEquals($expected->getData(), $result->getData());
+ $this->ocs->createShare();
}
public function testCreateShareUser() {
@@ -697,10 +708,11 @@ class Share20OCSTest extends \Test\TestCase {
$ocs = $this->getMockBuilder('OCA\Files_Sharing\API\Share20OCS')
->setConstructorArgs([
+ $this->appName,
+ $this->request,
$this->shareManager,
$this->groupManager,
$this->userManager,
- $this->request,
$this->rootFolder,
$this->urlGenerator,
$this->currentUser,
@@ -739,9 +751,6 @@ class Share20OCSTest extends \Test\TestCase {
$path->expects($this->once())
->method('lock')
->with(\OCP\Lock\ILockingProvider::LOCK_SHARED);
- $path->expects($this->once())
- ->method('unlock')
- ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED);
$this->shareManager->method('createShare')
->with($this->callback(function (\OCP\Share\IShare $share) use ($path) {
@@ -757,13 +766,17 @@ class Share20OCSTest extends \Test\TestCase {
}))
->will($this->returnArgument(0));
- $expected = new \OC_OCS_Result();
+ $expected = new DataResponse(['data' => null]);
$result = $ocs->createShare();
- $this->assertEquals($expected->getMeta(), $result->getMeta());
+ $this->assertInstanceOf(get_class($expected), $result);
$this->assertEquals($expected->getData(), $result->getData());
}
+ /**
+ * @expectedException \OCP\AppFramework\OCS\OCSNotFoundException
+ * @expectedExceptionMessage Please specify a valid user
+ */
public function testCreateShareGroupNoValidShareWith() {
$share = $this->newShare();
$this->shareManager->method('newShare')->willReturn($share);
@@ -795,16 +808,11 @@ class Share20OCSTest extends \Test\TestCase {
->with('valid-path')
->willReturn($path);
- $expected = new \OC_OCS_Result(null, 404, 'Please specify a valid user');
-
$path->expects($this->once())
->method('lock')
->with(\OCP\Lock\ILockingProvider::LOCK_SHARED);
- $result = $this->ocs->createShare();
-
- $this->assertEquals($expected->getMeta(), $result->getMeta());
- $this->assertEquals($expected->getData(), $result->getData());
+ $this->ocs->createShare();
}
public function testCreateShareGroup() {
@@ -813,10 +821,11 @@ class Share20OCSTest extends \Test\TestCase {
$ocs = $this->getMockBuilder('OCA\Files_Sharing\API\Share20OCS')
->setConstructorArgs([
+ $this->appName,
+ $this->request,
$this->shareManager,
$this->groupManager,
$this->userManager,
- $this->request,
$this->rootFolder,
$this->urlGenerator,
$this->currentUser,
@@ -835,9 +844,9 @@ class Share20OCSTest extends \Test\TestCase {
$userFolder = $this->getMockBuilder('\OCP\Files\Folder')->getMock();
$this->rootFolder->expects($this->once())
- ->method('getUserFolder')
- ->with('currentUser')
- ->willReturn($userFolder);
+ ->method('getUserFolder')
+ ->with('currentUser')
+ ->willReturn($userFolder);
$path = $this->getMockBuilder('\OCP\Files\Folder')->getMock();
$storage = $this->getMockBuilder('OCP\Files\Storage')->getMock();
@@ -846,9 +855,9 @@ class Share20OCSTest extends \Test\TestCase {
->willReturn(false);
$path->method('getStorage')->willReturn($storage);
$userFolder->expects($this->once())
- ->method('get')
- ->with('valid-path')
- ->willReturn($path);
+ ->method('get')
+ ->with('valid-path')
+ ->willReturn($path);
$this->groupManager->method('groupExists')->with('validGroup')->willReturn(true);
@@ -859,27 +868,28 @@ class Share20OCSTest extends \Test\TestCase {
$path->expects($this->once())
->method('lock')
->with(\OCP\Lock\ILockingProvider::LOCK_SHARED);
- $path->expects($this->once())
- ->method('unlock')
- ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED);
$this->shareManager->method('createShare')
->with($this->callback(function (\OCP\Share\IShare $share) use ($path) {
return $share->getNode() === $path &&
- $share->getPermissions() === \OCP\Constants::PERMISSION_ALL &&
- $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP &&
- $share->getSharedWith() === 'validGroup' &&
- $share->getSharedBy() === 'currentUser';
+ $share->getPermissions() === \OCP\Constants::PERMISSION_ALL &&
+ $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP &&
+ $share->getSharedWith() === 'validGroup' &&
+ $share->getSharedBy() === 'currentUser';
}))
->will($this->returnArgument(0));
- $expected = new \OC_OCS_Result();
+ $expected = new DataResponse(['data' => null]);
$result = $ocs->createShare();
- $this->assertEquals($expected->getMeta(), $result->getMeta());
+ $this->assertInstanceOf(get_class($expected), $result);
$this->assertEquals($expected->getData(), $result->getData());
}
+ /**
+ * @expectedException \OCP\AppFramework\OCS\OCSNotFoundException
+ * @expectedExceptionMessage Group sharing is disabled by the administrator
+ */
public function testCreateShareGroupNotAllowed() {
$share = $this->newShare();
$this->shareManager->method('newShare')->willReturn($share);
@@ -916,14 +926,13 @@ class Share20OCSTest extends \Test\TestCase {
->method('allowGroupSharing')
->willReturn(false);
- $expected = new \OC_OCS_Result(null, 404, 'Group sharing is disabled by the administrator');
-
- $result = $this->ocs->createShare();
-
- $this->assertEquals($expected->getMeta(), $result->getMeta());
- $this->assertEquals($expected->getData(), $result->getData());
+ $this->ocs->createShare();
}
+ /**
+ * @expectedException \OCP\AppFramework\OCS\OCSNotFoundException
+ * @expectedExceptionMessage Public link sharing is disabled by the administrator
+ */
public function testCreateShareLinkNoLinksAllowed() {
$this->request
->method('getParam')
@@ -943,13 +952,13 @@ class Share20OCSTest extends \Test\TestCase {
$this->shareManager->method('newShare')->willReturn(\OC::$server->getShareManager()->newShare());
- $expected = new \OC_OCS_Result(null, 404, 'Public link sharing is disabled by the administrator');
- $result = $this->ocs->createShare();
-
- $this->assertEquals($expected->getMeta(), $result->getMeta());
- $this->assertEquals($expected->getData(), $result->getData());
+ $this->ocs->createShare();
}
+ /**
+ * @expectedException \OCP\AppFramework\OCS\OCSForbiddenException
+ * @expectedExceptionMessage Public upload disabled by the administrator
+ */
public function testCreateShareLinkNoPublicUpload() {
$this->request
->method('getParam')
@@ -971,13 +980,13 @@ class Share20OCSTest extends \Test\TestCase {
$this->shareManager->method('newShare')->willReturn(\OC::$server->getShareManager()->newShare());
$this->shareManager->method('shareApiAllowLinks')->willReturn(true);
- $expected = new \OC_OCS_Result(null, 403, 'Public upload disabled by the administrator');
- $result = $this->ocs->createShare();
-
- $this->assertEquals($expected->getMeta(), $result->getMeta());
- $this->assertEquals($expected->getData(), $result->getData());
+ $this->ocs->createShare();
}
+ /**
+ * @expectedException \OCP\AppFramework\OCS\OCSNotFoundException
+ * @expectedExceptionMessage Public upload is only possible for publicly shared folders
+ */
public function testCreateShareLinkPublicUploadFile() {
$this->request
->method('getParam')
@@ -1000,11 +1009,7 @@ class Share20OCSTest extends \Test\TestCase {
$this->shareManager->method('shareApiAllowLinks')->willReturn(true);
$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
- $expected = new \OC_OCS_Result(null, 404, 'Public upload is only possible for publicly shared folders');
- $result = $this->ocs->createShare();
-
- $this->assertEquals($expected->getMeta(), $result->getMeta());
- $this->assertEquals($expected->getData(), $result->getData());
+ $this->ocs->createShare();
}
public function testCreateShareLinkPublicUploadFolder() {
@@ -1044,10 +1049,10 @@ class Share20OCSTest extends \Test\TestCase {
})
)->will($this->returnArgument(0));
- $expected = new \OC_OCS_Result(null);
+ $expected = new DataResponse(['data' => null]);
$result = $ocs->createShare();
- $this->assertEquals($expected->getMeta(), $result->getMeta());
+ $this->assertInstanceOf(get_class($expected), $result);
$this->assertEquals($expected->getData(), $result->getData());
}
@@ -1088,10 +1093,10 @@ class Share20OCSTest extends \Test\TestCase {
})
)->will($this->returnArgument(0));
- $expected = new \OC_OCS_Result(null);
+ $expected = new DataResponse(['data' => null]);
$result = $ocs->createShare();
- $this->assertEquals($expected->getMeta(), $result->getMeta());
+ $this->assertInstanceOf(get_class($expected), $result);
$this->assertEquals($expected->getData(), $result->getData());
}
@@ -1135,13 +1140,17 @@ class Share20OCSTest extends \Test\TestCase {
})
)->will($this->returnArgument(0));
- $expected = new \OC_OCS_Result(null);
+ $expected = new DataResponse(['data' => null]);
$result = $ocs->createShare();
- $this->assertEquals($expected->getMeta(), $result->getMeta());
+ $this->assertInstanceOf(get_class($expected), $result);
$this->assertEquals($expected->getData(), $result->getData());
}
+ /**
+ * @expectedException \OCP\AppFramework\OCS\OCSNotFoundException
+ * @expectedExceptionMessage Invalid date, date format must be YYYY-MM-DD
+ */
public function testCreateShareInvalidExpireDate() {
$ocs = $this->mockFormatShare();
@@ -1168,11 +1177,7 @@ class Share20OCSTest extends \Test\TestCase {
$this->shareManager->method('shareApiAllowLinks')->willReturn(true);
$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
- $expected = new \OC_OCS_Result(null, 404, 'Invalid date, date format must be YYYY-MM-DD');
- $result = $ocs->createShare();
-
- $this->assertEquals($expected->getMeta(), $result->getMeta());
- $this->assertEquals($expected->getData(), $result->getData());
+ $ocs->createShare();
}
/**
@@ -1185,10 +1190,11 @@ class Share20OCSTest extends \Test\TestCase {
$ocs = $this->getMockBuilder('OCA\Files_Sharing\API\Share20OCS')
->setConstructorArgs([
+ $this->appName,
+ $this->request,
$this->shareManager,
$this->groupManager,
$this->userManager,
- $this->request,
$this->rootFolder,
$this->urlGenerator,
$this->currentUser,
@@ -1236,6 +1242,10 @@ class Share20OCSTest extends \Test\TestCase {
$ocs->createShare();
}
+ /**
+ * @expectedException \OCP\AppFramework\OCS\OCSNotFoundException
+ * @expectedExceptionMessage Wrong share ID, share doesn't exist
+ */
public function testUpdateShareCantAccess() {
$node = $this->getMockBuilder('\OCP\Files\Folder')->getMock();
$share = $this->newShare();
@@ -1247,13 +1257,13 @@ class Share20OCSTest extends \Test\TestCase {
$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
- $expected = new \OC_OCS_Result(null, 404, 'Wrong share ID, share doesn\'t exist');
- $result = $this->ocs->updateShare(42);
-
- $this->assertEquals($expected->getMeta(), $result->getMeta());
- $this->assertEquals($expected->getData(), $result->getData());
+ $this->ocs->updateShare(42);
}
+ /**
+ * @expectedException \OCP\AppFramework\OCS\OCSBadRequestException
+ * @expectedExceptionMessage Wrong or no update parameter given
+ */
public function testUpdateNoParametersLink() {
$node = $this->getMockBuilder('\OCP\Files\Folder')->getMock();
$share = $this->newShare();
@@ -1268,13 +1278,13 @@ class Share20OCSTest extends \Test\TestCase {
$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
- $expected = new \OC_OCS_Result(null, 400, 'Wrong or no update parameter given');
- $result = $this->ocs->updateShare(42);
-
- $this->assertEquals($expected->getMeta(), $result->getMeta());
- $this->assertEquals($expected->getData(), $result->getData());
+ $this->ocs->updateShare(42);
}
+ /**
+ * @expectedException \OCP\AppFramework\OCS\OCSBadRequestException
+ * @expectedExceptionMessage Wrong or no update parameter given
+ */
public function testUpdateNoParametersOther() {
$node = $this->getMockBuilder('\OCP\Files\Folder')->getMock();
$share = $this->newShare();
@@ -1289,11 +1299,7 @@ class Share20OCSTest extends \Test\TestCase {
$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
- $expected = new \OC_OCS_Result(null, 400, 'Wrong or no update parameter given');
- $result = $this->ocs->updateShare(42);
-
- $this->assertEquals($expected->getMeta(), $result->getMeta());
- $this->assertEquals($expected->getData(), $result->getData());
+ $this->ocs->updateShare(42);
}
public function testUpdateLinkShareClear() {
@@ -1312,9 +1318,6 @@ class Share20OCSTest extends \Test\TestCase {
$node->expects($this->once())
->method('lock')
->with(\OCP\Lock\ILockingProvider::LOCK_SHARED);
- $node->expects($this->once())
- ->method('unlock')
- ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED);
$this->request
->method('getParam')
@@ -1334,10 +1337,10 @@ class Share20OCSTest extends \Test\TestCase {
})
)->will($this->returnArgument(0));
- $expected = new \OC_OCS_Result(null);
+ $expected = new DataResponse(['data' => null]);
$result = $ocs->updateShare(42);
- $this->assertEquals($expected->getMeta(), $result->getMeta());
+ $this->assertInstanceOf(get_class($expected), $result);
$this->assertEquals($expected->getData(), $result->getData());
}
@@ -1374,10 +1377,10 @@ class Share20OCSTest extends \Test\TestCase {
})
)->will($this->returnArgument(0));
- $expected = new \OC_OCS_Result(null);
+ $expected = new DataResponse(['data' => null]);
$result = $ocs->updateShare(42);
- $this->assertEquals($expected->getMeta(), $result->getMeta());
+ $this->assertInstanceOf(get_class($expected), $result);
$this->assertEquals($expected->getData(), $result->getData());
}
@@ -1412,13 +1415,17 @@ class Share20OCSTest extends \Test\TestCase {
})
)->will($this->returnArgument(0));
- $expected = new \OC_OCS_Result(null);
+ $expected = new DataResponse(['data' => null]);
$result = $ocs->updateShare(42);
- $this->assertEquals($expected->getMeta(), $result->getMeta());
+ $this->assertInstanceOf(get_class($expected), $result);
$this->assertEquals($expected->getData(), $result->getData());
}
+ /**
+ * @expectedException \OCP\AppFramework\OCS\OCSBadRequestException
+ * @expectedExceptionMessage Invalid date. Format must be YYYY-MM-DD
+ */
public function testUpdateLinkShareInvalidDate() {
$ocs = $this->mockFormatShare();
@@ -1441,11 +1448,7 @@ class Share20OCSTest extends \Test\TestCase {
$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
- $expected = new \OC_OCS_Result(null, 400, 'Invalid date. Format must be YYYY-MM-DD');
- $result = $ocs->updateShare(42);
-
- $this->assertEquals($expected->getMeta(), $result->getMeta());
- $this->assertEquals($expected->getData(), $result->getData());
+ $ocs->updateShare(42);
}
public function publicUploadParamsProvider() {
@@ -1470,6 +1473,8 @@ class Share20OCSTest extends \Test\TestCase {
/**
* @dataProvider publicUploadParamsProvider
+ * @expectedException \OCP\AppFramework\OCS\OCSForbiddenException
+ * @expectedExceptionMessage Public upload disabled by the administrator
*/
public function testUpdateLinkSharePublicUploadNotAllowed($params) {
$ocs = $this->mockFormatShare();
@@ -1489,13 +1494,13 @@ class Share20OCSTest extends \Test\TestCase {
$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(false);
- $expected = new \OC_OCS_Result(null, 403, 'Public upload disabled by the administrator');
- $result = $ocs->updateShare(42);
-
- $this->assertEquals($expected->getMeta(), $result->getMeta());
- $this->assertEquals($expected->getData(), $result->getData());
+ $ocs->updateShare(42);
}
+ /**
+ * @expectedException \OCP\AppFramework\OCS\OCSBadRequestException
+ * @expectedExceptionMessage Public upload is only possible for publicly shared folders
+ */
public function testUpdateLinkSharePublicUploadOnFile() {
$ocs = $this->mockFormatShare();
@@ -1518,11 +1523,7 @@ class Share20OCSTest extends \Test\TestCase {
$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
- $expected = new \OC_OCS_Result(null, 400, 'Public upload is only possible for publicly shared folders');
- $result = $ocs->updateShare(42);
-
- $this->assertEquals($expected->getMeta(), $result->getMeta());
- $this->assertEquals($expected->getData(), $result->getData());
+ $ocs->updateShare(42);
}
public function testUpdateLinkSharePasswordDoesNotChangeOther() {
@@ -1544,9 +1545,6 @@ class Share20OCSTest extends \Test\TestCase {
$node->expects($this->once())
->method('lock')
->with(\OCP\Lock\ILockingProvider::LOCK_SHARED);
- $node->expects($this->once())
- ->method('unlock')
- ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED);
$this->request
->method('getParam')
@@ -1564,10 +1562,10 @@ class Share20OCSTest extends \Test\TestCase {
})
)->will($this->returnArgument(0));
- $expected = new \OC_OCS_Result(null);
+ $expected = new DataResponse(['data' => null]);
$result = $ocs->updateShare(42);
- $this->assertEquals($expected->getMeta(), $result->getMeta());
+ $this->assertInstanceOf(get_class($expected), $result);
$this->assertEquals($expected->getData(), $result->getData());
}
@@ -1593,9 +1591,6 @@ class Share20OCSTest extends \Test\TestCase {
$node->expects($this->once())
->method('lock')
->with(\OCP\Lock\ILockingProvider::LOCK_SHARED);
- $node->expects($this->once())
- ->method('unlock')
- ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED);
$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
@@ -1610,10 +1605,10 @@ class Share20OCSTest extends \Test\TestCase {
})
)->will($this->returnArgument(0));
- $expected = new \OC_OCS_Result(null);
+ $expected = new DataResponse(['data' => null]);
$result = $ocs->updateShare(42);
- $this->assertEquals($expected->getMeta(), $result->getMeta());
+ $this->assertInstanceOf(get_class($expected), $result);
$this->assertEquals($expected->getData(), $result->getData());
}
@@ -1650,10 +1645,10 @@ class Share20OCSTest extends \Test\TestCase {
})
)->will($this->returnArgument(0));
- $expected = new \OC_OCS_Result(null);
+ $expected = new DataResponse(['data' => null]);
$result = $ocs->updateShare(42);
- $this->assertEquals($expected->getMeta(), $result->getMeta());
+ $this->assertInstanceOf(get_class($expected), $result);
$this->assertEquals($expected->getData(), $result->getData());
}
@@ -1692,13 +1687,17 @@ class Share20OCSTest extends \Test\TestCase {
$this->shareManager->method('getSharedWith')->willReturn([]);
- $expected = new \OC_OCS_Result(null);
+ $expected = new DataResponse(['data' => null]);
$result = $ocs->updateShare(42);
- $this->assertEquals($expected->getMeta(), $result->getMeta());
+ $this->assertInstanceOf(get_class($expected), $result);
$this->assertEquals($expected->getData(), $result->getData());
}
+ /**
+ * @expectedException \OCP\AppFramework\OCS\OCSBadRequestException
+ * @expectedExceptionMessage Can't change permissions for public share links
+ */
public function testUpdateLinkShareInvalidPermissions() {
$ocs = $this->mockFormatShare();
@@ -1724,11 +1723,7 @@ class Share20OCSTest extends \Test\TestCase {
$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
- $expected = new \OC_OCS_Result(null, 400, 'Can\'t change permissions for public share links');
- $result = $ocs->updateShare(42);
-
- $this->assertEquals($expected->getMeta(), $result->getMeta());
- $this->assertEquals($expected->getData(), $result->getData());
+ $ocs->updateShare(42);
}
public function testUpdateOtherPermissions() {
@@ -1759,10 +1754,10 @@ class Share20OCSTest extends \Test\TestCase {
$this->shareManager->method('getSharedWith')->willReturn([]);
- $expected = new \OC_OCS_Result(null);
+ $expected = new DataResponse(['data' => null]);
$result = $ocs->updateShare(42);
- $this->assertEquals($expected->getMeta(), $result->getMeta());
+ $this->assertInstanceOf(get_class($expected), $result);
$this->assertEquals($expected->getData(), $result->getData());
}
@@ -2049,8 +2044,6 @@ class Share20OCSTest extends \Test\TestCase {
[], $share, [], true
];
-
-
return $result;
}
@@ -2091,74 +2084,4 @@ class Share20OCSTest extends \Test\TestCase {
$this->assertTrue($exception);
}
}
-
- /**
- * @return Share20OCS
- */
- public function getOcsDisabledAPI() {
- $shareManager = $this->getMockBuilder('OCP\Share\IManager')
- ->disableOriginalConstructor()
- ->getMock();
- $shareManager
- ->expects($this->any())
- ->method('shareApiEnabled')
- ->willReturn(false);
-
- return new Share20OCS(
- $shareManager,
- $this->groupManager,
- $this->userManager,
- $this->request,
- $this->rootFolder,
- $this->urlGenerator,
- $this->currentUser,
- $this->l
- );
- }
-
- public function testGetShareApiDisabled() {
- $ocs = $this->getOcsDisabledAPI();
-
- $expected = new \OC_OCS_Result(null, 404, 'Share API is disabled');
- $result = $ocs->getShare('my:id');
-
- $this->assertEquals($expected, $result);
- }
-
- public function testDeleteShareApiDisabled() {
- $ocs = $this->getOcsDisabledAPI();
-
- $expected = new \OC_OCS_Result(null, 404, 'Share API is disabled');
- $result = $ocs->deleteShare('my:id');
-
- $this->assertEquals($expected, $result);
- }
-
-
- public function testCreateShareApiDisabled() {
- $ocs = $this->getOcsDisabledAPI();
-
- $expected = new \OC_OCS_Result(null, 404, 'Share API is disabled');
- $result = $ocs->createShare();
-
- $this->assertEquals($expected, $result);
- }
-
- public function testGetSharesApiDisabled() {
- $ocs = $this->getOcsDisabledAPI();
-
- $expected = new \OC_OCS_Result();
- $result = $ocs->getShares();
-
- $this->assertEquals($expected, $result);
- }
-
- public function testUpdateShareApiDisabled() {
- $ocs = $this->getOcsDisabledAPI();
-
- $expected = new \OC_OCS_Result(null, 404, 'Share API is disabled');
- $result = $ocs->updateShare('my:id');
-
- $this->assertEquals($expected, $result);
- }
}