1
0

ShareesContext.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. *
  4. * @author Joas Schilling <coding@schilljs.com>
  5. * @author Roeland Jago Douma <roeland@famdouma.nl>
  6. *
  7. * @license GNU AGPL version 3 or any later version
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. use Behat\Behat\Context\Context;
  24. use Behat\Behat\Context\SnippetAcceptingContext;
  25. use GuzzleHttp\Message\ResponseInterface;
  26. require __DIR__ . '/../../vendor/autoload.php';
  27. /**
  28. * Features context.
  29. */
  30. class ShareesContext implements Context, SnippetAcceptingContext {
  31. use Provisioning;
  32. use AppConfiguration;
  33. /**
  34. * @When /^getting sharees for$/
  35. * @param \Behat\Gherkin\Node\TableNode $body
  36. */
  37. public function whenGettingShareesFor($body) {
  38. $url = '/apps/files_sharing/api/v1/sharees';
  39. if ($body instanceof \Behat\Gherkin\Node\TableNode) {
  40. $parameters = [];
  41. foreach ($body->getRowsHash() as $key => $value) {
  42. $parameters[] = $key . '=' . $value;
  43. }
  44. if (!empty($parameters)) {
  45. $url .= '?' . implode('&', $parameters);
  46. }
  47. }
  48. $this->sendingTo('GET', $url);
  49. }
  50. /**
  51. * @Then /^"([^"]*)" sharees returned (are|is empty)$/
  52. * @param string $shareeType
  53. * @param string $isEmpty
  54. * @param \Behat\Gherkin\Node\TableNode|null $shareesList
  55. */
  56. public function thenListOfSharees($shareeType, $isEmpty, $shareesList = null) {
  57. if ($isEmpty !== 'is empty') {
  58. $sharees = $shareesList->getRows();
  59. $respondedArray = $this->getArrayOfShareesResponded($this->response, $shareeType);
  60. PHPUnit_Framework_Assert::assertEquals($sharees, $respondedArray);
  61. } else {
  62. $respondedArray = $this->getArrayOfShareesResponded($this->response, $shareeType);
  63. PHPUnit_Framework_Assert::assertEmpty($respondedArray);
  64. }
  65. }
  66. public function getArrayOfShareesResponded(ResponseInterface $response, $shareeType) {
  67. $elements = $response->xml()->data;
  68. $elements = json_decode(json_encode($elements), 1);
  69. if (strpos($shareeType, 'exact ') === 0) {
  70. $elements = $elements['exact'];
  71. $shareeType = substr($shareeType, 6);
  72. }
  73. $sharees = [];
  74. foreach ($elements[$shareeType] as $element) {
  75. $sharees[] = [$element['label'], $element['value']['shareType'], $element['value']['shareWith']];
  76. }
  77. return $sharees;
  78. }
  79. protected function resetAppConfigs() {
  80. $this->modifyServerConfig('core', 'shareapi_only_share_with_group_members', 'no');
  81. $this->modifyServerConfig('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes');
  82. $this->modifyServerConfig('core', 'shareapi_allow_group_sharing', 'yes');
  83. }
  84. }