diff options
Diffstat (limited to 'apps/files/tests/controller/apicontrollertest.php')
-rw-r--r-- | apps/files/tests/controller/apicontrollertest.php | 56 |
1 files changed, 53 insertions, 3 deletions
diff --git a/apps/files/tests/controller/apicontrollertest.php b/apps/files/tests/controller/apicontrollertest.php index 6fb8340ead8..a9b248a36fe 100644 --- a/apps/files/tests/controller/apicontrollertest.php +++ b/apps/files/tests/controller/apicontrollertest.php @@ -51,14 +51,27 @@ class ApiControllerTest extends TestCase { private $preview; /** @var ApiController */ private $apiController; + /** @var \OCP\Share\IManager */ + private $shareManager; public function setUp() { $this->request = $this->getMockBuilder('\OCP\IRequest') ->disableOriginalConstructor() ->getMock(); + $user = $this->getMock('\OCP\IUser'); + $user->expects($this->any()) + ->method('getUID') + ->will($this->returnValue('user1')); + $userSession = $this->getMock('\OCP\IUserSession'); + $userSession->expects($this->any()) + ->method('getUser') + ->will($this->returnValue($user)); $this->tagService = $this->getMockBuilder('\OCA\Files\Service\TagService') ->disableOriginalConstructor() ->getMock(); + $this->shareManager = $this->getMockBuilder('\OCP\Share\IManager') + ->disableOriginalConstructor() + ->getMock(); $this->preview = $this->getMockBuilder('\OCP\IPreview') ->disableOriginalConstructor() ->getMock(); @@ -66,8 +79,10 @@ class ApiControllerTest extends TestCase { $this->apiController = new ApiController( $this->appName, $this->request, + $userSession, $this->tagService, - $this->preview + $this->preview, + $this->shareManager ); } @@ -101,10 +116,32 @@ class ApiControllerTest extends TestCase { ->disableOriginalConstructor() ->getMock() ); + $node = $this->getMockBuilder('\OC\Files\Node\File') + ->disableOriginalConstructor() + ->getMock(); + $node->expects($this->once()) + ->method('getFileInfo') + ->will($this->returnValue($fileInfo)); $this->tagService->expects($this->once()) ->method('getFilesByTag') ->with($this->equalTo([$tagName])) - ->will($this->returnValue([$fileInfo])); + ->will($this->returnValue([$node])); + + $this->shareManager->expects($this->any()) + ->method('getSharesBy') + ->with( + $this->equalTo('user1'), + $this->anything(), + $node, + $this->equalTo(false), + $this->equalTo(1) + ) + ->will($this->returnCallback(function($userId, $shareType) { + if ($shareType === \OCP\Share::SHARE_TYPE_USER || $shareType === \OCP\Share::SHARE_TYPE_LINK) { + return ['dummy_share']; + } + return []; + })); $expected = new DataResponse([ 'files' => [ @@ -124,6 +161,7 @@ class ApiControllerTest extends TestCase { 'MyTagName' ] ], + 'shareTypes' => [\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_LINK] ], ], ]); @@ -166,10 +204,22 @@ class ApiControllerTest extends TestCase { ->disableOriginalConstructor() ->getMock() ); + $node1 = $this->getMockBuilder('\OC\Files\Node\File') + ->disableOriginalConstructor() + ->getMock(); + $node1->expects($this->once()) + ->method('getFileInfo') + ->will($this->returnValue($fileInfo1)); + $node2 = $this->getMockBuilder('\OC\Files\Node\File') + ->disableOriginalConstructor() + ->getMock(); + $node2->expects($this->once()) + ->method('getFileInfo') + ->will($this->returnValue($fileInfo2)); $this->tagService->expects($this->once()) ->method('getFilesByTag') ->with($this->equalTo([$tagName])) - ->will($this->returnValue([$fileInfo1, $fileInfo2])); + ->will($this->returnValue([$node1, $node2])); $expected = new DataResponse([ 'files' => [ |