CapabilitiesContext.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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())->data->capabilities;
  23. foreach ($formData->getHash() as $row) {
  24. $path_to_element = explode('@@@', $row['path_to_element']);
  25. $answeredValue = $capabilitiesXML->{$row['capability']};
  26. for ($i = 0; $i < count($path_to_element); $i++) {
  27. $answeredValue = $answeredValue->{$path_to_element[$i]};
  28. }
  29. $answeredValue = (string)$answeredValue;
  30. Assert::assertEquals(
  31. $row['value'] === "EMPTY" ? '' : $row['value'],
  32. $answeredValue,
  33. "Failed field " . $row['capability'] . " " . $row['path_to_element']
  34. );
  35. }
  36. }
  37. protected function resetAppConfigs() {
  38. $this->deleteServerConfig('core', 'shareapi_enabled');
  39. $this->deleteServerConfig('core', 'shareapi_allow_links');
  40. $this->deleteServerConfig('core', 'shareapi_allow_public_upload');
  41. $this->deleteServerConfig('core', 'shareapi_allow_resharing');
  42. $this->deleteServerConfig('files_sharing', 'outgoing_server2server_share_enabled');
  43. $this->deleteServerConfig('files_sharing', 'incoming_server2server_share_enabled');
  44. $this->deleteServerConfig('core', 'shareapi_enforce_links_password');
  45. $this->deleteServerConfig('core', 'shareapi_allow_public_notification');
  46. $this->deleteServerConfig('core', 'shareapi_default_expire_date');
  47. $this->deleteServerConfig('core', 'shareapi_enforce_expire_date');
  48. $this->deleteServerConfig('core', 'shareapi_allow_group_sharing');
  49. }
  50. }