1
0

FilesDropContext.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Roeland Jago Douma <roeland@famdouma.nl>
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Robin Appelman <robin@icewind.nl>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. use Behat\Behat\Context\Context;
  27. use Behat\Behat\Context\SnippetAcceptingContext;
  28. use GuzzleHttp\Client;
  29. require __DIR__ . '/../../vendor/autoload.php';
  30. class FilesDropContext implements Context, SnippetAcceptingContext {
  31. use WebDav;
  32. /**
  33. * @When Dropping file :path with :content
  34. */
  35. public function droppingFileWith($path, $content) {
  36. $client = new Client();
  37. $options = [];
  38. if (count($this->lastShareData->data->element) > 0) {
  39. $token = $this->lastShareData->data[0]->token;
  40. } else {
  41. $token = $this->lastShareData->data[0]->token;
  42. }
  43. $base = substr($this->baseUrl, 0, -4);
  44. $fullUrl = $base . "/public.php/dav/files/$token/$path";
  45. $options['headers'] = [
  46. 'X-REQUESTED-WITH' => 'XMLHttpRequest'
  47. ];
  48. $options['body'] = \GuzzleHttp\Psr7\Utils::streamFor($content);
  49. try {
  50. $this->response = $client->request('PUT', $fullUrl, $options);
  51. } catch (\GuzzleHttp\Exception\ClientException $e) {
  52. $this->response = $e->getResponse();
  53. }
  54. }
  55. /**
  56. * @When Creating folder :folder in drop
  57. */
  58. public function creatingFolderInDrop($folder) {
  59. $client = new Client();
  60. $options = [];
  61. if (count($this->lastShareData->data->element) > 0) {
  62. $token = $this->lastShareData->data[0]->token;
  63. } else {
  64. $token = $this->lastShareData->data[0]->token;
  65. }
  66. $base = substr($this->baseUrl, 0, -4);
  67. $fullUrl = $base . "/public.php/dav/files/$token/$folder";
  68. $options['headers'] = [
  69. 'X-REQUESTED-WITH' => 'XMLHttpRequest'
  70. ];
  71. try {
  72. $this->response = $client->request('MKCOL', $fullUrl, $options);
  73. } catch (\GuzzleHttp\Exception\ClientException $e) {
  74. $this->response = $e->getResponse();
  75. }
  76. }
  77. }