CollaborationContext.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2021, Joas Schilling <coding@schilljs.com>
  5. *
  6. * @author Joas Schilling <coding@schilljs.com>
  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\Gherkin\Node\TableNode;
  26. use PHPUnit\Framework\Assert;
  27. require __DIR__ . '/../../vendor/autoload.php';
  28. class CollaborationContext implements Context {
  29. use Provisioning;
  30. use AppConfiguration;
  31. /**
  32. * @Then /^get autocomplete for "([^"]*)"$/
  33. * @param TableNode|null $formData
  34. */
  35. public function getAutocomplete(string $search, TableNode $formData): void {
  36. $query = $search === 'null' ? null : $search;
  37. $this->sendRequestForJSON('GET', '/core/autocomplete/get?itemType=files&itemId=123&search=' . $query, [
  38. 'itemType' => 'files',
  39. 'itemId' => '123',
  40. 'search' => $query,
  41. ]);
  42. $this->theHTTPStatusCodeShouldBe(200);
  43. $data = json_decode($this->response->getBody()->getContents(), true);
  44. $suggestions = $data['ocs']['data'];
  45. Assert::assertCount(count($formData->getHash()), $suggestions, 'Suggestion count does not match');
  46. Assert::assertEquals($formData->getHash(), array_map(static function ($suggestion, $expected) {
  47. $data = [];
  48. if (isset($expected['id'])) {
  49. $data['id'] = $suggestion['id'];
  50. }
  51. if (isset($expected['source'])) {
  52. $data['source'] = $suggestion['source'];
  53. }
  54. return $data;
  55. }, $suggestions, $formData->getHash()));
  56. }
  57. protected function resetAppConfigs(): void {
  58. $this->deleteServerConfig('core', 'shareapi_allow_share_dialog_user_enumeration');
  59. $this->deleteServerConfig('core', 'shareapi_restrict_user_enumeration_to_group');
  60. $this->deleteServerConfig('core', 'shareapi_restrict_user_enumeration_to_phone');
  61. $this->deleteServerConfig('core', 'shareapi_restrict_user_enumeration_full_match');
  62. $this->deleteServerConfig('core', 'shareapi_only_share_with_group_members');
  63. }
  64. }