summaryrefslogtreecommitdiffstats
path: root/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php')
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php118
1 files changed, 113 insertions, 5 deletions
diff --git a/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php
index 1c9ebdd09b6..739c8f62540 100644
--- a/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php
@@ -32,6 +32,9 @@ use Sabre\DAV\PropPatch;
use Sabre\HTTP\RequestInterface;
use Sabre\HTTP\ResponseInterface;
use Test\TestCase;
+use OCA\DAV\Upload\FutureFile;
+use OCA\DAV\Connector\Sabre\Directory;
+use OCP\Files\FileInfo;
/**
* Copyright (c) 2015 Vincent Petry <pvince81@owncloud.com>
@@ -107,6 +110,12 @@ class FilesPluginTest extends TestCase {
$this->request,
$this->previewManager
);
+
+ $response = $this->getMockBuilder(ResponseInterface::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->server->httpResponse = $response;
+
$this->plugin->initialize($this->server);
}
@@ -140,13 +149,15 @@ class FilesPluginTest extends TestCase {
$node->expects($this->any())
->method('getDavPermissions')
->will($this->returnValue('DWCKMSR'));
+
+ $fileInfo = $this->createMock(FileInfo::class);
+ $fileInfo->expects($this->any())
+ ->method('isReadable')
+ ->willReturn(true);
+
$node->expects($this->any())
->method('getFileInfo')
- ->will($this->returnValue(
- $this->getMockBuilder('\OCP\Files\FileInfo')
- ->disableOriginalConstructor()
- ->getMock()
- ));
+ ->willReturn($fileInfo);
return $node;
}
@@ -305,6 +316,15 @@ class FilesPluginTest extends TestCase {
->getMock();
$node->expects($this->any())->method('getPath')->willReturn('/');
+ $fileInfo = $this->createMock(FileInfo::class);
+ $fileInfo->expects($this->any())
+ ->method('isReadable')
+ ->willReturn(true);
+
+ $node->expects($this->any())
+ ->method('getFileInfo')
+ ->willReturn($fileInfo);
+
$propFind = new PropFind(
'/',
[
@@ -321,6 +341,39 @@ class FilesPluginTest extends TestCase {
$this->assertEquals('my_fingerprint', $propFind->get(self::DATA_FINGERPRINT_PROPERTYNAME));
}
+ /**
+ * @expectedException \Sabre\DAV\Exception\NotFound
+ */
+ public function testGetPropertiesWhenNoPermission() {
+ /** @var \OCA\DAV\Connector\Sabre\Directory | \PHPUnit_Framework_MockObject_MockObject $node */
+ $node = $this->getMockBuilder('\OCA\DAV\Connector\Sabre\Directory')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $node->expects($this->any())->method('getPath')->willReturn('/');
+
+ $fileInfo = $this->createMock(FileInfo::class);
+ $fileInfo->expects($this->any())
+ ->method('isReadable')
+ ->willReturn(false);
+
+ $node->expects($this->any())
+ ->method('getFileInfo')
+ ->willReturn($fileInfo);
+
+ $propFind = new PropFind(
+ '/test',
+ [
+ self::DATA_FINGERPRINT_PROPERTYNAME,
+ ],
+ 0
+ );
+
+ $this->plugin->handleGetProperties(
+ $propFind,
+ $node
+ );
+ }
+
public function testUpdateProps() {
$node = $this->createTestNode('\OCA\DAV\Connector\Sabre\File');
@@ -535,4 +588,59 @@ class FilesPluginTest extends TestCase {
$this->assertEquals("false", $propFind->get(self::HAS_PREVIEW_PROPERTYNAME));
}
+
+ public function testBeforeMoveFutureFileSkip() {
+ $node = $this->createMock(Directory::class);
+
+ $this->tree->expects($this->any())
+ ->method('getNodeForPath')
+ ->with('source')
+ ->will($this->returnValue($node));
+ $this->server->httpResponse->expects($this->never())
+ ->method('setStatus');
+
+ $this->assertNull($this->plugin->beforeMoveFutureFile('source', 'target'));
+ }
+
+ public function testBeforeMoveFutureFileSkipNonExisting() {
+ $sourceNode = $this->createMock(FutureFile::class);
+
+ $this->tree->expects($this->any())
+ ->method('getNodeForPath')
+ ->with('source')
+ ->will($this->returnValue($sourceNode));
+ $this->tree->expects($this->any())
+ ->method('nodeExists')
+ ->with('target')
+ ->will($this->returnValue(false));
+ $this->server->httpResponse->expects($this->never())
+ ->method('setStatus');
+
+ $this->assertNull($this->plugin->beforeMoveFutureFile('source', 'target'));
+ }
+
+ public function testBeforeMoveFutureFileMoveIt() {
+ $sourceNode = $this->createMock(FutureFile::class);
+
+ $this->tree->expects($this->any())
+ ->method('getNodeForPath')
+ ->with('source')
+ ->will($this->returnValue($sourceNode));
+ $this->tree->expects($this->any())
+ ->method('nodeExists')
+ ->with('target')
+ ->will($this->returnValue(true));
+ $this->tree->expects($this->once())
+ ->method('move')
+ ->with('source', 'target');
+
+ $this->server->httpResponse->expects($this->once())
+ ->method('setHeader')
+ ->with('Content-Length', '0');
+ $this->server->httpResponse->expects($this->once())
+ ->method('setStatus')
+ ->with(204);
+
+ $this->assertFalse($this->plugin->beforeMoveFutureFile('source', 'target'));
+ }
}