/** * @dataProvider dataGetShare */ public function testGetShare(\OCP\Share\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->expects($this->once())->method('getShareById')->with($share->getFullId())->willReturn($share); $userFolder = $this->getMock('OCP\\Files\\Folder'); $userFolder->method('getRelativePath')->will($this->returnArgument(0)); $this->rootFolder->method('getUserFolder')->with($share->getShareOwner())->willReturn($userFolder); $this->urlGenerator->method('linkToRouteAbsolute')->willReturn('url'); $initiator = $this->getMock('OCP\\IUser'); $initiator->method('getUID')->willReturn('initiatorId'); $initiator->method('getDisplayName')->willReturn('initiatorDisplay'); $owner = $this->getMock('OCP\\IUser'); $owner->method('getUID')->willReturn('ownerId'); $owner->method('getDisplayName')->willReturn('ownerDisplay'); $user = $this->getMock('OCP\\IUser'); $user->method('getUID')->willReturn('userId'); $user->method('getDisplayName')->willReturn('userDisplay'); $group = $this->getMock('OCP\\IGroup'); $group->method('getGID')->willReturn('groupId'); $this->userManager->method('get')->will($this->returnValueMap([['userId', $user], ['initiatorId', $initiator], ['ownerId', $owner]])); $this->groupManager->method('get')->will($this->returnValueMap([['group', $group]])); $expected = new \OC_OCS_Result([$result]); $this->assertEquals($expected->getData(), $ocs->getShare($share->getId())->getData()); }
/** * @dataProvider dataGetShare */ 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->expects($this->once())->method('getShareById')->with($share->getId())->willReturn($share); $userFolder = $this->getMock('OCP\\Files\\Folder'); $userFolder->method('getRelativePath')->will($this->returnArgument(0)); $this->rootFolder->method('getUserFolder')->with($share->getShareOwner()->getUID())->willReturn($userFolder); $this->urlGenerator->method('linkToRouteAbsolute')->willReturn('url'); $expected = new \OC_OCS_Result($result); $this->assertEquals($expected->getData(), $ocs->getShare($share->getId())->getData()); }
/** * @dataProvider dataFormatShare * * @param array $expects * @param \OCP\Share\IShare $share * @param array $users * @param $exception */ public function testFormatShare(array $expects, \OCP\Share\IShare $share, array $users, $exception) { $this->userManager->method('get')->will($this->returnValueMap($users)); $this->urlGenerator->method('linkToRouteAbsolute')->with('files_sharing.sharecontroller.showShare', ['token' => 'myToken'])->willReturn('myLink'); $this->rootFolder->method('getUserFolder')->with($share->getShareOwner())->will($this->returnSelf()); $this->rootFolder->method('getRelativePath')->will($this->returnArgument(0)); try { $result = $this->invokePrivate($this->ocs, 'formatShare', [$share]); $this->assertFalse($exception); $this->assertEquals($expects, $result); } catch (NotFoundException $e) { $this->assertTrue($exception); } }