2014-06-28 20:28:08 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Sabre\DAV;
|
|
|
|
|
|
|
|
use Sabre\DAVServerTest;
|
|
|
|
use Sabre\HTTP;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests related to the PUT request.
|
|
|
|
*
|
2016-05-11 00:26:44 +00:00
|
|
|
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
|
2014-06-28 20:28:08 +00:00
|
|
|
* @author Evert Pot (http://evertpot.com/)
|
|
|
|
* @license http://sabre.io/license/ Modified BSD License
|
|
|
|
*/
|
|
|
|
class HttpDeleteTest extends DAVServerTest {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets up the DAV tree.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setUpTree() {
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->tree = new Mock\Collection('root', [
|
2014-06-28 20:28:08 +00:00
|
|
|
'file1' => 'foo',
|
2016-05-11 00:26:44 +00:00
|
|
|
'dir' => [
|
2014-06-28 20:28:08 +00:00
|
|
|
'subfile' => 'bar',
|
|
|
|
'subfile2' => 'baz',
|
2016-05-11 00:26:44 +00:00
|
|
|
],
|
|
|
|
]);
|
2014-06-28 20:28:08 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A successful DELETE
|
|
|
|
*/
|
|
|
|
public function testDelete() {
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$request = new HTTP\Request('DELETE', '/file1');
|
2014-06-28 20:28:08 +00:00
|
|
|
|
|
|
|
$response = $this->request($request);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
2016-05-11 00:26:44 +00:00
|
|
|
204,
|
|
|
|
$response->getStatus(),
|
|
|
|
"Incorrect status code. Response body: " . $response->getBodyAsString()
|
2014-06-28 20:28:08 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
2016-05-11 00:26:44 +00:00
|
|
|
[
|
|
|
|
'X-Sabre-Version' => [Version::VERSION],
|
|
|
|
'Content-Length' => ['0'],
|
|
|
|
],
|
|
|
|
$response->getHeaders()
|
2014-06-28 20:28:08 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deleting a Directory
|
|
|
|
*/
|
|
|
|
public function testDeleteDirectory() {
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$request = new HTTP\Request('DELETE', '/dir');
|
2014-06-28 20:28:08 +00:00
|
|
|
|
|
|
|
$response = $this->request($request);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
2016-05-11 00:26:44 +00:00
|
|
|
204,
|
|
|
|
$response->getStatus(),
|
|
|
|
"Incorrect status code. Response body: " . $response->getBodyAsString()
|
2014-06-28 20:28:08 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
2016-05-11 00:26:44 +00:00
|
|
|
[
|
|
|
|
'X-Sabre-Version' => [Version::VERSION],
|
|
|
|
'Content-Length' => ['0'],
|
|
|
|
],
|
|
|
|
$response->getHeaders()
|
2014-06-28 20:28:08 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DELETE on a node that does not exist
|
|
|
|
*/
|
|
|
|
public function testDeleteNotFound() {
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$request = new HTTP\Request('DELETE', '/file2');
|
2014-06-28 20:28:08 +00:00
|
|
|
$response = $this->request($request);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
2016-05-11 00:26:44 +00:00
|
|
|
404,
|
|
|
|
$response->getStatus(),
|
|
|
|
"Incorrect status code. Response body: " . $response->getBodyAsString()
|
2014-06-28 20:28:08 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DELETE with preconditions
|
|
|
|
*/
|
|
|
|
public function testDeletePreconditions() {
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$request = new HTTP\Request('DELETE', '/file1', [
|
|
|
|
'If-Match' => '"' . md5('foo') . '"',
|
|
|
|
]);
|
2014-06-28 20:28:08 +00:00
|
|
|
|
|
|
|
$response = $this->request($request);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
2016-05-11 00:26:44 +00:00
|
|
|
204,
|
|
|
|
$response->getStatus(),
|
|
|
|
"Incorrect status code. Response body: " . $response->getBodyAsString()
|
2014-06-28 20:28:08 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DELETE with incorrect preconditions
|
|
|
|
*/
|
|
|
|
public function testDeletePreconditionsFailed() {
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$request = new HTTP\Request('DELETE', '/file1', [
|
|
|
|
'If-Match' => '"' . md5('bar') . '"',
|
|
|
|
]);
|
2014-06-28 20:28:08 +00:00
|
|
|
|
|
|
|
$response = $this->request($request);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
2016-05-11 00:26:44 +00:00
|
|
|
412,
|
|
|
|
$response->getStatus(),
|
|
|
|
"Incorrect status code. Response body: " . $response->getBodyAsString()
|
2014-06-28 20:28:08 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|