You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AppNavigationContext.php 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 AppNavigationContext implements Context, ActorAwareInterface {
  25. use ActorAware;
  26. /**
  27. * @return Locator
  28. */
  29. public static function appNavigation() {
  30. return Locator::forThe()->id("app-navigation")->
  31. describedAs("App navigation");
  32. }
  33. /**
  34. * @return Locator
  35. */
  36. public static function appNavigationSectionItemFor($sectionText) {
  37. return Locator::forThe()->xpath("//li/a[normalize-space() = '$sectionText']/..")->
  38. descendantOf(self::appNavigation())->
  39. describedAs($sectionText . " section item in App Navigation");
  40. }
  41. /**
  42. * @return Locator
  43. */
  44. public static function appNavigationSectionItemInFor($caption, $sectionText) {
  45. return Locator::forThe()->xpath("//li[normalize-space() = '$caption']/following-sibling::li/a[normalize-space() = '$sectionText']/..")->
  46. descendantOf(self::appNavigation())->
  47. describedAs($sectionText . " section item of the $caption group in App Navigation");
  48. }
  49. /**
  50. * @return Locator
  51. */
  52. public static function appNavigationCurrentSectionItem() {
  53. return Locator::forThe()->css(".active")->
  54. descendantOf(self::appNavigation())->
  55. describedAs("Current section item in App Navigation");
  56. }
  57. /**
  58. * @return Locator
  59. */
  60. public static function buttonForTheSection($class, $section) {
  61. return Locator::forThe()->css("." . $class)->
  62. descendantOf(self::appNavigationSectionItemFor($section))->
  63. describedAs("The $class button on the $section section in App Navigation");
  64. }
  65. /**
  66. * @return Locator
  67. */
  68. public static function counterForTheSection($section) {
  69. return Locator::forThe()->css(".app-navigation-entry-utils-counter")->
  70. descendantOf(self::appNavigationSectionItemFor($section))->
  71. describedAs("The counter for the $section section in App Navigation");
  72. }
  73. /**
  74. * @Given I open the :section section
  75. */
  76. public function iOpenTheSection($section) {
  77. $this->actor->find(self::appNavigationSectionItemFor($section), 10)->click();
  78. }
  79. /**
  80. * @Given I open the :section section of the :caption group
  81. */
  82. public function iOpenTheSectionOf($caption, $section) {
  83. $this->actor->find(self::appNavigationSectionItemInFor($caption, $section), 10)->click();
  84. }
  85. /**
  86. * @Given I click the :class button on the :section section
  87. */
  88. public function iClickTheButtonInTheSection($class, $section) {
  89. $this->actor->find(self::buttonForTheSection($class, $section), 10)->click();
  90. }
  91. /**
  92. * @Then I see that the current section is :section
  93. */
  94. public function iSeeThatTheCurrentSectionIs($section) {
  95. PHPUnit_Framework_Assert::assertEquals($this->actor->find(self::appNavigationCurrentSectionItem(), 10)->getText(), $section);
  96. }
  97. /**
  98. * @Then I see that the section :section is shown
  99. */
  100. public function iSeeThatTheSectionIsShown($section) {
  101. WaitFor::elementToBeEventuallyShown($this->actor, self::appNavigationSectionItemFor($section));
  102. }
  103. /**
  104. * @Then I see that the section :section is not shown
  105. */
  106. public function iSeeThatTheSectionIsNotShown($section) {
  107. WaitFor::elementToBeEventuallyNotShown($this->actor, self::appNavigationSectionItemFor($section));
  108. }
  109. /**
  110. * @Then I see that the section :section has a count of :count
  111. */
  112. public function iSeeThatTheSectionHasACountOf($section, $count) {
  113. PHPUnit_Framework_Assert::assertEquals($this->actor->find(self::counterForTheSection($section), 10)->getText(), $count);
  114. }
  115. /**
  116. * @Then I see that the section :section does not have a count
  117. */
  118. public function iSeeThatTheSectionDoesNotHaveACount($section) {
  119. if (!WaitFor::elementToBeEventuallyNotShown(
  120. $this->actor,
  121. self::counterForTheSection($section),
  122. $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
  123. PHPUnit_Framework_Assert::fail("The counter for section $section is still shown after $timeout seconds");
  124. }
  125. }
  126. }