CommentsAppContext.php 3.4 KB

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