|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use GuzzleHttp\Client as GClient; |
|
4
|
|
|
use GuzzleHttp\Message\ResponseInterface; |
|
5
|
|
|
use Sabre\DAV\Client as SClient; |
|
6
|
|
|
|
|
7
|
|
|
require __DIR__ . '/../../vendor/autoload.php'; |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
trait WebDav { |
|
11
|
|
|
use Sharing; |
|
12
|
|
|
|
|
13
|
|
|
/** @var string*/ |
|
14
|
|
|
private $davPath = "remote.php/webdav"; |
|
15
|
|
|
/** @var ResponseInterface */ |
|
16
|
|
|
private $response; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @Given /^using dav path "([^"]*)"$/ |
|
20
|
|
|
*/ |
|
21
|
|
|
public function usingDavPath($davPath) { |
|
22
|
|
|
$this->davPath = $davPath; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function makeDavRequest($user, $method, $path, $headers, $body = null){ |
|
26
|
|
|
$fullUrl = substr($this->baseUrl, 0, -4) . $this->davPath . "$path"; |
|
27
|
|
|
$client = new GClient(); |
|
28
|
|
|
$options = []; |
|
29
|
|
|
if ($user === 'admin') { |
|
30
|
|
|
$options['auth'] = $this->adminUser; |
|
|
|
|
|
|
31
|
|
|
} else { |
|
32
|
|
|
$options['auth'] = [$user, $this->regularUser]; |
|
|
|
|
|
|
33
|
|
|
} |
|
34
|
|
|
$request = $client->createRequest($method, $fullUrl, $options); |
|
35
|
|
|
if (!is_null($headers)){ |
|
36
|
|
|
foreach ($headers as $key => $value) { |
|
37
|
|
|
$request->addHeader($key, $value); |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
if (!is_null($body)) { |
|
42
|
|
|
$request->setBody($body); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
return $client->send($request); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @Given /^User "([^"]*)" moved file "([^"]*)" to "([^"]*)"$/ |
|
50
|
|
|
* @param string $user |
|
51
|
|
|
* @param string $fileSource |
|
52
|
|
|
* @param string $fileDestination |
|
53
|
|
|
*/ |
|
54
|
|
View Code Duplication |
public function userMovedFile($user, $fileSource, $fileDestination){ |
|
55
|
|
|
$fullUrl = substr($this->baseUrl, 0, -4) . $this->davPath; |
|
56
|
|
|
$headers['Destination'] = $fullUrl . $fileDestination; |
|
|
|
|
|
|
57
|
|
|
$this->response = $this->makeDavRequest($user, "MOVE", $fileSource, $headers); |
|
58
|
|
|
PHPUnit_Framework_Assert::assertEquals(201, $this->response->getStatusCode()); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @When /^User "([^"]*)" moves file "([^"]*)" to "([^"]*)"$/ |
|
63
|
|
|
* @param string $user |
|
64
|
|
|
* @param string $fileSource |
|
65
|
|
|
* @param string $fileDestination |
|
66
|
|
|
*/ |
|
67
|
|
View Code Duplication |
public function userMovesFile($user, $fileSource, $fileDestination){ |
|
68
|
|
|
$fullUrl = substr($this->baseUrl, 0, -4) . $this->davPath; |
|
69
|
|
|
$headers['Destination'] = $fullUrl . $fileDestination; |
|
|
|
|
|
|
70
|
|
|
try { |
|
71
|
|
|
$this->response = $this->makeDavRequest($user, "MOVE", $fileSource, $headers); |
|
72
|
|
|
} catch (\GuzzleHttp\Exception\ClientException $e) { |
|
|
|
|
|
|
73
|
|
|
$this->response = $e->getResponse(); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @When /^User "([^"]*)" copies file "([^"]*)" to "([^"]*)"$/ |
|
79
|
|
|
* @param string $user |
|
80
|
|
|
* @param string $fileSource |
|
81
|
|
|
* @param string $fileDestination |
|
82
|
|
|
*/ |
|
83
|
|
View Code Duplication |
public function userCopiesFile($user, $fileSource, $fileDestination){ |
|
84
|
|
|
$fullUrl = substr($this->baseUrl, 0, -4) . $this->davPath; |
|
85
|
|
|
$headers['Destination'] = $fullUrl . $fileDestination; |
|
|
|
|
|
|
86
|
|
|
try { |
|
87
|
|
|
$this->response = $this->makeDavRequest($user, "COPY", $fileSource, $headers); |
|
88
|
|
|
} catch (\GuzzleHttp\Exception\ClientException $e) { |
|
|
|
|
|
|
89
|
|
|
$this->response = $e->getResponse(); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @When /^Downloading file "([^"]*)" with range "([^"]*)"$/ |
|
95
|
|
|
* @param string $fileSource |
|
96
|
|
|
* @param string $range |
|
97
|
|
|
*/ |
|
98
|
|
|
public function downloadFileWithRange($fileSource, $range){ |
|
99
|
|
|
$headers['Range'] = $range; |
|
|
|
|
|
|
100
|
|
|
$this->response = $this->makeDavRequest($this->currentUser, "GET", $fileSource, $headers); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @When /^Downloading last public shared file with range "([^"]*)"$/ |
|
105
|
|
|
* @param string $range |
|
106
|
|
|
*/ |
|
107
|
|
View Code Duplication |
public function downloadPublicFileWithRange($range){ |
|
108
|
|
|
$token = $this->lastShareData->data->token; |
|
109
|
|
|
$fullUrl = substr($this->baseUrl, 0, -4) . "public.php/webdav"; |
|
110
|
|
|
$headers['Range'] = $range; |
|
|
|
|
|
|
111
|
|
|
|
|
112
|
|
|
$client = new GClient(); |
|
113
|
|
|
$options = []; |
|
114
|
|
|
$options['auth'] = [$token, ""]; |
|
115
|
|
|
|
|
116
|
|
|
$request = $client->createRequest("GET", $fullUrl, $options); |
|
117
|
|
|
$request->addHeader('Range', $range); |
|
118
|
|
|
|
|
119
|
|
|
$this->response = $client->send($request); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @When /^Downloading last public shared file inside a folder "([^"]*)" with range "([^"]*)"$/ |
|
124
|
|
|
* @param string $range |
|
125
|
|
|
*/ |
|
126
|
|
View Code Duplication |
public function downloadPublicFileInsideAFolderWithRange($path, $range){ |
|
127
|
|
|
$token = $this->lastShareData->data->token; |
|
128
|
|
|
$fullUrl = substr($this->baseUrl, 0, -4) . "public.php/webdav" . "$path"; |
|
129
|
|
|
$headers['Range'] = $range; |
|
|
|
|
|
|
130
|
|
|
|
|
131
|
|
|
$client = new GClient(); |
|
132
|
|
|
$options = []; |
|
133
|
|
|
$options['auth'] = [$token, ""]; |
|
134
|
|
|
|
|
135
|
|
|
$request = $client->createRequest("GET", $fullUrl, $options); |
|
136
|
|
|
$request->addHeader('Range', $range); |
|
137
|
|
|
|
|
138
|
|
|
$this->response = $client->send($request); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @Then /^Downloaded content should be "([^"]*)"$/ |
|
143
|
|
|
* @param string $content |
|
144
|
|
|
*/ |
|
145
|
|
|
public function downloadedContentShouldBe($content){ |
|
146
|
|
|
PHPUnit_Framework_Assert::assertEquals($content, (string)$this->response->getBody()); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* @Then /^Downloaded content when downloading file "([^"]*)" with range "([^"]*)" should be "([^"]*)"$/ |
|
151
|
|
|
* @param string $fileSource |
|
152
|
|
|
* @param string $range |
|
153
|
|
|
* @param string $content |
|
154
|
|
|
*/ |
|
155
|
|
|
public function downloadedContentWhenDownloadindShouldBe($fileSource, $range, $content){ |
|
156
|
|
|
$this->downloadFileWithRange($fileSource, $range); |
|
157
|
|
|
$this->downloadedContentShouldBe($content); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* @When Downloading file :fileName |
|
162
|
|
|
* @param string $fileName |
|
163
|
|
|
*/ |
|
164
|
|
|
public function downloadingFile($fileName) { |
|
165
|
|
|
try { |
|
166
|
|
|
$this->response = $this->makeDavRequest($this->currentUser, 'GET', $fileName, []); |
|
167
|
|
|
} catch (\GuzzleHttp\Exception\ClientException $e) { |
|
|
|
|
|
|
168
|
|
|
$this->response = $e->getResponse(); |
|
169
|
|
|
} |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* @Then The following headers should be set |
|
174
|
|
|
* @param \Behat\Gherkin\Node\TableNode $table |
|
175
|
|
|
* @throws \Exception |
|
176
|
|
|
*/ |
|
177
|
|
|
public function theFollowingHeadersShouldBeSet(\Behat\Gherkin\Node\TableNode $table) { |
|
178
|
|
|
foreach($table->getTable() as $header) { |
|
179
|
|
|
$headerName = $header[0]; |
|
180
|
|
|
$expectedHeaderValue = $header[1]; |
|
181
|
|
|
$returnedHeader = $this->response->getHeader($headerName); |
|
182
|
|
|
if($returnedHeader !== $expectedHeaderValue) { |
|
183
|
|
|
throw new \Exception( |
|
184
|
|
|
sprintf( |
|
185
|
|
|
"Expected value '%s' for header '%s', got '%s'", |
|
186
|
|
|
$expectedHeaderValue, |
|
187
|
|
|
$headerName, |
|
188
|
|
|
$returnedHeader |
|
189
|
|
|
) |
|
190
|
|
|
); |
|
191
|
|
|
} |
|
192
|
|
|
} |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* @Then Downloaded content should start with :start |
|
197
|
|
|
* @param int $start |
|
198
|
|
|
* @throws \Exception |
|
199
|
|
|
*/ |
|
200
|
|
|
public function downloadedContentShouldStartWith($start) { |
|
201
|
|
|
if(strpos($this->response->getBody()->getContents(), $start) !== 0) { |
|
202
|
|
|
throw new \Exception( |
|
203
|
|
|
sprintf( |
|
204
|
|
|
"Expected '%s', got '%s'", |
|
205
|
|
|
$start, |
|
206
|
|
|
$this->response->getBody()->getContents() |
|
207
|
|
|
) |
|
208
|
|
|
); |
|
209
|
|
|
} |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* @Then /^as "([^"]*)" gets properties of folder "([^"]*)" with$/ |
|
214
|
|
|
* @param string $user |
|
215
|
|
|
* @param string $path |
|
216
|
|
|
* @param \Behat\Gherkin\Node\TableNode|null $propertiesTable |
|
217
|
|
|
*/ |
|
218
|
|
|
public function asGetsPropertiesOfFolderWith($user, $path, $propertiesTable) { |
|
219
|
|
|
$properties = null; |
|
220
|
|
|
if ($propertiesTable instanceof \Behat\Gherkin\Node\TableNode) { |
|
|
|
|
|
|
221
|
|
|
foreach ($propertiesTable->getRows() as $row) { |
|
222
|
|
|
$properties[] = $row[0]; |
|
223
|
|
|
} |
|
224
|
|
|
} |
|
225
|
|
|
$this->response = $this->listFolder($user, $path, 0, $properties); |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
/** |
|
229
|
|
|
* @Then the single response should contain a property :key with value :value |
|
230
|
|
|
* @param string $key |
|
231
|
|
|
* @param string $expectedValue |
|
232
|
|
|
* @throws \Exception |
|
233
|
|
|
*/ |
|
234
|
|
|
public function theSingleResponseShouldContainAPropertyWithValue($key, $expectedValue) { |
|
235
|
|
|
$keys = $this->response; |
|
236
|
|
|
if (!array_key_exists($key, $keys)) { |
|
237
|
|
|
throw new \Exception("Cannot find property \"$key\" with \"$expectedValue\""); |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
$value = $keys[$key]; |
|
241
|
|
|
if ($value != $expectedValue) { |
|
242
|
|
|
throw new \Exception("Property \"$key\" found with value \"$value\", expected \"$expectedValue\""); |
|
243
|
|
|
} |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
/** |
|
247
|
|
|
* @Then the response should contain a share-types property with |
|
248
|
|
|
*/ |
|
249
|
|
|
public function theResponseShouldContainAShareTypesPropertyWith($table) |
|
250
|
|
|
{ |
|
251
|
|
|
$keys = $this->response; |
|
252
|
|
|
if (!array_key_exists('{http://owncloud.org/ns}share-types', $keys)) { |
|
253
|
|
|
throw new \Exception("Cannot find property \"{http://owncloud.org/ns}share-types\""); |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
$foundTypes = []; |
|
257
|
|
|
$data = $keys['{http://owncloud.org/ns}share-types']; |
|
258
|
|
|
foreach ($data as $item) { |
|
259
|
|
|
if ($item['name'] !== '{http://owncloud.org/ns}share-type') { |
|
260
|
|
|
throw new \Exception('Invalid property found: "' . $item['name'] . '"'); |
|
261
|
|
|
} |
|
262
|
|
|
|
|
263
|
|
|
$foundTypes[] = $item['value']; |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
|
|
foreach ($table->getRows() as $row) { |
|
267
|
|
|
$key = array_search($row[0], $foundTypes); |
|
268
|
|
|
if ($key === false) { |
|
269
|
|
|
throw new \Exception('Expected type ' . $row[0] . ' not found'); |
|
270
|
|
|
} |
|
271
|
|
|
|
|
272
|
|
|
unset($foundTypes[$key]); |
|
273
|
|
|
} |
|
274
|
|
|
|
|
275
|
|
|
if ($foundTypes !== []) { |
|
276
|
|
|
throw new \Exception('Found more share types then specified: ' . $foundTypes); |
|
277
|
|
|
} |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
|
|
/** |
|
281
|
|
|
* @Then the response should contain an empty property :property |
|
282
|
|
|
* @param string $property |
|
283
|
|
|
* @throws \Exception |
|
284
|
|
|
*/ |
|
285
|
|
|
public function theResponseShouldContainAnEmptyProperty($property) { |
|
286
|
|
|
$properties = $this->response; |
|
287
|
|
|
if (!array_key_exists($property, $properties)) { |
|
288
|
|
|
throw new \Exception("Cannot find property \"$property\""); |
|
289
|
|
|
} |
|
290
|
|
|
|
|
291
|
|
|
if ($properties[$property] !== null) { |
|
292
|
|
|
throw new \Exception("Property \"$property\" is not empty"); |
|
293
|
|
|
} |
|
294
|
|
|
} |
|
295
|
|
|
|
|
296
|
|
|
|
|
297
|
|
|
/*Returns the elements of a propfind, $folderDepth requires 1 to see elements without children*/ |
|
298
|
|
View Code Duplication |
public function listFolder($user, $path, $folderDepth, $properties = null){ |
|
299
|
|
|
$fullUrl = substr($this->baseUrl, 0, -4); |
|
300
|
|
|
|
|
301
|
|
|
$settings = array( |
|
302
|
|
|
'baseUri' => $fullUrl, |
|
303
|
|
|
'userName' => $user, |
|
304
|
|
|
); |
|
305
|
|
|
|
|
306
|
|
|
if ($user === 'admin') { |
|
307
|
|
|
$settings['password'] = $this->adminUser[1]; |
|
308
|
|
|
} else { |
|
309
|
|
|
$settings['password'] = $this->regularUser; |
|
310
|
|
|
} |
|
311
|
|
|
|
|
312
|
|
|
$client = new SClient($settings); |
|
313
|
|
|
|
|
314
|
|
|
if (!$properties) { |
|
315
|
|
|
$properties = [ |
|
316
|
|
|
'{DAV:}getetag' |
|
317
|
|
|
]; |
|
318
|
|
|
} |
|
319
|
|
|
|
|
320
|
|
|
$response = $client->propfind($this->davPath . '/' . ltrim($path, '/'), $properties, $folderDepth); |
|
321
|
|
|
|
|
322
|
|
|
return $response; |
|
323
|
|
|
} |
|
324
|
|
|
|
|
325
|
|
|
/** |
|
326
|
|
|
* @Then /^user "([^"]*)" should see following elements$/ |
|
327
|
|
|
* @param string $user |
|
328
|
|
|
* @param \Behat\Gherkin\Node\TableNode|null $expectedElements |
|
329
|
|
|
*/ |
|
330
|
|
|
public function checkElementList($user, $expectedElements){ |
|
331
|
|
|
$elementList = $this->listFolder($user, '/', 3); |
|
332
|
|
|
if ($expectedElements instanceof \Behat\Gherkin\Node\TableNode) { |
|
|
|
|
|
|
333
|
|
|
$elementRows = $expectedElements->getRows(); |
|
334
|
|
|
$elementsSimplified = $this->simplifyArray($elementRows); |
|
335
|
|
|
foreach($elementsSimplified as $expectedElement) { |
|
336
|
|
|
$webdavPath = "/" . $this->davPath . $expectedElement; |
|
337
|
|
|
if (!array_key_exists($webdavPath,$elementList)){ |
|
338
|
|
|
PHPUnit_Framework_Assert::fail("$webdavPath" . " is not in propfind answer"); |
|
339
|
|
|
} |
|
340
|
|
|
} |
|
341
|
|
|
} |
|
342
|
|
|
} |
|
343
|
|
|
|
|
344
|
|
|
/** |
|
345
|
|
|
* @When User :user uploads file :source to :destination |
|
346
|
|
|
* @param string $user |
|
347
|
|
|
* @param string $source |
|
348
|
|
|
* @param string $destination |
|
349
|
|
|
*/ |
|
350
|
|
View Code Duplication |
public function userUploadsAFileTo($user, $source, $destination) |
|
351
|
|
|
{ |
|
352
|
|
|
$file = \GuzzleHttp\Stream\Stream::factory(fopen($source, 'r')); |
|
353
|
|
|
try { |
|
354
|
|
|
$this->response = $this->makeDavRequest($user, "PUT", $destination, [], $file); |
|
355
|
|
|
} catch (\GuzzleHttp\Exception\ServerException $e) { |
|
|
|
|
|
|
356
|
|
|
// 4xx and 5xx responses cause an exception |
|
357
|
|
|
$this->response = $e->getResponse(); |
|
358
|
|
|
} |
|
359
|
|
|
} |
|
360
|
|
|
|
|
361
|
|
|
/** |
|
362
|
|
|
* @When User :user uploads file with content :content to :destination |
|
363
|
|
|
*/ |
|
364
|
|
View Code Duplication |
public function userUploadsAFileWithContentTo($user, $content, $destination) |
|
365
|
|
|
{ |
|
366
|
|
|
$file = \GuzzleHttp\Stream\Stream::factory($content); |
|
367
|
|
|
try { |
|
368
|
|
|
$this->response = $this->makeDavRequest($user, "PUT", $destination, [], $file); |
|
369
|
|
|
} catch (\GuzzleHttp\Exception\ServerException $e) { |
|
|
|
|
|
|
370
|
|
|
// 4xx and 5xx responses cause an exception |
|
371
|
|
|
$this->response = $e->getResponse(); |
|
372
|
|
|
} |
|
373
|
|
|
} |
|
374
|
|
|
|
|
375
|
|
|
/** |
|
376
|
|
|
* @When User :user deletes file :file |
|
377
|
|
|
* @param string $user |
|
378
|
|
|
* @param string $file |
|
379
|
|
|
*/ |
|
380
|
|
View Code Duplication |
public function userDeletesFile($user, $file) { |
|
381
|
|
|
try { |
|
382
|
|
|
$this->response = $this->makeDavRequest($user, 'DELETE', $file, []); |
|
383
|
|
|
} catch (\GuzzleHttp\Exception\ServerException $e) { |
|
|
|
|
|
|
384
|
|
|
// 4xx and 5xx responses cause an exception |
|
385
|
|
|
$this->response = $e->getResponse(); |
|
386
|
|
|
} |
|
387
|
|
|
} |
|
388
|
|
|
|
|
389
|
|
|
/** |
|
390
|
|
|
* @Given User :user created a folder :destination |
|
391
|
|
|
* @param string $user |
|
392
|
|
|
* @param string $destination |
|
393
|
|
|
*/ |
|
394
|
|
View Code Duplication |
public function userCreatedAFolder($user, $destination){ |
|
395
|
|
|
try { |
|
396
|
|
|
$this->response = $this->makeDavRequest($user, "MKCOL", $destination, []); |
|
397
|
|
|
} catch (\GuzzleHttp\Exception\ServerException $e) { |
|
|
|
|
|
|
398
|
|
|
// 4xx and 5xx responses cause an exception |
|
399
|
|
|
$this->response = $e->getResponse(); |
|
400
|
|
|
} |
|
401
|
|
|
} |
|
402
|
|
|
|
|
403
|
|
|
/** |
|
404
|
|
|
* @Given user :user uploads chunk file :num of :total with :data to :destination |
|
405
|
|
|
* @param string $user |
|
406
|
|
|
* @param int $num |
|
407
|
|
|
* @param int $total |
|
408
|
|
|
* @param string $data |
|
409
|
|
|
* @param string $destination |
|
410
|
|
|
*/ |
|
411
|
|
|
public function userUploadsChunkFileOfWithToWithChecksum($user, $num, $total, $data, $destination) |
|
412
|
|
|
{ |
|
413
|
|
|
$num -= 1; |
|
414
|
|
|
$data = \GuzzleHttp\Stream\Stream::factory($data); |
|
415
|
|
|
$file = $destination . '-chunking-42-'.$total.'-'.$num; |
|
416
|
|
|
$this->makeDavRequest($user, 'PUT', $file, ['OC-Chunked' => '1'], $data); |
|
417
|
|
|
} |
|
418
|
|
|
|
|
419
|
|
|
/** |
|
420
|
|
|
* @Given user :user creates a new chunking upload with id :id |
|
421
|
|
|
*/ |
|
422
|
|
|
public function userCreatesANewChunkingUploadWithId($user, $id) |
|
423
|
|
|
{ |
|
424
|
|
|
$destination = '/uploads/'.$user.'/'.$id; |
|
425
|
|
|
$this->makeDavRequest($user, 'MKCOL', $destination, []); |
|
426
|
|
|
} |
|
427
|
|
|
|
|
428
|
|
|
/** |
|
429
|
|
|
* @Given user :user uploads new chunk file :num with :data to id :id |
|
430
|
|
|
*/ |
|
431
|
|
|
public function userUploadsNewChunkFileOfWithToId($user, $num, $data, $id) |
|
432
|
|
|
{ |
|
433
|
|
|
$data = \GuzzleHttp\Stream\Stream::factory($data); |
|
434
|
|
|
$destination = '/uploads/'.$user.'/'.$id.'/'.$num; |
|
435
|
|
|
$this->makeDavRequest($user, 'PUT', $destination, [], $data); |
|
436
|
|
|
} |
|
437
|
|
|
|
|
438
|
|
|
/** |
|
439
|
|
|
* @Given user :user moves new chunk file with id :id to :dest |
|
440
|
|
|
*/ |
|
441
|
|
|
public function userMovesNewChunkFileWithIdToMychunkedfile($user, $id, $dest) |
|
442
|
|
|
{ |
|
443
|
|
|
$source = '/uploads/'.$user.'/'.$id.'/.file'; |
|
444
|
|
|
$destination = substr($this->baseUrl, 0, -4) . $this->davPath . '/files/'.$user.$dest; |
|
445
|
|
|
$this->makeDavRequest($user, 'MOVE', $source, [ |
|
446
|
|
|
'Destination' => $destination |
|
447
|
|
|
]); |
|
448
|
|
|
} |
|
449
|
|
|
|
|
450
|
|
|
|
|
451
|
|
|
/** |
|
452
|
|
|
* @Given /^Downloading file "([^"]*)" as "([^"]*)"$/ |
|
453
|
|
|
*/ |
|
454
|
|
|
public function downloadingFileAs($fileName, $user) { |
|
455
|
|
|
try { |
|
456
|
|
|
$this->response = $this->makeDavRequest($user, 'GET', $fileName, []); |
|
457
|
|
|
} catch (\GuzzleHttp\Exception\ServerException $ex) { |
|
|
|
|
|
|
458
|
|
|
$this->response = $ex->getResponse(); |
|
459
|
|
|
} |
|
460
|
|
|
} |
|
461
|
|
|
|
|
462
|
|
|
/** |
|
463
|
|
|
* @When user :user favorites element :path |
|
464
|
|
|
*/ |
|
465
|
|
|
public function userFavoritesElement($user, $path){ |
|
466
|
|
|
$this->response = $this->changeFavStateOfAnElement($user, $path, 1, 0, null); |
|
467
|
|
|
} |
|
468
|
|
|
|
|
469
|
|
|
/** |
|
470
|
|
|
* @When user :user unfavorites element :path |
|
471
|
|
|
*/ |
|
472
|
|
|
public function userUnfavoritesElement($user, $path){ |
|
473
|
|
|
$this->response = $this->changeFavStateOfAnElement($user, $path, 0, 0, null); |
|
474
|
|
|
} |
|
475
|
|
|
|
|
476
|
|
|
/*Set the elements of a proppatch, $folderDepth requires 1 to see elements without children*/ |
|
477
|
|
View Code Duplication |
public function changeFavStateOfAnElement($user, $path, $favOrUnfav, $folderDepth, $properties = null){ |
|
478
|
|
|
$fullUrl = substr($this->baseUrl, 0, -4); |
|
479
|
|
|
$settings = array( |
|
480
|
|
|
'baseUri' => $fullUrl, |
|
481
|
|
|
'userName' => $user, |
|
482
|
|
|
); |
|
483
|
|
|
if ($user === 'admin') { |
|
484
|
|
|
$settings['password'] = $this->adminUser[1]; |
|
485
|
|
|
} else { |
|
486
|
|
|
$settings['password'] = $this->regularUser; |
|
487
|
|
|
} |
|
488
|
|
|
$client = new SClient($settings); |
|
489
|
|
|
if (!$properties) { |
|
490
|
|
|
$properties = [ |
|
491
|
|
|
'{http://owncloud.org/ns}favorite' => $favOrUnfav |
|
492
|
|
|
]; |
|
493
|
|
|
} |
|
494
|
|
|
|
|
495
|
|
|
$response = $client->proppatch($this->davPath . '/' . ltrim($path, '/'), $properties, $folderDepth); |
|
496
|
|
|
return $response; |
|
497
|
|
|
} |
|
498
|
|
|
|
|
499
|
|
|
/** |
|
500
|
|
|
* @Then /^as "([^"]*)" gets properties of file "([^"]*)" with$/ |
|
501
|
|
|
* @param string $user |
|
502
|
|
|
* @param string $path |
|
503
|
|
|
* @param \Behat\Gherkin\Node\TableNode|null $propertiesTable |
|
504
|
|
|
*/ |
|
505
|
|
|
public function asGetsPropertiesOfFileWith($user, $path, $propertiesTable) { |
|
506
|
|
|
$this->asGetsPropertiesOfFolderWith($user, $path, $propertiesTable); |
|
507
|
|
|
} |
|
508
|
|
|
} |
|
509
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: