1
0

FilesDropContext.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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/webdav' . $path;
  45. $options['auth'] = [$token, ''];
  46. $options['headers'] = [
  47. 'X-REQUESTED-WITH' => 'XMLHttpRequest'
  48. ];
  49. $options['body'] = \GuzzleHttp\Psr7\Utils::streamFor($content);
  50. try {
  51. $this->response = $client->request('PUT', $fullUrl, $options);
  52. } catch (\GuzzleHttp\Exception\ClientException $e) {
  53. $this->response = $e->getResponse();
  54. }
  55. }
  56. /**
  57. * @When Creating folder :folder in drop
  58. */
  59. public function creatingFolderInDrop($folder) {
  60. $client = new Client();
  61. $options = [];
  62. if (count($this->lastShareData->data->element) > 0) {
  63. $token = $this->lastShareData->data[0]->token;
  64. } else {
  65. $token = $this->lastShareData->data[0]->token;
  66. }
  67. $base = substr($this->baseUrl, 0, -4);
  68. $fullUrl = $base . '/public.php/webdav/' . $folder;
  69. $options['auth'] = [$token, ''];
  70. $options['headers'] = [
  71. 'X-REQUESTED-WITH' => 'XMLHttpRequest'
  72. ];
  73. try {
  74. $this->response = $client->request('MKCOL', $fullUrl, $options);
  75. } catch (\GuzzleHttp\Exception\ClientException $e) {
  76. $this->response = $e->getResponse();
  77. }
  78. }
  79. }