AppsManagementContext.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. use PHPUnit\Framework\Assert;
  26. class AppsManagementContext implements Context, ActorAwareInterface {
  27. use ActorAware;
  28. /**
  29. * @return Locator
  30. */
  31. public static function appsList() {
  32. return Locator::forThe()->xpath("//main[@id='app-content' or contains(@class, 'app-content')]//div[@id='apps-list']")->
  33. describedAs("Apps list in Apps Management");
  34. }
  35. /**
  36. * @return Locator
  37. */
  38. public static function enableButtonForApp($app) {
  39. return Locator::forThe()->button("Enable")->
  40. descendantOf(self::rowForApp($app))->
  41. describedAs("Enable button in the app list for $app");
  42. }
  43. /**
  44. * @return Locator
  45. */
  46. public static function enableButtonForAnyApp() {
  47. return Locator::forThe()->button("Enable")->
  48. descendantOf(self::appsList())->
  49. describedAs("Enable button in the app list for any app");
  50. }
  51. /**
  52. * @return Locator
  53. */
  54. public static function downloadAndEnableButtonForApp($app) {
  55. return Locator::forThe()->button("Download and enable")->
  56. descendantOf(self::rowForApp($app))->
  57. describedAs("Download & enable button in the app list for $app");
  58. }
  59. /**
  60. * @return Locator
  61. */
  62. public static function disableButtonForApp($app) {
  63. return Locator::forThe()->button("Disable")->
  64. descendantOf(self::rowForApp($app))->
  65. describedAs("Disable button in the app list for $app");
  66. }
  67. /**
  68. * @return Locator
  69. */
  70. public static function disableButtonForAnyApp() {
  71. return Locator::forThe()->button("Disable")->
  72. descendantOf(self::appsList())->
  73. describedAs("Disable button in the app list for any app");
  74. }
  75. /**
  76. * @return Locator
  77. */
  78. public static function enableAllBundleButton($bundle) {
  79. return Locator::forThe()->xpath("//div[@class='apps-header']/h2[normalize-space() = '$bundle']/input[@value='Enable all']")->
  80. descendantOf(self::appsList())->
  81. describedAs("Button to enable bundles");
  82. }
  83. /**
  84. * @return Locator
  85. */
  86. public static function rowForApp($app) {
  87. return Locator::forThe()->xpath("//div[@class='app-name'][normalize-space() = '$app']/..")->
  88. descendantOf(self::appsList())->
  89. describedAs("Row for app $app in Apps Management");
  90. }
  91. /**
  92. * @return Locator
  93. */
  94. public static function emptyAppList() {
  95. return Locator::forThe()->xpath("//div[@id='apps-list-empty']")->
  96. descendantOf(self::appsList())->
  97. describedAs("Empty apps list view");
  98. }
  99. /**
  100. * @return Locator
  101. */
  102. public static function appEntries() {
  103. return Locator::forThe()->xpath("//div[@class='section']")->
  104. descendantOf(self::appsList())->
  105. describedAs("Entries in apps list");
  106. }
  107. /**
  108. * @return Locator
  109. */
  110. public static function disabledAppEntries() {
  111. return Locator::forThe()->button("Disable")->
  112. descendantOf(self::appEntries())->
  113. describedAs("Disable button in the app list");
  114. }
  115. /**
  116. * @return Locator
  117. */
  118. public static function enabledAppEntries() {
  119. return Locator::forThe()->button("Enable")->
  120. descendantOf(self::appEntries())->
  121. describedAs("Enable button in the app list");
  122. }
  123. /**
  124. * @return Locator
  125. */
  126. public static function sidebar() {
  127. return Locator::forThe()->xpath("//*[@id=\"app-sidebar\" or contains(@class, 'app-sidebar')]")->
  128. describedAs("Sidebar in apps management");
  129. }
  130. /**
  131. * @When I enable the :app app
  132. */
  133. public function iEnableTheApp($app) {
  134. $this->actor->find(self::enableButtonForApp($app), 10)->click();
  135. }
  136. /**
  137. * @When I download and enable the :app app
  138. */
  139. public function iDownloadAndEnableTheApp($app) {
  140. $this->actor->find(self::downloadAndEnableButtonForApp($app), 10)->click();
  141. }
  142. /**
  143. * @When I disable the :app app
  144. */
  145. public function iDisableTheApp($app) {
  146. $this->actor->find(self::disableButtonForApp($app), 10)->click();
  147. }
  148. /**
  149. * @Then I see that the :app app has been enabled
  150. */
  151. public function iSeeThatTheAppHasBeenEnabled($app) {
  152. // TODO: Find a way to check if the enable button is removed
  153. Assert::assertTrue(
  154. $this->actor->find(self::disableButtonForApp($app), 10)->isVisible()
  155. );
  156. }
  157. /**
  158. * @Then I see that the :app app has been disabled
  159. */
  160. public function iSeeThatTheAppHasBeenDisabled($app) {
  161. // TODO: Find a way to check if the disable button is removed
  162. Assert::assertTrue(
  163. $this->actor->find(self::enableButtonForApp($app), 10)->isVisible()
  164. );
  165. }
  166. /**
  167. * @Then /^I see that there are no available updates$/
  168. */
  169. public function iSeeThatThereAreNoAvailableUpdates() {
  170. Assert::assertTrue(
  171. $this->actor->find(self::emptyAppList(), 10)->isVisible()
  172. );
  173. }
  174. /**
  175. * @Then /^I see that there some apps listed from the app store$/
  176. */
  177. public function iSeeThatThereSomeAppsListedFromTheAppStore() {
  178. if (!WaitFor::elementToBeEventuallyShown(
  179. $this->actor,
  180. self::appEntries(),
  181. $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
  182. Assert::fail("The apps from the app store were not shown yet after $timeout seconds");
  183. }
  184. }
  185. /**
  186. * @When /^I click on the "([^"]*)" app$/
  187. */
  188. public function iClickOnTheApp($app) {
  189. $this->actor->find(self::rowForApp($app), 10)->click();
  190. }
  191. /**
  192. * @Given /^I see that there are only disabled apps$/
  193. */
  194. public function iSeeThatThereAreOnlyDisabledApps() {
  195. try {
  196. $this->actor->find(self::disableButtonForAnyApp(), 2);
  197. Assert::fail("Found enabled apps");
  198. } catch (NoSuchElementException $exception) {
  199. }
  200. }
  201. /**
  202. * @Given /^I see that there are only enabled apps$/
  203. */
  204. public function iSeeThatThereAreOnlyEnabledApps() {
  205. try {
  206. $this->actor->find(self::enableButtonForAnyApp(), 2);
  207. Assert::fail("Found disabled apps");
  208. } catch (NoSuchElementException $exception) {
  209. }
  210. }
  211. /**
  212. * @Given /^I see the app bundles$/
  213. */
  214. public function iSeeTheAppBundles() {
  215. Assert::assertTrue(
  216. $this->actor->find(self::rowForApp('Auditing / Logging'), 10)->isVisible()
  217. );
  218. Assert::assertTrue(
  219. $this->actor->find(self::rowForApp('LDAP user and group backend'), 2)->isVisible()
  220. );
  221. }
  222. /**
  223. * @When /^I enable all apps from the "([^"]*)"$/
  224. */
  225. public function iEnableAllAppsFromThe($bundle) {
  226. $this->actor->find(self::enableAllBundleButton($bundle), 2)->click();
  227. }
  228. /**
  229. * @Given /^I see that the "([^"]*)" is disabled$/
  230. */
  231. public function iSeeThatTheIsDisabled($bundle) {
  232. Assert::assertTrue(
  233. $this->actor->find(self::enableAllBundleButton($bundle), 2)->isVisible()
  234. );
  235. }
  236. /**
  237. * @Given /^I see that the app details are shown$/
  238. */
  239. public function iSeeThatTheAppDetailsAreShown() {
  240. // The sidebar always exists in the DOM, so it has to be explicitly
  241. // waited for it to be visible instead of relying on the implicit wait
  242. // made to find the element.
  243. if (!WaitFor::elementToBeEventuallyShown(
  244. $this->actor,
  245. self::sidebar(),
  246. $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
  247. Assert::fail("The sidebar was not shown yet after $timeout seconds");
  248. }
  249. }
  250. }