Merge pull request #20691 from owncloud/share2.0_di_fixes

[Sharing 2.0] di fixes
This commit is contained in:
Thomas Müller 2015-11-25 15:25:50 +01:00
commit 9ec2f8886e
10 changed files with 396 additions and 466 deletions

View File

@ -26,25 +26,23 @@ class OCSShareWrapper {
* @return Share20OCS * @return Share20OCS
*/ */
private function getShare20OCS() { private function getShare20OCS() {
return new Share20OCS(new \OC\Share20\Manager( return new Share20OCS(
\OC::$server->getUserSession()->getUser(), new \OC\Share20\Manager(
\OC::$server->getUserManager(), \OC::$server->getLogger(),
\OC::$server->getGroupManager(), \OC::$server->getAppConfig(),
\OC::$server->getLogger(), new \OC\Share20\DefaultShareProvider(
\OC::$server->getAppConfig(), \OC::$server->getDatabaseConnection(),
\OC::$server->getUserFolder(), \OC::$server->getUserManager(),
new \OC\Share20\DefaultShareProvider( \OC::$server->getGroupManager(),
\OC::$server->getDatabaseConnection(), \OC::$server->getRootFolder()
\OC::$server->getUserManager(), )
\OC::$server->getGroupManager(), ),
\OC::$server->getUserFolder() \OC::$server->getGroupManager(),
) \OC::$server->getUserManager(),
), \OC::$server->getRequest(),
\OC::$server->getGroupManager(), \OC::$server->getRootFolder(),
\OC::$server->getUserManager(), \OC::$server->getURLGenerator(),
\OC::$server->getRequest(), \OC::$server->getUserSession()->getUser());
\OC::$server->getUserFolder(),
\OC::$server->getURLGenerator());
} }
public function getAllShares($params) { public function getAllShares($params) {

View File

@ -22,35 +22,53 @@ namespace OCA\Files_Sharing\API;
use OC\Share20\IShare; use OC\Share20\IShare;
use OCP\IGroupManager;
use OCP\IUserManager;
use OCP\IRequest;
use OCP\Files\Folder;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\Files\IRootFolder;
class Share20OCS { class Share20OCS {
/** @var \OC\Share20\Manager */ /** @var \OC\Share20\Manager */
private $shareManager; private $shareManager;
/** @var \OCP\IGroupManager */ /** @var IGroupManager */
private $groupManager; private $groupManager;
/** @var \OCP\IUserManager */ /** @var IUserManager */
private $userManager; private $userManager;
/** @var \OCP\IRequest */ /** @var IRequest */
private $request; private $request;
/** @var \OCP\Files\Folder */ /** @var IRootFolder */
private $userFolder; private $rootFolder;
public function __construct(\OC\Share20\Manager $shareManager, /** @var IUrlGenerator */
\OCP\IGroupManager $groupManager, private $urlGenerator;
\OCP\IUserManager $userManager,
\OCP\IRequest $request, /** @var IUser */
\OCP\Files\Folder $userFolder, private $currentUser;
\OCP\IURLGenerator $urlGenerator) {
public function __construct(
\OC\Share20\Manager $shareManager,
IGroupManager $groupManager,
IUserManager $userManager,
IRequest $request,
IRootFolder $rootFolder,
IURLGenerator $urlGenerator,
IUser $currentUser
) {
$this->shareManager = $shareManager; $this->shareManager = $shareManager;
$this->userManager = $userManager; $this->userManager = $userManager;
$this->groupManager = $groupManager; $this->groupManager = $groupManager;
$this->request = $request; $this->request = $request;
$this->userFolder = $userFolder; $this->rootFolder = $rootFolder;
$this->urlGenerator = $urlGenerator; $this->urlGenerator = $urlGenerator;
$this->currentUser = $currentUser;
} }
/** /**
@ -73,7 +91,7 @@ class Share20OCS {
]; ];
$path = $share->getPath(); $path = $share->getPath();
$result['path'] = $this->userFolder->getRelativePath($path->getPath()); $result['path'] = $this->rootFolder->getUserFolder($share->getShareOwner()->getUID())->getRelativePath($path->getPath());
if ($path instanceOf \OCP\Files\Folder) { if ($path instanceOf \OCP\Files\Folder) {
$result['item_type'] = 'folder'; $result['item_type'] = 'folder';
} else { } else {
@ -131,8 +149,12 @@ class Share20OCS {
return new \OC_OCS_Result(null, 404, 'wrong share ID, share doesn\'t exist.'); return new \OC_OCS_Result(null, 404, 'wrong share ID, share doesn\'t exist.');
} }
$share = $this->formatShare($share); if ($this->canAccessShare($share)) {
return new \OC_OCS_Result($share); $share = $this->formatShare($share);
return new \OC_OCS_Result($share);
} else {
return new \OC_OCS_Result(null, 404, 'wrong share ID, share doesn\'t exist.');
}
} }
/** /**
@ -156,6 +178,10 @@ class Share20OCS {
\OCA\Files_Sharing\API\Local::deleteShare(['id' => $id]); \OCA\Files_Sharing\API\Local::deleteShare(['id' => $id]);
} }
if (!$this->canAccessShare($share)) {
return new \OC_OCS_Result(null, 404, 'could not delete share');
}
try { try {
$this->shareManager->deleteShare($share); $this->shareManager->deleteShare($share);
} catch (\OC\Share20\Exception\BackendError $e) { } catch (\OC\Share20\Exception\BackendError $e) {
@ -164,4 +190,30 @@ class Share20OCS {
return new \OC_OCS_Result(); return new \OC_OCS_Result();
} }
/**
* @param IShare $share
* @return bool
*/
protected function canAccessShare(IShare $share) {
// Owner of the file and the sharer of the file can always get share
if ($share->getShareOwner() === $this->currentUser ||
$share->getSharedBy() === $this->currentUser
) {
return true;
}
// If the share is shared with you (or a group you are a member of)
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER &&
$share->getSharedWith() === $this->currentUser) {
return true;
}
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP &&
$share->getSharedWith()->inGroup($this->currentUser)) {
return true;
}
return false;
}
} }

View File

@ -20,29 +20,39 @@
*/ */
namespace OCA\Files_Sharing\Tests\API; namespace OCA\Files_Sharing\Tests\API;
use OC\Share20\IShare;
use OCA\Files_Sharing\API\Share20OCS; use OCA\Files_Sharing\API\Share20OCS;
use OCP\IGroupManager;
use OCP\IUserManager;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\Files\IRootFolder;
class Share20OCSTest extends \Test\TestCase { class Share20OCSTest extends \Test\TestCase {
/** @var OC\Share20\Manager */ /** @var \OC\Share20\Manager */
private $shareManager; private $shareManager;
/** @var OCP\IGroupManager */ /** @var IGroupManager */
private $groupManager; private $groupManager;
/** @var OCP\IUserManager */ /** @var IUserManager */
private $userManager; private $userManager;
/** @var OCP\IRequest */ /** @var IRequest */
private $request; private $request;
/** @var OCP\Files\Folder */ /** @var IRootFolder */
private $userFolder; private $rootFolder;
/** @var OCP\IURLGenerator */ /** @var IURLGenerator */
private $urlGenerator; private $urlGenerator;
/** @var OCS */ /** @var IUser */
private $currentUser;
/** @var Share20OCS */
private $ocs; private $ocs;
protected function setUp() { protected function setUp() {
@ -52,15 +62,19 @@ class Share20OCSTest extends \Test\TestCase {
$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->request = $this->getMock('OCP\IRequest'); $this->request = $this->getMock('OCP\IRequest');
$this->userFolder = $this->getMock('OCP\Files\Folder'); $this->rootFolder = $this->getMock('OCP\Files\IRootFolder');
$this->urlGenerator = $this->getMock('OCP\IURLGenerator'); $this->urlGenerator = $this->getMock('OCP\IURLGenerator');
$this->currentUser = $this->getMock('OCP\IUser');
$this->ocs = new Share20OCS($this->shareManager, $this->ocs = new Share20OCS(
$this->groupManager, $this->shareManager,
$this->userManager, $this->groupManager,
$this->request, $this->userManager,
$this->userFolder, $this->request,
$this->urlGenerator); $this->rootFolder,
$this->urlGenerator,
$this->currentUser
);
} }
public function testDeleteShareShareNotFound() { public function testDeleteShareShareNotFound() {
@ -76,6 +90,7 @@ class Share20OCSTest extends \Test\TestCase {
public function testDeleteShareCouldNotDelete() { public function testDeleteShareCouldNotDelete() {
$share = $this->getMock('OC\Share20\IShare'); $share = $this->getMock('OC\Share20\IShare');
$share->method('getShareOwner')->willReturn($this->currentUser);
$this->shareManager $this->shareManager
->expects($this->once()) ->expects($this->once())
->method('getShareById') ->method('getShareById')
@ -94,6 +109,7 @@ class Share20OCSTest extends \Test\TestCase {
public function testDeleteShare() { public function testDeleteShare() {
$share = $this->getMock('OC\Share20\IShare'); $share = $this->getMock('OC\Share20\IShare');
$share->method('getSharedBy')->willReturn($this->currentUser);
$this->shareManager $this->shareManager
->expects($this->once()) ->expects($this->once())
->method('getShareById') ->method('getShareById')
@ -119,7 +135,7 @@ class Share20OCSTest extends \Test\TestCase {
$this->assertEquals($expected, $this->ocs->getShare(42)); $this->assertEquals($expected, $this->ocs->getShare(42));
} }
public function createShare($id, $shareType, $sharedWith, $sharedBy, $path, $permissions, public function createShare($id, $shareType, $sharedWith, $sharedBy, $shareOwner, $path, $permissions,
$shareTime, $expiration, $parent, $target, $mail_send, $token=null, $shareTime, $expiration, $parent, $target, $mail_send, $token=null,
$password=null) { $password=null) {
$share = $this->getMock('OC\Share20\IShare'); $share = $this->getMock('OC\Share20\IShare');
@ -127,6 +143,7 @@ class Share20OCSTest extends \Test\TestCase {
$share->method('getShareType')->willReturn($shareType); $share->method('getShareType')->willReturn($shareType);
$share->method('getSharedWith')->willReturn($sharedWith); $share->method('getSharedWith')->willReturn($sharedWith);
$share->method('getSharedBy')->willReturn($sharedBy); $share->method('getSharedBy')->willReturn($sharedBy);
$share->method('getShareOwner')->willReturn($shareOwner);
$share->method('getPath')->willReturn($path); $share->method('getPath')->willReturn($path);
$share->method('getPermissions')->willReturn($permissions); $share->method('getPermissions')->willReturn($permissions);
$share->method('getShareTime')->willReturn($shareTime); $share->method('getShareTime')->willReturn($shareTime);
@ -173,17 +190,20 @@ class Share20OCSTest extends \Test\TestCase {
$folder->method('getParent')->willReturn($parentFolder); $folder->method('getParent')->willReturn($parentFolder);
// File shared with user // File shared with user
$share = $this->createShare(100, $share = $this->createShare(
\OCP\Share::SHARE_TYPE_USER, 100,
$user, \OCP\Share::SHARE_TYPE_USER,
$owner, $user,
$file, $owner,
4, $owner,
5, $file,
null, 4,
6, 5,
'target', null,
0); 6,
'target',
0
);
$expected = [ $expected = [
'id' => 100, 'id' => 100,
'share_type' => \OCP\Share::SHARE_TYPE_USER, 'share_type' => \OCP\Share::SHARE_TYPE_USER,
@ -209,17 +229,20 @@ class Share20OCSTest extends \Test\TestCase {
$data[] = [$share, $expected]; $data[] = [$share, $expected];
// Folder shared with group // Folder shared with group
$share = $this->createShare(101, $share = $this->createShare(
\OCP\Share::SHARE_TYPE_GROUP, 101,
$group, \OCP\Share::SHARE_TYPE_GROUP,
$owner, $group,
$folder, $owner,
4, $owner,
5, $folder,
null, 4,
6, 5,
'target', null,
0); 6,
'target',
0
);
$expected = [ $expected = [
'id' => 101, 'id' => 101,
'share_type' => \OCP\Share::SHARE_TYPE_GROUP, 'share_type' => \OCP\Share::SHARE_TYPE_GROUP,
@ -244,57 +267,24 @@ class Share20OCSTest extends \Test\TestCase {
]; ];
$data[] = [$share, $expected]; $data[] = [$share, $expected];
// Folder shared with remote
$share = $this->createShare(101,
\OCP\Share::SHARE_TYPE_REMOTE,
'user@remote.com',
$owner,
$folder,
4,
5,
null,
6,
'target',
0);
$expected = [
'id' => 101,
'share_type' => \OCP\Share::SHARE_TYPE_REMOTE,
'share_with' => 'user@remote.com',
'share_with_displayname' => 'user@remote.com',
'uid_owner' => 'ownerId',
'displayname_owner' => 'ownerDisplay',
'item_type' => 'folder',
'item_source' => 2,
'file_source' => 2,
'file_target' => 'target',
'file_parent' => 3,
'token' => null,
'expiration' => null,
'permissions' => 4,
'stime' => 5,
'parent' => 6,
'storage_id' => 'STORAGE',
'path' => 'folder',
'storage' => null, // HACK around static function
'mail_send' => 0,
];
$data[] = [$share, $expected];
// File shared by link with Expire // File shared by link with Expire
$expire = \DateTime::createFromFormat('Y-m-d h:i:s', '2000-01-02 01:02:03'); $expire = \DateTime::createFromFormat('Y-m-d h:i:s', '2000-01-02 01:02:03');
$share = $this->createShare(101, $share = $this->createShare(
\OCP\Share::SHARE_TYPE_LINK, 101,
null, \OCP\Share::SHARE_TYPE_LINK,
$owner, null,
$folder, $owner,
4, $owner,
5, $folder,
$expire, 4,
6, 5,
'target', $expire,
0, 6,
'token', 'target',
'password'); 0,
'token',
'password'
);
$expected = [ $expected = [
'id' => 101, 'id' => 101,
'share_type' => \OCP\Share::SHARE_TYPE_LINK, 'share_type' => \OCP\Share::SHARE_TYPE_LINK,
@ -327,20 +317,78 @@ class Share20OCSTest extends \Test\TestCase {
* @dataProvider dataGetShare * @dataProvider dataGetShare
*/ */
public function testGetShare(\OC\Share20\IShare $share, array $result) { public function testGetShare(\OC\Share20\IShare $share, array $result) {
$ocs = $this->getMockBuilder('OCA\Files_Sharing\API\Share20OCS')
->setConstructorArgs([
$this->shareManager,
$this->groupManager,
$this->userManager,
$this->request,
$this->rootFolder,
$this->urlGenerator,
$this->currentUser
])->setMethods(['canAccessShare'])
->getMock();
$ocs->method('canAccessShare')->willReturn(true);
$this->shareManager $this->shareManager
->expects($this->once()) ->expects($this->once())
->method('getShareById') ->method('getShareById')
->with($share->getId()) ->with($share->getId())
->willReturn($share); ->willReturn($share);
$this->userFolder $userFolder = $this->getMock('OCP\Files\Folder');
$userFolder
->method('getRelativePath') ->method('getRelativePath')
->will($this->returnArgument(0)); ->will($this->returnArgument(0));
$this->rootFolder->method('getUserFolder')
->with($share->getShareOwner()->getUID())
->willReturn($userFolder);
$this->urlGenerator $this->urlGenerator
->method('linkToRouteAbsolute') ->method('linkToRouteAbsolute')
->willReturn('url'); ->willReturn('url');
$expected = new \OC_OCS_Result($result); $expected = new \OC_OCS_Result($result);
$this->assertEquals($expected->getData(), $this->ocs->getShare($share->getId())->getData()); } $this->assertEquals($expected->getData(), $ocs->getShare($share->getId())->getData());
}
public function testCanAccessShare() {
$share = $this->getMock('OC\Share20\IShare');
$share->method('getShareOwner')->willReturn($this->currentUser);
$this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
$share = $this->getMock('OC\Share20\IShare');
$share->method('getSharedBy')->willReturn($this->currentUser);
$this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
$share = $this->getMock('OC\Share20\IShare');
$share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER);
$share->method('getSharedWith')->willReturn($this->currentUser);
$this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
$share = $this->getMock('OC\Share20\IShare');
$share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER);
$share->method('getSharedWith')->willReturn($this->getMock('OCP\IUser'));
$this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
$share = $this->getMock('OC\Share20\IShare');
$share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_GROUP);
$group = $this->getMock('OCP\IGroup');
$group->method('inGroup')->with($this->currentUser)->willReturn(true);
$share->method('getSharedWith')->willReturn($group);
$this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
$share = $this->getMock('OC\Share20\IShare');
$share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_GROUP);
$group = $this->getMock('OCP\IGroup');
$group->method('inGroup')->with($this->currentUser)->willReturn(false);
$share->method('getSharedWith')->willReturn($group);
$this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
$share = $this->getMock('OC\Share20\IShare');
$share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_LINK);
$this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
}
} }

View File

@ -23,49 +23,61 @@ namespace OC\Share20;
use OC\Share20\Exception\ShareNotFound; use OC\Share20\Exception\ShareNotFound;
use OC\Share20\Exception\BackendError; use OC\Share20\Exception\BackendError;
use OCP\IUser; use OCP\IUser;
use OCP\IGroupManager;
use OCP\IUserManager;
use OCP\Files\IRootFolder;
use OCP\IDBConnection;
use OCP\Files\Node;
class DefaultShareProvider implements IShareProvider { class DefaultShareProvider implements IShareProvider {
/** @var \OCP\IDBConnection */ /** @var IDBConnection */
private $dbConn; private $dbConn;
/** @var \OCP\IUserManager */ /** @var IUserManager */
private $userManager; private $userManager;
/** @var \OCP\IGroupManager */ /** @var IGroupManager */
private $groupManager; private $groupManager;
/** @var \OCP\Files\Folder */ /** @var IRootFolder */
private $userFolder; private $rootFolder;
public function __construct(\OCP\IDBConnection $connection, /**
\OCP\IUserManager $userManager, * DefaultShareProvider constructor.
\OCP\IGroupManager $groupManager, *
\OCP\Files\Folder $userFolder) { * @param IDBConnection $connection
* @param IUserManager $userManager
* @param IGroupManager $groupManager
* @param IRootFolder $rootFolder
*/
public function __construct(
IDBConnection $connection,
IUserManager $userManager,
IGroupManager $groupManager,
IRootFolder $rootFolder) {
$this->dbConn = $connection; $this->dbConn = $connection;
$this->userManager = $userManager; $this->userManager = $userManager;
$this->groupManager = $groupManager; $this->groupManager = $groupManager;
$this->userFolder = $userFolder; $this->rootFolder = $rootFolder;
} }
/** /**
* Share a path * Share a path
* *
* @param Share $share * @param IShare $share
* @return Share The share object * @return IShare The share object
*/ */
public function create(Share $share) { public function create(IShare $share) {
throw new \Exception();
} }
/** /**
* Update a share * Update a share
* *
* @param Share $share * @param IShare $share
* @return Share The share object * @return IShare The share object
*/ */
public function update(Share $share) { public function update(IShare $share) {
throw new \Exception();
} }
/** /**
@ -125,7 +137,6 @@ class DefaultShareProvider implements IShareProvider {
* @return Share[] * @return Share[]
*/ */
public function getShares(IUser $user, $shareType, $offset, $limit) { public function getShares(IUser $user, $shareType, $offset, $limit) {
throw new \Exception();
} }
/** /**
@ -163,8 +174,7 @@ class DefaultShareProvider implements IShareProvider {
* @param \OCP\Files\Node $path * @param \OCP\Files\Node $path
* @return IShare[] * @return IShare[]
*/ */
public function getSharesByPath(\OCP\IUser $user, \OCP\Files\Node $path) { public function getSharesByPath(IUser $user, Node $path) {
throw new \Exception();
} }
/** /**
@ -175,7 +185,6 @@ class DefaultShareProvider implements IShareProvider {
* @param Share * @param Share
*/ */
public function getSharedWithMe(IUser $user, $shareType = null) { public function getSharedWithMe(IUser $user, $shareType = null) {
throw new \Exception();
} }
/** /**
@ -186,7 +195,6 @@ class DefaultShareProvider implements IShareProvider {
* @param Share * @param Share
*/ */
public function getShareByToken($token, $password = null) { public function getShareByToken($token, $password = null) {
throw new \Exception();
} }
/** /**
@ -218,14 +226,14 @@ class DefaultShareProvider implements IShareProvider {
$share->setSharedBy($this->userManager->get($data['uid_owner'])); $share->setSharedBy($this->userManager->get($data['uid_owner']));
// TODO: getById can return an array. How to handle this properly?? // TODO: getById can return an array. How to handle this properly??
$path = $this->userFolder->getById((int)$data['file_source']); $folder = $this->rootFolder->getUserFolder($share->getSharedBy()->getUID());
$path = $path[0]; $path = $folder->getById((int)$data['file_source'])[0];
$share->setPath($path);
$owner = $path->getStorage()->getOwner('.'); $owner = $path->getOwner();
if ($owner !== false) { $share->setShareOwner($owner);
$share->setShareOwner($this->userManager->get($owner));
} $path = $this->rootFolder->getUserFolder($owner->getUID())->getById((int)$data['file_source'])[0];
$share->setPath($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']);
@ -235,5 +243,4 @@ class DefaultShareProvider implements IShareProvider {
return $share; return $share;
} }
}
}

View File

@ -38,7 +38,7 @@ interface IShare {
/** /**
* Set the path of this share * Set the path of this share
* *
* @param File|Folder $path * @param Node $path
* @return Share The modified object * @return Share The modified object
*/ */
public function setPath(Node $path); public function setPath(Node $path);

View File

@ -29,18 +29,18 @@ interface IShareProvider {
/** /**
* Share a path * Share a path
* *
* @param Share $share * @param IShare $share
* @return Share The share object * @return IShare The share object
*/ */
public function create(Share $share); public function create(IShare $share);
/** /**
* Update a share * Update a share
* *
* @param Share $share * @param IShare $share
* @return Share The share object * @return IShare The share object
*/ */
public function update(Share $share); public function update(IShare $share);
/** /**
* Delete a share * Delete a share

View File

@ -22,11 +22,7 @@ namespace OC\Share20;
use OCP\IAppConfig; use OCP\IAppConfig;
use OCP\IUserManager;
use OCP\IGroupManager;
use OCP\IUser;
use OCP\ILogger; use OCP\ILogger;
use OCP\Files\Folder;
use OC\Share20\Exception\ShareNotFound; use OC\Share20\Exception\ShareNotFound;
@ -40,37 +36,26 @@ class Manager {
*/ */
private $defaultProvider; private $defaultProvider;
/** @var IUser */
private $currentUser;
/** @var IUserManager */
private $userManager;
/** @var IGroupManager */
private $groupManager;
/** @var ILogger */ /** @var ILogger */
private $logger; private $logger;
/** @var IAppConfig */ /** @var IAppConfig */
private $appConfig; private $appConfig;
/** @var IFolder */ /**
private $userFolder; * Manager constructor.
*
public function __construct(IUser $user, * @param ILogger $logger
IUserManager $userManager, * @param IAppConfig $appConfig
IGroupManager $groupManager, * @param IShareProvider $defaultProvider
ILogger $logger, */
IAppConfig $appConfig, public function __construct(
Folder $userFolder, ILogger $logger,
IShareProvider $defaultProvider) { IAppConfig $appConfig,
$this->currentUser = $user; IShareProvider $defaultProvider
$this->userManager = $userManager; ) {
$this->groupManager = $groupManager;
$this->logger = $logger; $this->logger = $logger;
$this->appConfig = $appConfig; $this->appConfig = $appConfig;
$this->userFolder = $userFolder;
// TEMP SOLUTION JUST TO GET STARTED // TEMP SOLUTION JUST TO GET STARTED
$this->defaultProvider = $defaultProvider; $this->defaultProvider = $defaultProvider;
@ -78,12 +63,11 @@ class Manager {
/** /**
* Share a path * Share a path
* *
* @param Share $share * @param Share $share
* @return Share The share object * @return Share The share object
*/ */
public function createShare(Share $share) { public function createShare(Share $share) {
throw new \Exception();
} }
/** /**
@ -93,7 +77,6 @@ class Manager {
* @return Share The share object * @return Share The share object
*/ */
public function updateShare(Share $share) { public function updateShare(Share $share) {
throw new \Exception();
} }
/** /**
@ -118,7 +101,7 @@ class Manager {
/** /**
* Delete a share * Delete a share
* *
* @param Share $share * @param IShare $share
* @throws ShareNotFound * @throws ShareNotFound
* @throws \OC\Share20\Exception\BackendError * @throws \OC\Share20\Exception\BackendError
*/ */
@ -126,7 +109,7 @@ class Manager {
// Just to make sure we have all the info // Just to make sure we have all the info
$share = $this->getShareById($share->getId()); $share = $this->getShareById($share->getId());
$formatHookParams = function($share) { $formatHookParams = function(IShare $share) {
// Prepare hook // Prepare hook
$shareType = $share->getShareType(); $shareType = $share->getShareType();
$sharedWith = ''; $sharedWith = '';
@ -185,7 +168,6 @@ class Manager {
* @return Share[] * @return Share[]
*/ */
public function getShares($page=0, $perPage=50) { public function getShares($page=0, $perPage=50) {
throw new \Exception();
} }
/** /**
@ -203,12 +185,6 @@ class Manager {
$share = $this->defaultProvider->getShareById($id); $share = $this->defaultProvider->getShareById($id);
if ($share->getSharedWith() !== $this->currentUser &&
$share->getSharedBy() !== $this->currentUser &&
$share->getShareOwner() !== $this->currentUser) {
throw new ShareNotFound();
}
return $share; return $share;
} }
@ -222,7 +198,6 @@ class Manager {
* @return Share[] * @return Share[]
*/ */
public function getSharesByPath(\OCP\Files\Node $path, $page=0, $perPage=50) { public function getSharesByPath(\OCP\Files\Node $path, $page=0, $perPage=50) {
throw new \Exception();
} }
/** /**
@ -235,7 +210,6 @@ class Manager {
* @return Share[] * @return Share[]
*/ */
public function getSharedWithMe($shareType = null, $page=0, $perPage=50) { public function getSharedWithMe($shareType = null, $page=0, $perPage=50) {
throw new \Exception();
} }
/** /**
@ -246,10 +220,9 @@ class Manager {
* *
* @return Share * @return Share
* *
* @throws ShareNotFoundException * @throws ShareNotFound
*/ */
public function getShareByToken($token, $password=null) { public function getShareByToken($token, $password=null) {
throw new \Exception();
} }
/** /**
@ -277,6 +250,5 @@ class Manager {
* @param \OCP\Files\Node $path * @param \OCP\Files\Node $path
*/ */
public function getAccessList(\OCP\Files\Node $path) { public function getAccessList(\OCP\Files\Node $path) {
throw new \Exception();
} }
} }

View File

@ -58,7 +58,7 @@ class Share implements IShare {
/** /**
* Set the id of the share * Set the id of the share
* *
* @param int id * @param string $id
* @return Share The modified object * @return Share The modified object
*/ */
public function setId($id) { public function setId($id) {
@ -292,7 +292,7 @@ class Share implements IShare {
/** /**
* Set the target of this share * Set the target of this share
* *
* @param string target * @param string $target
* @return Share The modified object * @return Share The modified object
*/ */
public function setTarget($target) { public function setTarget($target) {

View File

@ -23,7 +23,7 @@ namespace Test\Share20;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\IGroupManager; use OCP\IGroupManager;
use OCP\Files\Folder; use OCP\Files\IRootFolder;
use OC\Share20\DefaultShareProvider; use OC\Share20\DefaultShareProvider;
class DefaultShareProviderTest extends \Test\TestCase { class DefaultShareProviderTest extends \Test\TestCase {
@ -37,8 +37,8 @@ class DefaultShareProviderTest extends \Test\TestCase {
/** @var IGroupManager */ /** @var IGroupManager */
protected $groupManager; protected $groupManager;
/** @var Folder */ /** @var IRootFolder */
protected $userFolder; protected $rootFolder;
/** @var DefaultShareProvider */ /** @var DefaultShareProvider */
protected $provider; protected $provider;
@ -47,7 +47,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->dbConn = \OC::$server->getDatabaseConnection(); $this->dbConn = \OC::$server->getDatabaseConnection();
$this->userManager = $this->getMock('OCP\IUserManager'); $this->userManager = $this->getMock('OCP\IUserManager');
$this->groupManager = $this->getMock('OCP\IGroupManager'); $this->groupManager = $this->getMock('OCP\IGroupManager');
$this->userFolder = $this->getMock('OCP\Files\Folder'); $this->rootFolder = $this->getMock('OCP\Files\IRootFolder');
//Empty share table //Empty share table
$this->dbConn->getQueryBuilder()->delete('share')->execute(); $this->dbConn->getQueryBuilder()->delete('share')->execute();
@ -56,7 +56,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->dbConn, $this->dbConn,
$this->userManager, $this->userManager,
$this->groupManager, $this->groupManager,
$this->userFolder $this->rootFolder
); );
} }
@ -65,7 +65,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
} }
/** /**
* @expectedException OC\Share20\Exception\ShareNotFound * @expectedException \OC\Share20\Exception\ShareNotFound
*/ */
public function testGetShareByIdNotExist() { public function testGetShareByIdNotExist() {
$this->provider->getShareById(1); $this->provider->getShareById(1);
@ -97,25 +97,30 @@ class DefaultShareProviderTest extends \Test\TestCase {
$id = $id['id']; $id = $id['id'];
$cursor->closeCursor(); $cursor->closeCursor();
$storage = $this->getMock('OC\Files\Storage\Storage');
$storage
->expects($this->once())
->method('getOwner')
->willReturn('shareOwner');
$path = $this->getMock('OCP\Files\File');
$path
->expects($this->once())
->method('getStorage')
->wilLReturn($storage);
$this->userFolder
->expects($this->once())
->method('getById')
->with(42)
->willReturn([$path]);
$sharedWith = $this->getMock('OCP\IUser'); $sharedWith = $this->getMock('OCP\IUser');
$sharedBy = $this->getMock('OCP\IUser'); $sharedBy = $this->getMock('OCP\IUser');
$sharedBy->method('getUID')->willReturn('sharedBy');
$shareOwner = $this->getMock('OCP\IUser'); $shareOwner = $this->getMock('OCP\IUser');
$shareOwner->method('getUID')->willReturn('shareOwner');
$sharedByPath = $this->getMock('\OCP\Files\File');
$ownerPath = $this->getMock('\OCP\Files\File');
$sharedByPath->method('getOwner')->willReturn($shareOwner);
$sharedByFolder = $this->getMock('\OCP\Files\Folder');
$sharedByFolder->method('getById')->with(42)->willReturn([$sharedByPath]);
$shareOwnerFolder = $this->getMock('\OCP\Files\Folder');
$shareOwnerFolder->method('getById')->with(42)->willReturn([$ownerPath]);
$this->rootFolder
->method('getUserFolder')
->will($this->returnValueMap([
['sharedBy', $sharedByFolder],
['shareOwner', $shareOwnerFolder],
]));
$this->userManager $this->userManager
->method('get') ->method('get')
->will($this->returnValueMap([ ->will($this->returnValueMap([
@ -131,7 +136,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals($sharedWith, $share->getSharedWith()); $this->assertEquals($sharedWith, $share->getSharedWith());
$this->assertEquals($sharedBy, $share->getSharedBy()); $this->assertEquals($sharedBy, $share->getSharedBy());
$this->assertEquals($shareOwner, $share->getShareOwner()); $this->assertEquals($shareOwner, $share->getShareOwner());
$this->assertEquals($path, $share->getPath()); $this->assertEquals($ownerPath, $share->getPath());
$this->assertEquals(13, $share->getPermissions()); $this->assertEquals(13, $share->getPermissions());
$this->assertEquals(null, $share->getToken()); $this->assertEquals(null, $share->getToken());
$this->assertEquals(null, $share->getExpirationDate()); $this->assertEquals(null, $share->getExpirationDate());
@ -164,25 +169,30 @@ class DefaultShareProviderTest extends \Test\TestCase {
$id = $id['id']; $id = $id['id'];
$cursor->closeCursor(); $cursor->closeCursor();
$storage = $this->getMock('OC\Files\Storage\Storage');
$storage
->expects($this->once())
->method('getOwner')
->willReturn('shareOwner');
$path = $this->getMock('OCP\Files\Folder');
$path
->expects($this->once())
->method('getStorage')
->wilLReturn($storage);
$this->userFolder
->expects($this->once())
->method('getById')
->with(42)
->willReturn([$path]);
$sharedWith = $this->getMock('OCP\IGroup'); $sharedWith = $this->getMock('OCP\IGroup');
$sharedBy = $this->getMock('OCP\IUser'); $sharedBy = $this->getMock('OCP\IUser');
$sharedBy->method('getUID')->willReturn('sharedBy');
$shareOwner = $this->getMock('OCP\IUser'); $shareOwner = $this->getMock('OCP\IUser');
$shareOwner->method('getUID')->willReturn('shareOwner');
$sharedByPath = $this->getMock('\OCP\Files\Folder');
$ownerPath = $this->getMock('\OCP\Files\Folder');
$sharedByPath->method('getOwner')->willReturn($shareOwner);
$sharedByFolder = $this->getMock('\OCP\Files\Folder');
$sharedByFolder->method('getById')->with(42)->willReturn([$sharedByPath]);
$shareOwnerFolder = $this->getMock('\OCP\Files\Folder');
$shareOwnerFolder->method('getById')->with(42)->willReturn([$ownerPath]);
$this->rootFolder
->method('getUserFolder')
->will($this->returnValueMap([
['sharedBy', $sharedByFolder],
['shareOwner', $shareOwnerFolder],
]));
$this->userManager $this->userManager
->method('get') ->method('get')
->will($this->returnValueMap([ ->will($this->returnValueMap([
@ -202,7 +212,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals($sharedWith, $share->getSharedWith()); $this->assertEquals($sharedWith, $share->getSharedWith());
$this->assertEquals($sharedBy, $share->getSharedBy()); $this->assertEquals($sharedBy, $share->getSharedBy());
$this->assertEquals($shareOwner, $share->getShareOwner()); $this->assertEquals($shareOwner, $share->getShareOwner());
$this->assertEquals($path, $share->getPath()); $this->assertEquals($ownerPath, $share->getPath());
$this->assertEquals(13, $share->getPermissions()); $this->assertEquals(13, $share->getPermissions());
$this->assertEquals(null, $share->getToken()); $this->assertEquals(null, $share->getToken());
$this->assertEquals(null, $share->getExpirationDate()); $this->assertEquals(null, $share->getExpirationDate());
@ -237,24 +247,29 @@ class DefaultShareProviderTest extends \Test\TestCase {
$id = $id['id']; $id = $id['id'];
$cursor->closeCursor(); $cursor->closeCursor();
$storage = $this->getMock('OC\Files\Storage\Storage');
$storage
->expects($this->once())
->method('getOwner')
->willReturn('shareOwner');
$path = $this->getMock('OCP\Files\Node');
$path
->expects($this->once())
->method('getStorage')
->wilLReturn($storage);
$this->userFolder
->expects($this->once())
->method('getById')
->with(42)
->willReturn([$path]);
$sharedBy = $this->getMock('OCP\IUser'); $sharedBy = $this->getMock('OCP\IUser');
$sharedBy->method('getUID')->willReturn('sharedBy');
$shareOwner = $this->getMock('OCP\IUser'); $shareOwner = $this->getMock('OCP\IUser');
$shareOwner->method('getUID')->willReturn('shareOwner');
$sharedByPath = $this->getMock('\OCP\Files\Folder');
$ownerPath = $this->getMock('\OCP\Files\Folder');
$sharedByPath->method('getOwner')->willReturn($shareOwner);
$sharedByFolder = $this->getMock('\OCP\Files\Folder');
$sharedByFolder->method('getById')->with(42)->willReturn([$sharedByPath]);
$shareOwnerFolder = $this->getMock('\OCP\Files\Folder');
$shareOwnerFolder->method('getById')->with(42)->willReturn([$ownerPath]);
$this->rootFolder
->method('getUserFolder')
->will($this->returnValueMap([
['sharedBy', $sharedByFolder],
['shareOwner', $shareOwnerFolder],
]));
$this->userManager $this->userManager
->method('get') ->method('get')
->will($this->returnValueMap([ ->will($this->returnValueMap([
@ -269,79 +284,13 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals('sharedWith', $share->getPassword()); $this->assertEquals('sharedWith', $share->getPassword());
$this->assertEquals($sharedBy, $share->getSharedBy()); $this->assertEquals($sharedBy, $share->getSharedBy());
$this->assertEquals($shareOwner, $share->getShareOwner()); $this->assertEquals($shareOwner, $share->getShareOwner());
$this->assertEquals($path, $share->getPath()); $this->assertEquals($ownerPath, $share->getPath());
$this->assertEquals(13, $share->getPermissions()); $this->assertEquals(13, $share->getPermissions());
$this->assertEquals('token', $share->getToken()); $this->assertEquals('token', $share->getToken());
$this->assertEquals(\DateTime::createFromFormat('Y-m-d H:i:s', '2000-01-02 00:00:00'), $share->getExpirationDate()); $this->assertEquals(\DateTime::createFromFormat('Y-m-d H:i:s', '2000-01-02 00:00:00'), $share->getExpirationDate());
$this->assertEquals('myTarget', $share->getTarget()); $this->assertEquals('myTarget', $share->getTarget());
} }
public function testGetShareByIdRemoteShare() {
$qb = $this->dbConn->getQueryBuilder();
$qb->insert('share')
->values([
'share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_REMOTE),
'share_with' => $qb->expr()->literal('sharedWith'),
'uid_owner' => $qb->expr()->literal('sharedBy'),
'item_type' => $qb->expr()->literal('file'),
'file_source' => $qb->expr()->literal(42),
'file_target' => $qb->expr()->literal('myTarget'),
'permissions' => $qb->expr()->literal(13),
]);
$this->assertEquals(1, $qb->execute());
// Get the id
$qb = $this->dbConn->getQueryBuilder();
$cursor = $qb->select('id')
->from('share')
->setMaxResults(1)
->orderBy('id', 'DESC')
->execute();
$id = $cursor->fetch();
$id = $id['id'];
$cursor->closeCursor();
$storage = $this->getMock('OC\Files\Storage\Storage');
$storage
->expects($this->once())
->method('getOwner')
->willReturn('shareOwner');
$path = $this->getMock('OCP\Files\Node');
$path
->expects($this->once())
->method('getStorage')
->wilLReturn($storage);
$this->userFolder
->expects($this->once())
->method('getById')
->with(42)
->willReturn([$path]);
$sharedBy = $this->getMock('OCP\IUser');
$shareOwner = $this->getMock('OCP\IUser');
$this->userManager
->method('get')
->will($this->returnValueMap([
['sharedBy', $sharedBy],
['shareOwner', $shareOwner],
]));
$share = $this->provider->getShareById($id);
$this->assertEquals($id, $share->getId());
$this->assertEquals(\OCP\Share::SHARE_TYPE_REMOTE, $share->getShareType());
$this->assertEquals('sharedWith', $share->getSharedWith());
$this->assertEquals($sharedBy, $share->getSharedBy());
$this->assertEquals($shareOwner, $share->getShareOwner());
$this->assertEquals($path, $share->getPath());
$this->assertEquals(13, $share->getPermissions());
$this->assertEquals(null, $share->getToken());
$this->assertEquals(null, $share->getExpirationDate());
$this->assertEquals('myTarget', $share->getTarget());
}
public function testDeleteSingleShare() { public function testDeleteSingleShare() {
$qb = $this->dbConn->getQueryBuilder(); $qb = $this->dbConn->getQueryBuilder();
$qb->insert('share') $qb->insert('share')
@ -376,7 +325,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->dbConn, $this->dbConn,
$this->userManager, $this->userManager,
$this->groupManager, $this->groupManager,
$this->userFolder, $this->rootFolder,
] ]
) )
->setMethods(['getShareById']) ->setMethods(['getShareById'])
@ -437,7 +386,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$db, $db,
$this->userManager, $this->userManager,
$this->groupManager, $this->groupManager,
$this->userFolder, $this->rootFolder,
] ]
) )
->setMethods(['getShareById']) ->setMethods(['getShareById'])
@ -504,30 +453,45 @@ class DefaultShareProviderTest extends \Test\TestCase {
]); ]);
$qb->execute(); $qb->execute();
$storage = $this->getMock('OC\Files\Storage\Storage');
$storage
->method('getOwner')
->willReturn('shareOwner');
$path1 = $this->getMock('OCP\Files\File');
$path1->expects($this->once())->method('getStorage')->willReturn($storage);
$path2 = $this->getMock('OCP\Files\Folder');
$path2->expects($this->once())->method('getStorage')->willReturn($storage);
$this->userFolder
->method('getById')
->will($this->returnValueMap([
[1, [$path1]],
[3, [$path2]],
]));
$shareOwner = $this->getMock('OCP\IUser'); $shareOwner = $this->getMock('OCP\IUser');
$shareOwner->method('getUID')->willReturn('shareOwner');
$user1 = $this->getMock('OCP\IUser'); $user1 = $this->getMock('OCP\IUser');
$user2 = $this->getMock('OCP\IUser'); $user2 = $this->getMock('OCP\IUser');
$user2->method('getUID')->willReturn('user2');
$user3 = $this->getMock('OCP\IUser'); $user3 = $this->getMock('OCP\IUser');
$user3->method('getUID')->willReturn('user3');
$user2Path = $this->getMock('\OCP\Files\File');
$user2Path->expects($this->once())->method('getOwner')->willReturn($shareOwner);
$user2Folder = $this->getMock('\OCP\Files\Folder');
$user2Folder->expects($this->once())
->method('getById')
->with(1)
->willReturn([$user2Path]);
$user3Path = $this->getMock('\OCP\Files\Folder');
$user3Path->expects($this->once())->method('getOwner')->willReturn($shareOwner);
$user3Folder = $this->getMock('\OCP\Files\Folder');
$user3Folder->expects($this->once())
->method('getById')
->with(3)
->willReturn([$user3Path]);
$ownerPath = $this->getMock('\OCP\Files\Folder');
$ownerFolder = $this->getMock('\OCP\Files\Folder');
$ownerFolder->method('getById')->willReturn([$ownerPath]);
$this->rootFolder
->method('getUserFolder')
->will($this->returnValueMap([
['shareOwner', $ownerFolder],
['user2', $user2Folder],
['user3', $user3Folder],
]));
$this->userManager $this->userManager
->method('get') ->method('get')
->will($this->returnValueMap([ ->will($this->returnValueMap([
['shareOwner', $shareOwner],
['user1', $user1], ['user1', $user1],
['user2', $user2], ['user2', $user2],
['user3', $user3], ['user3', $user3],
@ -552,7 +516,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals($user1, $children[0]->getSharedWith()); $this->assertEquals($user1, $children[0]->getSharedWith());
$this->assertEquals($user2, $children[0]->getSharedBy()); $this->assertEquals($user2, $children[0]->getSharedBy());
$this->assertEquals($shareOwner, $children[0]->getShareOwner()); $this->assertEquals($shareOwner, $children[0]->getShareOwner());
$this->assertEquals($path1, $children[0]->getPath()); $this->assertEquals($ownerPath, $children[0]->getPath());
$this->assertEquals(2, $children[0]->getPermissions()); $this->assertEquals(2, $children[0]->getPermissions());
$this->assertEquals(null, $children[0]->getToken()); $this->assertEquals(null, $children[0]->getToken());
$this->assertEquals(null, $children[0]->getExpirationDate()); $this->assertEquals(null, $children[0]->getExpirationDate());
@ -563,7 +527,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals($group1, $children[1]->getSharedWith()); $this->assertEquals($group1, $children[1]->getSharedWith());
$this->assertEquals($user3, $children[1]->getSharedBy()); $this->assertEquals($user3, $children[1]->getSharedBy());
$this->assertEquals($shareOwner, $children[1]->getShareOwner()); $this->assertEquals($shareOwner, $children[1]->getShareOwner());
$this->assertEquals($path2, $children[1]->getPath()); $this->assertEquals($ownerPath, $children[1]->getPath());
$this->assertEquals(4, $children[1]->getPermissions()); $this->assertEquals(4, $children[1]->getPermissions());
$this->assertEquals(null, $children[1]->getToken()); $this->assertEquals(null, $children[1]->getToken());
$this->assertEquals(null, $children[1]->getExpirationDate()); $this->assertEquals(null, $children[1]->getExpirationDate());

View File

@ -23,64 +23,39 @@ namespace Test\Share20;
use OC\Share20\Manager; use OC\Share20\Manager;
use OC\Share20\Exception; use OC\Share20\Exception;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IGroupManager;
use OCP\ILogger; use OCP\ILogger;
use OCP\IAppConfig; use OCP\IAppConfig;
use OCP\Files\Folder; use OC\Share20\IShareProvider;
use OCP\Share20\IShareProvider;
class ManagerTest extends \Test\TestCase { class ManagerTest extends \Test\TestCase {
/** @var Manager */ /** @var Manager */
protected $manager; protected $manager;
/** @var IUser */
protected $user;
/** @var IUserManager */
protected $userManager;
/** @var IGroupManager */
protected $groupManager;
/** @var ILogger */ /** @var ILogger */
protected $logger; protected $logger;
/** @var IAppConfig */ /** @var IAppConfig */
protected $appConfig; protected $appConfig;
/** @var Folder */
protected $userFolder;
/** @var IShareProvider */ /** @var IShareProvider */
protected $defaultProvider; protected $defaultProvider;
public function setUp() { public function setUp() {
$this->user = $this->getMock('\OCP\IUser');
$this->userManager = $this->getMock('\OCP\IUserManager');
$this->groupManager = $this->getMock('\OCP\IGroupManager');
$this->logger = $this->getMock('\OCP\ILogger'); $this->logger = $this->getMock('\OCP\ILogger');
$this->appConfig = $this->getMock('\OCP\IAppConfig'); $this->appConfig = $this->getMock('\OCP\IAppConfig');
$this->userFolder = $this->getMock('\OCP\Files\Folder');
$this->defaultProvider = $this->getMock('\OC\Share20\IShareProvider'); $this->defaultProvider = $this->getMock('\OC\Share20\IShareProvider');
$this->manager = new Manager( $this->manager = new Manager(
$this->user,
$this->userManager,
$this->groupManager,
$this->logger, $this->logger,
$this->appConfig, $this->appConfig,
$this->userFolder,
$this->defaultProvider $this->defaultProvider
); );
} }
/** /**
* @expectedException OC\Share20\Exception\ShareNotFound * @expectedException \OC\Share20\Exception\ShareNotFound
*/ */
public function testDeleteNoShareId() { public function testDeleteNoShareId() {
$share = $this->getMock('\OC\Share20\IShare'); $share = $this->getMock('\OC\Share20\IShare');
@ -115,12 +90,8 @@ class ManagerTest extends \Test\TestCase {
public function testDelete($shareType, $sharedWith, $sharedWith_string) { public function testDelete($shareType, $sharedWith, $sharedWith_string) {
$manager = $this->getMockBuilder('\OC\Share20\Manager') $manager = $this->getMockBuilder('\OC\Share20\Manager')
->setConstructorArgs([ ->setConstructorArgs([
$this->user,
$this->userManager,
$this->groupManager,
$this->logger, $this->logger,
$this->appConfig, $this->appConfig,
$this->userFolder,
$this->defaultProvider $this->defaultProvider
]) ])
->setMethods(['getShareById', 'deleteChildren']) ->setMethods(['getShareById', 'deleteChildren'])
@ -205,12 +176,8 @@ class ManagerTest extends \Test\TestCase {
public function testDeleteNested() { public function testDeleteNested() {
$manager = $this->getMockBuilder('\OC\Share20\Manager') $manager = $this->getMockBuilder('\OC\Share20\Manager')
->setConstructorArgs([ ->setConstructorArgs([
$this->user,
$this->userManager,
$this->groupManager,
$this->logger, $this->logger,
$this->appConfig, $this->appConfig,
$this->userFolder,
$this->defaultProvider $this->defaultProvider
]) ])
->setMethods(['getShareById']) ->setMethods(['getShareById'])
@ -349,12 +316,8 @@ class ManagerTest extends \Test\TestCase {
public function testDeleteChildren() { public function testDeleteChildren() {
$manager = $this->getMockBuilder('\OC\Share20\Manager') $manager = $this->getMockBuilder('\OC\Share20\Manager')
->setConstructorArgs([ ->setConstructorArgs([
$this->user,
$this->userManager,
$this->groupManager,
$this->logger, $this->logger,
$this->appConfig, $this->appConfig,
$this->userFolder,
$this->defaultProvider $this->defaultProvider
]) ])
->setMethods(['deleteShare']) ->setMethods(['deleteShare'])
@ -391,82 +354,8 @@ class ManagerTest extends \Test\TestCase {
$this->assertSame($shares, $result); $this->assertSame($shares, $result);
} }
/** public function testGetShareById() {
* @expectedException OC\Share20\Exception\ShareNotFound
*/
public function testGetShareByIdNotFoundInBackend() {
$this->defaultProvider
->expects($this->once())
->method('getShareById')
->with(42)
->will($this->throwException(new \OC\Share20\Exception\ShareNotFound()));
$this->manager->getShareById(42);
}
/**
* @expectedException OC\Share20\Exception\ShareNotFound
*/
public function testGetShareByIdNotAuthorized() {
$otherUser1 = $this->getMock('\OCP\IUser');
$otherUser2 = $this->getMock('\OCP\IUser');
$otherUser3 = $this->getMock('\OCP\IUser');
$share = $this->getMock('\OC\Share20\IShare'); $share = $this->getMock('\OC\Share20\IShare');
$share
->expects($this->once())
->method('getSharedWith')
->with()
->willReturn($otherUser1);
$share
->expects($this->once())
->method('getSharedBy')
->with()
->willReturn($otherUser2);
$share
->expects($this->once())
->method('getShareOwner')
->with()
->willReturn($otherUser3);
$this->defaultProvider
->expects($this->once())
->method('getShareById')
->with(42)
->willReturn($share);
$this->manager->getShareById(42);
}
public function dataGetShareById() {
return [
['getSharedWith'],
['getSharedBy'],
['getShareOwner'],
];
}
/**
* @dataProvider dataGetShareById
*/
public function testGetShareById($currentUserIs) {
$otherUser1 = $this->getMock('\OCP\IUser');
$otherUser2 = $this->getMock('\OCP\IUser');
$otherUser3 = $this->getMock('\OCP\IUser');
$share = $this->getMock('\OC\Share20\IShare');
$share
->method('getSharedWith')
->with()
->willReturn($currentUserIs === 'getSharedWith' ? $this->user : $otherUser1);
$share
->method('getSharedBy')
->with()
->willReturn($currentUserIs === 'getSharedBy' ? $this->user : $otherUser2);
$share
->method('getShareOwner')
->with()
->willReturn($currentUserIs === 'getShareOwner' ? $this->user : $otherUser3);
$this->defaultProvider $this->defaultProvider
->expects($this->once()) ->expects($this->once())