SettingsMenuContext.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 SettingsMenuContext implements Context, ActorAwareInterface {
  25. use ActorAware;
  26. /**
  27. * @return Locator
  28. */
  29. public static function settingsSectionInHeader() {
  30. return Locator::forThe()->xpath("//*[@id = 'header']//*[@id = 'settings']")->
  31. describedAs("Settings menu section in the header");
  32. }
  33. /**
  34. * @return Locator
  35. */
  36. public static function settingsMenuButton() {
  37. return Locator::forThe()->id("expand")->
  38. descendantOf(self::settingsSectionInHeader())->
  39. describedAs("Settings menu button");
  40. }
  41. /**
  42. * @return Locator
  43. */
  44. public static function settingsMenu() {
  45. return Locator::forThe()->id("expanddiv")->
  46. descendantOf(self::settingsSectionInHeader())->
  47. describedAs("Settings menu");
  48. }
  49. /**
  50. * @return Locator
  51. */
  52. public static function usersMenuItem() {
  53. return self::menuItemFor("Users");
  54. }
  55. /**
  56. * @return Locator
  57. */
  58. public static function usersAppsItem() {
  59. return self::menuItemFor("Apps");
  60. }
  61. /**
  62. * @return Locator
  63. */
  64. public static function logOutMenuItem() {
  65. return self::menuItemFor("Log out");
  66. }
  67. /**
  68. * @return Locator
  69. */
  70. private static function menuItemFor($itemText) {
  71. return Locator::forThe()->xpath("//a[normalize-space() = '$itemText']")->
  72. descendantOf(self::settingsMenu())->
  73. describedAs($itemText . " item in Settings menu");
  74. }
  75. /**
  76. * @param string $itemText
  77. * @return Locator
  78. */
  79. private static function settingsPanelFor($itemText) {
  80. return Locator::forThe()->xpath("//div[@id = 'app-navigation']//ul//li[@class = 'app-navigation-caption' and normalize-space() = '$itemText']")->
  81. describedAs($itemText . " item in Settings panel");
  82. }
  83. /**
  84. * @return array
  85. */
  86. public function menuItems() {
  87. return $this->actor->find(self::settingsMenu(), 10)
  88. ->getWrappedElement()->findAll('xpath', '//a');
  89. }
  90. /**
  91. * @When I open the Settings menu
  92. */
  93. public function iOpenTheSettingsMenu() {
  94. $this->actor->find(self::settingsMenuButton(), 10)->click();
  95. }
  96. /**
  97. * @When I open the User settings
  98. */
  99. public function iOpenTheUserSettings() {
  100. $this->iOpenTheSettingsMenu();
  101. $this->actor->find(self::usersMenuItem(), 2)->click();
  102. }
  103. /**
  104. * @When I open the Apps management
  105. */
  106. public function iOpenTheAppsManagement() {
  107. $this->iOpenTheSettingsMenu();
  108. $this->actor->find(self::usersAppsItem(), 2)->click();
  109. }
  110. /**
  111. * @When I visit the settings page
  112. */
  113. public function iVisitTheSettingsPage() {
  114. $this->iOpenTheSettingsMenu();
  115. $this->actor->find(self::menuItemFor('Settings'), 2)->click();
  116. }
  117. /**
  118. * @When I log out
  119. */
  120. public function iLogOut() {
  121. $this->iOpenTheSettingsMenu();
  122. $this->actor->find(self::logOutMenuItem(), 2)->click();
  123. }
  124. /**
  125. * @Then I see that the Settings menu is shown
  126. */
  127. public function iSeeThatTheSettingsMenuIsShown() {
  128. PHPUnit_Framework_Assert::assertTrue(
  129. $this->actor->find(self::settingsMenu(), 10)->isVisible());
  130. }
  131. /**
  132. * @Then I see that the Settings menu has only :items items
  133. */
  134. public function iSeeThatTheSettingsMenuHasOnlyXItems($items) {
  135. PHPUnit_Framework_Assert::assertCount(intval($items), self::menuItems());
  136. }
  137. /**
  138. * @Then I see that the :itemText item in the Settings menu is shown
  139. */
  140. public function iSeeThatTheItemInTheSettingsMenuIsShown($itemText) {
  141. PHPUnit_Framework_Assert::assertTrue(
  142. $this->actor->find(self::menuItemFor($itemText), 10)->isVisible());
  143. }
  144. /**
  145. * @Then I see that the :itemText item in the Settings menu is not shown
  146. */
  147. public function iSeeThatTheItemInTheSettingsMenuIsNotShown($itemText) {
  148. $this->iSeeThatTheSettingsMenuIsShown();
  149. try {
  150. PHPUnit_Framework_Assert::assertFalse(
  151. $this->actor->find(self::menuItemFor($itemText))->isVisible());
  152. } catch (NoSuchElementException $exception) {
  153. }
  154. }
  155. /**
  156. * @Then I see that the :itemText settings panel is shown
  157. */
  158. public function iSeeThatTheItemSettingsPanelIsShown($itemText) {
  159. PHPUnit_Framework_Assert::assertTrue(
  160. $this->actor->find(self::settingsPanelFor($itemText), 10)->isVisible()
  161. );
  162. }
  163. /**
  164. * @Then I see that the :itemText settings panel is not shown
  165. */
  166. public function iSeeThatTheItemSettingsPanelIsNotShown($itemText) {
  167. try {
  168. PHPUnit_Framework_Assert::assertFalse(
  169. $this->actor->find(self::settingsPanelFor($itemText), 10)->isVisible()
  170. );
  171. } catch (NoSuchElementException $exception) {
  172. }
  173. }
  174. }