浏览代码

Fix tests

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
tags/v17.0.0beta1
Roeland Jago Douma 4 年前
父节点
当前提交
85d5400314
没有帐户链接到提交者的电子邮件
共有 2 个文件被更改,包括 39 次插入63 次删除
  1. 2
    0
      apps/dav/lib/Connector/Sabre/SharesPlugin.php
  2. 37
    63
      apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php

+ 2
- 0
apps/dav/lib/Connector/Sabre/SharesPlugin.php 查看文件

@@ -158,6 +158,7 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin {
if (array_search($parentPath, $this->cachedFolders) === false) {
$node = $this->userFolder->get($sabreNode->getPath());
$shares = $this->getShare($node);
$this->cachedShares[$sabreNode->getId()] = $shares;
} else {
return [];
}
@@ -190,6 +191,7 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin {
) {
$folderNode = $this->userFolder->get($sabreNode->getPath());

$this->cachedFolders[] = $sabreNode->getPath();
$childShares = $this->getSharesFolder($folderNode);
foreach ($childShares as $id => $shares) {
$this->cachedShares[$id] = $shares;

+ 37
- 63
apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php 查看文件

@@ -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 [];

正在加载...
取消
保存