|
|
@@ -68,28 +68,17 @@ class SharesPluginTest extends \Test\TestCase { |
|
|
|
public function setUp() { |
|
|
|
parent::setUp(); |
|
|
|
$this->server = new \Sabre\DAV\Server(); |
|
|
|
$this->tree = $this->getMockBuilder(Tree::class) |
|
|
|
->disableOriginalConstructor() |
|
|
|
->getMock(); |
|
|
|
$this->shareManager = $this->getMockBuilder(IManager::class) |
|
|
|
->disableOriginalConstructor() |
|
|
|
->getMock(); |
|
|
|
$user = $this->getMockBuilder(IUser::class) |
|
|
|
->disableOriginalConstructor() |
|
|
|
->getMock(); |
|
|
|
$this->tree = $this->createMock(Tree::class); |
|
|
|
$this->shareManager = $this->createMock(IManager::class); |
|
|
|
$user = $this->createMock(IUser::class); |
|
|
|
$user->expects($this->once()) |
|
|
|
->method('getUID') |
|
|
|
->will($this->returnValue('user1')); |
|
|
|
$userSession = $this->getMockBuilder(IUserSession::class) |
|
|
|
->disableOriginalConstructor() |
|
|
|
->getMock(); |
|
|
|
$userSession = $this->createMock(IUserSession::class); |
|
|
|
$userSession->expects($this->once()) |
|
|
|
->method('getUser') |
|
|
|
->will($this->returnValue($user)); |
|
|
|
|
|
|
|
$this->userFolder = $this->getMockBuilder(Folder::class) |
|
|
|
->disableOriginalConstructor() |
|
|
|
->getMock(); |
|
|
|
$this->userFolder = $this->createMock(Folder::class); |
|
|
|
|
|
|
|
$this->plugin = new \OCA\DAV\Connector\Sabre\SharesPlugin( |
|
|
|
$this->tree, |
|
|
@@ -135,7 +124,10 @@ class SharesPluginTest extends \Test\TestCase { |
|
|
|
) |
|
|
|
->will($this->returnCallback(function($userId, $requestedShareType, $node, $flag, $limit) use ($shareTypes){ |
|
|
|
if (in_array($requestedShareType, $shareTypes)) { |
|
|
|
return ['dummyshare']; |
|
|
|
$share = $this->createMock(IShare::class); |
|
|
|
$share->method('getShareType') |
|
|
|
->willReturn($requestedShareType); |
|
|
|
return [$share]; |
|
|
|
} |
|
|
|
return []; |
|
|
|
})); |
|
|
@@ -162,30 +154,18 @@ class SharesPluginTest extends \Test\TestCase { |
|
|
|
* @dataProvider sharesGetPropertiesDataProvider |
|
|
|
*/ |
|
|
|
public function testPreloadThenGetProperties($shareTypes) { |
|
|
|
$sabreNode1 = $this->getMockBuilder(File::class) |
|
|
|
->disableOriginalConstructor() |
|
|
|
->getMock(); |
|
|
|
$sabreNode1->expects($this->any()) |
|
|
|
->method('getId') |
|
|
|
->will($this->returnValue(111)); |
|
|
|
$sabreNode1->expects($this->any()) |
|
|
|
->method('getPath'); |
|
|
|
$sabreNode2 = $this->getMockBuilder(File::class) |
|
|
|
->disableOriginalConstructor() |
|
|
|
->getMock(); |
|
|
|
$sabreNode2->expects($this->any()) |
|
|
|
->method('getId') |
|
|
|
->will($this->returnValue(222)); |
|
|
|
$sabreNode2->expects($this->any()) |
|
|
|
->method('getPath') |
|
|
|
->will($this->returnValue('/subdir/foo')); |
|
|
|
$sabreNode1 = $this->createMock(File::class); |
|
|
|
$sabreNode1->method('getId') |
|
|
|
->willReturn(111); |
|
|
|
$sabreNode2 = $this->createMock(File::class); |
|
|
|
$sabreNode2->method('getId') |
|
|
|
->willReturn(222); |
|
|
|
$sabreNode2->method('getPath') |
|
|
|
->willReturn('/subdir/foo'); |
|
|
|
|
|
|
|
$sabreNode = $this->getMockBuilder(Directory::class) |
|
|
|
->disableOriginalConstructor() |
|
|
|
->getMock(); |
|
|
|
$sabreNode->expects($this->any()) |
|
|
|
->method('getId') |
|
|
|
->will($this->returnValue(123)); |
|
|
|
$sabreNode = $this->createMock(Directory::class); |
|
|
|
$sabreNode->method('getId') |
|
|
|
->willReturn(123); |
|
|
|
// never, because we use getDirectoryListing from the Node API instead |
|
|
|
$sabreNode->expects($this->never()) |
|
|
|
->method('getChildren'); |
|
|
@@ -194,29 +174,19 @@ class SharesPluginTest extends \Test\TestCase { |
|
|
|
->will($this->returnValue('/subdir')); |
|
|
|
|
|
|
|
// node API nodes |
|
|
|
$node = $this->getMockBuilder(Folder::class) |
|
|
|
->disableOriginalConstructor() |
|
|
|
->getMock(); |
|
|
|
$node->expects($this->any()) |
|
|
|
->method('getId') |
|
|
|
->will($this->returnValue(123)); |
|
|
|
$node1 = $this->getMockBuilder(File::class) |
|
|
|
->disableOriginalConstructor() |
|
|
|
->getMock(); |
|
|
|
$node1->expects($this->any()) |
|
|
|
->method('getId') |
|
|
|
->will($this->returnValue(111)); |
|
|
|
$node2 = $this->getMockBuilder(File::class) |
|
|
|
->disableOriginalConstructor() |
|
|
|
->getMock(); |
|
|
|
$node2->expects($this->any()) |
|
|
|
->method('getId') |
|
|
|
->will($this->returnValue(222)); |
|
|
|
$node = $this->createMock(Folder::class); |
|
|
|
$node->method('getId') |
|
|
|
->willReturn(123); |
|
|
|
$node1 = $this->createMock(File::class); |
|
|
|
$node1->method('getId') |
|
|
|
->willReturn(111); |
|
|
|
$node2 = $this->createMock(File::class); |
|
|
|
$node2->method('getId') |
|
|
|
->willReturn(222); |
|
|
|
|
|
|
|
$this->userFolder->expects($this->once()) |
|
|
|
->method('get') |
|
|
|
$this->userFolder->method('get') |
|
|
|
->with('/subdir') |
|
|
|
->will($this->returnValue($node)); |
|
|
|
->willReturn($node); |
|
|
|
|
|
|
|
$dummyShares = array_map(function($type) { |
|
|
|
$share = $this->getMockBuilder(IShare::class)->getMock(); |
|
|
@@ -235,9 +205,13 @@ class SharesPluginTest extends \Test\TestCase { |
|
|
|
$this->equalTo(false), |
|
|
|
$this->equalTo(1) |
|
|
|
) |
|
|
|
->will($this->returnCallback(function($userId, $requestedShareType, $node, $flag, $limit) use ($shareTypes){ |
|
|
|
->will($this->returnCallback(function($userId, $requestedShareType, $node, $flag, $limit) use ($shareTypes, $dummyShares){ |
|
|
|
if ($node->getId() === 111 && in_array($requestedShareType, $shareTypes)) { |
|
|
|
return ['dummyshare']; |
|
|
|
foreach ($dummyShares as $dummyShare) { |
|
|
|
if ($dummyShare->getShareType() === $requestedShareType) { |
|
|
|
return [$dummyShare]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return []; |