|
|
|
|
@ -23,64 +23,39 @@ namespace Test\Share20; |
|
|
|
|
use OC\Share20\Manager; |
|
|
|
|
use OC\Share20\Exception; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use OCP\IUser; |
|
|
|
|
use OCP\IUserManager; |
|
|
|
|
use OCP\IGroupManager; |
|
|
|
|
use OCP\ILogger; |
|
|
|
|
use OCP\IAppConfig; |
|
|
|
|
use OCP\Files\Folder; |
|
|
|
|
use OCP\Share20\IShareProvider; |
|
|
|
|
use OC\Share20\IShareProvider; |
|
|
|
|
|
|
|
|
|
class ManagerTest extends \Test\TestCase { |
|
|
|
|
|
|
|
|
|
/** @var Manager */ |
|
|
|
|
protected $manager; |
|
|
|
|
|
|
|
|
|
/** @var IUser */ |
|
|
|
|
protected $user; |
|
|
|
|
|
|
|
|
|
/** @var IUserManager */ |
|
|
|
|
protected $userManager; |
|
|
|
|
|
|
|
|
|
/** @var IGroupManager */ |
|
|
|
|
protected $groupManager; |
|
|
|
|
|
|
|
|
|
/** @var ILogger */ |
|
|
|
|
protected $logger; |
|
|
|
|
|
|
|
|
|
/** @var IAppConfig */ |
|
|
|
|
protected $appConfig; |
|
|
|
|
|
|
|
|
|
/** @var Folder */ |
|
|
|
|
protected $userFolder; |
|
|
|
|
|
|
|
|
|
/** @var IShareProvider */ |
|
|
|
|
protected $defaultProvider; |
|
|
|
|
|
|
|
|
|
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->appConfig = $this->getMock('\OCP\IAppConfig'); |
|
|
|
|
$this->userFolder = $this->getMock('\OCP\Files\Folder'); |
|
|
|
|
$this->defaultProvider = $this->getMock('\OC\Share20\IShareProvider'); |
|
|
|
|
|
|
|
|
|
$this->manager = new Manager( |
|
|
|
|
$this->user, |
|
|
|
|
$this->userManager, |
|
|
|
|
$this->groupManager, |
|
|
|
|
$this->logger, |
|
|
|
|
$this->appConfig, |
|
|
|
|
$this->userFolder, |
|
|
|
|
$this->defaultProvider |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @expectedException OC\Share20\Exception\ShareNotFound |
|
|
|
|
* @expectedException \OC\Share20\Exception\ShareNotFound |
|
|
|
|
*/ |
|
|
|
|
public function testDeleteNoShareId() { |
|
|
|
|
$share = $this->getMock('\OC\Share20\IShare'); |
|
|
|
|
@ -115,12 +90,8 @@ class ManagerTest extends \Test\TestCase { |
|
|
|
|
public function testDelete($shareType, $sharedWith, $sharedWith_string) { |
|
|
|
|
$manager = $this->getMockBuilder('\OC\Share20\Manager') |
|
|
|
|
->setConstructorArgs([ |
|
|
|
|
$this->user, |
|
|
|
|
$this->userManager, |
|
|
|
|
$this->groupManager, |
|
|
|
|
$this->logger, |
|
|
|
|
$this->appConfig, |
|
|
|
|
$this->userFolder, |
|
|
|
|
$this->defaultProvider |
|
|
|
|
]) |
|
|
|
|
->setMethods(['getShareById', 'deleteChildren']) |
|
|
|
|
@ -205,12 +176,8 @@ class ManagerTest extends \Test\TestCase { |
|
|
|
|
public function testDeleteNested() { |
|
|
|
|
$manager = $this->getMockBuilder('\OC\Share20\Manager') |
|
|
|
|
->setConstructorArgs([ |
|
|
|
|
$this->user, |
|
|
|
|
$this->userManager, |
|
|
|
|
$this->groupManager, |
|
|
|
|
$this->logger, |
|
|
|
|
$this->appConfig, |
|
|
|
|
$this->userFolder, |
|
|
|
|
$this->defaultProvider |
|
|
|
|
]) |
|
|
|
|
->setMethods(['getShareById']) |
|
|
|
|
@ -349,12 +316,8 @@ class ManagerTest extends \Test\TestCase { |
|
|
|
|
public function testDeleteChildren() { |
|
|
|
|
$manager = $this->getMockBuilder('\OC\Share20\Manager') |
|
|
|
|
->setConstructorArgs([ |
|
|
|
|
$this->user, |
|
|
|
|
$this->userManager, |
|
|
|
|
$this->groupManager, |
|
|
|
|
$this->logger, |
|
|
|
|
$this->appConfig, |
|
|
|
|
$this->userFolder, |
|
|
|
|
$this->defaultProvider |
|
|
|
|
]) |
|
|
|
|
->setMethods(['deleteShare']) |
|
|
|
|
@ -391,82 +354,8 @@ class ManagerTest extends \Test\TestCase { |
|
|
|
|
$this->assertSame($shares, $result); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @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'); |
|
|
|
|
|
|
|
|
|
public function testGetShareById() { |
|
|
|
|
$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 |
|
|
|
|
->expects($this->once()) |
|
|
|
|
|