summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2016-10-24 10:57:47 +0200
committerGitHub <noreply@github.com>2016-10-24 10:57:47 +0200
commit57a5551c3d542f1412754d0f519cfaf03ced4eb3 (patch)
treef480d88d2d6dd2ba5ba725d733bec1a5129948a3
parentab91fa2660f15102b29254bc1c236101c6dcc6a3 (diff)
parent6604e76e9482f35cbec4d02c7ffb792c889fd2e5 (diff)
downloadnextcloud-server-57a5551c3d542f1412754d0f519cfaf03ced4eb3.tar.gz
nextcloud-server-57a5551c3d542f1412754d0f519cfaf03ced4eb3.zip
Merge pull request #1853 from nextcloud/fix_di_share_api
Moved Share20OCS to proper Controller location
-rw-r--r--apps/files_sharing/lib/AppInfo/Application.php14
-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.php8
-rw-r--r--apps/files_sharing/tests/ApiTest.php10
-rw-r--r--apps/files_sharing/tests/Controller/ShareAPIControllerTest.php (renamed from apps/files_sharing/tests/API/Share20OCSTest.php)137
-rw-r--r--apps/files_sharing/tests/Middleware/OCSShareAPIMiddlewareTest.php30
6 files changed, 126 insertions, 132 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) {
diff --git a/apps/files_sharing/tests/Middleware/OCSShareAPIMiddlewareTest.php b/apps/files_sharing/tests/Middleware/OCSShareAPIMiddlewareTest.php
index 6a2460396de..3b6257adf92 100644
--- a/apps/files_sharing/tests/Middleware/OCSShareAPIMiddlewareTest.php
+++ b/apps/files_sharing/tests/Middleware/OCSShareAPIMiddlewareTest.php
@@ -2,9 +2,11 @@
namespace OCA\Files_Sharing\Tests\Middleware;
+use OCA\Files_Sharing\Controller\ShareAPIController;
use OCA\Files_Sharing\Middleware\OCSShareAPIMiddleware;
use OCP\AppFramework\Controller;
use OCP\AppFramework\OCS\OCSNotFoundException;
+use OCP\AppFramework\OCSController;
use OCP\IL10N;
use OCP\Share\IManager;
@@ -13,7 +15,7 @@ use OCP\Share\IManager;
*/
class OCSShareAPIMiddlewareTest extends \Test\TestCase {
- /** @var IManager */
+ /** @var IManager|\PHPUnit_Framework_MockObject_MockObject */
private $shareManager;
/** @var IL10N */
private $l;
@@ -21,8 +23,10 @@ class OCSShareAPIMiddlewareTest extends \Test\TestCase {
private $middleware;
public function setUp() {
- $this->shareManager = $this->getMockBuilder('OCP\Share\IManager')->getMock();
- $this->l = $this->getMockBuilder('OCP\IL10N')->getMock();
+ parent::setUp();
+
+ $this->shareManager = $this->createMock(IManager::class);
+ $this->l = $this->createMock(IL10N::class);
$this->l->method('t')->will($this->returnArgument(0));
@@ -32,32 +36,32 @@ class OCSShareAPIMiddlewareTest extends \Test\TestCase {
public function dataBeforeController() {
return [
[
- $this->getMockBuilder('OCP\AppFramework\Controller')->disableOriginalConstructor()->getMock(),
+ $this->createMock(Controller::class),
false,
false
],
[
- $this->getMockBuilder('OCP\AppFramework\Controller')->disableOriginalConstructor()->getMock(),
+ $this->createMock(Controller::class),
true,
false
],
[
- $this->getMockBuilder('OCP\AppFramework\OCSController')->disableOriginalConstructor()->getMock(),
+ $this->createMock(OCSController::class),
false,
false
],
[
- $this->getMockBuilder('OCP\AppFramework\OCSController')->disableOriginalConstructor()->getMock(),
+ $this->createMock(OCSController::class),
true,
false
],
[
- $this->getMockBuilder('OCA\Files_Sharing\API\Share20OCS')->disableOriginalConstructor()->getMock(),
+ $this->createMock(ShareAPIController::class),
false,
true
],
[
- $this->getMockBuilder('OCA\Files_Sharing\API\Share20OCS')->disableOriginalConstructor()->getMock(),
+ $this->createMock(ShareAPIController::class),
true,
false
],
@@ -85,13 +89,13 @@ class OCSShareAPIMiddlewareTest extends \Test\TestCase {
public function dataAfterController() {
return [
[
- $this->getMockBuilder('OCP\AppFramework\Controller')->disableOriginalConstructor()->getMock(),
+ $this->createMock(Controller::class),
],
[
- $this->getMockBuilder('OCP\AppFramework\OCSController')->disableOriginalConstructor()->getMock(),
+ $this->createMock(OCSController::class),
],
[
- $this->getMockBuilder('OCA\Files_Sharing\API\Share20OCS')->disableOriginalConstructor()->getMock(),
+ $this->createMock(ShareAPIController::class),
],
];
}
@@ -103,7 +107,7 @@ class OCSShareAPIMiddlewareTest extends \Test\TestCase {
* @param bool $called
*/
public function testAfterController(Controller $controller) {
- if ($controller instanceof OCA\Files_Sharing\API\Share20OCS) {
+ if ($controller instanceof ShareAPIController) {
$controller->expects($this->once())->method('cleanup');
}