Make the share object lazy

Share providers can now just pass in a fileId. And the node will only be
created once needed.
This commit is contained in:
Roeland Jago Douma 2016-02-04 12:51:23 +01:00
parent cd16ba5cb3
commit fc215d0980
7 changed files with 116 additions and 74 deletions

View File

@ -618,7 +618,8 @@ class Server extends ServerContainer implements IServerContainer {
$c->getGroupManager(), $c->getGroupManager(),
$c->getL10N('core'), $c->getL10N('core'),
$factory, $factory,
$c->getUserManager() $c->getUserManager(),
$c->getRootFolder()
); );
return $manager; return $manager;

View File

@ -711,7 +711,7 @@ class DefaultShareProvider implements IShareProvider {
* @throws InvalidShare * @throws InvalidShare
*/ */
private function createShare($data) { private function createShare($data) {
$share = new Share(); $share = new Share($this->rootFolder);
$share->setId((int)$data['id']) $share->setId((int)$data['id'])
->setShareType((int)$data['share_type']) ->setShareType((int)$data['share_type'])
->setPermissions((int)$data['permissions']) ->setPermissions((int)$data['permissions'])
@ -744,8 +744,7 @@ class DefaultShareProvider implements IShareProvider {
$share->setShareOwner($data['uid_owner']); $share->setShareOwner($data['uid_owner']);
} }
$path = $this->getNode($share->getShareOwner(), (int)$data['file_source']); $share->setNodeId((int)$data['file_source']);
$share->setNode($path);
if ($data['expiration'] !== null) { if ($data['expiration'] !== null) {
$expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']); $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']);

View File

@ -21,6 +21,7 @@
namespace OC\Share20; namespace OC\Share20;
use OCP\Files\IRootFolder;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\Share\IManager; use OCP\Share\IManager;
use OCP\Share\IProviderFactory; use OCP\Share\IProviderFactory;
@ -45,30 +46,24 @@ class Manager implements IManager {
/** @var IProviderFactory */ /** @var IProviderFactory */
private $factory; private $factory;
/** @var ILogger */ /** @var ILogger */
private $logger; private $logger;
/** @var IConfig */ /** @var IConfig */
private $config; private $config;
/** @var ISecureRandom */ /** @var ISecureRandom */
private $secureRandom; private $secureRandom;
/** @var IHasher */ /** @var IHasher */
private $hasher; private $hasher;
/** @var IMountManager */ /** @var IMountManager */
private $mountManager; private $mountManager;
/** @var IGroupManager */ /** @var IGroupManager */
private $groupManager; private $groupManager;
/** @var IL10N */ /** @var IL10N */
private $l; private $l;
/** @var IUserManager */ /** @var IUserManager */
private $userManager; private $userManager;
/** @var IRootFolder */
private $rootFolder;
/** /**
* Manager constructor. * Manager constructor.
@ -92,7 +87,8 @@ class Manager implements IManager {
IGroupManager $groupManager, IGroupManager $groupManager,
IL10N $l, IL10N $l,
IProviderFactory $factory, IProviderFactory $factory,
IUserManager $userManager IUserManager $userManager,
IRootFolder $rootFolder
) { ) {
$this->logger = $logger; $this->logger = $logger;
$this->config = $config; $this->config = $config;
@ -103,6 +99,7 @@ class Manager implements IManager {
$this->l = $l; $this->l = $l;
$this->factory = $factory; $this->factory = $factory;
$this->userManager = $userManager; $this->userManager = $userManager;
$this->rootFolder = $rootFolder;
} }
/** /**
@ -888,7 +885,7 @@ class Manager implements IManager {
* @return \OCP\Share\IShare; * @return \OCP\Share\IShare;
*/ */
public function newShare() { public function newShare() {
return new \OC\Share20\Share(); return new \OC\Share20\Share($this->rootFolder);
} }
/** /**

View File

@ -20,7 +20,9 @@
*/ */
namespace OC\Share20; namespace OC\Share20;
use OCP\Files\IRootFolder;
use OCP\Files\Node; use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\IUser; use OCP\IUser;
use OCP\IGroup; use OCP\IGroup;
@ -31,14 +33,16 @@ class Share implements \OCP\Share\IShare {
/** @var string */ /** @var string */
private $providerId; private $providerId;
/** @var Node */ /** @var Node */
private $path; private $node;
/** @var int */
private $fileId;
/** @var int */ /** @var int */
private $shareType; private $shareType;
/** @var IUser|IGroup */ /** @var string */
private $sharedWith; private $sharedWith;
/** @var IUser */ /** @var string */
private $sharedBy; private $sharedBy;
/** @var IUser */ /** @var string */
private $shareOwner; private $shareOwner;
/** @var int */ /** @var int */
private $permissions; private $permissions;
@ -57,6 +61,13 @@ class Share implements \OCP\Share\IShare {
/** @var bool */ /** @var bool */
private $mailSend; private $mailSend;
/** @var IRootFolder */
private $rootFolder;
public function __construct(IRootFolder $rootFolder) {
$this->rootFolder = $rootFolder;
}
/** /**
* @inheritdoc * @inheritdoc
*/ */
@ -90,8 +101,8 @@ class Share implements \OCP\Share\IShare {
/** /**
* @inheritdoc * @inheritdoc
*/ */
public function setNode(Node $path) { public function setNode(Node $node) {
$this->path = $path; $this->node = $node;
return $this; return $this;
} }
@ -99,7 +110,32 @@ class Share implements \OCP\Share\IShare {
* @inheritdoc * @inheritdoc
*/ */
public function getNode() { public function getNode() {
return $this->path; if ($this->node === null) {
if ($this->shareOwner === null || $this->fileId === null) {
throw new NotFoundException();
}
$userFolder = $this->rootFolder->getUserFolder($this->shareOwner);
$nodes = $userFolder->getById($this->fileId);
if (empty($nodes)) {
throw new NotFoundException();
}
$this->node = $nodes[0];
}
return $this->node;
}
/**
* @inheritdoc
*/
public function setNodeId($fileId) {
$this->node = null;
$this->fileId = $fileId;
return $this;
} }
/** /**

View File

@ -24,8 +24,7 @@ namespace OCP\Share;
use OCP\Files\File; use OCP\Files\File;
use OCP\Files\Folder; use OCP\Files\Folder;
use OCP\Files\Node; use OCP\Files\Node;
use OCP\IUser; use OCP\Files\NotFoundException;
use OCP\IGroup;
/** /**
* Interface IShare * Interface IShare
@ -55,20 +54,29 @@ interface IShare {
/** /**
* Set the node of the file/folder that is shared * Set the node of the file/folder that is shared
* *
* @param File|Folder $path * @param Node $node
* @return \OCP\Share\IShare The modified object * @return \OCP\Share\IShare The modified object
* @since 9.0.0 * @since 9.0.0
*/ */
public function setNode(Node $path); public function setNode(Node $node);
/** /**
* Get the node of the file/folder that is shared * Get the node of the file/folder that is shared
* *
* @return File|Folder * @return File|Folder
* @since 9.0.0 * @since 9.0.0
* @throws NotFoundException
*/ */
public function getNode(); public function getNode();
/**
* Set file id for lazy evaluation of the node
* @param int $fileId
* @return \OCP\Share\IShare The modified object
* @since 9.0.0
*/
public function setNodeId($fileId);
/** /**
* Set the shareType * Set the shareType
* *

View File

@ -561,7 +561,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
} }
public function testCreateUserShare() { public function testCreateUserShare() {
$share = new \OC\Share20\Share(); $share = new \OC\Share20\Share($this->rootFolder);
$shareOwner = $this->getMock('OCP\IUser'); $shareOwner = $this->getMock('OCP\IUser');
$shareOwner->method('getUID')->WillReturn('shareOwner'); $shareOwner->method('getUID')->WillReturn('shareOwner');
@ -609,7 +609,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
} }
public function testCreateGroupShare() { public function testCreateGroupShare() {
$share = new \OC\Share20\Share(); $share = new \OC\Share20\Share($this->rootFolder);
$shareOwner = $this->getMock('\OCP\IUser'); $shareOwner = $this->getMock('\OCP\IUser');
$shareOwner->method('getUID')->willReturn('shareOwner'); $shareOwner->method('getUID')->willReturn('shareOwner');
@ -657,7 +657,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
} }
public function testCreateLinkShare() { public function testCreateLinkShare() {
$share = new \OC\Share20\Share(); $share = new \OC\Share20\Share($this->rootFolder);
$shareOwner = $this->getMock('\OCP\IUser'); $shareOwner = $this->getMock('\OCP\IUser');
$shareOwner->method('getUID')->willReturn('shareOwner'); $shareOwner->method('getUID')->willReturn('shareOwner');

View File

@ -20,6 +20,7 @@
*/ */
namespace Test\Share20; namespace Test\Share20;
use OCP\Files\IRootFolder;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\Share\IProviderFactory; use OCP\Share\IProviderFactory;
use OCP\Share\IShare; use OCP\Share\IShare;
@ -35,7 +36,6 @@ use OCP\Security\ISecureRandom;
use OCP\Security\IHasher; use OCP\Security\IHasher;
use OCP\Files\Mount\IMountManager; use OCP\Files\Mount\IMountManager;
use OCP\IGroupManager; use OCP\IGroupManager;
use Sabre\VObject\Property\VCard\DateTime;
/** /**
* Class ManagerTest * Class ManagerTest
@ -47,36 +47,28 @@ class ManagerTest extends \Test\TestCase {
/** @var Manager */ /** @var Manager */
protected $manager; protected $manager;
/** @var ILogger */ /** @var ILogger */
protected $logger; protected $logger;
/** @var IConfig */ /** @var IConfig */
protected $config; protected $config;
/** @var ISecureRandom */ /** @var ISecureRandom */
protected $secureRandom; protected $secureRandom;
/** @var IHasher */ /** @var IHasher */
protected $hasher; protected $hasher;
/** @var IShareProvider | \PHPUnit_Framework_MockObject_MockObject */ /** @var IShareProvider | \PHPUnit_Framework_MockObject_MockObject */
protected $defaultProvider; protected $defaultProvider;
/** @var IMountManager */ /** @var IMountManager */
protected $mountManager; protected $mountManager;
/** @var IGroupManager */ /** @var IGroupManager */
protected $groupManager; protected $groupManager;
/** @var IL10N */ /** @var IL10N */
protected $l; protected $l;
/** @var DummyFactory */ /** @var DummyFactory */
protected $factory; protected $factory;
/** @var IUserManager */ /** @var IUserManager */
protected $userManager; protected $userManager;
/** @var IRootFolder | \PHPUnit_Framework_MockObject_MockObject */
protected $rootFolder;
public function setUp() { public function setUp() {
@ -87,6 +79,7 @@ class ManagerTest extends \Test\TestCase {
$this->mountManager = $this->getMock('\OCP\Files\Mount\IMountManager'); $this->mountManager = $this->getMock('\OCP\Files\Mount\IMountManager');
$this->groupManager = $this->getMock('\OCP\IGroupManager'); $this->groupManager = $this->getMock('\OCP\IGroupManager');
$this->userManager = $this->getMock('\OCP\IUserManager'); $this->userManager = $this->getMock('\OCP\IUserManager');
$this->rootFolder = $this->getMock('\OCP\Files\IRootFolder');
$this->l = $this->getMock('\OCP\IL10N'); $this->l = $this->getMock('\OCP\IL10N');
$this->l->method('t') $this->l->method('t')
@ -105,7 +98,8 @@ class ManagerTest extends \Test\TestCase {
$this->groupManager, $this->groupManager,
$this->l, $this->l,
$this->factory, $this->factory,
$this->userManager $this->userManager,
$this->rootFolder
); );
$this->defaultProvider = $this->getMockBuilder('\OC\Share20\DefaultShareProvider') $this->defaultProvider = $this->getMockBuilder('\OC\Share20\DefaultShareProvider')
@ -131,7 +125,8 @@ class ManagerTest extends \Test\TestCase {
$this->groupManager, $this->groupManager,
$this->l, $this->l,
$this->factory, $this->factory,
$this->userManager $this->userManager,
$this->rootFolder
]); ]);
} }
@ -792,7 +787,7 @@ class ManagerTest extends \Test\TestCase {
* @expectedExceptionMessage Only sharing with group members is allowed * @expectedExceptionMessage Only sharing with group members is allowed
*/ */
public function testUserCreateChecksShareWithGroupMembersOnlyDifferentGroups() { public function testUserCreateChecksShareWithGroupMembersOnlyDifferentGroups() {
$share = new \OC\Share20\Share(); $share = $this->manager->newShare();
$sharedBy = $this->getMock('\OCP\IUser'); $sharedBy = $this->getMock('\OCP\IUser');
$sharedWith = $this->getMock('\OCP\IUser'); $sharedWith = $this->getMock('\OCP\IUser');
@ -822,7 +817,7 @@ class ManagerTest extends \Test\TestCase {
} }
public function testUserCreateChecksShareWithGroupMembersOnlySharedGroup() { public function testUserCreateChecksShareWithGroupMembersOnlySharedGroup() {
$share = new \OC\Share20\Share(); $share = $this->manager->newShare();
$sharedBy = $this->getMock('\OCP\IUser'); $sharedBy = $this->getMock('\OCP\IUser');
$sharedWith = $this->getMock('\OCP\IUser'); $sharedWith = $this->getMock('\OCP\IUser');
@ -904,8 +899,7 @@ class ManagerTest extends \Test\TestCase {
->setProviderId('foo') ->setProviderId('foo')
->setId('bar'); ->setId('bar');
$share2 = new \OC\Share20\Share(); $share2 = $this->manager->newShare();
$owner2 = $this->getMock('\OCP\IUser');
$share2->setShareType(\OCP\Share::SHARE_TYPE_GROUP) $share2->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
->setShareOwner('shareOwner2') ->setShareOwner('shareOwner2')
->setProviderId('foo') ->setProviderId('foo')
@ -928,7 +922,7 @@ class ManagerTest extends \Test\TestCase {
} }
public function testUserCreateChecksIdenticalPathNotSharedWithUser() { public function testUserCreateChecksIdenticalPathNotSharedWithUser() {
$share = new \OC\Share20\Share(); $share = $this->manager->newShare();
$sharedWith = $this->getMock('\OCP\IUser'); $sharedWith = $this->getMock('\OCP\IUser');
$path = $this->getMock('\OCP\Files\Node'); $path = $this->getMock('\OCP\Files\Node');
$share->setSharedWith('sharedWith') $share->setSharedWith('sharedWith')
@ -939,7 +933,7 @@ class ManagerTest extends \Test\TestCase {
$this->userManager->method('get')->with('sharedWith')->willReturn($sharedWith); $this->userManager->method('get')->with('sharedWith')->willReturn($sharedWith);
$share2 = new \OC\Share20\Share(); $share2 = $this->manager->newShare();
$share2->setShareType(\OCP\Share::SHARE_TYPE_GROUP) $share2->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
->setShareOwner('shareOwner2') ->setShareOwner('shareOwner2')
->setProviderId('foo') ->setProviderId('foo')
@ -967,7 +961,7 @@ class ManagerTest extends \Test\TestCase {
* @expectedExceptionMessage Only sharing within your own groups is allowed * @expectedExceptionMessage Only sharing within your own groups is allowed
*/ */
public function testGroupCreateChecksShareWithGroupMembersOnlyNotInGroup() { public function testGroupCreateChecksShareWithGroupMembersOnlyNotInGroup() {
$share = new \OC\Share20\Share(); $share = $this->manager->newShare();
$user = $this->getMock('\OCP\IUser'); $user = $this->getMock('\OCP\IUser');
$group = $this->getMock('\OCP\IGroup'); $group = $this->getMock('\OCP\IGroup');
@ -988,7 +982,7 @@ class ManagerTest extends \Test\TestCase {
} }
public function testGroupCreateChecksShareWithGroupMembersOnlyInGroup() { public function testGroupCreateChecksShareWithGroupMembersOnlyInGroup() {
$share = new \OC\Share20\Share(); $share = $this->manager->newShare();
$user = $this->getMock('\OCP\IUser'); $user = $this->getMock('\OCP\IUser');
$group = $this->getMock('\OCP\IGroup'); $group = $this->getMock('\OCP\IGroup');
@ -1028,7 +1022,7 @@ class ManagerTest extends \Test\TestCase {
->setProviderId('foo') ->setProviderId('foo')
->setId('bar'); ->setId('bar');
$share2 = new \OC\Share20\Share(); $share2 = $this->manager->newShare();
$share2->setSharedWith('sharedWith') $share2->setSharedWith('sharedWith')
->setProviderId('foo') ->setProviderId('foo')
->setId('baz'); ->setId('baz');
@ -1041,14 +1035,14 @@ class ManagerTest extends \Test\TestCase {
} }
public function testGroupCreateChecksPathAlreadySharedWithDifferentGroup() { public function testGroupCreateChecksPathAlreadySharedWithDifferentGroup() {
$share = new \OC\Share20\Share(); $share = $this->manager->newShare();
$share->setSharedWith('sharedWith'); $share->setSharedWith('sharedWith');
$path = $this->getMock('\OCP\Files\Node'); $path = $this->getMock('\OCP\Files\Node');
$share->setNode($path); $share->setNode($path);
$share2 = new \OC\Share20\Share(); $share2 = $this->manager->newShare();
$share2->setSharedWith('sharedWith2'); $share2->setSharedWith('sharedWith2');
$this->defaultProvider->method('getSharesByPath') $this->defaultProvider->method('getSharesByPath')
@ -1063,7 +1057,7 @@ class ManagerTest extends \Test\TestCase {
* @expectedExceptionMessage Link sharing not allowed * @expectedExceptionMessage Link sharing not allowed
*/ */
public function testLinkCreateChecksNoLinkSharesAllowed() { public function testLinkCreateChecksNoLinkSharesAllowed() {
$share = new \OC\Share20\Share(); $share = $this->manager->newShare();
$this->config $this->config
->method('getAppValue') ->method('getAppValue')
@ -1079,7 +1073,7 @@ class ManagerTest extends \Test\TestCase {
* @expectedExceptionMessage Link shares can't have reshare permissions * @expectedExceptionMessage Link shares can't have reshare permissions
*/ */
public function testLinkCreateChecksSharePermissions() { public function testLinkCreateChecksSharePermissions() {
$share = new \OC\Share20\Share(); $share = $this->manager->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_SHARE); $share->setPermissions(\OCP\Constants::PERMISSION_SHARE);
@ -1097,7 +1091,7 @@ class ManagerTest extends \Test\TestCase {
* @expectedExceptionMessage Link shares can't have delete permissions * @expectedExceptionMessage Link shares can't have delete permissions
*/ */
public function testLinkCreateChecksDeletePermissions() { public function testLinkCreateChecksDeletePermissions() {
$share = new \OC\Share20\Share(); $share = $this->manager->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_DELETE); $share->setPermissions(\OCP\Constants::PERMISSION_DELETE);
@ -1115,7 +1109,7 @@ class ManagerTest extends \Test\TestCase {
* @expectedExceptionMessage Public upload not allowed * @expectedExceptionMessage Public upload not allowed
*/ */
public function testLinkCreateChecksNoPublicUpload() { public function testLinkCreateChecksNoPublicUpload() {
$share = new \OC\Share20\Share(); $share = $this->manager->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE); $share->setPermissions(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE);
@ -1130,7 +1124,7 @@ class ManagerTest extends \Test\TestCase {
} }
public function testLinkCreateChecksPublicUpload() { public function testLinkCreateChecksPublicUpload() {
$share = new \OC\Share20\Share(); $share = $this->manager->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE); $share->setPermissions(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE);
@ -1145,7 +1139,7 @@ class ManagerTest extends \Test\TestCase {
} }
public function testLinkCreateChecksReadOnly() { public function testLinkCreateChecksReadOnly() {
$share = new \OC\Share20\Share(); $share = $this->manager->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_READ); $share->setPermissions(\OCP\Constants::PERMISSION_READ);
@ -1316,7 +1310,7 @@ class ManagerTest extends \Test\TestCase {
->getMock(); ->getMock();
$manager->expects($this->once())->method('canShare')->willReturn(false); $manager->expects($this->once())->method('canShare')->willReturn(false);
$share = new \OC\Share20\Share(); $share = $this->manager->newShare();
$manager->createShare($share); $manager->createShare($share);
} }
@ -1610,7 +1604,8 @@ class ManagerTest extends \Test\TestCase {
$this->groupManager, $this->groupManager,
$this->l, $this->l,
$factory, $factory,
$this->userManager $this->userManager,
$this->rootFolder
); );
$share = $this->getMock('\OCP\Share\IShare'); $share = $this->getMock('\OCP\Share\IShare');
@ -1695,7 +1690,7 @@ class ManagerTest extends \Test\TestCase {
->getMock(); ->getMock();
$manager->expects($this->once())->method('canShare')->willReturn(false); $manager->expects($this->once())->method('canShare')->willReturn(false);
$share = new \OC\Share20\Share(); $share = $this->manager->newShare();
$manager->updateShare($share); $manager->updateShare($share);
} }
@ -1711,13 +1706,13 @@ class ManagerTest extends \Test\TestCase {
]) ])
->getMock(); ->getMock();
$originalShare = new \OC\Share20\Share(); $originalShare = $this->manager->newShare();
$originalShare->setShareType(\OCP\Share::SHARE_TYPE_GROUP); $originalShare->setShareType(\OCP\Share::SHARE_TYPE_GROUP);
$manager->expects($this->once())->method('canShare')->willReturn(true); $manager->expects($this->once())->method('canShare')->willReturn(true);
$manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare); $manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare);
$share = new \OC\Share20\Share(); $share = $this->manager->newShare();
$share->setProviderId('foo') $share->setProviderId('foo')
->setId('42') ->setId('42')
->setShareType(\OCP\Share::SHARE_TYPE_USER); ->setShareType(\OCP\Share::SHARE_TYPE_USER);
@ -1737,14 +1732,14 @@ class ManagerTest extends \Test\TestCase {
]) ])
->getMock(); ->getMock();
$originalShare = new \OC\Share20\Share(); $originalShare = $this->manager->newShare();
$originalShare->setShareType(\OCP\Share::SHARE_TYPE_GROUP) $originalShare->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
->setSharedWith('origGroup'); ->setSharedWith('origGroup');
$manager->expects($this->once())->method('canShare')->willReturn(true); $manager->expects($this->once())->method('canShare')->willReturn(true);
$manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare); $manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare);
$share = new \OC\Share20\Share(); $share = $this->manager->newShare();
$share->setProviderId('foo') $share->setProviderId('foo')
->setId('42') ->setId('42')
->setShareType(\OCP\Share::SHARE_TYPE_GROUP) ->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
@ -1765,14 +1760,14 @@ class ManagerTest extends \Test\TestCase {
]) ])
->getMock(); ->getMock();
$originalShare = new \OC\Share20\Share(); $originalShare = $this->manager->newShare();
$originalShare->setShareType(\OCP\Share::SHARE_TYPE_USER) $originalShare->setShareType(\OCP\Share::SHARE_TYPE_USER)
->setSharedWith('sharedWith'); ->setSharedWith('sharedWith');
$manager->expects($this->once())->method('canShare')->willReturn(true); $manager->expects($this->once())->method('canShare')->willReturn(true);
$manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare); $manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare);
$share = new \OC\Share20\Share(); $share = $this->manager->newShare();
$share->setProviderId('foo') $share->setProviderId('foo')
->setId('42') ->setId('42')
->setShareType(\OCP\Share::SHARE_TYPE_USER) ->setShareType(\OCP\Share::SHARE_TYPE_USER)
@ -1793,19 +1788,22 @@ class ManagerTest extends \Test\TestCase {
]) ])
->getMock(); ->getMock();
$originalShare = new \OC\Share20\Share(); $originalShare = $this->manager->newShare();
$originalShare->setShareType(\OCP\Share::SHARE_TYPE_USER) $originalShare->setShareType(\OCP\Share::SHARE_TYPE_USER)
->setSharedWith('origUser'); ->setSharedWith('origUser');
$manager->expects($this->once())->method('canShare')->willReturn(true); $manager->expects($this->once())->method('canShare')->willReturn(true);
$manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare); $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') $share->setProviderId('foo')
->setId('42') ->setId('42')
->setShareType(\OCP\Share::SHARE_TYPE_USER) ->setShareType(\OCP\Share::SHARE_TYPE_USER)
->setSharedWith('origUser') ->setSharedWith('origUser')
->setShareOwner('newUser'); ->setShareOwner('newUser')
->setNode($node);
$this->defaultProvider->expects($this->once()) $this->defaultProvider->expects($this->once())
->method('update') ->method('update')
@ -1831,19 +1829,22 @@ class ManagerTest extends \Test\TestCase {
]) ])
->getMock(); ->getMock();
$originalShare = new \OC\Share20\Share(); $originalShare = $this->manager->newShare();
$originalShare->setShareType(\OCP\Share::SHARE_TYPE_GROUP) $originalShare->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
->setSharedWith('origUser'); ->setSharedWith('origUser');
$manager->expects($this->once())->method('canShare')->willReturn(true); $manager->expects($this->once())->method('canShare')->willReturn(true);
$manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare); $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') $share->setProviderId('foo')
->setId('42') ->setId('42')
->setShareType(\OCP\Share::SHARE_TYPE_GROUP) ->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
->setSharedWith('origUser') ->setSharedWith('origUser')
->setShareOwner('owner'); ->setShareOwner('owner')
->setNode($node);
$this->defaultProvider->expects($this->once()) $this->defaultProvider->expects($this->once())
->method('update') ->method('update')
@ -1871,7 +1872,7 @@ class ManagerTest extends \Test\TestCase {
]) ])
->getMock(); ->getMock();
$originalShare = new \OC\Share20\Share(); $originalShare = $this->manager->newShare();
$originalShare->setShareType(\OCP\Share::SHARE_TYPE_LINK); $originalShare->setShareType(\OCP\Share::SHARE_TYPE_LINK);
$tomorrow = new \DateTime(); $tomorrow = new \DateTime();