FilesDropContext.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. use Behat\Behat\Context\Context;
  7. use Behat\Behat\Context\SnippetAcceptingContext;
  8. use GuzzleHttp\Client;
  9. require __DIR__ . '/../../vendor/autoload.php';
  10. class FilesDropContext implements Context, SnippetAcceptingContext {
  11. use WebDav;
  12. /**
  13. * @When Dropping file :path with :content
  14. */
  15. public function droppingFileWith($path, $content) {
  16. $client = new Client();
  17. $options = [];
  18. if (count($this->lastShareData->data->element) > 0) {
  19. $token = $this->lastShareData->data[0]->token;
  20. } else {
  21. $token = $this->lastShareData->data[0]->token;
  22. }
  23. $base = substr($this->baseUrl, 0, -4);
  24. $fullUrl = $base . "/public.php/dav/files/$token/$path";
  25. $options['headers'] = [
  26. 'X-REQUESTED-WITH' => 'XMLHttpRequest'
  27. ];
  28. $options['body'] = \GuzzleHttp\Psr7\Utils::streamFor($content);
  29. try {
  30. $this->response = $client->request('PUT', $fullUrl, $options);
  31. } catch (\GuzzleHttp\Exception\ClientException $e) {
  32. $this->response = $e->getResponse();
  33. }
  34. }
  35. /**
  36. * @When Creating folder :folder in drop
  37. */
  38. public function creatingFolderInDrop($folder) {
  39. $client = new Client();
  40. $options = [];
  41. if (count($this->lastShareData->data->element) > 0) {
  42. $token = $this->lastShareData->data[0]->token;
  43. } else {
  44. $token = $this->lastShareData->data[0]->token;
  45. }
  46. $base = substr($this->baseUrl, 0, -4);
  47. $fullUrl = $base . "/public.php/dav/files/$token/$folder";
  48. $options['headers'] = [
  49. 'X-REQUESTED-WITH' => 'XMLHttpRequest'
  50. ];
  51. try {
  52. $this->response = $client->request('MKCOL', $fullUrl, $options);
  53. } catch (\GuzzleHttp\Exception\ClientException $e) {
  54. $this->response = $e->getResponse();
  55. }
  56. }
  57. }