1
0

FederationContext.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. *
  4. * @author Joas Schilling <coding@schilljs.com>
  5. * @author Sergio Bertolin <sbertolin@solidgear.es>
  6. * @author Sergio Bertolín <sbertolin@solidgear.es>
  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 GuzzleHttp\Client;
  27. use GuzzleHttp\Message\ResponseInterface;
  28. require __DIR__ . '/../../vendor/autoload.php';
  29. /**
  30. * Federation context.
  31. */
  32. class FederationContext implements Context, SnippetAcceptingContext {
  33. use WebDav;
  34. /**
  35. * @Given /^User "([^"]*)" from server "(LOCAL|REMOTE)" shares "([^"]*)" with user "([^"]*)" from server "(LOCAL|REMOTE)"$/
  36. *
  37. * @param string $sharerUser
  38. * @param string $sharerServer "LOCAL" or "REMOTE"
  39. * @param string $sharerPath
  40. * @param string $shareeUser
  41. * @param string $shareeServer "LOCAL" or "REMOTE"
  42. */
  43. public function federateSharing($sharerUser, $sharerServer, $sharerPath, $shareeUser, $shareeServer){
  44. if ($shareeServer == "REMOTE"){
  45. $shareWith = "$shareeUser@" . substr($this->remoteBaseUrl, 0, -4);
  46. } else {
  47. $shareWith = "$shareeUser@" . substr($this->localBaseUrl, 0, -4);
  48. }
  49. $previous = $this->usingServer($sharerServer);
  50. $this->createShare($sharerUser, $sharerPath, 6, $shareWith, null, null, null);
  51. $this->usingServer($previous);
  52. }
  53. /**
  54. * @When /^User "([^"]*)" from server "(LOCAL|REMOTE)" accepts last pending share$/
  55. * @param string $user
  56. * @param string $server
  57. */
  58. public function acceptLastPendingShare($user, $server){
  59. $previous = $this->usingServer($server);
  60. $this->asAn($user);
  61. $this->sendingToWith('GET', "/apps/files_sharing/api/v1/remote_shares/pending", null);
  62. $this->theHTTPStatusCodeShouldBe('200');
  63. $this->theOCSStatusCodeShouldBe('100');
  64. $share_id = $this->response->xml()->data[0]->element[0]->id;
  65. $this->sendingToWith('POST', "/apps/files_sharing/api/v1/remote_shares/pending/{$share_id}", null);
  66. $this->theHTTPStatusCodeShouldBe('200');
  67. $this->theOCSStatusCodeShouldBe('100');
  68. $this->usingServer($previous);
  69. }
  70. }