CommentsAppContext.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  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. use PHPUnit\Framework\Assert;
  25. class CommentsAppContext implements Context, ActorAwareInterface {
  26. use ActorAware;
  27. /**
  28. * @return Locator
  29. */
  30. public static function newCommentField() {
  31. return Locator::forThe()->css("div.newCommentRow .message")->
  32. descendantOf(FilesAppContext::detailsView())->
  33. describedAs("New comment field in details view in Files app");
  34. }
  35. /**
  36. * @return Locator
  37. */
  38. public static function submitNewCommentButton() {
  39. return Locator::forThe()->css("div.newCommentRow .submit")->
  40. descendantOf(FilesAppContext::detailsView())->
  41. describedAs("Submit new comment button in details view in Files app");
  42. }
  43. /**
  44. * @return Locator
  45. */
  46. public static function commentList() {
  47. return Locator::forThe()->css("ul.comments")->
  48. descendantOf(FilesAppContext::detailsView())->
  49. describedAs("Comment list in details view in Files app");
  50. }
  51. /**
  52. * @return Locator
  53. */
  54. public static function commentWithText($text) {
  55. return Locator::forThe()->xpath("//div[normalize-space() = '$text']/ancestor::li")->
  56. descendantOf(self::commentList())->
  57. describedAs("Comment with text \"$text\" in details view in Files app");
  58. }
  59. /**
  60. * @return Locator
  61. */
  62. public static function emptyContent() {
  63. return Locator::forThe()->css(".emptycontent")->
  64. descendantOf(FilesAppContext::detailsView())->
  65. describedAs("Empty content in details view in Files app");
  66. }
  67. /**
  68. * @When /^I create a new comment with "([^"]*)" as message$/
  69. */
  70. public function iCreateANewCommentWithAsMessage($commentText) {
  71. $this->actor->find(self::newCommentField(), 10)->setValue($commentText);
  72. $this->actor->find(self::submitNewCommentButton())->click();
  73. }
  74. /**
  75. * @Then /^I see that there are no comments$/
  76. */
  77. public function iSeeThatThereAreNoComments() {
  78. if (!WaitFor::elementToBeEventuallyShown(
  79. $this->actor,
  80. self::emptyContent(),
  81. $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
  82. Assert::fail("The no comments message is not visible yet after $timeout seconds");
  83. }
  84. }
  85. /**
  86. * @Then /^I see a comment with "([^"]*)" as message$/
  87. */
  88. public function iSeeACommentWithAsMessage($commentText) {
  89. Assert::assertTrue(
  90. $this->actor->find(self::commentWithText($commentText), 10)->isVisible());
  91. }
  92. /**
  93. * @Then /^I see that there is no comment with "([^"]*)" as message$/
  94. */
  95. public function iSeeThatThereIsNoCommentWithAsMessage($commentText) {
  96. try {
  97. Assert::assertFalse(
  98. $this->actor->find(self::commentWithText($commentText))->isVisible());
  99. } catch (NoSuchElementException $exception) {
  100. }
  101. }
  102. }