PublicShareContext.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <?php
  2. /**
  3. *
  4. * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com)
  5. *
  6. * @license GNU AGPL version 3 or any later version
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. use Behat\Behat\Context\Context;
  23. class PublicShareContext implements Context, ActorAwareInterface {
  24. use ActorAware;
  25. use FileListAncestorSetter;
  26. /**
  27. * @return Locator
  28. */
  29. public static function passwordField() {
  30. return Locator::forThe()->field("password")->
  31. describedAs("Password field in Authenticate page");
  32. }
  33. /**
  34. * @return Locator
  35. */
  36. public static function authenticateButton() {
  37. return Locator::forThe()->id("password-submit")->
  38. describedAs("Authenticate button in Authenticate page");
  39. }
  40. /**
  41. * @return Locator
  42. */
  43. public static function wrongPasswordMessage() {
  44. return Locator::forThe()->xpath("//*[@class = 'warning' and normalize-space() = 'The password is wrong. Try again.']")->
  45. describedAs("Wrong password message in Authenticate page");
  46. }
  47. /**
  48. * @return Locator
  49. */
  50. public static function shareMenuButton() {
  51. return Locator::forThe()->id("header-actions-toggle")->
  52. describedAs("Share menu button in Shared file page");
  53. }
  54. /**
  55. * @return Locator
  56. */
  57. public static function shareMenu() {
  58. return Locator::forThe()->id("header-actions-menu")->
  59. describedAs("Share menu in Shared file page");
  60. }
  61. /**
  62. * @return Locator
  63. */
  64. public static function downloadItemInShareMenu() {
  65. return Locator::forThe()->id("download")->
  66. descendantOf(self::shareMenu())->
  67. describedAs("Download item in Share menu in Shared file page");
  68. }
  69. /**
  70. * @return Locator
  71. */
  72. public static function directLinkItemInShareMenu() {
  73. return Locator::forThe()->id("directLink-container")->
  74. descendantOf(self::shareMenu())->
  75. describedAs("Direct link item in Share menu in Shared file page");
  76. }
  77. /**
  78. * @return Locator
  79. */
  80. public static function saveItemInShareMenu() {
  81. return Locator::forThe()->id("save-external-share")->
  82. descendantOf(self::shareMenu())->
  83. describedAs("Save item in Share menu in Shared file page");
  84. }
  85. /**
  86. * @return Locator
  87. */
  88. public static function textPreview() {
  89. return Locator::forThe()->css(".text-preview")->
  90. describedAs("Text preview in Shared file page");
  91. }
  92. /**
  93. * @return Locator
  94. */
  95. public static function downloadButton() {
  96. return Locator::forThe()->id("downloadFile")->
  97. describedAs("Download button in Shared file page");
  98. }
  99. /**
  100. * @When I visit the shared link I wrote down
  101. */
  102. public function iVisitTheSharedLinkIWroteDown() {
  103. $this->actor->getSession()->visit($this->actor->getSharedNotebook()["shared link"]);
  104. }
  105. /**
  106. * @When I visit the direct download shared link I wrote down
  107. */
  108. public function iVisitTheDirectDownloadSharedLinkIWroteDown() {
  109. $this->actor->getSession()->visit($this->actor->getSharedNotebook()["shared link"] . "/download");
  110. }
  111. /**
  112. * @When I authenticate with password :password
  113. */
  114. public function iAuthenticateWithPassword($password) {
  115. $this->actor->find(self::passwordField(), 10)->setValue($password);
  116. $this->actor->find(self::authenticateButton())->click();
  117. }
  118. /**
  119. * @When I open the Share menu
  120. */
  121. public function iOpenTheShareMenu() {
  122. $this->actor->find(self::shareMenuButton(), 10)->click();
  123. }
  124. /**
  125. * @Then I see that the current page is the Authenticate page for the shared link I wrote down
  126. */
  127. public function iSeeThatTheCurrentPageIsTheAuthenticatePageForTheSharedLinkIWroteDown() {
  128. PHPUnit_Framework_Assert::assertEquals(
  129. $this->actor->getSharedNotebook()["shared link"] . "/authenticate/showShare",
  130. $this->actor->getSession()->getCurrentUrl());
  131. }
  132. /**
  133. * @Then I see that the current page is the Authenticate page for the direct download shared link I wrote down
  134. */
  135. public function iSeeThatTheCurrentPageIsTheAuthenticatePageForTheDirectDownloadSharedLinkIWroteDown() {
  136. PHPUnit_Framework_Assert::assertEquals(
  137. $this->actor->getSharedNotebook()["shared link"] . "/authenticate/downloadShare",
  138. $this->actor->getSession()->getCurrentUrl());
  139. }
  140. /**
  141. * @Then I see that the current page is the shared link I wrote down
  142. */
  143. public function iSeeThatTheCurrentPageIsTheSharedLinkIWroteDown() {
  144. PHPUnit_Framework_Assert::assertEquals(
  145. $this->actor->getSharedNotebook()["shared link"],
  146. $this->actor->getSession()->getCurrentUrl());
  147. $this->setFileListAncestorForActor(null, $this->actor);
  148. }
  149. /**
  150. * @Then I see that the current page is the direct download shared link I wrote down
  151. */
  152. public function iSeeThatTheCurrentPageIsTheDirectDownloadSharedLinkIWroteDown() {
  153. PHPUnit_Framework_Assert::assertEquals(
  154. $this->actor->getSharedNotebook()["shared link"] . "/download",
  155. $this->actor->getSession()->getCurrentUrl());
  156. }
  157. /**
  158. * @Then I see that a wrong password for the shared file message is shown
  159. */
  160. public function iSeeThatAWrongPasswordForTheSharedFileMessageIsShown() {
  161. PHPUnit_Framework_Assert::assertTrue(
  162. $this->actor->find(self::wrongPasswordMessage(), 10)->isVisible());
  163. }
  164. /**
  165. * @Then I see that the Share menu is shown
  166. */
  167. public function iSeeThatTheShareMenuIsShown() {
  168. // Unlike other menus, the Share menu is always present in the DOM, so
  169. // the element could be found when it was no made visible yet due to the
  170. // command not having been processed by the browser.
  171. if (!WaitFor::elementToBeEventuallyShown(
  172. $this->actor, self::shareMenu(), $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
  173. PHPUnit_Framework_Assert::fail("The Share menu is not visible yet after $timeout seconds");
  174. }
  175. // The acceptance tests are run in a window wider than the mobile breakpoint, so the
  176. // download item should not be shown in the menu (although it will be in
  177. // the DOM).
  178. PHPUnit_Framework_Assert::assertFalse(
  179. $this->actor->find(self::downloadItemInShareMenu())->isVisible());
  180. PHPUnit_Framework_Assert::assertTrue(
  181. $this->actor->find(self::directLinkItemInShareMenu())->isVisible());
  182. PHPUnit_Framework_Assert::assertTrue(
  183. $this->actor->find(self::saveItemInShareMenu())->isVisible());
  184. }
  185. /**
  186. * @Then I see that the Share menu button is not shown
  187. */
  188. public function iSeeThatTheShareMenuButtonIsNotShown() {
  189. try {
  190. PHPUnit_Framework_Assert::assertFalse(
  191. $this->actor->find(self::shareMenuButton())->isVisible());
  192. } catch (NoSuchElementException $exception) {
  193. }
  194. }
  195. /**
  196. * @Then I see that the shared file preview shows the text :text
  197. */
  198. public function iSeeThatTheSharedFilePreviewShowsTheText($text) {
  199. PHPUnit_Framework_Assert::assertContains($text, $this->actor->find(self::textPreview(), 10)->getText());
  200. }
  201. /**
  202. * @Then I see that the download button is shown
  203. */
  204. public function iSeeThatTheDownloadButtonIsShown() {
  205. if (!WaitFor::elementToBeEventuallyShown(
  206. $this->actor, self::downloadButton(), $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
  207. PHPUnit_Framework_Assert::fail("The download button is not visible yet after $timeout seconds");
  208. }
  209. }
  210. /**
  211. * @Then I see that the download button is not shown
  212. */
  213. public function iSeeThatTheDownloadButtonIsNotShown() {
  214. try {
  215. PHPUnit_Framework_Assert::assertFalse(
  216. $this->actor->find(self::downloadButton())->isVisible());
  217. } catch (NoSuchElementException $exception) {
  218. }
  219. }
  220. }