1
0

AppSettingsContext.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. class AppSettingsContext implements Context, ActorAwareInterface {
  25. use ActorAware;
  26. /**
  27. * @return Locator
  28. */
  29. public static function appSettings() {
  30. return Locator::forThe()->id("app-settings")->
  31. describedAs("App settings");
  32. }
  33. /**
  34. * @return Locator
  35. */
  36. public static function appSettingsContent() {
  37. return Locator::forThe()->id("app-settings-content")->
  38. descendantOf(self::appSettings())->
  39. describedAs("App settings");
  40. }
  41. /**
  42. * @return Locator
  43. */
  44. public static function appSettingsOpenButton() {
  45. return Locator::forThe()->xpath("//div[@id = 'app-settings-header']/button")->
  46. descendantOf(self::appSettings())->
  47. describedAs("The button to open the app settings");
  48. }
  49. /**
  50. * @return Locator
  51. */
  52. public static function checkboxInTheSettings($id) {
  53. return Locator::forThe()->xpath("//input[@id = '$id']")->
  54. descendantOf(self::appSettingsContent())->
  55. describedAs("The $id checkbox in the settings");
  56. }
  57. /**
  58. * @return Locator
  59. */
  60. public static function checkboxLabelInTheSettings($id) {
  61. return Locator::forThe()->xpath("//label[@for = '$id']")->
  62. descendantOf(self::appSettingsContent())->
  63. describedAs("The label for the $id checkbox in the settings");
  64. }
  65. /**
  66. * @Given I open the settings
  67. */
  68. public function iOpenTheSettings() {
  69. $this->actor->find(self::appSettingsOpenButton())->click();
  70. }
  71. /**
  72. * @Given I toggle the :id checkbox in the settings
  73. */
  74. public function iToggleTheCheckboxInTheSettingsTo($id) {
  75. $locator = self::CheckboxInTheSettings($id);
  76. // If locator is not visible, fallback to label
  77. if (!$this->actor->find(self::CheckboxInTheSettings($id))->isVisible()) {
  78. $locator = self::checkboxLabelInTheSettings($id);
  79. }
  80. $this->actor->find($locator)->click();
  81. }
  82. /**
  83. * @Then I see that the settings are opened
  84. */
  85. public function iSeeThatTheSettingsAreOpened() {
  86. WaitFor::elementToBeEventuallyShown($this->actor, self::appSettingsContent());
  87. }
  88. }