diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2016-10-21 20:25:07 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2016-10-24 09:52:34 +0200 |
commit | ea07bbc562d797efab3e9c4e068689850cf3de3e (patch) | |
tree | ffdf0c651c3a3c69aff9af55581eed25ae75e059 | |
parent | 598c145430d813c05b3a980345462c45f801d733 (diff) | |
download | nextcloud-server-ea07bbc562d797efab3e9c4e068689850cf3de3e.tar.gz nextcloud-server-ea07bbc562d797efab3e9c4e068689850cf3de3e.zip |
Move Share20OCS to ShareAPIController
It was already a controller just still residing in its old location.
* Moved ShareAPIController to user plain userID instead of user object
* Moved Share20OCS to ShareAPIController
* Removed initisation of class from Application.php and leave it to the
AppFramework
* Fixed tests
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
-rw-r--r-- | apps/files_sharing/lib/AppInfo/Application.php | 14 | ||||
-rw-r--r-- | apps/files_sharing/lib/Controller/ShareAPIController.php (renamed from apps/files_sharing/lib/API/Share20OCS.php) | 59 | ||||
-rw-r--r-- | apps/files_sharing/lib/Middleware/OCSShareAPIMiddleware.php | 8 | ||||
-rw-r--r-- | apps/files_sharing/tests/ApiTest.php | 10 | ||||
-rw-r--r-- | apps/files_sharing/tests/Controller/ShareAPIControllerTest.php (renamed from apps/files_sharing/tests/API/Share20OCSTest.php) | 137 |
5 files changed, 109 insertions, 119 deletions
diff --git a/apps/files_sharing/lib/AppInfo/Application.php b/apps/files_sharing/lib/AppInfo/Application.php index 357860e8fa0..29cdf702a51 100644 --- a/apps/files_sharing/lib/AppInfo/Application.php +++ b/apps/files_sharing/lib/AppInfo/Application.php @@ -28,7 +28,6 @@ namespace OCA\Files_Sharing\AppInfo; use OCA\FederatedFileSharing\DiscoveryManager; -use OCA\Files_Sharing\API\Share20OCS; use OCA\Files_Sharing\Middleware\OCSShareAPIMiddleware; use OCA\Files_Sharing\MountProvider; use OCP\AppFramework\App; @@ -78,19 +77,6 @@ class Application extends App { $c->query('HttpClientService') ); }); - $container->registerService('ShareAPIController', function (SimpleContainer $c) use ($server) { - return new Share20OCS( - $c->query('AppName'), - $c->query('Request'), - $server->getShareManager(), - $server->getGroupManager(), - $server->getUserManager(), - $server->getRootFolder(), - $server->getURLGenerator(), - $server->getUserSession()->getUser(), - $server->getL10N($c->query('AppName')) - ); - }); /** * Core class wrappers diff --git a/apps/files_sharing/lib/API/Share20OCS.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index 8d00d176678..ad9ac6c0851 100644 --- a/apps/files_sharing/lib/API/Share20OCS.php +++ b/apps/files_sharing/lib/Controller/ShareAPIController.php @@ -21,7 +21,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/> * */ -namespace OCA\Files_Sharing\API; +namespace OCA\Files_Sharing\Controller; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCS\OCSBadRequestException; @@ -50,7 +50,7 @@ use OCP\Share\IShare; * * @package OCA\Files_Sharing\API */ -class Share20OCS extends OCSController { +class ShareAPIController extends OCSController { /** @var IManager */ private $shareManager; @@ -64,7 +64,7 @@ class Share20OCS extends OCSController { private $rootFolder; /** @var IURLGenerator */ private $urlGenerator; - /** @var IUser */ + /** @var string */ private $currentUser; /** @var IL10N */ private $l; @@ -81,7 +81,7 @@ class Share20OCS extends OCSController { * @param IUserManager $userManager * @param IRootFolder $rootFolder * @param IURLGenerator $urlGenerator - * @param IUser $currentUser + * @param string $userId * @param IL10N $l10n */ public function __construct( @@ -92,7 +92,7 @@ class Share20OCS extends OCSController { IUserManager $userManager, IRootFolder $rootFolder, IURLGenerator $urlGenerator, - IUser $currentUser, + $userId, IL10N $l10n ) { parent::__construct($appName, $request); @@ -103,7 +103,7 @@ class Share20OCS extends OCSController { $this->request = $request; $this->rootFolder = $rootFolder; $this->urlGenerator = $urlGenerator; - $this->currentUser = $currentUser; + $this->currentUser = $userId; $this->l = $l10n; } @@ -133,7 +133,7 @@ class Share20OCS extends OCSController { 'displayname_file_owner' => $shareOwner !== null ? $shareOwner->getDisplayName() : $share->getShareOwner(), ]; - $userFolder = $this->rootFolder->getUserFolder($this->currentUser->getUID()); + $userFolder = $this->rootFolder->getUserFolder($this->currentUser); if ($recipientNode) { $node = $recipientNode; } else { @@ -287,7 +287,7 @@ class Share20OCS extends OCSController { throw new OCSNotFoundException($this->l->t('Please specify a file or folder path')); } - $userFolder = $this->rootFolder->getUserFolder($this->currentUser->getUID()); + $userFolder = $this->rootFolder->getUserFolder($this->currentUser); try { $path = $userFolder->get($path); } catch (NotFoundException $e) { @@ -352,7 +352,7 @@ class Share20OCS extends OCSController { * For now we only allow 1 link share. * Return the existing link share if this is a duplicate */ - $existingShares = $this->shareManager->getSharesBy($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_LINK, $path, false, 1, 0); + $existingShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $path, false, 1, 0); if (!empty($existingShares)) { return new DataResponse($this->formatShare($existingShares[0])); } @@ -405,7 +405,7 @@ class Share20OCS extends OCSController { } $share->setShareType($shareType); - $share->setSharedBy($this->currentUser->getUID()); + $share->setSharedBy($this->currentUser); try { $share = $this->shareManager->createShare($share); @@ -426,13 +426,13 @@ class Share20OCS extends OCSController { * @return DataResponse */ private function getSharedWithMe($node = null) { - $userShares = $this->shareManager->getSharedWith($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_USER, $node, -1, 0); - $groupShares = $this->shareManager->getSharedWith($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_GROUP, $node, -1, 0); + $userShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, -1, 0); + $groupShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, -1, 0); $shares = array_merge($userShares, $groupShares); $shares = array_filter($shares, function (IShare $share) { - return $share->getShareOwner() !== $this->currentUser->getUID(); + return $share->getShareOwner() !== $this->currentUser; }); $formatted = []; @@ -463,11 +463,11 @@ class Share20OCS extends OCSController { /** @var \OCP\Share\IShare[] $shares */ $shares = []; foreach ($nodes as $node) { - $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_USER, $node, false, -1, 0)); - $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_GROUP, $node, false, -1, 0)); - $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_LINK, $node, false, -1, 0)); + $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, false, -1, 0)); + $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, false, -1, 0)); + $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $node, false, -1, 0)); if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { - $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_REMOTE, $node, false, -1, 0)); + $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_REMOTE, $node, false, -1, 0)); } } @@ -510,7 +510,7 @@ class Share20OCS extends OCSController { ) { if ($path !== null) { - $userFolder = $this->rootFolder->getUserFolder($this->currentUser->getUID()); + $userFolder = $this->rootFolder->getUserFolder($this->currentUser); try { $path = $userFolder->get($path); $this->lock($path); @@ -538,13 +538,13 @@ class Share20OCS extends OCSController { } // Get all shares - $userShares = $this->shareManager->getSharesBy($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_USER, $path, $reshares, -1, 0); - $groupShares = $this->shareManager->getSharesBy($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_GROUP, $path, $reshares, -1, 0); - $linkShares = $this->shareManager->getSharesBy($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_LINK, $path, $reshares, -1, 0); + $userShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $path, $reshares, -1, 0); + $groupShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $path, $reshares, -1, 0); + $linkShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $path, $reshares, -1, 0); $shares = array_merge($userShares, $groupShares, $linkShares); if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { - $federatedShares = $this->shareManager->getSharesBy($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_REMOTE, $path, $reshares, -1, 0); + $federatedShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_REMOTE, $path, $reshares, -1, 0); $shares = array_merge($shares, $federatedShares); } @@ -671,10 +671,10 @@ class Share20OCS extends OCSController { } } - if ($permissions !== null && $share->getShareOwner() !== $this->currentUser->getUID()) { + if ($permissions !== null && $share->getShareOwner() !== $this->currentUser) { /* Check if this is an incomming share */ - $incomingShares = $this->shareManager->getSharedWith($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_USER, $share->getNode(), -1, 0); - $incomingShares = array_merge($incomingShares, $this->shareManager->getSharedWith($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_GROUP, $share->getNode(), -1, 0)); + $incomingShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $share->getNode(), -1, 0); + $incomingShares = array_merge($incomingShares, $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $share->getNode(), -1, 0)); /** @var \OCP\Share\IShare[] $incomingShares */ if (!empty($incomingShares)) { @@ -710,22 +710,23 @@ class Share20OCS extends OCSController { } // Owner of the file and the sharer of the file can always get share - if ($share->getShareOwner() === $this->currentUser->getUID() || - $share->getSharedBy() === $this->currentUser->getUID() + 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->getUID() + $share->getSharedWith() === $this->currentUser ) { return true; } if ($checkGroups && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { $sharedWith = $this->groupManager->get($share->getSharedWith()); - if ($sharedWith->inGroup($this->currentUser)) { + $user = $this->userManager->get($this->currentUser); + if ($user !== null && $sharedWith->inGroup($user)) { return true; } } diff --git a/apps/files_sharing/lib/Middleware/OCSShareAPIMiddleware.php b/apps/files_sharing/lib/Middleware/OCSShareAPIMiddleware.php index 04a6545c9a7..5d2c168e876 100644 --- a/apps/files_sharing/lib/Middleware/OCSShareAPIMiddleware.php +++ b/apps/files_sharing/lib/Middleware/OCSShareAPIMiddleware.php @@ -2,7 +2,7 @@ namespace OCA\Files_Sharing\Middleware; -use OCA\Files_Sharing\API\Share20OCS; +use OCA\Files_Sharing\Controller\ShareAPIController; use OCP\AppFramework\Http\Response; use OCP\AppFramework\Middleware; use OCP\AppFramework\OCS\OCSNotFoundException; @@ -28,7 +28,7 @@ class OCSShareAPIMiddleware extends Middleware { * @throws OCSNotFoundException */ public function beforeController($controller, $methodName) { - if ($controller instanceof Share20OCS) { + if ($controller instanceof ShareAPIController) { if (!$this->shareManager->shareApiEnabled()) { throw new OCSNotFoundException($this->l->t('Share API is disabled')); } @@ -42,8 +42,8 @@ class OCSShareAPIMiddleware extends Middleware { * @return Response */ public function afterController($controller, $methodName, Response $response) { - if ($controller instanceof Share20OCS) { - /** @var Share20OCS $controller */ + if ($controller instanceof ShareAPIController) { + /** @var ShareAPIController $controller */ $controller->cleanup(); } diff --git a/apps/files_sharing/tests/ApiTest.php b/apps/files_sharing/tests/ApiTest.php index aff3aadd7e7..6ab0cb4e1a6 100644 --- a/apps/files_sharing/tests/ApiTest.php +++ b/apps/files_sharing/tests/ApiTest.php @@ -30,6 +30,7 @@ namespace OCA\Files_Sharing\Tests; use OC\Files\Cache\Scanner; +use OCA\Files_Sharing\Controller\ShareAPIController; use OCP\AppFramework\OCS\OCSBadRequestException; use OCP\AppFramework\OCS\OCSException; use OCP\AppFramework\OCS\OCSForbiddenException; @@ -92,18 +93,16 @@ class ApiTest extends TestCase { /** * @param string $userId The userId of the caller - * @return \OCA\Files_Sharing\API\Share20OCS + * @return \OCA\Files_Sharing\Controller\ShareAPIController */ private function createOCS($userId) { - $currentUser = \OC::$server->getUserManager()->get($userId); - $l = $this->getMockBuilder('\OCP\IL10N')->getMock(); $l->method('t') ->will($this->returnCallback(function($text, $parameters = []) { return vsprintf($text, $parameters); })); - return new \OCA\Files_Sharing\API\Share20OCS( + return new ShareAPIController( self::APP_NAME, $this->getMockBuilder('OCP\IRequest')->getMock(), $this->shareManager, @@ -111,7 +110,7 @@ class ApiTest extends TestCase { \OC::$server->getUserManager(), \OC::$server->getRootFolder(), \OC::$server->getURLGenerator(), - $currentUser, + $userId, $l ); } @@ -715,7 +714,6 @@ class ApiTest extends TestCase { /* * Test as recipient */ - $request = $this->createRequest(['path' => '/', 'subfiles' => 'true']); $ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER3); $result = $ocs->getShares(); $ocs->cleanup(); diff --git a/apps/files_sharing/tests/API/Share20OCSTest.php b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php index f9579b89935..6ad0576b6fa 100644 --- a/apps/files_sharing/tests/API/Share20OCSTest.php +++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php @@ -21,13 +21,13 @@ * along with this program. If not, see <http://www.gnu.org/licenses/> * */ -namespace OCA\Files_Sharing\Tests\API; +namespace OCA\Files_Sharing\Tests\Controller; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCS\OCSNotFoundException; use OCP\Files\Folder; use OCP\IL10N; -use OCA\Files_Sharing\API\Share20OCS; +use OCA\Files_Sharing\Controller\ShareAPIController; use OCP\Files\NotFoundException; use OCP\IGroupManager; use OCP\IUserManager; @@ -36,14 +36,15 @@ use OCP\IURLGenerator; use OCP\IUser; use OCP\Files\IRootFolder; use OCP\Lock\LockedException; +use OCP\Share\IManager; /** - * Class Share20OCSTest + * Class ShareAPIControllerTest * - * @package OCA\Files_Sharing\Tests\API + * @package OCA\Files_Sharing\Tests\Controller * @group DB */ -class Share20OCSTest extends \Test\TestCase { +class ShareAPIControllerTest extends \Test\TestCase { /** @var string */ private $appName = 'files_sharing'; @@ -66,38 +67,35 @@ class Share20OCSTest extends \Test\TestCase { /** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */ private $urlGenerator; - /** @var IUser|\PHPUnit_Framework_MockObject_MockObject */ + /** @var string|\PHPUnit_Framework_MockObject_MockObject */ private $currentUser; - /** @var Share20OCS */ + /** @var ShareAPIController */ private $ocs; /** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */ private $l; protected function setUp() { - $this->shareManager = $this->getMockBuilder('OCP\Share\IManager') - ->disableOriginalConstructor() - ->getMock(); + $this->shareManager = $this->createMock(IManager::class); $this->shareManager ->expects($this->any()) ->method('shareApiEnabled') ->willReturn(true); - $this->groupManager = $this->getMockBuilder('OCP\IGroupManager')->getMock(); - $this->userManager = $this->getMockBuilder('OCP\IUserManager')->getMock(); - $this->request = $this->getMockBuilder('OCP\IRequest')->getMock(); - $this->rootFolder = $this->getMockBuilder('OCP\Files\IRootFolder')->getMock(); - $this->urlGenerator = $this->getMockBuilder('OCP\IURLGenerator')->getMock(); - $this->currentUser = $this->getMockBuilder('OCP\IUser')->getMock(); - $this->currentUser->method('getUID')->willReturn('currentUser'); - - $this->l = $this->getMockBuilder('\OCP\IL10N')->getMock(); + $this->groupManager = $this->createMock(IGroupManager::class); + $this->userManager = $this->createMock(IUserManager::class); + $this->request = $this->createMock(IRequest::class); + $this->rootFolder = $this->createMock(IRootFolder::class); + $this->urlGenerator = $this->createMock(IURLGenerator::class); + $this->currentUser = 'currentUser'; + + $this->l = $this->createMock(IL10N::class); $this->l->method('t') ->will($this->returnCallback(function($text, $parameters = []) { return vsprintf($text, $parameters); })); - $this->ocs = new Share20OCS( + $this->ocs = new ShareAPIController( $this->appName, $this->request, $this->shareManager, @@ -111,10 +109,10 @@ class Share20OCSTest extends \Test\TestCase { } /** - * @return Share20OCS|\PHPUnit_Framework_MockObject_MockObject + * @return ShareAPIController|\PHPUnit_Framework_MockObject_MockObject */ private function mockFormatShare() { - return $this->getMockBuilder(Share20OCS::class) + return $this->getMockBuilder(ShareAPIController::class) ->setConstructorArgs([ $this->appName, $this->request, @@ -158,7 +156,7 @@ class Share20OCSTest extends \Test\TestCase { $node = $this->getMockBuilder('\OCP\Files\File')->getMock(); $share = $this->newShare(); - $share->setSharedBy($this->currentUser->getUID()) + $share->setSharedBy($this->currentUser) ->setNode($node); $this->shareManager ->expects($this->once()) @@ -189,7 +187,7 @@ class Share20OCSTest extends \Test\TestCase { $node = $this->getMockBuilder('\OCP\Files\File')->getMock(); $share = $this->newShare(); - $share->setSharedBy($this->currentUser->getUID()) + $share->setSharedBy($this->currentUser) ->setNode($node); $this->shareManager ->expects($this->once()) @@ -421,7 +419,8 @@ class Share20OCSTest extends \Test\TestCase { * @dataProvider dataGetShare */ public function testGetShare(\OCP\Share\IShare $share, array $result) { - $ocs = $this->getMockBuilder('OCA\Files_Sharing\API\Share20OCS') + /** @var ShareAPIController|\PHPUnit_Framework_MockObject_MockObject $ocs */ + $ocs = $this->getMockBuilder(ShareAPIController::class) ->setConstructorArgs([ $this->appName, $this->request, @@ -455,7 +454,7 @@ class Share20OCSTest extends \Test\TestCase { ->willReturn([$share->getNode()]); $this->rootFolder->method('getUserFolder') - ->with($this->currentUser->getUID()) + ->with($this->currentUser) ->willReturn($userFolder); $this->urlGenerator @@ -510,16 +509,16 @@ class Share20OCSTest extends \Test\TestCase { public function testCanAccessShare() { $share = $this->getMockBuilder('OCP\Share\IShare')->getMock(); - $share->method('getShareOwner')->willReturn($this->currentUser->getUID()); + $share->method('getShareOwner')->willReturn($this->currentUser); $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); $share = $this->getMockBuilder('OCP\Share\IShare')->getMock(); - $share->method('getSharedBy')->willReturn($this->currentUser->getUID()); + $share->method('getSharedBy')->willReturn($this->currentUser); $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); $share = $this->getMockBuilder('OCP\Share\IShare')->getMock(); $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER); - $share->method('getSharedWith')->willReturn($this->currentUser->getUID()); + $share->method('getSharedWith')->willReturn($this->currentUser); $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); $share = $this->getMockBuilder('OCP\Share\IShare')->getMock(); @@ -531,11 +530,15 @@ class Share20OCSTest extends \Test\TestCase { $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_GROUP); $share->method('getSharedWith')->willReturn('group'); + $user = $this->createMock(IUser::class); + $this->userManager->method('get') + ->with($this->currentUser) + ->willReturn($user); + $group = $this->getMockBuilder('OCP\IGroup')->getMock(); - $group->method('inGroup')->with($this->currentUser)->willReturn(true); + $group->method('inGroup')->with($user)->willReturn(true); $group2 = $this->getMockBuilder('OCP\IGroup')->getMock(); - $group2->method('inGroup')->with($this->currentUser)->willReturn(false); - + $group2->method('inGroup')->with($user)->willReturn(false); $this->groupManager->method('get')->will($this->returnValueMap([ ['group', $group], @@ -679,8 +682,8 @@ class Share20OCSTest extends \Test\TestCase { $share = $this->newShare(); $this->shareManager->method('newShare')->willReturn($share); - /** @var \OCA\Files_Sharing\API\Share20OCS $ocs */ - $ocs = $this->getMockBuilder('OCA\Files_Sharing\API\Share20OCS') + /** @var \OCA\Files_Sharing\Controller\ShareAPIController $ocs */ + $ocs = $this->getMockBuilder(ShareAPIController::class) ->setConstructorArgs([ $this->appName, $this->request, @@ -776,7 +779,8 @@ class Share20OCSTest extends \Test\TestCase { $share = $this->newShare(); $this->shareManager->method('newShare')->willReturn($share); - $ocs = $this->getMockBuilder('OCA\Files_Sharing\API\Share20OCS') + /** @var ShareAPIController|\PHPUnit_Framework_MockObject_MockObject $ocs */ + $ocs = $this->getMockBuilder(ShareAPIController::class) ->setConstructorArgs([ $this->appName, $this->request, @@ -895,7 +899,7 @@ class Share20OCSTest extends \Test\TestCase { ->with('OCA\Files_Sharing\External\Storage') ->willReturn(false); $path->method('getStorage')->willReturn($storage); - $this->rootFolder->method('getUserFolder')->with($this->currentUser->getUID())->will($this->returnSelf()); + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->will($this->returnSelf()); $this->rootFolder->method('get')->with('valid-path')->willReturn($path); $this->shareManager->method('newShare')->willReturn(\OC::$server->getShareManager()->newShare()); @@ -914,7 +918,7 @@ class Share20OCSTest extends \Test\TestCase { ->with('OCA\Files_Sharing\External\Storage') ->willReturn(false); $path->method('getStorage')->willReturn($storage); - $this->rootFolder->method('getUserFolder')->with($this->currentUser->getUID())->will($this->returnSelf()); + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->will($this->returnSelf()); $this->rootFolder->method('get')->with('valid-path')->willReturn($path); $this->shareManager->method('newShare')->willReturn(\OC::$server->getShareManager()->newShare()); @@ -934,7 +938,7 @@ class Share20OCSTest extends \Test\TestCase { ->with('OCA\Files_Sharing\External\Storage') ->willReturn(false); $path->method('getStorage')->willReturn($storage); - $this->rootFolder->method('getUserFolder')->with($this->currentUser->getUID())->will($this->returnSelf()); + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->will($this->returnSelf()); $this->rootFolder->method('get')->with('valid-path')->willReturn($path); $this->shareManager->method('newShare')->willReturn(\OC::$server->getShareManager()->newShare()); @@ -953,7 +957,7 @@ class Share20OCSTest extends \Test\TestCase { ->with('OCA\Files_Sharing\External\Storage') ->willReturn(false); $path->method('getStorage')->willReturn($storage); - $this->rootFolder->method('getUserFolder')->with($this->currentUser->getUID())->will($this->returnSelf()); + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->will($this->returnSelf()); $this->rootFolder->method('get')->with('valid-path')->willReturn($path); $this->shareManager->method('newShare')->willReturn(\OC::$server->getShareManager()->newShare()); @@ -987,7 +991,7 @@ class Share20OCSTest extends \Test\TestCase { ->with('OCA\Files_Sharing\External\Storage') ->willReturn(false); $path->method('getStorage')->willReturn($storage); - $this->rootFolder->method('getUserFolder')->with($this->currentUser->getUID())->will($this->returnSelf()); + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->will($this->returnSelf()); $this->rootFolder->method('get')->with('valid-path')->willReturn($path); $this->shareManager->method('newShare')->willReturn(\OC::$server->getShareManager()->newShare()); @@ -1031,7 +1035,7 @@ class Share20OCSTest extends \Test\TestCase { ->with('OCA\Files_Sharing\External\Storage') ->willReturn(false); $path->method('getStorage')->willReturn($storage); - $this->rootFolder->method('getUserFolder')->with($this->currentUser->getUID())->will($this->returnSelf()); + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->will($this->returnSelf()); $this->rootFolder->method('get')->with('valid-path')->willReturn($path); $this->shareManager->method('newShare')->willReturn(\OC::$server->getShareManager()->newShare()); @@ -1072,7 +1076,7 @@ class Share20OCSTest extends \Test\TestCase { ->with('OCA\Files_Sharing\External\Storage') ->willReturn(false); $path->method('getStorage')->willReturn($storage); - $this->rootFolder->method('getUserFolder')->with($this->currentUser->getUID())->will($this->returnSelf()); + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->will($this->returnSelf()); $this->rootFolder->method('get')->with('valid-path')->willReturn($path); $this->shareManager->method('newShare')->willReturn(\OC::$server->getShareManager()->newShare()); @@ -1090,7 +1094,8 @@ class Share20OCSTest extends \Test\TestCase { $share = \OC::$server->getShareManager()->newShare(); $this->shareManager->method('newShare')->willReturn($share); - $ocs = $this->getMockBuilder('OCA\Files_Sharing\API\Share20OCS') + /** @var ShareAPIController|\PHPUnit_Framework_MockObject_MockObject $ocs */ + $ocs = $this->getMockBuilder(ShareAPIController::class) ->setConstructorArgs([ $this->appName, $this->request, @@ -1161,7 +1166,7 @@ class Share20OCSTest extends \Test\TestCase { $node = $this->getMockBuilder('\OCP\Files\Folder')->getMock(); $share = $this->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) - ->setSharedBy($this->currentUser->getUID()) + ->setSharedBy($this->currentUser) ->setShareType(\OCP\Share::SHARE_TYPE_LINK) ->setNode($node); @@ -1182,7 +1187,7 @@ class Share20OCSTest extends \Test\TestCase { $node = $this->getMockBuilder('\OCP\Files\Folder')->getMock(); $share = $this->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) - ->setSharedBy($this->currentUser->getUID()) + ->setSharedBy($this->currentUser) ->setShareType(\OCP\Share::SHARE_TYPE_GROUP) ->setNode($node); @@ -1201,7 +1206,7 @@ class Share20OCSTest extends \Test\TestCase { $node = $this->getMockBuilder('\OCP\Files\Folder')->getMock(); $share = $this->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) - ->setSharedBy($this->currentUser->getUID()) + ->setSharedBy($this->currentUser) ->setShareType(\OCP\Share::SHARE_TYPE_LINK) ->setPassword('password') ->setExpirationDate(new \DateTime()) @@ -1236,7 +1241,7 @@ class Share20OCSTest extends \Test\TestCase { $share = \OC::$server->getShareManager()->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) - ->setSharedBy($this->currentUser->getUID()) + ->setSharedBy($this->currentUser) ->setShareType(\OCP\Share::SHARE_TYPE_LINK) ->setNode($folder); @@ -1271,7 +1276,7 @@ class Share20OCSTest extends \Test\TestCase { $share = \OC::$server->getShareManager()->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) - ->setSharedBy($this->currentUser->getUID()) + ->setSharedBy($this->currentUser) ->setShareType(\OCP\Share::SHARE_TYPE_LINK) ->setPassword('password') ->setNode($folder); @@ -1306,7 +1311,7 @@ class Share20OCSTest extends \Test\TestCase { $share = \OC::$server->getShareManager()->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) - ->setSharedBy($this->currentUser->getUID()) + ->setSharedBy($this->currentUser) ->setShareType(\OCP\Share::SHARE_TYPE_LINK) ->setNode($folder); @@ -1344,7 +1349,7 @@ class Share20OCSTest extends \Test\TestCase { $share = \OC::$server->getShareManager()->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) - ->setSharedBy($this->currentUser->getUID()) + ->setSharedBy($this->currentUser) ->setShareType(\OCP\Share::SHARE_TYPE_LINK) ->setNode($folder); @@ -1365,7 +1370,7 @@ class Share20OCSTest extends \Test\TestCase { $share = \OC::$server->getShareManager()->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) - ->setSharedBy($this->currentUser->getUID()) + ->setSharedBy($this->currentUser) ->setShareType(\OCP\Share::SHARE_TYPE_LINK) ->setNode($file); @@ -1384,7 +1389,7 @@ class Share20OCSTest extends \Test\TestCase { $node = $this->getMockBuilder('\OCP\Files\File')->getMock(); $share = $this->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) - ->setSharedBy($this->currentUser->getUID()) + ->setSharedBy($this->currentUser) ->setShareType(\OCP\Share::SHARE_TYPE_LINK) ->setPassword('password') ->setExpirationDate($date) @@ -1418,7 +1423,7 @@ class Share20OCSTest extends \Test\TestCase { $node = $this->getMockBuilder('\OCP\Files\File')->getMock(); $share = $this->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) - ->setSharedBy($this->currentUser->getUID()) + ->setSharedBy($this->currentUser) ->setShareType(\OCP\Share::SHARE_TYPE_LINK) ->setPassword('password') ->setExpirationDate(new \DateTime()) @@ -1458,7 +1463,7 @@ class Share20OCSTest extends \Test\TestCase { $share = \OC::$server->getShareManager()->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) - ->setSharedBy($this->currentUser->getUID()) + ->setSharedBy($this->currentUser) ->setShareType(\OCP\Share::SHARE_TYPE_LINK) ->setPassword('password') ->setExpirationDate($date) @@ -1492,7 +1497,7 @@ class Share20OCSTest extends \Test\TestCase { $share = \OC::$server->getShareManager()->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) - ->setSharedBy($this->currentUser->getUID()) + ->setSharedBy($this->currentUser) ->setShareType(\OCP\Share::SHARE_TYPE_LINK) ->setPassword('password') ->setExpirationDate($date) @@ -1532,7 +1537,7 @@ class Share20OCSTest extends \Test\TestCase { $share = \OC::$server->getShareManager()->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) - ->setSharedBy($this->currentUser->getUID()) + ->setSharedBy($this->currentUser) ->setShareType(\OCP\Share::SHARE_TYPE_LINK) ->setPassword('password') ->setExpirationDate($date) @@ -1552,7 +1557,7 @@ class Share20OCSTest extends \Test\TestCase { $share = \OC::$server->getShareManager()->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) - ->setSharedBy($this->currentUser->getUID()) + ->setSharedBy($this->currentUser) ->setShareType(\OCP\Share::SHARE_TYPE_USER) ->setNode($file); @@ -1582,7 +1587,7 @@ class Share20OCSTest extends \Test\TestCase { $share = \OC::$server->getShareManager()->newShare(); $share ->setId(42) - ->setSharedBy($this->currentUser->getUID()) + ->setSharedBy($this->currentUser) ->setShareOwner('anotheruser') ->setShareType(\OCP\Share::SHARE_TYPE_GROUP) ->setSharedWith('group1') @@ -1594,7 +1599,7 @@ class Share20OCSTest extends \Test\TestCase { $incomingShare = \OC::$server->getShareManager()->newShare(); $incomingShare ->setId(42) - ->setSharedBy($this->currentUser->getUID()) + ->setSharedBy($this->currentUser) ->setShareOwner('anotheruser') ->setShareType(\OCP\Share::SHARE_TYPE_GROUP) ->setSharedWith('group1') @@ -1609,7 +1614,7 @@ class Share20OCSTest extends \Test\TestCase { $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); - $this->shareManager->expects($this->any(0)) + $this->shareManager->expects($this->any()) ->method('getSharedWith') ->will($this->returnValueMap([ ['currentUser', \OCP\Share::SHARE_TYPE_USER, $share->getNode(), -1, 0, []], @@ -1634,8 +1639,8 @@ class Share20OCSTest extends \Test\TestCase { $share = \OC::$server->getShareManager()->newShare(); $share ->setId(42) - ->setSharedBy($this->currentUser->getUID()) - ->setShareOwner($this->currentUser->getUID()) + ->setSharedBy($this->currentUser) + ->setShareOwner($this->currentUser) ->setShareType(\OCP\Share::SHARE_TYPE_GROUP) ->setSharedWith('group1') ->setPermissions(\OCP\Constants::PERMISSION_READ) @@ -1646,8 +1651,8 @@ class Share20OCSTest extends \Test\TestCase { $incomingShare = \OC::$server->getShareManager()->newShare(); $incomingShare ->setId(42) - ->setSharedBy($this->currentUser->getUID()) - ->setShareOwner($this->currentUser->getUID()) + ->setSharedBy($this->currentUser) + ->setShareOwner($this->currentUser) ->setShareType(\OCP\Share::SHARE_TYPE_GROUP) ->setSharedWith('group1') ->setPermissions(\OCP\Constants::PERMISSION_READ) @@ -1655,7 +1660,7 @@ class Share20OCSTest extends \Test\TestCase { $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); - $this->shareManager->expects($this->any(0)) + $this->shareManager->expects($this->any()) ->method('getSharedWith') ->will($this->returnValueMap([ ['currentUser', \OCP\Share::SHARE_TYPE_USER, $share->getNode(), -1, 0, []], @@ -1973,7 +1978,7 @@ class Share20OCSTest extends \Test\TestCase { $this->rootFolder->method('getUserFolder') - ->with($this->currentUser->getUID()) + ->with($this->currentUser) ->will($this->returnSelf()); if (!$exception) { |