You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AppSettingsContext.php 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. *
  4. * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com)
  5. * @copyright Copyright (c) 2018, John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  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 PHPUnit\Framework\Assert;
  25. class AppSettingsContext implements Context, ActorAwareInterface {
  26. use ActorAware;
  27. /**
  28. * @return Locator
  29. */
  30. public static function appSettings() {
  31. return Locator::forThe()->id("app-settings")->
  32. describedAs("App settings");
  33. }
  34. /**
  35. * @return Locator
  36. */
  37. public static function appSettingsContent() {
  38. return Locator::forThe()->xpath("//div[@id = 'app-settings-content' or @id = 'app-settings__content']")->
  39. descendantOf(self::appSettings())->
  40. describedAs("App settings");
  41. }
  42. /**
  43. * @return Locator
  44. */
  45. public static function appSettingsOpenButton() {
  46. return Locator::forThe()->xpath("//div[@id = 'app-settings-header' or @id = 'app-settings__header']/button")->
  47. descendantOf(self::appSettings())->
  48. describedAs("The button to open the app settings");
  49. }
  50. /**
  51. * @return Locator
  52. */
  53. public static function checkboxInTheSettings($id) {
  54. return Locator::forThe()->xpath("//input[@id = '$id']")->
  55. descendantOf(self::appSettingsContent())->
  56. describedAs("The $id checkbox in the settings");
  57. }
  58. /**
  59. * @return Locator
  60. */
  61. public static function checkboxLabelInTheSettings($id) {
  62. return Locator::forThe()->xpath("//label[@for = '$id']")->
  63. descendantOf(self::appSettingsContent())->
  64. describedAs("The label for the $id checkbox in the settings");
  65. }
  66. /**
  67. * @Given I open the settings
  68. */
  69. public function iOpenTheSettings() {
  70. $this->actor->find(self::appSettingsOpenButton(), 10)->click();
  71. }
  72. /**
  73. * @Given I toggle the :id checkbox in the settings
  74. */
  75. public function iToggleTheCheckboxInTheSettingsTo($id) {
  76. $this->actor->find(self::checkboxLabelInTheSettings($id), 10)->click();
  77. }
  78. /**
  79. * @Then I see that the settings are opened
  80. */
  81. public function iSeeThatTheSettingsAreOpened() {
  82. if (!WaitFor::elementToBeEventuallyShown(
  83. $this->actor,
  84. self::appSettingsContent(),
  85. $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
  86. Assert::fail("The app settings are not open yet after $timeout seconds");
  87. }
  88. }
  89. }