Fix tests
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
parent
42f00e80c7
commit
85d5400314
|
@ -158,6 +158,7 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin {
|
||||||
if (array_search($parentPath, $this->cachedFolders) === false) {
|
if (array_search($parentPath, $this->cachedFolders) === false) {
|
||||||
$node = $this->userFolder->get($sabreNode->getPath());
|
$node = $this->userFolder->get($sabreNode->getPath());
|
||||||
$shares = $this->getShare($node);
|
$shares = $this->getShare($node);
|
||||||
|
$this->cachedShares[$sabreNode->getId()] = $shares;
|
||||||
} else {
|
} else {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
@ -190,6 +191,7 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin {
|
||||||
) {
|
) {
|
||||||
$folderNode = $this->userFolder->get($sabreNode->getPath());
|
$folderNode = $this->userFolder->get($sabreNode->getPath());
|
||||||
|
|
||||||
|
$this->cachedFolders[] = $sabreNode->getPath();
|
||||||
$childShares = $this->getSharesFolder($folderNode);
|
$childShares = $this->getSharesFolder($folderNode);
|
||||||
foreach ($childShares as $id => $shares) {
|
foreach ($childShares as $id => $shares) {
|
||||||
$this->cachedShares[$id] = $shares;
|
$this->cachedShares[$id] = $shares;
|
||||||
|
|
|
@ -68,28 +68,17 @@ class SharesPluginTest extends \Test\TestCase {
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->server = new \Sabre\DAV\Server();
|
$this->server = new \Sabre\DAV\Server();
|
||||||
$this->tree = $this->getMockBuilder(Tree::class)
|
$this->tree = $this->createMock(Tree::class);
|
||||||
->disableOriginalConstructor()
|
$this->shareManager = $this->createMock(IManager::class);
|
||||||
->getMock();
|
$user = $this->createMock(IUser::class);
|
||||||
$this->shareManager = $this->getMockBuilder(IManager::class)
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
$user = $this->getMockBuilder(IUser::class)
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
$user->expects($this->once())
|
$user->expects($this->once())
|
||||||
->method('getUID')
|
->method('getUID')
|
||||||
->will($this->returnValue('user1'));
|
->will($this->returnValue('user1'));
|
||||||
$userSession = $this->getMockBuilder(IUserSession::class)
|
$userSession = $this->createMock(IUserSession::class);
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
$userSession->expects($this->once())
|
$userSession->expects($this->once())
|
||||||
->method('getUser')
|
->method('getUser')
|
||||||
->will($this->returnValue($user));
|
->will($this->returnValue($user));
|
||||||
|
$this->userFolder = $this->createMock(Folder::class);
|
||||||
$this->userFolder = $this->getMockBuilder(Folder::class)
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
|
|
||||||
$this->plugin = new \OCA\DAV\Connector\Sabre\SharesPlugin(
|
$this->plugin = new \OCA\DAV\Connector\Sabre\SharesPlugin(
|
||||||
$this->tree,
|
$this->tree,
|
||||||
|
@ -135,7 +124,10 @@ class SharesPluginTest extends \Test\TestCase {
|
||||||
)
|
)
|
||||||
->will($this->returnCallback(function($userId, $requestedShareType, $node, $flag, $limit) use ($shareTypes){
|
->will($this->returnCallback(function($userId, $requestedShareType, $node, $flag, $limit) use ($shareTypes){
|
||||||
if (in_array($requestedShareType, $shareTypes)) {
|
if (in_array($requestedShareType, $shareTypes)) {
|
||||||
return ['dummyshare'];
|
$share = $this->createMock(IShare::class);
|
||||||
|
$share->method('getShareType')
|
||||||
|
->willReturn($requestedShareType);
|
||||||
|
return [$share];
|
||||||
}
|
}
|
||||||
return [];
|
return [];
|
||||||
}));
|
}));
|
||||||
|
@ -162,30 +154,18 @@ class SharesPluginTest extends \Test\TestCase {
|
||||||
* @dataProvider sharesGetPropertiesDataProvider
|
* @dataProvider sharesGetPropertiesDataProvider
|
||||||
*/
|
*/
|
||||||
public function testPreloadThenGetProperties($shareTypes) {
|
public function testPreloadThenGetProperties($shareTypes) {
|
||||||
$sabreNode1 = $this->getMockBuilder(File::class)
|
$sabreNode1 = $this->createMock(File::class);
|
||||||
->disableOriginalConstructor()
|
$sabreNode1->method('getId')
|
||||||
->getMock();
|
->willReturn(111);
|
||||||
$sabreNode1->expects($this->any())
|
$sabreNode2 = $this->createMock(File::class);
|
||||||
->method('getId')
|
$sabreNode2->method('getId')
|
||||||
->will($this->returnValue(111));
|
->willReturn(222);
|
||||||
$sabreNode1->expects($this->any())
|
$sabreNode2->method('getPath')
|
||||||
->method('getPath');
|
->willReturn('/subdir/foo');
|
||||||
$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'));
|
|
||||||
|
|
||||||
$sabreNode = $this->getMockBuilder(Directory::class)
|
$sabreNode = $this->createMock(Directory::class);
|
||||||
->disableOriginalConstructor()
|
$sabreNode->method('getId')
|
||||||
->getMock();
|
->willReturn(123);
|
||||||
$sabreNode->expects($this->any())
|
|
||||||
->method('getId')
|
|
||||||
->will($this->returnValue(123));
|
|
||||||
// never, because we use getDirectoryListing from the Node API instead
|
// never, because we use getDirectoryListing from the Node API instead
|
||||||
$sabreNode->expects($this->never())
|
$sabreNode->expects($this->never())
|
||||||
->method('getChildren');
|
->method('getChildren');
|
||||||
|
@ -194,29 +174,19 @@ class SharesPluginTest extends \Test\TestCase {
|
||||||
->will($this->returnValue('/subdir'));
|
->will($this->returnValue('/subdir'));
|
||||||
|
|
||||||
// node API nodes
|
// node API nodes
|
||||||
$node = $this->getMockBuilder(Folder::class)
|
$node = $this->createMock(Folder::class);
|
||||||
->disableOriginalConstructor()
|
$node->method('getId')
|
||||||
->getMock();
|
->willReturn(123);
|
||||||
$node->expects($this->any())
|
$node1 = $this->createMock(File::class);
|
||||||
->method('getId')
|
$node1->method('getId')
|
||||||
->will($this->returnValue(123));
|
->willReturn(111);
|
||||||
$node1 = $this->getMockBuilder(File::class)
|
$node2 = $this->createMock(File::class);
|
||||||
->disableOriginalConstructor()
|
$node2->method('getId')
|
||||||
->getMock();
|
->willReturn(222);
|
||||||
$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));
|
|
||||||
|
|
||||||
$this->userFolder->expects($this->once())
|
$this->userFolder->method('get')
|
||||||
->method('get')
|
|
||||||
->with('/subdir')
|
->with('/subdir')
|
||||||
->will($this->returnValue($node));
|
->willReturn($node);
|
||||||
|
|
||||||
$dummyShares = array_map(function($type) {
|
$dummyShares = array_map(function($type) {
|
||||||
$share = $this->getMockBuilder(IShare::class)->getMock();
|
$share = $this->getMockBuilder(IShare::class)->getMock();
|
||||||
|
@ -235,9 +205,13 @@ class SharesPluginTest extends \Test\TestCase {
|
||||||
$this->equalTo(false),
|
$this->equalTo(false),
|
||||||
$this->equalTo(1)
|
$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)) {
|
if ($node->getId() === 111 && in_array($requestedShareType, $shareTypes)) {
|
||||||
return ['dummyshare'];
|
foreach ($dummyShares as $dummyShare) {
|
||||||
|
if ($dummyShare->getShareType() === $requestedShareType) {
|
||||||
|
return [$dummyShare];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return [];
|
return [];
|
||||||
|
|
Loading…
Reference in New Issue