1
0

CapabilitiesContext.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. use Behat\Behat\Context\Context;
  8. use Behat\Behat\Context\SnippetAcceptingContext;
  9. use PHPUnit\Framework\Assert;
  10. require __DIR__ . '/../../vendor/autoload.php';
  11. /**
  12. * Capabilities context.
  13. */
  14. class CapabilitiesContext implements Context, SnippetAcceptingContext {
  15. use BasicStructure;
  16. use AppConfiguration;
  17. /**
  18. * @Then /^fields of capabilities match with$/
  19. * @param \Behat\Gherkin\Node\TableNode|null $formData
  20. */
  21. public function checkCapabilitiesResponse(\Behat\Gherkin\Node\TableNode $formData) {
  22. $capabilitiesXML = simplexml_load_string($this->response->getBody());
  23. Assert::assertNotFalse($capabilitiesXML, 'Failed to fetch capabilities');
  24. $capabilitiesXML = $capabilitiesXML->data->capabilities;
  25. foreach ($formData->getHash() as $row) {
  26. $path_to_element = explode('@@@', $row['path_to_element']);
  27. $answeredValue = $capabilitiesXML->{$row['capability']};
  28. for ($i = 0; $i < count($path_to_element); $i++) {
  29. $answeredValue = $answeredValue->{$path_to_element[$i]};
  30. }
  31. $answeredValue = (string)$answeredValue;
  32. Assert::assertEquals(
  33. $row['value'] === 'EMPTY' ? '' : $row['value'],
  34. $answeredValue,
  35. 'Failed field ' . $row['capability'] . ' ' . $row['path_to_element']
  36. );
  37. }
  38. }
  39. protected function resetAppConfigs() {
  40. $this->deleteServerConfig('core', 'shareapi_enabled');
  41. $this->deleteServerConfig('core', 'shareapi_allow_links');
  42. $this->deleteServerConfig('core', 'shareapi_allow_public_upload');
  43. $this->deleteServerConfig('core', 'shareapi_allow_resharing');
  44. $this->deleteServerConfig('files_sharing', 'outgoing_server2server_share_enabled');
  45. $this->deleteServerConfig('files_sharing', 'incoming_server2server_share_enabled');
  46. $this->deleteServerConfig('core', 'shareapi_enforce_links_password');
  47. $this->deleteServerConfig('core', 'shareapi_allow_public_notification');
  48. $this->deleteServerConfig('core', 'shareapi_default_expire_date');
  49. $this->deleteServerConfig('core', 'shareapi_enforce_expire_date');
  50. $this->deleteServerConfig('core', 'shareapi_allow_group_sharing');
  51. }
  52. }