1<?php
2
3namespace Sabre\DAV;
4
5use Sabre\DAVServerTest;
6use Sabre\HTTP;
7
8/**
9 * Tests related to the PUT request.
10 *
11 * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/).
12 * @author Evert Pot (http://evertpot.com/)
13 * @license http://sabre.io/license/ Modified BSD License
14 */
15class HttpDeleteTest extends DAVServerTest {
16
17    /**
18     * Sets up the DAV tree.
19     *
20     * @return void
21     */
22    public function setUpTree() {
23
24        $this->tree = new Mock\Collection('root', [
25            'file1' => 'foo',
26            'dir' => [
27                'subfile' => 'bar',
28                'subfile2' => 'baz',
29            ],
30        ]);
31
32    }
33
34    /**
35     * A successful DELETE
36     */
37    public function testDelete() {
38
39        $request = new HTTP\Request('DELETE', '/file1');
40
41        $response = $this->request($request);
42
43        $this->assertEquals(
44            204,
45            $response->getStatus(),
46            "Incorrect status code. Response body:  " . $response->getBodyAsString()
47        );
48
49        $this->assertEquals(
50            [
51                'X-Sabre-Version' => [Version::VERSION],
52                'Content-Length' => ['0'],
53            ],
54            $response->getHeaders()
55        );
56
57    }
58
59    /**
60     * Deleting a Directory
61     */
62    public function testDeleteDirectory() {
63
64        $request = new HTTP\Request('DELETE', '/dir');
65
66        $response = $this->request($request);
67
68        $this->assertEquals(
69            204,
70            $response->getStatus(),
71            "Incorrect status code. Response body:  " . $response->getBodyAsString()
72        );
73
74        $this->assertEquals(
75            [
76                'X-Sabre-Version' => [Version::VERSION],
77                'Content-Length' => ['0'],
78            ],
79            $response->getHeaders()
80        );
81
82    }
83
84    /**
85     * DELETE on a node that does not exist
86     */
87    public function testDeleteNotFound() {
88
89        $request = new HTTP\Request('DELETE', '/file2');
90        $response = $this->request($request);
91
92        $this->assertEquals(
93            404,
94            $response->getStatus(),
95            "Incorrect status code. Response body:  " . $response->getBodyAsString()
96        );
97
98    }
99
100    /**
101     * DELETE with preconditions
102     */
103    public function testDeletePreconditions() {
104
105        $request = new HTTP\Request('DELETE', '/file1', [
106            'If-Match' => '"' . md5('foo') . '"',
107        ]);
108
109        $response = $this->request($request);
110
111        $this->assertEquals(
112            204,
113            $response->getStatus(),
114            "Incorrect status code. Response body:  " . $response->getBodyAsString()
115        );
116
117    }
118
119    /**
120     * DELETE with incorrect preconditions
121     */
122    public function testDeletePreconditionsFailed() {
123
124        $request = new HTTP\Request('DELETE', '/file1', [
125            'If-Match' => '"' . md5('bar') . '"',
126        ]);
127
128        $response = $this->request($request);
129
130        $this->assertEquals(
131            412,
132            $response->getStatus(),
133            "Incorrect status code. Response body:  " . $response->getBodyAsString()
134        );
135
136    }
137}
138