|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use GuzzleHttp\Client; |
|
4
|
|
|
use GuzzleHttp\Message\ResponseInterface; |
|
5
|
|
|
|
|
6
|
|
|
require __DIR__ . '/../../vendor/autoload.php'; |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
trait Sharing { |
|
11
|
|
|
use Provisioning; |
|
12
|
|
|
|
|
13
|
|
|
/** @var int */ |
|
14
|
|
|
private $sharingApiVersion = 1; |
|
15
|
|
|
|
|
16
|
|
|
/** @var SimpleXMLElement */ |
|
17
|
|
|
private $lastShareData = null; |
|
18
|
|
|
|
|
19
|
|
|
/** @var int */ |
|
20
|
|
|
private $savedShareId = null; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @Given /^as "([^"]*)" creating a share with$/ |
|
24
|
|
|
* @param string $user |
|
25
|
|
|
* @param \Behat\Gherkin\Node\TableNode|null $body |
|
26
|
|
|
*/ |
|
27
|
|
|
public function asCreatingAShareWith($user, $body) { |
|
28
|
|
|
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares"; |
|
29
|
|
|
$client = new Client(); |
|
30
|
|
|
$options = []; |
|
31
|
|
|
if ($user === 'admin') { |
|
32
|
|
|
$options['auth'] = $this->adminUser; |
|
|
|
|
|
|
33
|
|
|
} else { |
|
34
|
|
|
$options['auth'] = [$user, $this->regularUser]; |
|
|
|
|
|
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
View Code Duplication |
if ($body instanceof \Behat\Gherkin\Node\TableNode) { |
|
|
|
|
|
|
38
|
|
|
$fd = $body->getRowsHash(); |
|
39
|
|
|
if (array_key_exists('expireDate', $fd)){ |
|
40
|
|
|
$dateModification = $fd['expireDate']; |
|
41
|
|
|
$fd['expireDate'] = date('Y-m-d', strtotime($dateModification)); |
|
42
|
|
|
} |
|
43
|
|
|
$options['body'] = $fd; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
try { |
|
47
|
|
|
$this->response = $client->send($client->createRequest("POST", $fullUrl, $options)); |
|
48
|
|
|
} catch (\GuzzleHttp\Exception\ClientException $ex) { |
|
|
|
|
|
|
49
|
|
|
$this->response = $ex->getResponse(); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
$this->lastShareData = $this->response->xml(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @When /^creating a share with$/ |
|
57
|
|
|
* @param \Behat\Gherkin\Node\TableNode|null $body |
|
58
|
|
|
*/ |
|
59
|
|
|
public function creatingShare($body) { |
|
60
|
|
|
$this->asCreatingAShareWith($this->currentUser, $body); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @Then /^Public shared file "([^"]*)" can be downloaded$/ |
|
65
|
|
|
*/ |
|
66
|
|
|
public function checkPublicSharedFile($filename) { |
|
67
|
|
|
$client = new Client(); |
|
68
|
|
|
$options = []; |
|
69
|
|
View Code Duplication |
if (count($this->lastShareData->data->element) > 0){ |
|
|
|
|
|
|
70
|
|
|
$url = $this->lastShareData->data[0]->url; |
|
71
|
|
|
} |
|
72
|
|
|
else{ |
|
73
|
|
|
$url = $this->lastShareData->data->url; |
|
74
|
|
|
} |
|
75
|
|
|
$fullUrl = $url . "/download"; |
|
76
|
|
|
$options['save_to'] = "./$filename"; |
|
77
|
|
|
$this->response = $client->get($fullUrl, $options); |
|
78
|
|
|
$finfo = new finfo; |
|
79
|
|
|
$fileinfo = $finfo->file("./$filename", FILEINFO_MIME_TYPE); |
|
80
|
|
|
PHPUnit_Framework_Assert::assertEquals($fileinfo, "text/plain"); |
|
81
|
|
|
if (file_exists("./$filename")) { |
|
82
|
|
|
unlink("./$filename"); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @Then /^Public shared file "([^"]*)" with password "([^"]*)" can be downloaded$/ |
|
88
|
|
|
*/ |
|
89
|
|
|
public function checkPublicSharedFileWithPassword($filename, $password) { |
|
90
|
|
|
$client = new Client(); |
|
91
|
|
|
$options = []; |
|
92
|
|
View Code Duplication |
if (count($this->lastShareData->data->element) > 0){ |
|
|
|
|
|
|
93
|
|
|
$token = $this->lastShareData->data[0]->token; |
|
94
|
|
|
} |
|
95
|
|
|
else{ |
|
96
|
|
|
$token = $this->lastShareData->data->token; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
$fullUrl = substr($this->baseUrl, 0, -4) . "public.php/webdav"; |
|
100
|
|
|
$options['auth'] = [$token, $password]; |
|
101
|
|
|
$options['save_to'] = "./$filename"; |
|
102
|
|
|
$this->response = $client->get($fullUrl, $options); |
|
103
|
|
|
$finfo = new finfo; |
|
104
|
|
|
$fileinfo = $finfo->file("./$filename", FILEINFO_MIME_TYPE); |
|
105
|
|
|
PHPUnit_Framework_Assert::assertEquals($fileinfo, "text/plain"); |
|
106
|
|
|
if (file_exists("./$filename")) { |
|
107
|
|
|
unlink("./$filename"); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @When /^Adding expiration date to last share$/ |
|
113
|
|
|
*/ |
|
114
|
|
|
public function addingExpirationDate() { |
|
115
|
|
|
$share_id = (string) $this->lastShareData->data[0]->id; |
|
116
|
|
|
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/$share_id"; |
|
117
|
|
|
$client = new Client(); |
|
118
|
|
|
$options = []; |
|
119
|
|
View Code Duplication |
if ($this->currentUser === 'admin') { |
|
|
|
|
|
|
120
|
|
|
$options['auth'] = $this->adminUser; |
|
121
|
|
|
} else { |
|
122
|
|
|
$options['auth'] = [$this->currentUser, $this->regularUser]; |
|
123
|
|
|
} |
|
124
|
|
|
$date = date('Y-m-d', strtotime("+3 days")); |
|
125
|
|
|
$options['body'] = ['expireDate' => $date]; |
|
126
|
|
|
$this->response = $client->send($client->createRequest("PUT", $fullUrl, $options)); |
|
127
|
|
|
PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode()); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @When /^Updating last share with$/ |
|
132
|
|
|
* @param \Behat\Gherkin\Node\TableNode|null $body |
|
133
|
|
|
*/ |
|
134
|
|
|
public function updatingLastShare($body) { |
|
135
|
|
|
$share_id = (string) $this->lastShareData->data[0]->id; |
|
136
|
|
|
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/$share_id"; |
|
137
|
|
|
$client = new Client(); |
|
138
|
|
|
$options = []; |
|
139
|
|
View Code Duplication |
if ($this->currentUser === 'admin') { |
|
|
|
|
|
|
140
|
|
|
$options['auth'] = $this->adminUser; |
|
141
|
|
|
} else { |
|
142
|
|
|
$options['auth'] = [$this->currentUser, $this->regularUser]; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
View Code Duplication |
if ($body instanceof \Behat\Gherkin\Node\TableNode) { |
|
|
|
|
|
|
146
|
|
|
$fd = $body->getRowsHash(); |
|
147
|
|
|
if (array_key_exists('expireDate', $fd)){ |
|
148
|
|
|
$dateModification = $fd['expireDate']; |
|
149
|
|
|
$fd['expireDate'] = date('Y-m-d', strtotime($dateModification)); |
|
150
|
|
|
} |
|
151
|
|
|
$options['body'] = $fd; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
try { |
|
155
|
|
|
$this->response = $client->send($client->createRequest("PUT", $fullUrl, $options)); |
|
156
|
|
|
} catch (\GuzzleHttp\Exception\ClientException $ex) { |
|
|
|
|
|
|
157
|
|
|
$this->response = $ex->getResponse(); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode()); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
public function createShare($user, |
|
164
|
|
|
$path = null, |
|
165
|
|
|
$shareType = null, |
|
166
|
|
|
$shareWith = null, |
|
167
|
|
|
$publicUpload = null, |
|
168
|
|
|
$password = null, |
|
169
|
|
|
$permissions = null){ |
|
170
|
|
|
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares"; |
|
171
|
|
|
$client = new Client(); |
|
172
|
|
|
$options = []; |
|
173
|
|
|
|
|
174
|
|
|
if ($user === 'admin') { |
|
175
|
|
|
$options['auth'] = $this->adminUser; |
|
176
|
|
|
} else { |
|
177
|
|
|
$options['auth'] = [$user, $this->regularUser]; |
|
178
|
|
|
} |
|
179
|
|
|
$fd = []; |
|
180
|
|
|
if (!is_null($path)){ |
|
181
|
|
|
$fd['path'] = $path; |
|
182
|
|
|
} |
|
183
|
|
|
if (!is_null($shareType)){ |
|
184
|
|
|
$fd['shareType'] = $shareType; |
|
185
|
|
|
} |
|
186
|
|
|
if (!is_null($shareWith)){ |
|
187
|
|
|
$fd['shareWith'] = $shareWith; |
|
188
|
|
|
} |
|
189
|
|
|
if (!is_null($publicUpload)){ |
|
190
|
|
|
$fd['publicUpload'] = $publicUpload; |
|
191
|
|
|
} |
|
192
|
|
|
if (!is_null($password)){ |
|
193
|
|
|
$fd['password'] = $password; |
|
194
|
|
|
} |
|
195
|
|
|
if (!is_null($permissions)){ |
|
196
|
|
|
$fd['permissions'] = $permissions; |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
$options['body'] = $fd; |
|
200
|
|
|
|
|
201
|
|
|
try { |
|
202
|
|
|
$this->response = $client->send($client->createRequest("POST", $fullUrl, $options)); |
|
203
|
|
|
$this->lastShareData = $this->response->xml(); |
|
204
|
|
|
} catch (\GuzzleHttp\Exception\ClientException $ex) { |
|
|
|
|
|
|
205
|
|
|
$this->response = $ex->getResponse(); |
|
206
|
|
|
} |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
public function isFieldInResponse($field, $contentExpected){ |
|
210
|
|
|
$data = $this->response->xml()->data[0]; |
|
211
|
|
|
if ((string)$field == 'expiration'){ |
|
212
|
|
|
$contentExpected = date('Y-m-d', strtotime($contentExpected)) . " 00:00:00"; |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
if (count($data->element) > 0){ |
|
216
|
|
|
foreach($data as $element) { |
|
217
|
|
View Code Duplication |
if ($contentExpected == "A_TOKEN"){ |
|
|
|
|
|
|
218
|
|
|
return (strlen((string)$element->$field) == 15); |
|
219
|
|
|
} |
|
220
|
|
|
elseif ($contentExpected == "A_NUMBER"){ |
|
221
|
|
|
return is_numeric((string)$element->$field); |
|
222
|
|
|
} |
|
223
|
|
|
elseif($contentExpected == "AN_URL"){ |
|
224
|
|
|
return $this->isExpectedUrl((string)$element->$field, "index.php/s/"); |
|
225
|
|
|
} |
|
226
|
|
|
elseif ((string)$element->$field == $contentExpected){ |
|
227
|
|
|
return True; |
|
228
|
|
|
} |
|
229
|
|
|
else{ |
|
230
|
|
|
print($element->$field); |
|
231
|
|
|
} |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
return False; |
|
235
|
|
|
} else { |
|
236
|
|
View Code Duplication |
if ($contentExpected == "A_TOKEN"){ |
|
|
|
|
|
|
237
|
|
|
return (strlen((string)$data->$field) == 15); |
|
238
|
|
|
} |
|
239
|
|
|
elseif ($contentExpected == "A_NUMBER"){ |
|
240
|
|
|
return is_numeric((string)$data->$field); |
|
241
|
|
|
} |
|
242
|
|
|
elseif($contentExpected == "AN_URL"){ |
|
243
|
|
|
return $this->isExpectedUrl((string)$data->$field, "index.php/s/"); |
|
244
|
|
|
} |
|
245
|
|
|
elseif ($data->$field == $contentExpected){ |
|
246
|
|
|
return True; |
|
247
|
|
|
} |
|
248
|
|
|
return False; |
|
249
|
|
|
} |
|
250
|
|
|
} |
|
251
|
|
|
|
|
252
|
|
|
/** |
|
253
|
|
|
* @Then /^File "([^"]*)" should be included in the response$/ |
|
254
|
|
|
* |
|
255
|
|
|
* @param string $filename |
|
256
|
|
|
*/ |
|
257
|
|
|
public function checkSharedFileInResponse($filename){ |
|
258
|
|
|
PHPUnit_Framework_Assert::assertEquals(True, $this->isFieldInResponse('file_target', "/$filename")); |
|
259
|
|
|
} |
|
260
|
|
|
|
|
261
|
|
|
/** |
|
262
|
|
|
* @Then /^File "([^"]*)" should not be included in the response$/ |
|
263
|
|
|
* |
|
264
|
|
|
* @param string $filename |
|
265
|
|
|
*/ |
|
266
|
|
|
public function checkSharedFileNotInResponse($filename){ |
|
267
|
|
|
PHPUnit_Framework_Assert::assertEquals(False, $this->isFieldInResponse('file_target', "/$filename")); |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
/** |
|
271
|
|
|
* @Then /^User "([^"]*)" should be included in the response$/ |
|
272
|
|
|
* |
|
273
|
|
|
* @param string $user |
|
274
|
|
|
*/ |
|
275
|
|
|
public function checkSharedUserInResponse($user){ |
|
276
|
|
|
PHPUnit_Framework_Assert::assertEquals(True, $this->isFieldInResponse('share_with', "$user")); |
|
277
|
|
|
} |
|
278
|
|
|
|
|
279
|
|
|
/** |
|
280
|
|
|
* @Then /^User "([^"]*)" should not be included in the response$/ |
|
281
|
|
|
* |
|
282
|
|
|
* @param string $user |
|
283
|
|
|
*/ |
|
284
|
|
|
public function checkSharedUserNotInResponse($user){ |
|
285
|
|
|
PHPUnit_Framework_Assert::assertEquals(False, $this->isFieldInResponse('share_with', "$user")); |
|
286
|
|
|
} |
|
287
|
|
|
|
|
288
|
|
|
public function isUserOrGroupInSharedData($userOrGroup){ |
|
289
|
|
|
$data = $this->response->xml()->data[0]; |
|
290
|
|
|
foreach($data as $element) { |
|
291
|
|
|
if ($element->share_with == $userOrGroup){ |
|
292
|
|
|
return True; |
|
293
|
|
|
} |
|
294
|
|
|
} |
|
295
|
|
|
return False; |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
/** |
|
299
|
|
|
* @Given /^file "([^"]*)" of user "([^"]*)" is shared with user "([^"]*)"$/ |
|
300
|
|
|
* |
|
301
|
|
|
* @param string $filepath |
|
302
|
|
|
* @param string $user1 |
|
303
|
|
|
* @param string $user2 |
|
304
|
|
|
*/ |
|
305
|
|
View Code Duplication |
public function assureFileIsShared($filepath, $user1, $user2){ |
|
306
|
|
|
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares" . "?path=$filepath"; |
|
307
|
|
|
$client = new Client(); |
|
308
|
|
|
$options = []; |
|
309
|
|
|
if ($user1 === 'admin') { |
|
310
|
|
|
$options['auth'] = $this->adminUser; |
|
311
|
|
|
} else { |
|
312
|
|
|
$options['auth'] = [$user1, $this->regularUser]; |
|
313
|
|
|
} |
|
314
|
|
|
$this->response = $client->get($fullUrl, $options); |
|
315
|
|
|
if ($this->isUserOrGroupInSharedData($user2)){ |
|
316
|
|
|
return; |
|
317
|
|
|
} else { |
|
318
|
|
|
$this->createShare($user1, $filepath, 0, $user2, null, null, null); |
|
319
|
|
|
} |
|
320
|
|
|
$this->response = $client->get($fullUrl, $options); |
|
321
|
|
|
PHPUnit_Framework_Assert::assertEquals(True, $this->isUserOrGroupInSharedData($user2)); |
|
322
|
|
|
} |
|
323
|
|
|
|
|
324
|
|
|
/** |
|
325
|
|
|
* @Given /^file "([^"]*)" of user "([^"]*)" is shared with group "([^"]*)"$/ |
|
326
|
|
|
* |
|
327
|
|
|
* @param string $filepath |
|
328
|
|
|
* @param string $user |
|
329
|
|
|
* @param string $group |
|
330
|
|
|
*/ |
|
331
|
|
View Code Duplication |
public function assureFileIsSharedWithGroup($filepath, $user, $group){ |
|
332
|
|
|
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares" . "?path=$filepath"; |
|
333
|
|
|
$client = new Client(); |
|
334
|
|
|
$options = []; |
|
335
|
|
|
if ($user === 'admin') { |
|
336
|
|
|
$options['auth'] = $this->adminUser; |
|
337
|
|
|
} else { |
|
338
|
|
|
$options['auth'] = [$user, $this->regularUser]; |
|
339
|
|
|
} |
|
340
|
|
|
$this->response = $client->get($fullUrl, $options); |
|
341
|
|
|
if ($this->isUserOrGroupInSharedData($group)){ |
|
342
|
|
|
return; |
|
343
|
|
|
} else { |
|
344
|
|
|
$this->createShare($user, $filepath, 1, $group, null, null, null); |
|
345
|
|
|
} |
|
346
|
|
|
$this->response = $client->get($fullUrl, $options); |
|
347
|
|
|
PHPUnit_Framework_Assert::assertEquals(True, $this->isUserOrGroupInSharedData($group)); |
|
348
|
|
|
} |
|
349
|
|
|
|
|
350
|
|
|
/** |
|
351
|
|
|
* @When /^Deleting last share$/ |
|
352
|
|
|
*/ |
|
353
|
|
|
public function deletingLastShare(){ |
|
354
|
|
|
$share_id = $this->lastShareData->data[0]->id; |
|
355
|
|
|
$url = "/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/$share_id"; |
|
356
|
|
|
$this->sendingToWith("DELETE", $url, null); |
|
|
|
|
|
|
357
|
|
|
} |
|
358
|
|
|
|
|
359
|
|
|
/** |
|
360
|
|
|
* @When /^Getting info of last share$/ |
|
361
|
|
|
*/ |
|
362
|
|
|
public function gettingInfoOfLastShare(){ |
|
363
|
|
|
$share_id = $this->lastShareData->data[0]->id; |
|
364
|
|
|
$url = "/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/$share_id"; |
|
365
|
|
|
$this->sendingToWith("GET", $url, null); |
|
|
|
|
|
|
366
|
|
|
} |
|
367
|
|
|
|
|
368
|
|
|
/** |
|
369
|
|
|
* @Then /^last share_id is included in the answer$/ |
|
370
|
|
|
*/ |
|
371
|
|
|
public function checkingLastShareIDIsIncluded(){ |
|
372
|
|
|
$share_id = $this->lastShareData->data[0]->id; |
|
373
|
|
|
if (!$this->isFieldInResponse('id', $share_id)){ |
|
374
|
|
|
PHPUnit_Framework_Assert::fail("Share id $share_id not found in response"); |
|
375
|
|
|
} |
|
376
|
|
|
} |
|
377
|
|
|
|
|
378
|
|
|
/** |
|
379
|
|
|
* @Then /^last share_id is included in the answer as parent$/ |
|
380
|
|
|
*/ |
|
381
|
|
View Code Duplication |
public function checkingLastShareIDIsIncludedAsParent(){ |
|
382
|
|
|
$share_id = $this->lastShareData->data[0]->id; |
|
383
|
|
|
//This is a problem before 9.0, setupFS is called with every api call so a new share id is created |
|
384
|
|
|
//we just need to check the parent id to match with the returned id. |
|
385
|
|
|
if (!$this->isFieldInResponse('parent', $share_id)){ |
|
386
|
|
|
PHPUnit_Framework_Assert::fail("Share id $share_id not found in response as parent"); |
|
387
|
|
|
} |
|
388
|
|
|
} |
|
389
|
|
|
|
|
390
|
|
|
/** |
|
391
|
|
|
* @Then /^last share_id is not included in the answer$/ |
|
392
|
|
|
*/ |
|
393
|
|
|
public function checkingLastShareIDIsNotIncluded(){ |
|
394
|
|
|
$share_id = $this->lastShareData->data[0]->id; |
|
395
|
|
|
if ($this->isFieldInResponse('id', $share_id)){ |
|
396
|
|
|
PHPUnit_Framework_Assert::fail("Share id $share_id has been found in response"); |
|
397
|
|
|
} |
|
398
|
|
|
} |
|
399
|
|
|
|
|
400
|
|
|
/** |
|
401
|
|
|
* @Then /^last share_id is not included in the answer as parent$/ |
|
402
|
|
|
*/ |
|
403
|
|
View Code Duplication |
public function checkingLastShareIDIsNotIncludedAsParent(){ |
|
404
|
|
|
$share_id = $this->lastShareData->data[0]->id; |
|
405
|
|
|
//This is a problem before 9.0, setupFS is called with every api call so a new share id is created |
|
406
|
|
|
//we just need to check the parent id to match with the returned id. |
|
407
|
|
|
if ($this->isFieldInResponse('parent', $share_id)){ |
|
408
|
|
|
PHPUnit_Framework_Assert::fail("Share id $share_id has been found in response as parent"); |
|
409
|
|
|
} |
|
410
|
|
|
} |
|
411
|
|
|
|
|
412
|
|
|
/** |
|
413
|
|
|
* @Then /^Share fields of last share match with$/ |
|
414
|
|
|
* @param \Behat\Gherkin\Node\TableNode|null $body |
|
415
|
|
|
*/ |
|
416
|
|
|
public function checkShareFields($body){ |
|
417
|
|
|
if ($body instanceof \Behat\Gherkin\Node\TableNode) { |
|
|
|
|
|
|
418
|
|
|
$fd = $body->getRowsHash(); |
|
419
|
|
|
|
|
420
|
|
|
foreach($fd as $field => $value) { |
|
421
|
|
View Code Duplication |
if (substr($field, 0, 10 ) === "share_with"){ |
|
|
|
|
|
|
422
|
|
|
$value = str_replace("REMOTE", substr($this->remoteBaseUrl, 0, -5), $value); |
|
|
|
|
|
|
423
|
|
|
$value = str_replace("LOCAL", substr($this->localBaseUrl, 0, -5), $value); |
|
|
|
|
|
|
424
|
|
|
} |
|
425
|
|
View Code Duplication |
if (substr($field, 0, 6 ) === "remote"){ |
|
|
|
|
|
|
426
|
|
|
$value = str_replace("REMOTE", substr($this->remoteBaseUrl, 0, -4), $value); |
|
|
|
|
|
|
427
|
|
|
$value = str_replace("LOCAL", substr($this->localBaseUrl, 0, -4), $value); |
|
|
|
|
|
|
428
|
|
|
} |
|
429
|
|
|
if (!$this->isFieldInResponse($field, $value)){ |
|
430
|
|
|
PHPUnit_Framework_Assert::fail("$field" . " doesn't have value " . "$value"); |
|
431
|
|
|
} |
|
432
|
|
|
} |
|
433
|
|
|
} |
|
434
|
|
|
} |
|
435
|
|
|
|
|
436
|
|
|
/** |
|
437
|
|
|
* @Then As :user remove all shares from the file named :fileName |
|
438
|
|
|
*/ |
|
439
|
|
|
public function asRemoveAllSharesFromTheFileNamed($user, $fileName) { |
|
440
|
|
|
$url = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares?format=json"; |
|
441
|
|
|
$client = new \GuzzleHttp\Client(); |
|
442
|
|
|
$res = $client->get( |
|
443
|
|
|
$url, |
|
444
|
|
|
[ |
|
445
|
|
|
'auth' => [ |
|
446
|
|
|
$user, |
|
447
|
|
|
'123456', |
|
448
|
|
|
], |
|
449
|
|
|
'headers' => [ |
|
450
|
|
|
'Content-Type' => 'application/json', |
|
451
|
|
|
], |
|
452
|
|
|
] |
|
453
|
|
|
); |
|
454
|
|
|
$json = json_decode($res->getBody()->getContents(), true); |
|
455
|
|
|
$deleted = false; |
|
456
|
|
|
foreach($json['ocs']['data'] as $data) { |
|
457
|
|
|
if (stripslashes($data['path']) === $fileName) { |
|
458
|
|
|
$id = $data['id']; |
|
459
|
|
|
$client->delete( |
|
460
|
|
|
$this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/{$id}", |
|
461
|
|
|
[ |
|
462
|
|
|
'auth' => [ |
|
463
|
|
|
$user, |
|
464
|
|
|
'123456', |
|
465
|
|
|
], |
|
466
|
|
|
'headers' => [ |
|
467
|
|
|
'Content-Type' => 'application/json', |
|
468
|
|
|
], |
|
469
|
|
|
] |
|
470
|
|
|
); |
|
471
|
|
|
$deleted = true; |
|
472
|
|
|
} |
|
473
|
|
|
} |
|
474
|
|
|
|
|
475
|
|
|
if($deleted === false) { |
|
476
|
|
|
throw new \Exception("Could not delete file $fileName"); |
|
477
|
|
|
} |
|
478
|
|
|
} |
|
479
|
|
|
|
|
480
|
|
|
/** |
|
481
|
|
|
* @When save last share id |
|
482
|
|
|
*/ |
|
483
|
|
|
public function saveLastShareId() |
|
484
|
|
|
{ |
|
485
|
|
|
$this->savedShareId = $this->lastShareData['data']['id']; |
|
486
|
|
|
} |
|
487
|
|
|
|
|
488
|
|
|
/** |
|
489
|
|
|
* @Then share ids should match |
|
490
|
|
|
*/ |
|
491
|
|
|
public function shareIdsShouldMatch() |
|
492
|
|
|
{ |
|
493
|
|
|
if ($this->savedShareId !== $this->lastShareData['data']['id']) { |
|
494
|
|
|
throw new \Exception('Expected the same link share to be returned'); |
|
495
|
|
|
} |
|
496
|
|
|
} |
|
497
|
|
|
} |
|
498
|
|
|
|
|
499
|
|
|
|
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: