|
7 | 7 | * @author Joas Schilling <[email protected]> |
8 | 8 | * @author John Molakvoæ <[email protected]> |
9 | 9 | * @author Lukas Reschke <[email protected]> |
| 10 | + * @author Maxence Lange <[email protected]> |
10 | 11 | * @author Morris Jobke <[email protected]> |
11 | 12 | * @author Robin Appelman <[email protected]> |
12 | 13 | * @author Roeland Jago Douma <[email protected]> |
|
31 | 32 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
32 | 33 | * |
33 | 34 | */ |
| 35 | + |
34 | 36 | use GuzzleHttp\Client as GClient; |
35 | | -use GuzzleHttp\Message\ResponseInterface; |
36 | 37 | use PHPUnit\Framework\Assert; |
| 38 | +use Psr\Http\Message\ResponseInterface; |
37 | 39 | use Sabre\DAV\Client as SClient; |
38 | 40 | use Sabre\DAV\Xml\Property\ResourceType; |
39 | 41 |
|
|
43 | 45 | trait WebDav { |
44 | 46 | use Sharing; |
45 | 47 |
|
46 | | - /** @var string */ |
47 | | - private $davPath = "remote.php/webdav"; |
48 | | - /** @var boolean */ |
49 | | - private $usingOldDavPath = true; |
| 48 | + private string $davPath = "remote.php/webdav"; |
| 49 | + private bool $usingOldDavPath = true; |
| 50 | + private ?array $storedETAG = null; // map with user as key and another map as value, which has path as key and etag as value |
| 51 | + private ?int $storedFileID = null; |
50 | 52 | /** @var ResponseInterface */ |
51 | 53 | private $response; |
52 | | - /** @var array map with user as key and another map as value, which has path as key and etag as value */ |
53 | | - private $storedETAG = null; |
54 | | - /** @var int */ |
55 | | - private $storedFileID = null; |
56 | | - |
| 54 | + private array $parsedResponse = []; |
57 | 55 | private string $s3MultipartDestination; |
58 | 56 | private string $uploadId; |
59 | 57 |
|
@@ -237,7 +235,7 @@ public function search(): void { |
237 | 235 | public function searchFavorite(): void { |
238 | 236 | $this->searchFile( |
239 | 237 | $this->currentUser, |
240 | | - null, |
| 238 | + '<oc:favorite/>', |
241 | 239 | null, |
242 | 240 | '<d:eq> |
243 | 241 | <d:prop> |
@@ -333,19 +331,32 @@ public function asTheFileOrFolderExists($user, $entry, $path) { |
333 | 331 | $this->response = $this->listFolder($user, $path, 0); |
334 | 332 | } |
335 | 333 |
|
| 334 | + /** |
| 335 | + * @Then the response should be empty |
| 336 | + * @throws \Exception |
| 337 | + */ |
| 338 | + public function theResponseShouldBeEmpty(): void { |
| 339 | + $response = ($this->response instanceof ResponseInterface) ? $this->convertResponseToDavEntries() : $this->response; |
| 340 | + if ($response === []) { |
| 341 | + return; |
| 342 | + } |
| 343 | + |
| 344 | + throw new \Exception('response is not empty'); |
| 345 | + } |
| 346 | + |
336 | 347 | /** |
337 | 348 | * @Then the single response should contain a property :key with value :value |
338 | 349 | * @param string $key |
339 | 350 | * @param string $expectedValue |
340 | 351 | * @throws \Exception |
341 | 352 | */ |
342 | 353 | public function theSingleResponseShouldContainAPropertyWithValue($key, $expectedValue) { |
343 | | - $keys = $this->response; |
344 | | - if (!array_key_exists($key, $keys)) { |
| 354 | + $response = ($this->response instanceof ResponseInterface) ? $this->convertResponseToDavSingleEntry() : $this->response; |
| 355 | + if (!array_key_exists($key, $response)) { |
345 | 356 | throw new \Exception("Cannot find property \"$key\" with \"$expectedValue\""); |
346 | 357 | } |
347 | 358 |
|
348 | | - $value = $keys[$key]; |
| 359 | + $value = $response[$key]; |
349 | 360 | if ($value instanceof ResourceType) { |
350 | 361 | $value = $value->getValue(); |
351 | 362 | if (empty($value)) { |
@@ -533,6 +544,7 @@ public function searchFile(string $user, ?string $properties = null, ?string $sc |
533 | 544 | $this->response = $this->makeDavRequest($user, "SEARCH", '', [ |
534 | 545 | 'Content-Type' => 'text/xml' |
535 | 546 | ], $body, ''); |
| 547 | + |
536 | 548 | var_dump((string)$this->response->getBody()); |
537 | 549 | } catch (\GuzzleHttp\Exception\ServerException $e) { |
538 | 550 | // 5xx responses cause a server exception |
@@ -1112,4 +1124,32 @@ public function theUploadShouldFailOnObjectStorage() { |
1112 | 1124 | $this->theHTTPStatusCodeShouldBe(500); |
1113 | 1125 | } |
1114 | 1126 | } |
| 1127 | + |
| 1128 | + /** |
| 1129 | + * @return array |
| 1130 | + * @throws Exception |
| 1131 | + */ |
| 1132 | + private function convertResponseToDavSingleEntry(): array { |
| 1133 | + $results = $this->convertResponseToDavEntries(); |
| 1134 | + if (count($results) > 1) { |
| 1135 | + throw new \Exception('result is empty or contain more than one (1) entry'); |
| 1136 | + } |
| 1137 | + |
| 1138 | + return array_shift($results); |
| 1139 | + } |
| 1140 | + |
| 1141 | + /** |
| 1142 | + * @return array |
| 1143 | + */ |
| 1144 | + private function convertResponseToDavEntries(): array { |
| 1145 | + $client = $this->getSabreClient($this->currentUser); |
| 1146 | + $parsedResponse = $client->parseMultiStatus((string)$this->response->getBody()); |
| 1147 | + |
| 1148 | + $results = []; |
| 1149 | + foreach ($parsedResponse as $href => $statusList) { |
| 1150 | + $results[$href] = $statusList[200] ?? []; |
| 1151 | + } |
| 1152 | + |
| 1153 | + return $results; |
| 1154 | + } |
1115 | 1155 | } |
0 commit comments