FilesDropContext.php 2.5 KB

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