[Pkg-owncloud-commits] [php-sabredav] 56/80: Triggering COPY events in the right order.
David Prévot
taffit at moszumanska.debian.org
Thu Jan 7 02:56:34 UTC 2016
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository php-sabredav.
commit 6f7dfce310f3a873a71bcbddda5e1ec6740dc313
Author: Evert Pot <me at evertpot.com>
Date: Mon Jan 4 23:00:01 2016 -0500
Triggering COPY events in the right order.
Also rewrote the unittests to be more modern.
Fixes #721
---
lib/DAV/CorePlugin.php | 4 +-
tests/Sabre/DAV/CopyTest.php | 37 ------
tests/Sabre/DAV/HttpCopyTest.php | 199 +++++++++++++++++++++++++++++++
tests/Sabre/DAV/HttpMoveTest.php | 16 +--
tests/Sabre/DAV/ServerCopyMoveTest.php | 209 ---------------------------------
5 files changed, 209 insertions(+), 256 deletions(-)
diff --git a/lib/DAV/CorePlugin.php b/lib/DAV/CorePlugin.php
index 69361cf..70fd701 100644
--- a/lib/DAV/CorePlugin.php
+++ b/lib/DAV/CorePlugin.php
@@ -675,12 +675,12 @@ class CorePlugin extends ServerPlugin {
$copyInfo = $this->server->getCopyAndMoveInfo($request);
+ if (!$this->server->emit('beforeBind', [$copyInfo['destination']])) return false;
if ($copyInfo['destinationExists']) {
if (!$this->server->emit('beforeUnbind', [$copyInfo['destination']])) return false;
$this->server->tree->delete($copyInfo['destination']);
-
}
- if (!$this->server->emit('beforeBind', [$copyInfo['destination']])) return false;
+
$this->server->tree->copy($path, $copyInfo['destination']);
$this->server->emit('afterBind', [$copyInfo['destination']]);
diff --git a/tests/Sabre/DAV/CopyTest.php b/tests/Sabre/DAV/CopyTest.php
deleted file mode 100644
index 56d2529..0000000
--- a/tests/Sabre/DAV/CopyTest.php
+++ /dev/null
@@ -1,37 +0,0 @@
-<?php
-
-namespace Sabre\DAV;
-
-use Sabre\HTTP;
-
-class CopyTest extends \PHPUnit_Framework_TestCase {
-
- public function setUp() {
-
- \Sabre\TestUtil::clearTempDir();
-
- }
-
- /**
- * This test makes sure that a path like /foo cannot be copied into a path
- * like /foo/bar/
- *
- * @expectedException \Sabre\DAV\Exception\Conflict
- */
- public function testCopyIntoSubPath() {
-
- $dir = new FS\Directory(SABRE_TEMPDIR);
- $server = new Server($dir);
-
- $dir->createDirectory('foo');
-
- $request = new HTTP\Request('COPY','/foo', [
- 'Destination' => '/foo/bar',
- ]);
- $response = new HTTP\ResponseMock();
-
- $server->invokeMethod($request, $response);
-
- }
-
-}
diff --git a/tests/Sabre/DAV/HttpCopyTest.php b/tests/Sabre/DAV/HttpCopyTest.php
new file mode 100644
index 0000000..b5e6436
--- /dev/null
+++ b/tests/Sabre/DAV/HttpCopyTest.php
@@ -0,0 +1,199 @@
+<?php
+
+namespace Sabre\DAV;
+
+use Sabre\DAVServerTest;
+use Sabre\HTTP;
+
+/**
+ * Tests related to the COPY request.
+ *
+ * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
+ * @author Evert Pot (http://evertpot.com/)
+ * @license http://sabre.io/license/ Modified BSD License
+ */
+class HttpCopyTest extends DAVServerTest {
+
+ /**
+ * Sets up the DAV tree.
+ *
+ * @return void
+ */
+ function setUpTree() {
+
+ $this->tree = new Mock\Collection('root', [
+ 'file1' => 'content1',
+ 'file2' => 'content2',
+ 'coll1' => [
+ 'file3' => 'content3',
+ 'file4' => 'content4',
+ ]
+ ]);
+
+ }
+
+ function testCopyFile() {
+
+ $request = new HTTP\Request('COPY', '/file1', [
+ 'Destination' => '/file5'
+ ]);
+ $response = $this->request($request);
+ $this->assertEquals(201, $response->getStatus());
+ $this->assertEquals('content1', $this->tree->getChild('file5')->get());
+
+ }
+
+ function testCopyFileToSelf() {
+
+ $request = new HTTP\Request('COPY', '/file1', [
+ 'Destination' => '/file1'
+ ]);
+ $response = $this->request($request);
+ $this->assertEquals(403, $response->getStatus());
+
+ }
+
+ function testCopyFileToExisting() {
+
+ $request = new HTTP\Request('COPY', '/file1', [
+ 'Destination' => '/file2'
+ ]);
+ $response = $this->request($request);
+ $this->assertEquals(204, $response->getStatus());
+ $this->assertEquals('content1', $this->tree->getChild('file2')->get());
+
+ }
+
+ function testCopyFileToExistingOverwriteT() {
+
+ $request = new HTTP\Request('COPY', '/file1', [
+ 'Destination' => '/file2',
+ 'Overwrite' => 'T',
+ ]);
+ $response = $this->request($request);
+ $this->assertEquals(204, $response->getStatus());
+ $this->assertEquals('content1', $this->tree->getChild('file2')->get());
+
+ }
+
+ function testCopyFileToExistingOverwriteBadValue() {
+
+ $request = new HTTP\Request('COPY', '/file1', [
+ 'Destination' => '/file2',
+ 'Overwrite' => 'B',
+ ]);
+ $response = $this->request($request);
+ $this->assertEquals(400, $response->getStatus());
+
+ }
+
+ function testCopyFileNonExistantParent() {
+
+ $request = new HTTP\Request('COPY', '/file1', [
+ 'Destination' => '/notfound/file2',
+ ]);
+ $response = $this->request($request);
+ $this->assertEquals(409, $response->getStatus());
+
+ }
+
+ function testCopyFileToExistingOverwriteF() {
+
+ $request = new HTTP\Request('COPY', '/file1', [
+ 'Destination' => '/file2',
+ 'Overwrite' => 'F',
+ ]);
+ $response = $this->request($request);
+ $this->assertEquals(412, $response->getStatus());
+ $this->assertEquals('content2', $this->tree->getChild('file2')->get());
+
+ }
+
+ function testCopyFileToExistinBlockedCreateDestination() {
+
+ $this->server->on('beforeBind', function($path) {
+
+ if ($path === 'file2') {
+ return false;
+ }
+
+ });
+ $request = new HTTP\Request('COPY', '/file1', [
+ 'Destination' => '/file2',
+ 'Overwrite' => 'T',
+ ]);
+ $response = $this->request($request);
+
+ // This checks if the destination file is intact.
+ $this->assertEquals('content2', $this->tree->getChild('file2')->get());
+
+ }
+
+ function testCopyColl() {
+
+ $request = new HTTP\Request('COPY', '/coll1', [
+ 'Destination' => '/coll2'
+ ]);
+ $response = $this->request($request);
+ $this->assertEquals(201, $response->getStatus());
+ $this->assertEquals('content3', $this->tree->getChild('coll2')->getChild('file3')->get());
+
+ }
+
+ function testCopyCollToSelf() {
+
+ $request = new HTTP\Request('COPY', '/coll1', [
+ 'Destination' => '/coll1'
+ ]);
+ $response = $this->request($request);
+ $this->assertEquals(403, $response->getStatus());
+
+ }
+
+ function testCopyCollToExisting() {
+
+ $request = new HTTP\Request('COPY', '/coll1', [
+ 'Destination' => '/file2'
+ ]);
+ $response = $this->request($request);
+ $this->assertEquals(204, $response->getStatus());
+ $this->assertEquals('content3', $this->tree->getChild('file2')->getChild('file3')->get());
+
+ }
+
+ function testCopyCollToExistingOverwriteT() {
+
+ $request = new HTTP\Request('COPY', '/coll1', [
+ 'Destination' => '/file2',
+ 'Overwrite' => 'T',
+ ]);
+ $response = $this->request($request);
+ $this->assertEquals(204, $response->getStatus());
+ $this->assertEquals('content3', $this->tree->getChild('file2')->getChild('file3')->get());
+
+ }
+
+ function testCopyCollToExistingOverwriteF() {
+
+ $request = new HTTP\Request('COPY', '/coll1', [
+ 'Destination' => '/file2',
+ 'Overwrite' => 'F',
+ ]);
+ $response = $this->request($request);
+ $this->assertEquals(412, $response->getStatus());
+ $this->assertEquals('content2', $this->tree->getChild('file2')->get());
+
+ }
+
+ function testCopyCollIntoSubtree() {
+
+ $request = new HTTP\Request('COPY', '/coll1', [
+ 'Destination' => '/coll1/subcol',
+ ]);
+ $response = $this->request($request);
+ $this->assertEquals(409, $response->getStatus());
+
+ }
+
+
+}
diff --git a/tests/Sabre/DAV/HttpMoveTest.php b/tests/Sabre/DAV/HttpMoveTest.php
index fd78b87..52f7c67 100644
--- a/tests/Sabre/DAV/HttpMoveTest.php
+++ b/tests/Sabre/DAV/HttpMoveTest.php
@@ -45,7 +45,7 @@ class HttpMoveTest extends DAVServerTest {
'Destination' => '/file3'
]);
$response = $this->request($request);
- $this->assertEquals(201, $response->getStatus(), print_r($response,true));
+ $this->assertEquals(201, $response->getStatus(), print_r($response, true));
$this->assertEquals('content1', $this->tree->getChild('file3')->get());
$this->assertFalse($this->tree->childExists('file1'));
@@ -57,7 +57,7 @@ class HttpMoveTest extends DAVServerTest {
'Destination' => '/file2'
]);
$response = $this->request($request);
- $this->assertEquals(204, $response->getStatus(), print_r($response,true));
+ $this->assertEquals(204, $response->getStatus(), print_r($response, true));
$this->assertEquals('content1', $this->tree->getChild('file2')->get());
$this->assertFalse($this->tree->childExists('file1'));
@@ -67,10 +67,10 @@ class HttpMoveTest extends DAVServerTest {
$request = new HTTP\Request('MOVE', '/file1', [
'Destination' => '/file2',
- 'Overwrite' => 'T',
+ 'Overwrite' => 'T',
]);
$response = $this->request($request);
- $this->assertEquals(204, $response->getStatus(), print_r($response,true));
+ $this->assertEquals(204, $response->getStatus(), print_r($response, true));
$this->assertEquals('content1', $this->tree->getChild('file2')->get());
$this->assertFalse($this->tree->childExists('file1'));
@@ -80,10 +80,10 @@ class HttpMoveTest extends DAVServerTest {
$request = new HTTP\Request('MOVE', '/file1', [
'Destination' => '/file2',
- 'Overwrite' => 'F',
+ 'Overwrite' => 'F',
]);
$response = $this->request($request);
- $this->assertEquals(412, $response->getStatus(), print_r($response,true));
+ $this->assertEquals(412, $response->getStatus(), print_r($response, true));
$this->assertEquals('content1', $this->tree->getChild('file1')->get());
$this->assertEquals('content2', $this->tree->getChild('file2')->get());
$this->assertTrue($this->tree->childExists('file1'));
@@ -100,7 +100,7 @@ class HttpMoveTest extends DAVServerTest {
$this->server->on('beforeUnbind', function($path) {
- if ($path==='file1') {
+ if ($path === 'file1') {
throw new \Sabre\DAV\Exception\Forbidden('uh oh');
}
@@ -109,7 +109,7 @@ class HttpMoveTest extends DAVServerTest {
'Destination' => '/file2'
]);
$response = $this->request($request);
- $this->assertEquals(403, $response->getStatus(), print_r($response,true));
+ $this->assertEquals(403, $response->getStatus(), print_r($response, true));
$this->assertEquals('content1', $this->tree->getChild('file1')->get());
$this->assertEquals('content2', $this->tree->getChild('file2')->get());
$this->assertTrue($this->tree->childExists('file1'));
diff --git a/tests/Sabre/DAV/ServerCopyMoveTest.php b/tests/Sabre/DAV/ServerCopyMoveTest.php
deleted file mode 100644
index 423bc66..0000000
--- a/tests/Sabre/DAV/ServerCopyMoveTest.php
+++ /dev/null
@@ -1,209 +0,0 @@
-<?php
-
-namespace Sabre\DAV;
-
-use Sabre\HTTP;
-
-require_once 'Sabre/HTTP/ResponseMock.php';
-
-class ServerCopyMoveTest extends \PHPUnit_Framework_TestCase {
-
- private $response;
- /**
- * @var Server
- */
- private $server;
-
- function setUp() {
-
- $this->response = new HTTP\ResponseMock();
- $dir = new FS\Directory(SABRE_TEMPDIR);
- $tree = new Tree($dir);
- $this->server = new Server($tree);
- $this->server->sapi = new HTTP\SapiMock();
- $this->server->debugExceptions = true;
- $this->server->httpResponse = $this->response;
- file_put_contents(SABRE_TEMPDIR . '/test.txt', 'Test contents');
- file_put_contents(SABRE_TEMPDIR . '/test2.txt', 'Test contents2');
- mkdir(SABRE_TEMPDIR . '/col');
- file_put_contents(SABRE_TEMPDIR . 'col/test.txt', 'Test contents');
-
- }
-
- function tearDown() {
-
- $cleanUp = array('test.txt','testput.txt','testcol','test2.txt','test3.txt','col/test.txt','col','col2/test.txt','col2');
- foreach($cleanUp as $file) {
- $tmpFile = SABRE_TEMPDIR . '/' . $file;
- if (file_exists($tmpFile)) {
-
- if (is_dir($tmpFile)) {
- rmdir($tmpFile);
- } else {
- unlink($tmpFile);
- }
-
- }
- }
-
- }
-
-
- function testCopyOverWrite() {
-
- $serverVars = array(
- 'REQUEST_URI' => '/test.txt',
- 'REQUEST_METHOD' => 'COPY',
- 'HTTP_DESTINATION' => '/test2.txt',
- );
-
- $request = HTTP\Sapi::createFromServerArray($serverVars);
- $this->server->httpRequest = ($request);
- $this->server->exec();
-
- $this->assertEquals(204, $this->response->status, 'Received an incorrect HTTP status. Full body inspection: ' . $this->response->body);
- $this->assertEquals(array(
- 'X-Sabre-Version' => [Version::VERSION],
- 'Content-Length' => ['0'],
- ),
- $this->response->getHeaders()
- );
-
- $this->assertEquals('Test contents', file_get_contents(SABRE_TEMPDIR. '/test2.txt'));
-
- }
-
- function testCopyToSelf() {
-
- $serverVars = array(
- 'REQUEST_URI' => '/test.txt',
- 'REQUEST_METHOD' => 'COPY',
- 'HTTP_DESTINATION' => '/test.txt',
- );
-
- $request = HTTP\Sapi::createFromServerArray($serverVars);
- $this->server->httpRequest = ($request);
- $this->server->exec();
-
- $this->assertEquals(403, $this->response->status, 'Received an incorrect HTTP status. Full body inspection: ' . $this->response->body);
- $this->assertEquals('Test contents', file_get_contents(SABRE_TEMPDIR. '/test.txt'));
-
- }
-
- function testNonExistantParent() {
-
- $serverVars = array(
- 'REQUEST_URI' => '/test.txt',
- 'REQUEST_METHOD' => 'COPY',
- 'HTTP_DESTINATION' => '/testcol2/test2.txt',
- 'HTTP_OVERWRITE' => 'F',
- );
-
- $request = HTTP\Sapi::createFromServerArray($serverVars);
- $this->server->httpRequest = ($request);
- $this->server->exec();
-
- $this->assertEquals(array(
- 'X-Sabre-Version' => [Version::VERSION],
- 'Content-Type' => ['application/xml; charset=utf-8'],
- ),
- $this->response->getHeaders()
- );
-
- $this->assertEquals(409, $this->response->status);
-
- }
-
- function testRandomOverwriteHeader() {
-
- $serverVars = array(
- 'REQUEST_URI' => '/test.txt',
- 'REQUEST_METHOD' => 'COPY',
- 'HTTP_DESTINATION' => '/testcol2/test2.txt',
- 'HTTP_OVERWRITE' => 'SURE!',
- );
-
- $request = HTTP\Sapi::createFromServerArray($serverVars);
- $this->server->httpRequest = ($request);
- $this->server->exec();
-
- $this->assertEquals(400, $this->response->status);
-
- }
-
- function testCopyDirectory() {
-
- $serverVars = array(
- 'REQUEST_URI' => '/col',
- 'REQUEST_METHOD' => 'COPY',
- 'HTTP_DESTINATION' => '/col2',
- );
-
- $request = HTTP\Sapi::createFromServerArray($serverVars);
- $this->server->httpRequest = ($request);
- $this->server->exec();
-
- $this->assertEquals(201, $this->response->status, 'Full response: ' . $this->response->getBodyAsString());
-
- $this->assertEquals(array(
- 'X-Sabre-Version' => [Version::VERSION],
- 'Content-Length' => ['0'],
- ),
- $this->response->getHeaders()
- );
-
- $this->assertEquals('Test contents',file_get_contents(SABRE_TEMPDIR . '/col2/test.txt'));
-
- }
-
- function testSimpleCopyFile() {
-
- $serverVars = array(
- 'REQUEST_URI' => '/test.txt',
- 'REQUEST_METHOD' => 'COPY',
- 'HTTP_DESTINATION' => '/test3.txt',
- );
-
- $request = HTTP\Sapi::createFromServerArray($serverVars);
- $this->server->httpRequest = ($request);
- $this->server->exec();
-
- $this->assertEquals(array(
- 'X-Sabre-Version' => [Version::VERSION],
- 'Content-Length' => ['0'],
- ),
- $this->response->getHeaders()
- );
-
- $this->assertEquals(201, $this->response->status);
- $this->assertEquals('Test contents', file_get_contents(SABRE_TEMPDIR . '/test3.txt'));
-
- }
-
- function testSimpleCopyCollection() {
-
- $serverVars = array(
- 'REQUEST_URI' => '/col',
- 'REQUEST_METHOD' => 'COPY',
- 'HTTP_DESTINATION' => '/col2',
- );
-
- $request = HTTP\Sapi::createFromServerArray($serverVars);
- $this->server->httpRequest = ($request);
- $this->server->exec();
-
- $this->assertEquals(201, $this->response->status, 'Incorrect status received. Full response body: ' . $this->response->body);
-
- $this->assertEquals(array(
- 'X-Sabre-Version' => [Version::VERSION],
- 'Content-Length' => ['0'],
- ),
- $this->response->getHeaders()
- );
-
-
- $this->assertEquals('Test contents',file_get_contents(SABRE_TEMPDIR . '/col2/test.txt'));
-
- }
-
-}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabredav.git
More information about the Pkg-owncloud-commits
mailing list