1
0

AppsManagementContext.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <?php
  2. /**
  3. *
  4. * @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net>
  5. *
  6. * @author Julius Härtl <jus@bitgrid.net>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. use Behat\Behat\Context\Context;
  25. class AppsManagementContext implements Context, ActorAwareInterface {
  26. use ActorAware;
  27. /**
  28. * @return Locator
  29. */
  30. public static function enableButtonForApp($app) {
  31. return Locator::forThe()->button("Enable")->
  32. descendantOf(self::rowForApp($app))->
  33. describedAs("Enable button in the app list for $app");
  34. }
  35. /**
  36. * @return Locator
  37. */
  38. public static function downloadAndEnableButtonForApp($app) {
  39. return Locator::forThe()->button("Download and enable")->
  40. descendantOf(self::rowForApp($app))->
  41. describedAs("Download & enable button in the app list for $app");
  42. }
  43. /**
  44. * @return Locator
  45. */
  46. public static function disableButtonForApp($app) {
  47. return Locator::forThe()->button("Disable")->
  48. descendantOf(self::rowForApp($app))->
  49. describedAs("Disable button in the app list for $app");
  50. }
  51. /**
  52. * @return Locator
  53. */
  54. public static function bundleButton($bundle) {
  55. return Locator::forThe()->xpath("//div[@id='app-content']//div[@class='apps-header']/h2[normalize-space() = '$bundle']/input")->
  56. describedAs("Button to enable / disable bundles");
  57. }
  58. /**
  59. * @return Locator
  60. */
  61. public static function rowForApp($app) {
  62. return Locator::forThe()->xpath("//div[@id='app-content']//div[@class='app-name'][normalize-space() = '$app']/..")->
  63. describedAs("Row for app $app in Apps Management");
  64. }
  65. /**
  66. * @return Locator
  67. */
  68. public static function emptyAppList() {
  69. return Locator::forThe()->xpath("//div[@id='app-content']//div[@id='apps-list-empty']")->
  70. describedAs("Empty apps list view");
  71. }
  72. /**
  73. * @return Locator
  74. */
  75. public static function appEntries() {
  76. return Locator::forThe()->xpath("//div[@id='app-content']//div[@class='section']")->
  77. describedAs("Entries in apps list");
  78. }
  79. /**
  80. * @return Locator
  81. */
  82. public static function disabledAppEntries() {
  83. return Locator::forThe()->button("Disable")->
  84. descendantOf(self::appEntries())->
  85. describedAs("Disable button in the app list");
  86. }
  87. /**
  88. * @return Locator
  89. */
  90. public static function enabledAppEntries() {
  91. return Locator::forThe()->button("Enable")->
  92. descendantOf(self::appEntries())->
  93. describedAs("Enable button in the app list");
  94. }
  95. /**
  96. * @return Locator
  97. */
  98. public static function sidebar() {
  99. return Locator::forThe()->id("app-sidebar")->
  100. describedAs("Sidebar in apps management");
  101. }
  102. /**
  103. * @When I enable the :app app
  104. */
  105. public function iEnableTheApp($app) {
  106. $this->actor->find(self::enableButtonForApp($app), 10)->click();
  107. }
  108. /**
  109. * @When I download and enable the :app app
  110. */
  111. public function iDownloadAndEnableTheApp($app) {
  112. $this->actor->find(self::downloadAndEnableButtonForApp($app), 10)->click();
  113. }
  114. /**
  115. * @When I disable the :app app
  116. */
  117. public function iDisableTheApp($app) {
  118. $this->actor->find(self::disableButtonForApp($app), 10)->click();
  119. }
  120. /**
  121. * @Then I see that the :app app has been enabled
  122. */
  123. public function iSeeThatTheAppHasBeenEnabled($app) {
  124. // TODO: Find a way to check if the enable button is removed
  125. $this->actor->find(self::disableButtonForApp($app), 10);
  126. }
  127. /**
  128. * @Then I see that the :app app has been disabled
  129. */
  130. public function iSeeThatTheAppHasBeenDisabled($app) {
  131. // TODO: Find a way to check if the disable button is removed
  132. $this->actor->find(self::enableButtonForApp($app), 10);
  133. }
  134. /**
  135. * @Then /^I see that there are no available updates$/
  136. */
  137. public function iSeeThatThereAreNoAvailableUpdates() {
  138. PHPUnit_Framework_Assert::assertTrue(
  139. $this->actor->find(self::emptyAppList(), 10)->isVisible()
  140. );
  141. }
  142. /**
  143. * @Then /^I see that there some apps listed from the app store$/
  144. */
  145. public function iSeeThatThereSomeAppsListedFromTheAppStore() {
  146. WaitFor::elementToBeEventuallyShown($this->actor, self::appEntries(), 10);
  147. }
  148. /**
  149. * @When /^I click on the "([^"]*)" app$/
  150. */
  151. public function iClickOnTheApp($app) {
  152. $this->actor->find(self::rowForApp($app), 10)->click();
  153. }
  154. /**
  155. * @Given /^I see that there are only disabled apps$/
  156. */
  157. public function iSeeThatThereAreOnlyDisabledApps() {
  158. $buttons = $this->actor->getSession()->getDriver()->find("//input[@value = 'Disable']");
  159. PHPUnit\Framework\Assert::assertEmpty($buttons, 'Found disabled apps');
  160. }
  161. /**
  162. * @Given /^I see that there are only enabled apps$/
  163. */
  164. public function iSeeThatThereAreOnlyEnabledApps() {
  165. $buttons = $this->actor->getSession()->getDriver()->find("//input[@value = 'Enable']");
  166. PHPUnit\Framework\Assert::assertEmpty($buttons, 'Found disabled apps');
  167. }
  168. /**
  169. * @Given /^I see the app bundles$/
  170. */
  171. public function iSeeTheAppBundles() {
  172. $this->actor->find(self::rowForApp('Auditing / Logging'), 2);
  173. $this->actor->find(self::rowForApp('LDAP user and group backend'), 2);
  174. }
  175. /**
  176. * @When /^I enable all apps from the "([^"]*)"$/
  177. */
  178. public function iEnableAllAppsFromThe($bundle) {
  179. $this->actor->find(self::bundleButton($bundle), 2)->click();
  180. }
  181. /**
  182. * @Given /^I see that the "([^"]*)" is disabled$/
  183. */
  184. public function iSeeThatTheIsDisabled($bundle) {
  185. PHPUnit\Framework\Assert::assertEquals('Enable all', $this->actor->find(self::bundleButton($bundle))->getValue());
  186. }
  187. /**
  188. * @Given /^I see that the app details are shown$/
  189. */
  190. public function iSeeThatTheAppDetailsAreShown() {
  191. // The sidebar always exists in the DOM, so it has to be explicitly
  192. // waited for it to be visible instead of relying on the implicit wait
  193. // made to find the element.
  194. if (!WaitFor::elementToBeEventuallyShown(
  195. $this->actor,
  196. self::sidebar(),
  197. $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
  198. PHPUnit_Framework_Assert::fail("The sidebar was not shown yet after $timeout seconds");
  199. }
  200. }
  201. }