1
0

PublicShareContext.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. use PHPUnit\Framework\Assert;
  24. class PublicShareContext implements Context, ActorAwareInterface {
  25. use ActorAware;
  26. use FileListAncestorSetter;
  27. /**
  28. * @return Locator
  29. */
  30. public static function passwordField() {
  31. return Locator::forThe()->field("password")->
  32. describedAs("Password field in Authenticate page");
  33. }
  34. /**
  35. * @return Locator
  36. */
  37. public static function authenticateButton() {
  38. return Locator::forThe()->id("password-submit")->
  39. describedAs("Authenticate button in Authenticate page");
  40. }
  41. /**
  42. * @return Locator
  43. */
  44. public static function wrongPasswordMessage() {
  45. return Locator::forThe()->css(".warning .wrongPasswordMsg")->
  46. describedAs("Wrong password message in Authenticate page");
  47. }
  48. /**
  49. * @return Locator
  50. */
  51. public static function shareMenuButton() {
  52. return Locator::forThe()->id("header-actions-toggle")->
  53. describedAs("Share menu button in Shared file page");
  54. }
  55. /**
  56. * @return Locator
  57. */
  58. public static function shareMenu() {
  59. return Locator::forThe()->id("header-actions-menu")->
  60. describedAs("Share menu in Shared file page");
  61. }
  62. /**
  63. * @return Locator
  64. */
  65. public static function downloadItemInShareMenu() {
  66. return Locator::forThe()->id("download")->
  67. descendantOf(self::shareMenu())->
  68. describedAs("Download item in Share menu in Shared file page");
  69. }
  70. /**
  71. * @return Locator
  72. */
  73. public static function directLinkItemInShareMenu() {
  74. return Locator::forThe()->id("directLink-container")->
  75. descendantOf(self::shareMenu())->
  76. describedAs("Direct link item in Share menu in Shared file page");
  77. }
  78. /**
  79. * @return Locator
  80. */
  81. public static function saveItemInShareMenu() {
  82. return Locator::forThe()->id("save-external-share")->
  83. descendantOf(self::shareMenu())->
  84. describedAs("Save item in Share menu in Shared file page");
  85. }
  86. /**
  87. * @return Locator
  88. */
  89. public static function textPreview() {
  90. return Locator::forThe()->css(".text-preview")->
  91. describedAs("Text preview in Shared file page");
  92. }
  93. /**
  94. * @return Locator
  95. */
  96. public static function downloadButton() {
  97. return Locator::forThe()->id("downloadFile")->
  98. describedAs("Download button in Shared file page");
  99. }
  100. /**
  101. * @When I visit the shared link I wrote down
  102. */
  103. public function iVisitTheSharedLinkIWroteDown() {
  104. $this->actor->getSession()->visit($this->actor->getSharedNotebook()["shared link"]);
  105. }
  106. /**
  107. * @When I visit the direct download shared link I wrote down
  108. */
  109. public function iVisitTheDirectDownloadSharedLinkIWroteDown() {
  110. $this->actor->getSession()->visit($this->actor->getSharedNotebook()["shared link"] . "/download");
  111. }
  112. /**
  113. * @When I authenticate with password :password
  114. */
  115. public function iAuthenticateWithPassword($password) {
  116. $this->actor->find(self::passwordField(), 10)->setValue($password);
  117. $this->actor->find(self::authenticateButton())->click();
  118. }
  119. /**
  120. * @When I open the Share menu
  121. */
  122. public function iOpenTheShareMenu() {
  123. $this->actor->find(self::shareMenuButton(), 10)->click();
  124. }
  125. /**
  126. * @Then I see that the current page is the Authenticate page for the shared link I wrote down
  127. */
  128. public function iSeeThatTheCurrentPageIsTheAuthenticatePageForTheSharedLinkIWroteDown() {
  129. Assert::assertEquals(
  130. $this->actor->getSharedNotebook()["shared link"] . "/authenticate/showShare",
  131. $this->actor->getSession()->getCurrentUrl());
  132. }
  133. /**
  134. * @Then I see that the current page is the Authenticate page for the direct download shared link I wrote down
  135. */
  136. public function iSeeThatTheCurrentPageIsTheAuthenticatePageForTheDirectDownloadSharedLinkIWroteDown() {
  137. Assert::assertEquals(
  138. $this->actor->getSharedNotebook()["shared link"] . "/authenticate/downloadShare",
  139. $this->actor->getSession()->getCurrentUrl());
  140. }
  141. /**
  142. * @Then I see that the current page is the shared link I wrote down
  143. */
  144. public function iSeeThatTheCurrentPageIsTheSharedLinkIWroteDown() {
  145. Assert::assertEquals(
  146. $this->actor->getSharedNotebook()["shared link"],
  147. $this->actor->getSession()->getCurrentUrl());
  148. $this->setFileListAncestorForActor(null, $this->actor);
  149. }
  150. /**
  151. * @Then I see that the current page is the direct download shared link I wrote down
  152. */
  153. public function iSeeThatTheCurrentPageIsTheDirectDownloadSharedLinkIWroteDown() {
  154. Assert::assertEquals(
  155. $this->actor->getSharedNotebook()["shared link"] . "/download",
  156. $this->actor->getSession()->getCurrentUrl());
  157. }
  158. /**
  159. * @Then I see that a wrong password for the shared file message is shown
  160. */
  161. public function iSeeThatAWrongPasswordForTheSharedFileMessageIsShown() {
  162. Assert::assertTrue(
  163. $this->actor->find(self::wrongPasswordMessage(), 10)->isVisible());
  164. }
  165. /**
  166. * @Then I see that the Share menu is shown
  167. */
  168. public function iSeeThatTheShareMenuIsShown() {
  169. // Unlike other menus, the Share menu is always present in the DOM, so
  170. // the element could be found when it was no made visible yet due to the
  171. // command not having been processed by the browser.
  172. if (!WaitFor::elementToBeEventuallyShown(
  173. $this->actor, self::shareMenu(), $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
  174. Assert::fail("The Share menu is not visible yet after $timeout seconds");
  175. }
  176. // The acceptance tests are run in a window wider than the mobile breakpoint, so the
  177. // download item should not be shown in the menu (although it will be in
  178. // the DOM).
  179. Assert::assertFalse(
  180. $this->actor->find(self::downloadItemInShareMenu())->isVisible(),
  181. "Download item in share menu is visible");
  182. Assert::assertTrue(
  183. $this->actor->find(self::directLinkItemInShareMenu())->isVisible(),
  184. "Direct link item in share menu is not visible");
  185. Assert::assertTrue(
  186. $this->actor->find(self::saveItemInShareMenu())->isVisible(),
  187. "Save item in share menu is not visible");
  188. }
  189. /**
  190. * @Then I see that the Share menu button is not shown
  191. */
  192. public function iSeeThatTheShareMenuButtonIsNotShown() {
  193. try {
  194. Assert::assertFalse(
  195. $this->actor->find(self::shareMenuButton())->isVisible());
  196. } catch (NoSuchElementException $exception) {
  197. }
  198. }
  199. /**
  200. * @Then I see that the shared file preview shows the text :text
  201. */
  202. public function iSeeThatTheSharedFilePreviewShowsTheText($text) {
  203. Assert::assertStringContainsString($text, $this->actor->find(self::textPreview(), 10)->getText());
  204. }
  205. /**
  206. * @Then I see that the download button is shown
  207. */
  208. public function iSeeThatTheDownloadButtonIsShown() {
  209. if (!WaitFor::elementToBeEventuallyShown(
  210. $this->actor, self::downloadButton(), $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
  211. Assert::fail("The download button is not visible yet after $timeout seconds");
  212. }
  213. }
  214. /**
  215. * @Then I see that the download button is not shown
  216. */
  217. public function iSeeThatTheDownloadButtonIsNotShown() {
  218. try {
  219. Assert::assertFalse(
  220. $this->actor->find(self::downloadButton())->isVisible());
  221. } catch (NoSuchElementException $exception) {
  222. }
  223. }
  224. }