1
0

AppNavigationContext.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 appNavigationCurrentSectionItem() {
  45. return Locator::forThe()->css(".active")->
  46. descendantOf(self::appNavigation())->
  47. describedAs("Current section item in App Navigation");
  48. }
  49. /**
  50. * @return Locator
  51. */
  52. public static function buttonForTheSection($class, $section) {
  53. return Locator::forThe()->css("." . $class)->
  54. descendantOf(self::appNavigationSectionItemFor($section))->
  55. describedAs("The $class button on the $section section in App Navigation");
  56. }
  57. /**
  58. * @return Locator
  59. */
  60. public static function counterForTheSection($section) {
  61. return Locator::forThe()->css(".app-navigation-entry-utils-counter")->
  62. descendantOf(self::appNavigationSectionItemFor($section))->
  63. describedAs("The counter for the $section section in App Navigation");
  64. }
  65. /**
  66. * @Given I open the :section section
  67. */
  68. public function iOpenTheSection($section) {
  69. $this->actor->find(self::appNavigationSectionItemFor($section), 10)->click();
  70. }
  71. /**
  72. * @Given I click the :class button on the :section section
  73. */
  74. public function iClickTheButtonInTheSection($class, $section) {
  75. $this->actor->find(self::buttonForTheSection($class, $section), 10)->click();
  76. }
  77. /**
  78. * @Then I see that the current section is :section
  79. */
  80. public function iSeeThatTheCurrentSectionIs($section) {
  81. PHPUnit_Framework_Assert::assertEquals($this->actor->find(self::appNavigationCurrentSectionItem(), 10)->getText(), $section);
  82. }
  83. /**
  84. * @Then I see that the section :section is shown
  85. */
  86. public function iSeeThatTheSectionIsShown($section) {
  87. WaitFor::elementToBeEventuallyShown($this->actor, self::appNavigationSectionItemFor($section));
  88. }
  89. /**
  90. * @Then I see that the section :section is not shown
  91. */
  92. public function iSeeThatTheSectionIsNotShown($section) {
  93. WaitFor::elementToBeEventuallyNotShown($this->actor, self::appNavigationSectionItemFor($section));
  94. }
  95. /**
  96. * @Then I see that the section :section has a count of :count
  97. */
  98. public function iSeeThatTheSectionHasACountOf($section, $count) {
  99. PHPUnit_Framework_Assert::assertEquals($this->actor->find(self::counterForTheSection($section), 10)->getText(), $count);
  100. }
  101. /**
  102. * @Then I see that the section :section does not have a count
  103. */
  104. public function iSeeThatTheSectionDoesNotHaveACount($section) {
  105. if (!WaitFor::elementToBeEventuallyNotShown(
  106. $this->actor,
  107. self::counterForTheSection($section),
  108. $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
  109. PHPUnit_Framework_Assert::fail("The counter for section $section is still shown after $timeout seconds");
  110. }
  111. }
  112. }