summaryrefslogtreecommitdiffstats
path: root/tests/lib/share20/managertest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/share20/managertest.php')
-rw-r--r--tests/lib/share20/managertest.php549
1 files changed, 333 insertions, 216 deletions
diff --git a/tests/lib/share20/managertest.php b/tests/lib/share20/managertest.php
index 6043d30a0bb..131bc7fbfd2 100644
--- a/tests/lib/share20/managertest.php
+++ b/tests/lib/share20/managertest.php
@@ -20,6 +20,8 @@
*/
namespace Test\Share20;
+use OCP\Files\IRootFolder;
+use OCP\IUserManager;
use OCP\Share\IProviderFactory;
use OCP\Share\IShare;
use OC\Share20\Manager;
@@ -34,7 +36,6 @@ use OCP\Security\ISecureRandom;
use OCP\Security\IHasher;
use OCP\Files\Mount\IMountManager;
use OCP\IGroupManager;
-use Sabre\VObject\Property\VCard\DateTime;
/**
* Class ManagerTest
@@ -46,33 +47,28 @@ class ManagerTest extends \Test\TestCase {
/** @var Manager */
protected $manager;
-
/** @var ILogger */
protected $logger;
-
/** @var IConfig */
protected $config;
-
/** @var ISecureRandom */
protected $secureRandom;
-
/** @var IHasher */
protected $hasher;
-
/** @var IShareProvider | \PHPUnit_Framework_MockObject_MockObject */
protected $defaultProvider;
-
/** @var IMountManager */
protected $mountManager;
-
/** @var IGroupManager */
protected $groupManager;
-
/** @var IL10N */
protected $l;
-
/** @var DummyFactory */
protected $factory;
+ /** @var IUserManager */
+ protected $userManager;
+ /** @var IRootFolder | \PHPUnit_Framework_MockObject_MockObject */
+ protected $rootFolder;
public function setUp() {
@@ -82,6 +78,8 @@ class ManagerTest extends \Test\TestCase {
$this->hasher = $this->getMock('\OCP\Security\IHasher');
$this->mountManager = $this->getMock('\OCP\Files\Mount\IMountManager');
$this->groupManager = $this->getMock('\OCP\IGroupManager');
+ $this->userManager = $this->getMock('\OCP\IUserManager');
+ $this->rootFolder = $this->getMock('\OCP\Files\IRootFolder');
$this->l = $this->getMock('\OCP\IL10N');
$this->l->method('t')
@@ -99,7 +97,9 @@ class ManagerTest extends \Test\TestCase {
$this->mountManager,
$this->groupManager,
$this->l,
- $this->factory
+ $this->factory,
+ $this->userManager,
+ $this->rootFolder
);
$this->defaultProvider = $this->getMockBuilder('\OC\Share20\DefaultShareProvider')
@@ -124,12 +124,14 @@ class ManagerTest extends \Test\TestCase {
$this->mountManager,
$this->groupManager,
$this->l,
- $this->factory
+ $this->factory,
+ $this->userManager,
+ $this->rootFolder
]);
}
/**
- * @expectedException \OC\Share20\Exception\ShareNotFound
+ * @expectedException \OCP\Share\Exceptions\ShareNotFound
*/
public function testDeleteNoShareId() {
$share = $this->getMock('\OCP\Share\IShare');
@@ -151,24 +153,21 @@ class ManagerTest extends \Test\TestCase {
$group->method('getGID')->willReturn('sharedWithGroup');
return [
- [\OCP\Share::SHARE_TYPE_USER, $user, 'sharedWithUser'],
- [\OCP\Share::SHARE_TYPE_GROUP, $group, 'sharedWithGroup'],
- [\OCP\Share::SHARE_TYPE_LINK, '', ''],
- [\OCP\Share::SHARE_TYPE_REMOTE, 'foo@bar.com', 'foo@bar.com'],
+ [\OCP\Share::SHARE_TYPE_USER, 'sharedWithUser'],
+ [\OCP\Share::SHARE_TYPE_GROUP, 'sharedWithGroup'],
+ [\OCP\Share::SHARE_TYPE_LINK, ''],
+ [\OCP\Share::SHARE_TYPE_REMOTE, 'foo@bar.com'],
];
}
/**
* @dataProvider dataTestDelete
*/
- public function testDelete($shareType, $sharedWith, $sharedWith_string) {
+ public function testDelete($shareType, $sharedWith) {
$manager = $this->createManagerMock()
->setMethods(['getShareById', 'deleteChildren'])
->getMock();
- $sharedBy = $this->getMock('\OCP\IUser');
- $sharedBy->method('getUID')->willReturn('sharedBy');
-
$path = $this->getMock('\OCP\Files\File');
$path->method('getId')->willReturn(1);
@@ -177,7 +176,7 @@ class ManagerTest extends \Test\TestCase {
->setProviderId('prov')
->setShareType($shareType)
->setSharedWith($sharedWith)
- ->setSharedBy($sharedBy)
+ ->setSharedBy('sharedBy')
->setNode($path)
->setTarget('myTarget');
@@ -198,7 +197,7 @@ class ManagerTest extends \Test\TestCase {
'itemType' => 'file',
'itemSource' => 1,
'shareType' => $shareType,
- 'shareWith' => $sharedWith_string,
+ 'shareWith' => $sharedWith,
'itemparent' => null,
'uidOwner' => 'sharedBy',
'fileSource' => 1,
@@ -210,7 +209,7 @@ class ManagerTest extends \Test\TestCase {
'itemType' => 'file',
'itemSource' => 1,
'shareType' => $shareType,
- 'shareWith' => $sharedWith_string,
+ 'shareWith' => $sharedWith,
'itemparent' => null,
'uidOwner' => 'sharedBy',
'fileSource' => 1,
@@ -221,7 +220,7 @@ class ManagerTest extends \Test\TestCase {
'itemType' => 'file',
'itemSource' => 1,
'shareType' => $shareType,
- 'shareWith' => $sharedWith_string,
+ 'shareWith' => $sharedWith,
'itemparent' => null,
'uidOwner' => 'sharedBy',
'fileSource' => 1,
@@ -243,22 +242,90 @@ class ManagerTest extends \Test\TestCase {
$manager->deleteShare($share);
}
- public function testDeleteNested() {
+ public function testDeleteLazyShare() {
$manager = $this->createManagerMock()
- ->setMethods(['getShareById'])
+ ->setMethods(['getShareById', 'deleteChildren'])
->getMock();
- $sharedBy1 = $this->getMock('\OCP\IUser');
- $sharedBy1->method('getUID')->willReturn('sharedBy1');
- $sharedBy2 = $this->getMock('\OCP\IUser');
- $sharedBy2->method('getUID')->willReturn('sharedBy2');
- $sharedBy3 = $this->getMock('\OCP\IUser');
- $sharedBy3->method('getUID')->willReturn('sharedBy3');
+ $share = $this->manager->newShare();
+ $share->setId(42)
+ ->setProviderId('prov')
+ ->setShareType(\OCP\Share::SHARE_TYPE_USER)
+ ->setSharedWith('sharedWith')
+ ->setSharedBy('sharedBy')
+ ->setShareOwner('shareOwner')
+ ->setTarget('myTarget')
+ ->setNodeId(1)
+ ->setNodeType('file');
+
+ $this->rootFolder->expects($this->never())->method($this->anything());
+
+ $manager->expects($this->once())->method('getShareById')->with('prov:42')->willReturn($share);
+ $manager->expects($this->once())->method('deleteChildren')->with($share);
+
+ $this->defaultProvider
+ ->expects($this->once())
+ ->method('delete')
+ ->with($share);
+
+ $hookListner = $this->getMockBuilder('Dummy')->setMethods(['pre', 'post'])->getMock();
+ \OCP\Util::connectHook('OCP\Share', 'pre_unshare', $hookListner, 'pre');
+ \OCP\Util::connectHook('OCP\Share', 'post_unshare', $hookListner, 'post');
+
+ $hookListnerExpectsPre = [
+ 'id' => 42,
+ 'itemType' => 'file',
+ 'itemSource' => 1,
+ 'shareType' => \OCP\Share::SHARE_TYPE_USER,
+ 'shareWith' => 'sharedWith',
+ 'itemparent' => null,
+ 'uidOwner' => 'sharedBy',
+ 'fileSource' => 1,
+ 'fileTarget' => 'myTarget',
+ ];
+
+ $hookListnerExpectsPost = [
+ 'id' => 42,
+ 'itemType' => 'file',
+ 'itemSource' => 1,
+ 'shareType' => \OCP\Share::SHARE_TYPE_USER,
+ 'shareWith' => 'sharedWith',
+ 'itemparent' => null,
+ 'uidOwner' => 'sharedBy',
+ 'fileSource' => 1,
+ 'fileTarget' => 'myTarget',
+ 'deletedShares' => [
+ [
+ 'id' => 42,
+ 'itemType' => 'file',
+ 'itemSource' => 1,
+ 'shareType' => \OCP\Share::SHARE_TYPE_USER,
+ 'shareWith' => 'sharedWith',
+ 'itemparent' => null,
+ 'uidOwner' => 'sharedBy',
+ 'fileSource' => 1,
+ 'fileTarget' => 'myTarget',
+ ],
+ ],
+ ];
+
- $sharedWith1 = $this->getMock('\OCP\IUser');
- $sharedWith1->method('getUID')->willReturn('sharedWith1');
- $sharedWith2 = $this->getMock('\OCP\IGroup');
- $sharedWith2->method('getGID')->willReturn('sharedWith2');
+ $hookListner
+ ->expects($this->exactly(1))
+ ->method('pre')
+ ->with($hookListnerExpectsPre);
+ $hookListner
+ ->expects($this->exactly(1))
+ ->method('post')
+ ->with($hookListnerExpectsPost);
+
+ $manager->deleteShare($share);
+ }
+
+ public function testDeleteNested() {
+ $manager = $this->createManagerMock()
+ ->setMethods(['getShareById'])
+ ->getMock();
$path = $this->getMock('\OCP\Files\File');
$path->method('getId')->willReturn(1);
@@ -267,8 +334,8 @@ class ManagerTest extends \Test\TestCase {
$share1->setId(42)
->setProviderId('prov')
->setShareType(\OCP\Share::SHARE_TYPE_USER)
- ->setSharedWith($sharedWith1)
- ->setSharedBy($sharedBy1)
+ ->setSharedWith('sharedWith1')
+ ->setSharedBy('sharedBy1')
->setNode($path)
->setTarget('myTarget1');
@@ -276,8 +343,8 @@ class ManagerTest extends \Test\TestCase {
$share2->setId(43)
->setProviderId('prov')
->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
- ->setSharedWith($sharedWith2)
- ->setSharedBy($sharedBy2)
+ ->setSharedWith('sharedWith2')
+ ->setSharedBy('sharedBy2')
->setNode($path)
->setTarget('myTarget2')
->setParent(42);
@@ -286,7 +353,7 @@ class ManagerTest extends \Test\TestCase {
$share3->setId(44)
->setProviderId('prov')
->setShareType(\OCP\Share::SHARE_TYPE_LINK)
- ->setSharedBy($sharedBy3)
+ ->setSharedBy('sharedBy3')
->setNode($path)
->setTarget('myTarget3')
->setParent(43);
@@ -504,72 +571,72 @@ class ManagerTest extends \Test\TestCase {
}
public function dataGeneralChecks() {
- $user = $this->getMock('\OCP\IUser');
- $user2 = $this->getMock('\OCP\IUser');
- $group = $this->getMock('\OCP\IGroup');
+ $user0 = 'user0';
+ $user2 = 'user1';
+ $group0 = 'group0';
$file = $this->getMock('\OCP\Files\File');
$node = $this->getMock('\OCP\Files\Node');
$data = [
- [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $file, null, $user, $user, 31, null, null), 'SharedWith should be an IUser', true],
- [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $file, $group, $user, $user, 31, null, null), 'SharedWith should be an IUser', true],
- [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $file, 'foo@bar.com', $user, $user, 31, null, null), 'SharedWith should be an IUser', true],
- [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $file, null, $user, $user, 31, null, null), 'SharedWith should be an IGroup', true],
- [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $file, $user2, $user, $user, 31, null, null), 'SharedWith should be an IGroup', true],
- [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $file, 'foo@bar.com', $user, $user, 31, null, null), 'SharedWith should be an IGroup', true],
- [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $file, $user2, $user, $user, 31, null, null), 'SharedWith should be empty', true],
- [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $file, $group, $user, $user, 31, null, null), 'SharedWith should be empty', true],
- [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $file, 'foo@bar.com', $user, $user, 31, null, null), 'SharedWith should be empty', true],
- [$this->createShare(null, -1, $file, null, $user, $user, 31, null, null), 'unkown share type', true],
-
- [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $file, $user2, null, $user, 31, null, null), 'SharedBy should be set', true],
- [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $file, $group, null, $user, 31, null, null), 'SharedBy should be set', true],
- [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $file, null, null, $user, 31, null, null), 'SharedBy should be set', true],
-
- [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $file, $user, $user, $user, 31, null, null), 'Can\'t share with yourself', true],
-
- [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, null, $user2, $user, $user, 31, null, null), 'Path should be set', true],
- [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, null, $group, $user, $user, 31, null, null), 'Path should be set', true],
- [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, null, null, $user, $user, 31, null, null), 'Path should be set', true],
-
- [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $node, $user2, $user, $user, 31, null, null), 'Path should be either a file or a folder', true],
- [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $node, $group, $user, $user, 31, null, null), 'Path should be either a file or a folder', true],
- [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $node, null, $user, $user, 31, null, null), 'Path should be either a file or a folder', true],
+ [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $file, null, $user0, $user0, 31, null, null), 'SharedWith is not a valid user', true],
+ [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $file, $group0, $user0, $user0, 31, null, null), 'SharedWith is not a valid user', true],
+ [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $file, 'foo@bar.com', $user0, $user0, 31, null, null), 'SharedWith is not a valid user', true],
+ [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $file, null, $user0, $user0, 31, null, null), 'SharedWith is not a valid group', true],
+ [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $file, $user2, $user0, $user0, 31, null, null), 'SharedWith is not a valid group', true],
+ [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $file, 'foo@bar.com', $user0, $user0, 31, null, null), 'SharedWith is not a valid group', true],
+ [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $file, $user2, $user0, $user0, 31, null, null), 'SharedWith should be empty', true],
+ [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $file, $group0, $user0, $user0, 31, null, null), 'SharedWith should be empty', true],
+ [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $file, 'foo@bar.com', $user0, $user0, 31, null, null), 'SharedWith should be empty', true],
+ [$this->createShare(null, -1, $file, null, $user0, $user0, 31, null, null), 'unkown share type', true],
+
+ [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $file, $user2, null, $user0, 31, null, null), 'SharedBy should be set', true],
+ [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $file, $group0, null, $user0, 31, null, null), 'SharedBy should be set', true],
+ [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $file, null, null, $user0, 31, null, null), 'SharedBy should be set', true],
+
+ [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $file, $user0, $user0, $user0, 31, null, null), 'Can\'t share with yourself', true],
+
+ [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, null, $user2, $user0, $user0, 31, null, null), 'Path should be set', true],
+ [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, null, $group0, $user0, $user0, 31, null, null), 'Path should be set', true],
+ [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, null, null, $user0, $user0, 31, null, null), 'Path should be set', true],
+
+ [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $node, $user2, $user0, $user0, 31, null, null), 'Path should be either a file or a folder', true],
+ [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $node, $group0, $user0, $user0, 31, null, null), 'Path should be either a file or a folder', true],
+ [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $node, null, $user0, $user0, 31, null, null), 'Path should be either a file or a folder', true],
];
$nonShareAble = $this->getMock('\OCP\Files\Folder');
$nonShareAble->method('isShareable')->willReturn(false);
$nonShareAble->method('getPath')->willReturn('path');
- $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $nonShareAble, $user2, $user, $user, 31, null, null), 'You are not allowed to share path', true];
- $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $nonShareAble, $group, $user, $user, 31, null, null), 'You are not allowed to share path', true];
- $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $nonShareAble, null, $user, $user, 31, null, null), 'You are not allowed to share path', true];
+ $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $nonShareAble, $user2, $user0, $user0, 31, null, null), 'You are not allowed to share path', true];
+ $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $nonShareAble, $group0, $user0, $user0, 31, null, null), 'You are not allowed to share path', true];
+ $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $nonShareAble, null, $user0, $user0, 31, null, null), 'You are not allowed to share path', true];
$limitedPermssions = $this->getMock('\OCP\Files\File');
$limitedPermssions->method('isShareable')->willReturn(true);
$limitedPermssions->method('getPermissions')->willReturn(\OCP\Constants::PERMISSION_READ);
$limitedPermssions->method('getPath')->willReturn('path');
- $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $limitedPermssions, $user2, $user, $user, null, null, null), 'A share requires permissions', true];
- $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $limitedPermssions, $group, $user, $user, null, null, null), 'A share requires permissions', true];
- $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $limitedPermssions, null, $user, $user, null, null, null), 'A share requires permissions', true];
+ $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $limitedPermssions, $user2, $user0, $user0, null, null, null), 'A share requires permissions', true];
+ $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $limitedPermssions, $group0, $user0, $user0, null, null, null), 'A share requires permissions', true];
+ $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $limitedPermssions, null, $user0, $user0, null, null, null), 'A share requires permissions', true];
- $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $limitedPermssions, $user2, $user, $user, 31, null, null), 'Cannot increase permissions of path', true];
- $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $limitedPermssions, $group, $user, $user, 17, null, null), 'Cannot increase permissions of path', true];
- $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $limitedPermssions, null, $user, $user, 3, null, null), 'Cannot increase permissions of path', true];
+ $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $limitedPermssions, $user2, $user0, $user0, 31, null, null), 'Cannot increase permissions of path', true];
+ $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $limitedPermssions, $group0, $user0, $user0, 17, null, null), 'Cannot increase permissions of path', true];
+ $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $limitedPermssions, null, $user0, $user0, 3, null, null), 'Cannot increase permissions of path', true];
$allPermssions = $this->getMock('\OCP\Files\Folder');
$allPermssions->method('isShareable')->willReturn(true);
$allPermssions->method('getPermissions')->willReturn(\OCP\Constants::PERMISSION_ALL);
- $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $allPermssions, $user2, $user, $user, 30, null, null), 'Shares need at least read permissions', true];
- $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $allPermssions, $group, $user, $user, 2, null, null), 'Shares need at least read permissions', true];
- $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $allPermssions, null, $user, $user, 16, null, null), 'Shares need at least read permissions', true];
+ $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $allPermssions, $user2, $user0, $user0, 30, null, null), 'Shares need at least read permissions', true];
+ $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $allPermssions, $group0, $user0, $user0, 2, null, null), 'Shares need at least read permissions', true];
+ $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $allPermssions, null, $user0, $user0, 16, null, null), 'Shares need at least read permissions', true];
- $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $allPermssions, $user2, $user, $user, 31, null, null), null, false];
- $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $allPermssions, $group, $user, $user, 3, null, null), null, false];
- $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $allPermssions, null, $user, $user, 17, null, null), null, false];
+ $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $allPermssions, $user2, $user0, $user0, 31, null, null), null, false];
+ $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $allPermssions, $group0, $user0, $user0, 3, null, null), null, false];
+ $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $allPermssions, null, $user0, $user0, 17, null, null), null, false];
return $data;
}
@@ -583,10 +650,19 @@ class ManagerTest extends \Test\TestCase {
public function testGeneralChecks($share, $exceptionMessage, $exception) {
$thrown = null;
+ $this->userManager->method('userExists')->will($this->returnValueMap([
+ ['user0', true],
+ ['user1', true],
+ ]));
+
+ $this->groupManager->method('groupExists')->will($this->returnValueMap([
+ ['group0', true],
+ ]));
+
try {
$this->invokePrivate($this->manager, 'generalCreateChecks', [$share]);
$thrown = false;
- } catch (\OC\HintException $e) {
+ } catch (\OCP\Share\Exceptions\GenericShareException $e) {
$this->assertEquals($exceptionMessage, $e->getHint());
$thrown = true;
} catch(\InvalidArgumentException $e) {
@@ -598,7 +674,7 @@ class ManagerTest extends \Test\TestCase {
}
/**
- * @expectedException \OC\HintException
+ * @expectedException \OCP\Share\Exceptions\GenericShareException
* @expectedExceptionMessage Expiration date is in the past
*/
public function testvalidateExpirationDateInPast() {
@@ -644,7 +720,7 @@ class ManagerTest extends \Test\TestCase {
try {
$this->invokePrivate($this->manager, 'validateExpirationDate', [$share]);
- } catch (\OC\HintException $e) {
+ } catch (\OCP\Share\Exceptions\GenericShareException $e) {
$this->assertEquals('Cannot set expiration date more than 3 days in the future', $e->getMessage());
$this->assertEquals('Cannot set expiration date more than 3 days in the future', $e->getHint());
$this->assertEquals(404, $e->getCode());
@@ -791,11 +867,11 @@ class ManagerTest extends \Test\TestCase {
* @expectedExceptionMessage Only sharing with group members is allowed
*/
public function testUserCreateChecksShareWithGroupMembersOnlyDifferentGroups() {
- $share = new \OC\Share20\Share();
+ $share = $this->manager->newShare();
$sharedBy = $this->getMock('\OCP\IUser');
$sharedWith = $this->getMock('\OCP\IUser');
- $share->setSharedBy($sharedBy)->setSharedWith($sharedWith);
+ $share->setSharedBy('sharedBy')->setSharedWith('sharedWith');
$this->groupManager
->method('getUserGroupIds')
@@ -806,6 +882,11 @@ class ManagerTest extends \Test\TestCase {
])
);
+ $this->userManager->method('get')->will($this->returnValueMap([
+ ['sharedBy', $sharedBy],
+ ['sharedWith', $sharedWith],
+ ]));
+
$this->config
->method('getAppValue')
->will($this->returnValueMap([
@@ -816,11 +897,11 @@ class ManagerTest extends \Test\TestCase {
}
public function testUserCreateChecksShareWithGroupMembersOnlySharedGroup() {
- $share = new \OC\Share20\Share();
+ $share = $this->manager->newShare();
$sharedBy = $this->getMock('\OCP\IUser');
$sharedWith = $this->getMock('\OCP\IUser');
- $share->setSharedBy($sharedBy)->setSharedWith($sharedWith);
+ $share->setSharedBy('sharedBy')->setSharedWith('sharedWith');
$path = $this->getMock('\OCP\Files\Node');
$share->setNode($path);
@@ -834,6 +915,11 @@ class ManagerTest extends \Test\TestCase {
])
);
+ $this->userManager->method('get')->will($this->returnValueMap([
+ ['sharedBy', $sharedBy],
+ ['sharedWith', $sharedWith],
+ ]));
+
$this->config
->method('getAppValue')
->will($this->returnValueMap([
@@ -859,10 +945,10 @@ class ManagerTest extends \Test\TestCase {
$sharedWith = $this->getMock('\OCP\IUser');
$path = $this->getMock('\OCP\Files\Node');
- $share->setSharedWith($sharedWith)->setNode($path)
+ $share->setSharedWith('sharedWith')->setNode($path)
->setProviderId('foo')->setId('bar');
- $share2->setSharedWith($sharedWith)->setNode($path)
+ $share2->setSharedWith('sharedWith')->setNode($path)
->setProviderId('foo')->setId('baz');
$this->defaultProvider
@@ -881,28 +967,31 @@ class ManagerTest extends \Test\TestCase {
$share = $this->manager->newShare();
$sharedWith = $this->getMock('\OCP\IUser');
- $owner = $this->getMock('\OCP\IUser');
+ $sharedWith->method('getUID')->willReturn('sharedWith');
+
+ $this->userManager->method('get')->with('sharedWith')->willReturn($sharedWith);
+
$path = $this->getMock('\OCP\Files\Node');
- $share->setSharedWith($sharedWith)
+ $share->setSharedWith('sharedWith')
->setNode($path)
- ->setShareOwner($owner)
+ ->setShareOwner('shareOwner')
->setProviderId('foo')
->setId('bar');
- $share2 = new \OC\Share20\Share();
- $owner2 = $this->getMock('\OCP\IUser');
+ $share2 = $this->manager->newShare();
$share2->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
- ->setShareOwner($owner2)
+ ->setShareOwner('shareOwner2')
->setProviderId('foo')
- ->setId('baz');
+ ->setId('baz')
+ ->setSharedWith('group');
$group = $this->getMock('\OCP\IGroup');
$group->method('inGroup')
->with($sharedWith)
->willReturn(true);
- $share2->setSharedWith($group);
+ $this->groupManager->method('get')->with('group')->willReturn($group);
$this->defaultProvider
->method('getSharesByPath')
@@ -913,20 +1002,20 @@ class ManagerTest extends \Test\TestCase {
}
public function testUserCreateChecksIdenticalPathNotSharedWithUser() {
- $share = new \OC\Share20\Share();
+ $share = $this->manager->newShare();
$sharedWith = $this->getMock('\OCP\IUser');
- $owner = $this->getMock('\OCP\IUser');
$path = $this->getMock('\OCP\Files\Node');
- $share->setSharedWith($sharedWith)
+ $share->setSharedWith('sharedWith')
->setNode($path)
- ->setShareOwner($owner)
+ ->setShareOwner('shareOwner')
->setProviderId('foo')
->setId('bar');
- $share2 = new \OC\Share20\Share();
- $owner2 = $this->getMock('\OCP\IUser');
+ $this->userManager->method('get')->with('sharedWith')->willReturn($sharedWith);
+
+ $share2 = $this->manager->newShare();
$share2->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
- ->setShareOwner($owner2)
+ ->setShareOwner('shareOwner2')
->setProviderId('foo')
->setId('baz');
@@ -935,7 +1024,9 @@ class ManagerTest extends \Test\TestCase {
->with($sharedWith)
->willReturn(false);
- $share2->setSharedWith($group);
+ $this->groupManager->method('get')->with('group')->willReturn($group);
+
+ $share2->setSharedWith('group');
$this->defaultProvider
->method('getSharesByPath')
@@ -950,13 +1041,16 @@ class ManagerTest extends \Test\TestCase {
* @expectedExceptionMessage Only sharing within your own groups is allowed
*/
public function testGroupCreateChecksShareWithGroupMembersOnlyNotInGroup() {
- $share = new \OC\Share20\Share();
+ $share = $this->manager->newShare();
- $sharedBy = $this->getMock('\OCP\IUser');
- $sharedWith = $this->getMock('\OCP\IGroup');
- $share->setSharedBy($sharedBy)->setSharedWith($sharedWith);
+ $user = $this->getMock('\OCP\IUser');
+ $group = $this->getMock('\OCP\IGroup');
+ $share->setSharedBy('user')->setSharedWith('group');
+
+ $group->method('inGroup')->with($user)->willReturn(false);
- $sharedWith->method('inGroup')->with($sharedBy)->willReturn(false);
+ $this->groupManager->method('get')->with('group')->willReturn($group);
+ $this->userManager->method('get')->with('user')->willReturn($user);
$this->config
->method('getAppValue')
@@ -968,13 +1062,16 @@ class ManagerTest extends \Test\TestCase {
}
public function testGroupCreateChecksShareWithGroupMembersOnlyInGroup() {
- $share = new \OC\Share20\Share();
+ $share = $this->manager->newShare();
- $sharedBy = $this->getMock('\OCP\IUser');
- $sharedWith = $this->getMock('\OCP\IGroup');
- $share->setSharedBy($sharedBy)->setSharedWith($sharedWith);
+ $user = $this->getMock('\OCP\IUser');
+ $group = $this->getMock('\OCP\IGroup');
+ $share->setSharedBy('user')->setSharedWith('group');
+
+ $this->userManager->method('get')->with('user')->willReturn($user);
+ $this->groupManager->method('get')->with('group')->willReturn($group);
- $sharedWith->method('inGroup')->with($sharedBy)->willReturn(true);
+ $group->method('inGroup')->with($user)->willReturn(true);
$path = $this->getMock('\OCP\Files\Node');
$share->setNode($path);
@@ -999,15 +1096,14 @@ class ManagerTest extends \Test\TestCase {
public function testGroupCreateChecksPathAlreadySharedWithSameGroup() {
$share = $this->manager->newShare();
- $sharedWith = $this->getMock('\OCP\IGroup');
$path = $this->getMock('\OCP\Files\Node');
- $share->setSharedWith($sharedWith)
+ $share->setSharedWith('sharedWith')
->setNode($path)
->setProviderId('foo')
->setId('bar');
- $share2 = new \OC\Share20\Share();
- $share2->setSharedWith($sharedWith)
+ $share2 = $this->manager->newShare();
+ $share2->setSharedWith('sharedWith')
->setProviderId('foo')
->setId('baz');
@@ -1019,17 +1115,15 @@ class ManagerTest extends \Test\TestCase {
}
public function testGroupCreateChecksPathAlreadySharedWithDifferentGroup() {
- $share = new \OC\Share20\Share();
+ $share = $this->manager->newShare();
- $sharedWith = $this->getMock('\OCP\IGroup');
- $share->setSharedWith($sharedWith);
+ $share->setSharedWith('sharedWith');
$path = $this->getMock('\OCP\Files\Node');
$share->setNode($path);
- $share2 = new \OC\Share20\Share();
- $sharedWith2 = $this->getMock('\OCP\IGroup');
- $share2->setSharedWith($sharedWith2);
+ $share2 = $this->manager->newShare();
+ $share2->setSharedWith('sharedWith2');
$this->defaultProvider->method('getSharesByPath')
->with($path)
@@ -1043,7 +1137,7 @@ class ManagerTest extends \Test\TestCase {
* @expectedExceptionMessage Link sharing not allowed
*/
public function testLinkCreateChecksNoLinkSharesAllowed() {
- $share = new \OC\Share20\Share();
+ $share = $this->manager->newShare();
$this->config
->method('getAppValue')
@@ -1059,7 +1153,7 @@ class ManagerTest extends \Test\TestCase {
* @expectedExceptionMessage Link shares can't have reshare permissions
*/
public function testLinkCreateChecksSharePermissions() {
- $share = new \OC\Share20\Share();
+ $share = $this->manager->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_SHARE);
@@ -1077,7 +1171,7 @@ class ManagerTest extends \Test\TestCase {
* @expectedExceptionMessage Link shares can't have delete permissions
*/
public function testLinkCreateChecksDeletePermissions() {
- $share = new \OC\Share20\Share();
+ $share = $this->manager->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_DELETE);
@@ -1095,7 +1189,7 @@ class ManagerTest extends \Test\TestCase {
* @expectedExceptionMessage Public upload not allowed
*/
public function testLinkCreateChecksNoPublicUpload() {
- $share = new \OC\Share20\Share();
+ $share = $this->manager->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE);
@@ -1110,7 +1204,7 @@ class ManagerTest extends \Test\TestCase {
}
public function testLinkCreateChecksPublicUpload() {
- $share = new \OC\Share20\Share();
+ $share = $this->manager->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE);
@@ -1125,7 +1219,7 @@ class ManagerTest extends \Test\TestCase {
}
public function testLinkCreateChecksReadOnly() {
- $share = new \OC\Share20\Share();
+ $share = $this->manager->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_READ);
@@ -1238,7 +1332,9 @@ class ManagerTest extends \Test\TestCase {
->with($user)
->willReturn($groupIds);
- $res = $this->manager->sharingDisabledForUser($user);
+ $this->userManager->method('get')->with('user')->willReturn($user);
+
+ $res = $this->manager->sharingDisabledForUser('user');
$this->assertEquals($expected, $res);
}
@@ -1278,7 +1374,7 @@ class ManagerTest extends \Test\TestCase {
$user = $this->getMock('\OCP\IUser');
$share = $this->manager->newShare();
- $share->setSharedBy($user);
+ $share->setSharedBy('user');
$res = $this->invokePrivate($manager, 'canShare', [$share]);
$this->assertEquals($expected, $res);
@@ -1294,7 +1390,7 @@ class ManagerTest extends \Test\TestCase {
->getMock();
$manager->expects($this->once())->method('canShare')->willReturn(false);
- $share = new \OC\Share20\Share();
+ $share = $this->manager->newShare();
$manager->createShare($share);
}
@@ -1303,9 +1399,8 @@ class ManagerTest extends \Test\TestCase {
->setMethods(['canShare', 'generalCreateChecks', 'userCreateChecks', 'pathCreateChecks'])
->getMock();
- $sharedWith = $this->getMock('\OCP\IUser');
- $sharedBy = $this->getMock('\OCP\IUser');
$shareOwner = $this->getMock('\OCP\IUser');
+ $shareOwner->method('getUID')->willReturn('shareOwner');
$path = $this->getMock('\OCP\Files\File');
$path->method('getOwner')->willReturn($shareOwner);
@@ -1315,8 +1410,8 @@ class ManagerTest extends \Test\TestCase {
null,
\OCP\Share::SHARE_TYPE_USER,
$path,
- $sharedWith,
- $sharedBy,
+ 'sharedWith',
+ 'sharedBy',
null,
\OCP\Constants::PERMISSION_ALL);
@@ -1342,7 +1437,7 @@ class ManagerTest extends \Test\TestCase {
$share->expects($this->once())
->method('setShareOwner')
- ->with($shareOwner);
+ ->with('shareOwner');
$share->expects($this->once())
->method('setTarget')
->with('/target');
@@ -1355,9 +1450,8 @@ class ManagerTest extends \Test\TestCase {
->setMethods(['canShare', 'generalCreateChecks', 'groupCreateChecks', 'pathCreateChecks'])
->getMock();
- $sharedWith = $this->getMock('\OCP\IGroup');
- $sharedBy = $this->getMock('\OCP\IUser');
$shareOwner = $this->getMock('\OCP\IUser');
+ $shareOwner->method('getUID')->willReturn('shareOwner');
$path = $this->getMock('\OCP\Files\File');
$path->method('getOwner')->willReturn($shareOwner);
@@ -1367,8 +1461,8 @@ class ManagerTest extends \Test\TestCase {
null,
\OCP\Share::SHARE_TYPE_GROUP,
$path,
- $sharedWith,
- $sharedBy,
+ 'sharedWith',
+ 'sharedBy',
null,
\OCP\Constants::PERMISSION_ALL);
@@ -1394,7 +1488,7 @@ class ManagerTest extends \Test\TestCase {
$share->expects($this->once())
->method('setShareOwner')
- ->with($shareOwner);
+ ->with('shareOwner');
$share->expects($this->once())
->method('setTarget')
->with('/target');
@@ -1414,9 +1508,8 @@ class ManagerTest extends \Test\TestCase {
])
->getMock();
- $sharedBy = $this->getMock('\OCP\IUser');
- $sharedBy->method('getUID')->willReturn('sharedBy');
$shareOwner = $this->getMock('\OCP\IUser');
+ $shareOwner->method('getUID')->willReturn('shareOwner');
$path = $this->getMock('\OCP\Files\File');
$path->method('getOwner')->willReturn($shareOwner);
@@ -1428,7 +1521,7 @@ class ManagerTest extends \Test\TestCase {
$share = $this->manager->newShare();
$share->setShareType(\OCP\Share::SHARE_TYPE_LINK)
->setNode($path)
- ->setSharedBy($sharedBy)
+ ->setSharedBy('sharedBy')
->setPermissions(\OCP\Constants::PERMISSION_ALL)
->setExpirationDate($date)
->setPassword('password');
@@ -1515,7 +1608,7 @@ class ManagerTest extends \Test\TestCase {
/** @var IShare $share */
$share = $manager->createShare($share);
- $this->assertSame($shareOwner, $share->getShareOwner());
+ $this->assertSame('shareOwner', $share->getShareOwner());
$this->assertEquals('/target', $share->getTarget());
$this->assertSame($date, $share->getExpirationDate());
$this->assertEquals('token', $share->getToken());
@@ -1536,9 +1629,8 @@ class ManagerTest extends \Test\TestCase {
])
->getMock();
- $sharedWith = $this->getMock('\OCP\IUser');
- $sharedBy = $this->getMock('\OCP\IUser');
$shareOwner = $this->getMock('\OCP\IUser');
+ $shareOwner->method('getUID')->willReturn('shareOwner');
$path = $this->getMock('\OCP\Files\File');
$path->method('getOwner')->willReturn($shareOwner);
@@ -1548,8 +1640,8 @@ class ManagerTest extends \Test\TestCase {
null,
\OCP\Share::SHARE_TYPE_USER,
$path,
- $sharedWith,
- $sharedBy,
+ 'sharedWith',
+ 'sharedBy',
null,
\OCP\Constants::PERMISSION_ALL);
@@ -1569,7 +1661,7 @@ class ManagerTest extends \Test\TestCase {
$share->expects($this->once())
->method('setShareOwner')
- ->with($shareOwner);
+ ->with('shareOwner');
$share->expects($this->once())
->method('setTarget')
->with('/target');
@@ -1591,7 +1683,9 @@ class ManagerTest extends \Test\TestCase {
$this->mountManager,
$this->groupManager,
$this->l,
- $factory
+ $factory,
+ $this->userManager,
+ $this->rootFolder
);
$share = $this->getMock('\OCP\Share\IShare');
@@ -1676,7 +1770,7 @@ class ManagerTest extends \Test\TestCase {
->getMock();
$manager->expects($this->once())->method('canShare')->willReturn(false);
- $share = new \OC\Share20\Share();
+ $share = $this->manager->newShare();
$manager->updateShare($share);
}
@@ -1692,13 +1786,13 @@ class ManagerTest extends \Test\TestCase {
])
->getMock();
- $originalShare = new \OC\Share20\Share();
+ $originalShare = $this->manager->newShare();
$originalShare->setShareType(\OCP\Share::SHARE_TYPE_GROUP);
$manager->expects($this->once())->method('canShare')->willReturn(true);
$manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare);
- $share = new \OC\Share20\Share();
+ $share = $this->manager->newShare();
$share->setProviderId('foo')
->setId('42')
->setShareType(\OCP\Share::SHARE_TYPE_USER);
@@ -1718,21 +1812,18 @@ class ManagerTest extends \Test\TestCase {
])
->getMock();
- $origGroup = $this->getMock('\OCP\IGroup');
- $newGroup = $this->getMock('\OCP\IGroup');
-
- $originalShare = new \OC\Share20\Share();
+ $originalShare = $this->manager->newShare();
$originalShare->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
- ->setSharedWith($origGroup);
+ ->setSharedWith('origGroup');
$manager->expects($this->once())->method('canShare')->willReturn(true);
$manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare);
- $share = new \OC\Share20\Share();
+ $share = $this->manager->newShare();
$share->setProviderId('foo')
->setId('42')
->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
- ->setSharedWith($newGroup);
+ ->setSharedWith('newGroup');
$manager->updateShare($share);
}
@@ -1749,22 +1840,19 @@ class ManagerTest extends \Test\TestCase {
])
->getMock();
- $origUser = $this->getMock('\OCP\IUser');
- $newUser = $this->getMock('\OCP\IUser');
-
- $originalShare = new \OC\Share20\Share();
+ $originalShare = $this->manager->newShare();
$originalShare->setShareType(\OCP\Share::SHARE_TYPE_USER)
- ->setSharedWith($origUser);
+ ->setSharedWith('sharedWith');
$manager->expects($this->once())->method('canShare')->willReturn(true);
$manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare);
- $share = new \OC\Share20\Share();
+ $share = $this->manager->newShare();
$share->setProviderId('foo')
->setId('42')
->setShareType(\OCP\Share::SHARE_TYPE_USER)
- ->setSharedWith($newUser)
- ->setShareOwner($newUser);
+ ->setSharedWith('newUser')
+ ->setShareOwner('newUser');
$manager->updateShare($share);
}
@@ -1780,22 +1868,27 @@ class ManagerTest extends \Test\TestCase {
])
->getMock();
- $origUser = $this->getMock('\OCP\IUser');
- $newUser = $this->getMock('\OCP\IUser');
-
- $originalShare = new \OC\Share20\Share();
+ $originalShare = $this->manager->newShare();
$originalShare->setShareType(\OCP\Share::SHARE_TYPE_USER)
- ->setSharedWith($origUser);
+ ->setSharedWith('origUser')
+ ->setPermissions(1);
+
+ $node = $this->getMock('\OCP\Files\File');
+ $node->method('getId')->willReturn(100);
+ $node->method('getPath')->willReturn('/newUser/files/myPath');
$manager->expects($this->once())->method('canShare')->willReturn(true);
$manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare);
- $share = new \OC\Share20\Share();
+ $share = $this->manager->newShare();
$share->setProviderId('foo')
->setId('42')
->setShareType(\OCP\Share::SHARE_TYPE_USER)
- ->setSharedWith($origUser)
- ->setShareOwner($newUser);
+ ->setSharedWith('origUser')
+ ->setShareOwner('newUser')
+ ->setSharedBy('sharer')
+ ->setPermissions(31)
+ ->setNode($node);
$this->defaultProvider->expects($this->once())
->method('update')
@@ -1806,6 +1899,20 @@ class ManagerTest extends \Test\TestCase {
\OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListner, 'post');
$hookListner->expects($this->never())->method('post');
+ $this->rootFolder->method('getUserFolder')->with('newUser')->will($this->returnSelf());
+ $this->rootFolder->method('getRelativePath')->with('/newUser/files/myPath')->willReturn('/myPath');
+
+ $hookListner2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ \OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListner2, 'post');
+ $hookListner2->expects($this->once())->method('post')->with([
+ 'itemType' => 'file',
+ 'itemSource' => 100,
+ 'shareType' => \OCP\Share::SHARE_TYPE_USER,
+ 'shareWith' => 'origUser',
+ 'uidOwner' => 'sharer',
+ 'permissions' => 31,
+ 'path' => '/myPath',
+ ]);
$manager->updateShare($share);
}
@@ -1821,22 +1928,24 @@ class ManagerTest extends \Test\TestCase {
])
->getMock();
- $origGroup = $this->getMock('\OCP\IGroup');
- $user = $this->getMock('\OCP\IUser');
-
- $originalShare = new \OC\Share20\Share();
+ $originalShare = $this->manager->newShare();
$originalShare->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
- ->setSharedWith($origGroup);
+ ->setSharedWith('origUser')
+ ->setPermissions(31);
$manager->expects($this->once())->method('canShare')->willReturn(true);
$manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare);
- $share = new \OC\Share20\Share();
+ $node = $this->getMock('\OCP\Files\File');
+
+ $share = $this->manager->newShare();
$share->setProviderId('foo')
->setId('42')
->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
- ->setSharedWith($origGroup)
- ->setShareOwner($user);
+ ->setSharedWith('origUser')
+ ->setShareOwner('owner')
+ ->setNode($node)
+ ->setPermissions(31);
$this->defaultProvider->expects($this->once())
->method('update')
@@ -1847,6 +1956,9 @@ class ManagerTest extends \Test\TestCase {
\OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListner, 'post');
$hookListner->expects($this->never())->method('post');
+ $hookListner2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ \OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListner2, 'post');
+ $hookListner2->expects($this->never())->method('post');
$manager->updateShare($share);
}
@@ -1864,11 +1976,9 @@ class ManagerTest extends \Test\TestCase {
])
->getMock();
- $user = $this->getMock('\OCP\IUser');
- $user->method('getUID')->willReturn('owner');
-
- $originalShare = new \OC\Share20\Share();
- $originalShare->setShareType(\OCP\Share::SHARE_TYPE_LINK);
+ $originalShare = $this->manager->newShare();
+ $originalShare->setShareType(\OCP\Share::SHARE_TYPE_LINK)
+ ->setPermissions(15);
$tomorrow = new \DateTime();
$tomorrow->setTime(0,0,0);
@@ -1881,11 +1991,12 @@ class ManagerTest extends \Test\TestCase {
$share->setProviderId('foo')
->setId('42')
->setShareType(\OCP\Share::SHARE_TYPE_LINK)
- ->setSharedBy($user)
- ->setShareOwner($user)
+ ->setSharedBy('owner')
+ ->setShareOwner('owner')
->setPassword('password')
->setExpirationDate($tomorrow)
- ->setNode($file);
+ ->setNode($file)
+ ->setPermissions(15);
$manager->expects($this->once())->method('canShare')->willReturn(true);
$manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare);
@@ -1905,6 +2016,10 @@ class ManagerTest extends \Test\TestCase {
'uidOwner' => 'owner',
]);
+ $hookListner2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ \OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListner2, 'post');
+ $hookListner2->expects($this->never())->method('post');
+
$manager->updateShare($share);
}
@@ -1930,24 +2045,20 @@ class ManagerTest extends \Test\TestCase {
$share = $this->manager->newShare();
$share->setShareType(\OCP\Share::SHARE_TYPE_USER);
- $sharedWith = $this->getMock('\OCP\IUser');
- $share->setSharedWith($sharedWith);
+ $share->setSharedWith('sharedWith');
- $recipient = $this->getMock('\OCP\IUser');
-
- $this->manager->moveShare($share, $recipient);
+ $this->manager->moveShare($share, 'recipient');
}
public function testMoveShareUser() {
$share = $this->manager->newShare();
$share->setShareType(\OCP\Share::SHARE_TYPE_USER);
- $recipient = $this->getMock('\OCP\IUser');
- $share->setSharedWith($recipient);
+ $share->setSharedWith('recipient');
- $this->defaultProvider->method('move')->with($share, $recipient)->will($this->returnArgument(0));
+ $this->defaultProvider->method('move')->with($share, 'recipient')->will($this->returnArgument(0));
- $this->manager->moveShare($share, $recipient);
+ $this->manager->moveShare($share, 'recipient');
}
/**
@@ -1959,27 +2070,33 @@ class ManagerTest extends \Test\TestCase {
$share->setShareType(\OCP\Share::SHARE_TYPE_GROUP);
$sharedWith = $this->getMock('\OCP\IGroup');
- $share->setSharedWith($sharedWith);
+ $share->setSharedWith('shareWith');
$recipient = $this->getMock('\OCP\IUser');
$sharedWith->method('inGroup')->with($recipient)->willReturn(false);
- $this->manager->moveShare($share, $recipient);
+ $this->groupManager->method('get')->with('shareWith')->willReturn($sharedWith);
+ $this->userManager->method('get')->with('recipient')->willReturn($recipient);
+
+ $this->manager->moveShare($share, 'recipient');
}
public function testMoveShareGroup() {
$share = $this->manager->newShare();
$share->setShareType(\OCP\Share::SHARE_TYPE_GROUP);
- $sharedWith = $this->getMock('\OCP\IGroup');
- $share->setSharedWith($sharedWith);
+ $group = $this->getMock('\OCP\IGroup');
+ $share->setSharedWith('group');
$recipient = $this->getMock('\OCP\IUser');
- $sharedWith->method('inGroup')->with($recipient)->willReturn(true);
+ $group->method('inGroup')->with($recipient)->willReturn(true);
- $this->defaultProvider->method('move')->with($share, $recipient)->will($this->returnArgument(0));
+ $this->groupManager->method('get')->with('group')->willReturn($group);
+ $this->userManager->method('get')->with('recipient')->willReturn($recipient);
- $this->manager->moveShare($share, $recipient);
+ $this->defaultProvider->method('move')->with($share, 'recipient')->will($this->returnArgument(0));
+
+ $this->manager->moveShare($share, 'recipient');
}
}