*/
namespace Test\Share20;
+use OCP\Files\IRootFolder;
use OCP\IUserManager;
use OCP\Share\IProviderFactory;
use OCP\Share\IShare;
use OCP\Security\IHasher;
use OCP\Files\Mount\IMountManager;
use OCP\IGroupManager;
-use Sabre\VObject\Property\VCard\DateTime;
/**
* Class ManagerTest
/** @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() {
$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')
$this->groupManager,
$this->l,
$this->factory,
- $this->userManager
+ $this->userManager,
+ $this->rootFolder
);
$this->defaultProvider = $this->getMockBuilder('\OC\Share20\DefaultShareProvider')
$this->groupManager,
$this->l,
$this->factory,
- $this->userManager
+ $this->userManager,
+ $this->rootFolder
]);
}
* @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');
}
public function testUserCreateChecksShareWithGroupMembersOnlySharedGroup() {
- $share = new \OC\Share20\Share();
+ $share = $this->manager->newShare();
$sharedBy = $this->getMock('\OCP\IUser');
$sharedWith = $this->getMock('\OCP\IUser');
->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('shareOwner2')
->setProviderId('foo')
}
public function testUserCreateChecksIdenticalPathNotSharedWithUser() {
- $share = new \OC\Share20\Share();
+ $share = $this->manager->newShare();
$sharedWith = $this->getMock('\OCP\IUser');
$path = $this->getMock('\OCP\Files\Node');
$share->setSharedWith('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)
->setShareOwner('shareOwner2')
->setProviderId('foo')
* @expectedExceptionMessage Only sharing within your own groups is allowed
*/
public function testGroupCreateChecksShareWithGroupMembersOnlyNotInGroup() {
- $share = new \OC\Share20\Share();
+ $share = $this->manager->newShare();
$user = $this->getMock('\OCP\IUser');
$group = $this->getMock('\OCP\IGroup');
}
public function testGroupCreateChecksShareWithGroupMembersOnlyInGroup() {
- $share = new \OC\Share20\Share();
+ $share = $this->manager->newShare();
$user = $this->getMock('\OCP\IUser');
$group = $this->getMock('\OCP\IGroup');
->setProviderId('foo')
->setId('bar');
- $share2 = new \OC\Share20\Share();
+ $share2 = $this->manager->newShare();
$share2->setSharedWith('sharedWith')
->setProviderId('foo')
->setId('baz');
}
public function testGroupCreateChecksPathAlreadySharedWithDifferentGroup() {
- $share = new \OC\Share20\Share();
+ $share = $this->manager->newShare();
$share->setSharedWith('sharedWith');
$path = $this->getMock('\OCP\Files\Node');
$share->setNode($path);
- $share2 = new \OC\Share20\Share();
+ $share2 = $this->manager->newShare();
$share2->setSharedWith('sharedWith2');
$this->defaultProvider->method('getSharesByPath')
* @expectedExceptionMessage Link sharing not allowed
*/
public function testLinkCreateChecksNoLinkSharesAllowed() {
- $share = new \OC\Share20\Share();
+ $share = $this->manager->newShare();
$this->config
->method('getAppValue')
* @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);
* @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);
* @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);
}
public function testLinkCreateChecksPublicUpload() {
- $share = new \OC\Share20\Share();
+ $share = $this->manager->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE);
}
public function testLinkCreateChecksReadOnly() {
- $share = new \OC\Share20\Share();
+ $share = $this->manager->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_READ);
->getMock();
$manager->expects($this->once())->method('canShare')->willReturn(false);
- $share = new \OC\Share20\Share();
+ $share = $this->manager->newShare();
$manager->createShare($share);
}
$this->groupManager,
$this->l,
$factory,
- $this->userManager
+ $this->userManager,
+ $this->rootFolder
);
$share = $this->getMock('\OCP\Share\IShare');
->getMock();
$manager->expects($this->once())->method('canShare')->willReturn(false);
- $share = new \OC\Share20\Share();
+ $share = $this->manager->newShare();
$manager->updateShare($share);
}
])
->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);
])
->getMock();
- $originalShare = new \OC\Share20\Share();
+ $originalShare = $this->manager->newShare();
$originalShare->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
->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)
])
->getMock();
- $originalShare = new \OC\Share20\Share();
+ $originalShare = $this->manager->newShare();
$originalShare->setShareType(\OCP\Share::SHARE_TYPE_USER)
->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)
])
->getMock();
- $originalShare = new \OC\Share20\Share();
+ $originalShare = $this->manager->newShare();
$originalShare->setShareType(\OCP\Share::SHARE_TYPE_USER)
->setSharedWith('origUser');
$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_USER)
->setSharedWith('origUser')
- ->setShareOwner('newUser');
+ ->setShareOwner('newUser')
+ ->setNode($node);
$this->defaultProvider->expects($this->once())
->method('update')
])
->getMock();
- $originalShare = new \OC\Share20\Share();
+ $originalShare = $this->manager->newShare();
$originalShare->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
->setSharedWith('origUser');
$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('origUser')
- ->setShareOwner('owner');
+ ->setShareOwner('owner')
+ ->setNode($node);
$this->defaultProvider->expects($this->once())
->method('update')
])
->getMock();
- $originalShare = new \OC\Share20\Share();
+ $originalShare = $this->manager->newShare();
$originalShare->setShareType(\OCP\Share::SHARE_TYPE_LINK);
$tomorrow = new \DateTime();