1
0

UsersSettingsContext.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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 UsersSettingsContext implements Context, ActorAwareInterface {
  25. use ActorAware;
  26. /**
  27. * @return Locator
  28. */
  29. public static function newUserForm() {
  30. return Locator::forThe()->id("new-user")->
  31. describedAs("New user form in Users Settings");
  32. }
  33. /**
  34. * @return Locator
  35. */
  36. public static function userNameFieldForNewUser() {
  37. return Locator::forThe()->field("newusername")->
  38. describedAs("User name field for new user in Users Settings");
  39. }
  40. /**
  41. * @return Locator
  42. */
  43. public static function displayNameFieldForNewUser() {
  44. return Locator::forThe()->field("newdisplayname")->
  45. describedAs("Display name field for new user in Users Settings");
  46. }
  47. /**
  48. * @return Locator
  49. */
  50. public static function passwordFieldForNewUser() {
  51. return Locator::forThe()->field("newuserpassword")->
  52. describedAs("Password field for new user in Users Settings");
  53. }
  54. /**
  55. * @return Locator
  56. */
  57. public static function newUserButton() {
  58. return Locator::forThe()->id("new-user-button")->
  59. describedAs("New user button in Users Settings");
  60. }
  61. /**
  62. * @return Locator
  63. */
  64. public static function createNewUserButton() {
  65. return Locator::forThe()->xpath("//form[@id = 'new-user']//input[@type = 'submit']")->
  66. describedAs("Create user button in Users Settings");
  67. }
  68. /**
  69. * @return Locator
  70. */
  71. public static function rowForUser($user) {
  72. return Locator::forThe()->xpath("//div[@id='app-content']/div/div[normalize-space() = '$user']/..")->
  73. describedAs("Row for user $user in Users Settings");
  74. }
  75. /**
  76. * Warning: you need to watch out for the proper classes order
  77. *
  78. * @return Locator
  79. */
  80. public static function classCellForUser($class, $user) {
  81. return Locator::forThe()->xpath("//*[contains(concat(' ', normalize-space(@class), ' '), ' $class ')]")->
  82. descendantOf(self::rowForUser($user))->
  83. describedAs("$class cell for user $user in Users Settings");
  84. }
  85. /**
  86. * @return Locator
  87. */
  88. public static function inputForUserInCell($cell, $user) {
  89. return Locator::forThe()->css("input")->
  90. descendantOf(self::classCellForUser($cell, $user))->
  91. describedAs("$cell input for user $user in Users Settings");
  92. }
  93. /**
  94. * @return Locator
  95. */
  96. public static function displayNameCellForUser($user) {
  97. return self::inputForUserInCell("displayName", $user);
  98. }
  99. /**
  100. * @return Locator
  101. */
  102. public static function optionInInputForUser($cell, $user) {
  103. return Locator::forThe()->css(".multiselect__option--highlight")->
  104. descendantOf(self::classCellForUser($cell, $user))->
  105. describedAs("Selected $cell option in $cell input for user $user in Users Settings");
  106. }
  107. /**
  108. * @return Locator
  109. */
  110. public static function actionsMenuOf($user) {
  111. return Locator::forThe()->css(".icon-more")->
  112. descendantOf(self::rowForUser($user))->
  113. describedAs("Actions menu for user $user in Users Settings");
  114. }
  115. /**
  116. * @return Locator
  117. */
  118. public static function theAction($action, $user) {
  119. return Locator::forThe()->xpath("//button[normalize-space() = '$action']")->
  120. descendantOf(self::rowForUser($user))->
  121. describedAs("$action action for the user $user row in Users Settings");
  122. }
  123. /**
  124. * @return Locator
  125. */
  126. public static function theColumn($column) {
  127. return Locator::forThe()->xpath("//div[@class='user-list-grid']//div[normalize-space() = '$column']")->
  128. describedAs("The $column column in Users Settings");
  129. }
  130. /**
  131. * @return Locator
  132. */
  133. public static function selectedSelectOption($cell, $user) {
  134. return Locator::forThe()->css(".multiselect__single")->
  135. descendantOf(self::classCellForUser($cell, $user))->
  136. describedAs("The selected option of the $cell select for the user $user in Users Settings");
  137. }
  138. /**
  139. * @When I click the New user button
  140. */
  141. public function iClickTheNewUserButton() {
  142. $this->actor->find(self::newUserButton())->click();
  143. }
  144. /**
  145. * @When I click the :action action in the :user actions menu
  146. */
  147. public function iClickTheAction($action, $user) {
  148. $this->actor->find(self::theAction($action, $user))->click();
  149. }
  150. /**
  151. * @When I open the actions menu for the user :user
  152. */
  153. public function iOpenTheActionsMenuOf($user) {
  154. $this->actor->find(self::actionsMenuOf($user))->click();
  155. }
  156. /**
  157. * @When I set the user name for the new user to :user
  158. */
  159. public function iSetTheUserNameForTheNewUserTo($user) {
  160. $this->actor->find(self::userNameFieldForNewUser(), 10)->setValue($user);
  161. }
  162. /**
  163. * @When I set the display name for the new user to :displayName
  164. */
  165. public function iSetTheDisplayNameForTheNewUserTo($displayName) {
  166. $this->actor->find(self::displayNameFieldForNewUser(), 10)->setValue($displayName);
  167. }
  168. /**
  169. * @When I set the password for the new user to :password
  170. */
  171. public function iSetThePasswordForTheNewUserTo($password) {
  172. $this->actor->find(self::passwordFieldForNewUser(), 10)->setValue($password);
  173. }
  174. /**
  175. * @When I create the new user
  176. */
  177. public function iCreateTheNewUser() {
  178. $this->actor->find(self::createNewUserButton(), 10)->click();
  179. }
  180. /**
  181. * @When I create user :user with password :password
  182. */
  183. public function iCreateUserWithPassword($user, $password) {
  184. $this->actor->find(self::userNameFieldForNewUser(), 10)->setValue($user);
  185. $this->actor->find(self::passwordFieldForNewUser())->setValue($password);
  186. $this->actor->find(self::createNewUserButton())->click();
  187. }
  188. /**
  189. * @When I set the :field for :user to :value
  190. */
  191. public function iSetTheFieldForUserTo($field, $user, $value) {
  192. $this->actor->find(self::inputForUserInCell($field, $user), 2)->setValue($value . "\r");
  193. }
  194. /**
  195. * Assigning/withdrawing is the same action (it toggles).
  196. *
  197. * @When I assign the user :user to the group :group
  198. * @When I withdraw the user :user from the group :group
  199. */
  200. public function iAssignTheUserToTheGroup($user, $group) {
  201. $this->actor->find(self::inputForUserInCell('groups', $user))->setValue($group);
  202. $this->actor->find(self::optionInInputForUser('groups', $user))->click();
  203. }
  204. /**
  205. * @When I set the user :user quota to :quota
  206. */
  207. public function iSetTheUserQuotaTo($user, $quota) {
  208. $this->actor->find(self::inputForUserInCell('quota', $user))->setValue($quota);
  209. $this->actor->find(self::optionInInputForUser('quota', $user))->click();
  210. }
  211. /**
  212. * @Then I see that the list of users contains the user :user
  213. */
  214. public function iSeeThatTheListOfUsersContainsTheUser($user) {
  215. WaitFor::elementToBeEventuallyShown($this->actor, self::rowForUser($user));
  216. }
  217. /**
  218. * @Then I see that the list of users does not contains the user :user
  219. */
  220. public function iSeeThatTheListOfUsersDoesNotContainsTheUser($user) {
  221. WaitFor::elementToBeEventuallyNotShown($this->actor, self::rowForUser($user));
  222. }
  223. /**
  224. * @Then I see that the new user form is shown
  225. */
  226. public function iSeeThatTheNewUserFormIsShown() {
  227. PHPUnit_Framework_Assert::assertTrue(
  228. $this->actor->find(self::newUserForm(), 10)->isVisible());
  229. }
  230. /**
  231. * @Then I see that the :action action in the :user actions menu is shown
  232. */
  233. public function iSeeTheAction($action, $user) {
  234. PHPUnit_Framework_Assert::assertTrue(
  235. $this->actor->find(self::theAction($action, $user), 10)->isVisible());
  236. }
  237. /**
  238. * @Then I see that the :column column is shown
  239. */
  240. public function iSeeThatTheColumnIsShown($column) {
  241. PHPUnit_Framework_Assert::assertTrue(
  242. $this->actor->find(self::theColumn($column), 10)->isVisible());
  243. }
  244. /**
  245. * @Then I see that the :field of :user is :value
  246. */
  247. public function iSeeThatTheFieldOfUserIs($field, $user, $value) {
  248. PHPUnit_Framework_Assert::assertEquals(
  249. $this->actor->find(self::inputForUserInCell($field, $user), 10)->getValue(), $value);
  250. }
  251. /**
  252. * @Then I see that the display name for the user :user is :displayName
  253. */
  254. public function iSeeThatTheDisplayNameForTheUserIs($user, $displayName) {
  255. PHPUnit_Framework_Assert::assertEquals($displayName, $this->actor->find(self::displayNameCellForUser($user), 10)->getValue());
  256. }
  257. /**
  258. * @Then I see that the :cell cell for user :user is done loading
  259. */
  260. public function iSeeThatTheCellForUserIsDoneLoading($cell, $user) {
  261. WaitFor::elementToBeEventuallyShown($this->actor, self::classCellForUser($cell.' icon-loading-small', $user));
  262. WaitFor::elementToBeEventuallyNotShown($this->actor, self::classCellForUser($cell.' icon-loading-small', $user));
  263. }
  264. /**
  265. * @Then I see that the user quota of :user is :quota
  266. */
  267. public function iSeeThatTheuserQuotaIs($user, $quota) {
  268. PHPUnit_Framework_Assert::assertEquals(
  269. $this->actor->find(self::selectedSelectOption('quota', $user), 2)->getText(), $quota);
  270. }
  271. }