ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
HttpCopyTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Sabre\DAV;
4 
6 use Sabre\HTTP;
7 
15 class HttpCopyTest extends DAVServerTest {
16 
22  function setUpTree() {
23 
24  $this->tree = new Mock\Collection('root', [
25  'file1' => 'content1',
26  'file2' => 'content2',
27  'coll1' => [
28  'file3' => 'content3',
29  'file4' => 'content4',
30  ]
31  ]);
32 
33  }
34 
35  function testCopyFile() {
36 
37  $request = new HTTP\Request('COPY', '/file1', [
38  'Destination' => '/file5'
39  ]);
40  $response = $this->request($request);
41  $this->assertEquals(201, $response->getStatus());
42  $this->assertEquals('content1', $this->tree->getChild('file5')->get());
43 
44  }
45 
46  function testCopyFileToSelf() {
47 
48  $request = new HTTP\Request('COPY', '/file1', [
49  'Destination' => '/file1'
50  ]);
51  $response = $this->request($request);
52  $this->assertEquals(403, $response->getStatus());
53 
54  }
55 
57 
58  $request = new HTTP\Request('COPY', '/file1', [
59  'Destination' => '/file2'
60  ]);
61  $response = $this->request($request);
62  $this->assertEquals(204, $response->getStatus());
63  $this->assertEquals('content1', $this->tree->getChild('file2')->get());
64 
65  }
66 
68 
69  $request = new HTTP\Request('COPY', '/file1', [
70  'Destination' => '/file2',
71  'Overwrite' => 'T',
72  ]);
73  $response = $this->request($request);
74  $this->assertEquals(204, $response->getStatus());
75  $this->assertEquals('content1', $this->tree->getChild('file2')->get());
76 
77  }
78 
80 
81  $request = new HTTP\Request('COPY', '/file1', [
82  'Destination' => '/file2',
83  'Overwrite' => 'B',
84  ]);
85  $response = $this->request($request);
86  $this->assertEquals(400, $response->getStatus());
87 
88  }
89 
91 
92  $request = new HTTP\Request('COPY', '/file1', [
93  'Destination' => '/notfound/file2',
94  ]);
95  $response = $this->request($request);
96  $this->assertEquals(409, $response->getStatus());
97 
98  }
99 
101 
102  $request = new HTTP\Request('COPY', '/file1', [
103  'Destination' => '/file2',
104  'Overwrite' => 'F',
105  ]);
106  $response = $this->request($request);
107  $this->assertEquals(412, $response->getStatus());
108  $this->assertEquals('content2', $this->tree->getChild('file2')->get());
109 
110  }
111 
113 
114  $this->server->on('beforeBind', function($path) {
115 
116  if ($path === 'file2') {
117  return false;
118  }
119 
120  });
121  $request = new HTTP\Request('COPY', '/file1', [
122  'Destination' => '/file2',
123  'Overwrite' => 'T',
124  ]);
125  $response = $this->request($request);
126 
127  // This checks if the destination file is intact.
128  $this->assertEquals('content2', $this->tree->getChild('file2')->get());
129 
130  }
131 
132  function testCopyColl() {
133 
134  $request = new HTTP\Request('COPY', '/coll1', [
135  'Destination' => '/coll2'
136  ]);
137  $response = $this->request($request);
138  $this->assertEquals(201, $response->getStatus());
139  $this->assertEquals('content3', $this->tree->getChild('coll2')->getChild('file3')->get());
140 
141  }
142 
143  function testCopyCollToSelf() {
144 
145  $request = new HTTP\Request('COPY', '/coll1', [
146  'Destination' => '/coll1'
147  ]);
148  $response = $this->request($request);
149  $this->assertEquals(403, $response->getStatus());
150 
151  }
152 
154 
155  $request = new HTTP\Request('COPY', '/coll1', [
156  'Destination' => '/file2'
157  ]);
158  $response = $this->request($request);
159  $this->assertEquals(204, $response->getStatus());
160  $this->assertEquals('content3', $this->tree->getChild('file2')->getChild('file3')->get());
161 
162  }
163 
165 
166  $request = new HTTP\Request('COPY', '/coll1', [
167  'Destination' => '/file2',
168  'Overwrite' => 'T',
169  ]);
170  $response = $this->request($request);
171  $this->assertEquals(204, $response->getStatus());
172  $this->assertEquals('content3', $this->tree->getChild('file2')->getChild('file3')->get());
173 
174  }
175 
177 
178  $request = new HTTP\Request('COPY', '/coll1', [
179  'Destination' => '/file2',
180  'Overwrite' => 'F',
181  ]);
182  $response = $this->request($request);
183  $this->assertEquals(412, $response->getStatus());
184  $this->assertEquals('content2', $this->tree->getChild('file2')->get());
185 
186  }
187 
189 
190  $request = new HTTP\Request('COPY', '/coll1', [
191  'Destination' => '/coll1/subcol',
192  ]);
193  $response = $this->request($request);
194  $this->assertEquals(409, $response->getStatus());
195 
196  }
197 
198 
199 }
$path
Definition: aliased.php:25
setUpTree()
Sets up the DAV tree.
foreach($paths as $path) $request
Definition: asyncclient.php:32
testCopyFileToExistinBlockedCreateDestination()
Collection class.
Definition: Collection.php:15
This class may be used as a basis for other webdav-related unittests.
Tests related to the COPY request.
request($request, $expectedStatus=null)
Makes a request, and returns a response object.
$response