summaryrefslogtreecommitdiffstats
path: root/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2017-03-30 11:30:37 +0200
committerJoas Schilling <coding@schilljs.com>2017-04-26 15:46:38 +0200
commit7b6e4d0dd2dce40fcc7da9de2b7e49b26dfe1914 (patch)
tree84a9055b4904ce08acaff40bc5a0d6d481635676 /apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php
parentec8d7010e54138f87a5c17216b6863188db136a4 (diff)
downloadnextcloud-server-7b6e4d0dd2dce40fcc7da9de2b7e49b26dfe1914.tar.gz
nextcloud-server-7b6e4d0dd2dce40fcc7da9de2b7e49b26dfe1914.zip
Fix FutureFile MOVE to keep destination node
Sabre usually deletes the target node on MOVE before proceeding with the actual move operation. This fix prevents this to happen in case the source node is a FutureFile.
Diffstat (limited to 'apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php')
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php63
1 files changed, 63 insertions, 0 deletions
diff --git a/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php
index 1c9ebdd09b6..e0dea49c49b 100644
--- a/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php
@@ -32,6 +32,8 @@ 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;
/**
* Copyright (c) 2015 Vincent Petry <pvince81@owncloud.com>
@@ -107,6 +109,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);
}
@@ -535,4 +543,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'));
+ }
}