FilePickerContext.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /**
  3. *
  4. * @copyright Copyright (c) 2018, 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 FilePickerContext implements Context, ActorAwareInterface {
  24. use ActorAware;
  25. /**
  26. * @return Locator
  27. */
  28. public static function dialog() {
  29. return Locator::forThe()->css(".oc-dialog")->
  30. describedAs("File picker dialog");
  31. }
  32. /**
  33. * @return Locator
  34. */
  35. public static function fileListContainer() {
  36. return Locator::forThe()->css("#oc-dialog-filepicker-content")->
  37. descendantOf(self::dialog())->
  38. describedAs("File list container in the file picker dialog");
  39. }
  40. /**
  41. * @return Locator
  42. */
  43. public static function rowForFile($fileName) {
  44. return Locator::forThe()->xpath("//*[@id = 'picker-filestable']//*[contains(concat(' ', normalize-space(@class), ' '), ' filename ') and normalize-space() = '$fileName']/ancestor::tr")->
  45. descendantOf(self::fileListContainer())->
  46. describedAs("Row for file $fileName in the file picker dialog");
  47. }
  48. /**
  49. * @return Locator
  50. */
  51. public static function buttonRow() {
  52. return Locator::forThe()->css(".oc-dialog-buttonrow")->
  53. descendantOf(self::dialog())->
  54. describedAs("Button row in the file picker dialog");
  55. }
  56. /**
  57. * @return Locator
  58. */
  59. private static function buttonFor($buttonText) {
  60. // "Copy" and "Move" buttons text is set to "Copy to XXX" and "Move to
  61. // XXX" when a folder is selected.
  62. return Locator::forThe()->xpath("//button[starts-with(normalize-space(), '$buttonText')]")->
  63. descendantOf(self::buttonRow())->
  64. describedAs($buttonText . " button in the file picker dialog");
  65. }
  66. /**
  67. * @return Locator
  68. */
  69. public static function copyButton() {
  70. return self::buttonFor("Copy");
  71. }
  72. /**
  73. * @return Locator
  74. */
  75. public static function moveButton() {
  76. return self::buttonFor("Move");
  77. }
  78. /**
  79. * @return Locator
  80. */
  81. public static function chooseButton() {
  82. return self::buttonFor("Choose");
  83. }
  84. /**
  85. * @When I select :fileName in the file picker
  86. */
  87. public function iSelectInTheFilePicker($fileName) {
  88. $this->actor->find(self::rowForFile($fileName), 10)->click();
  89. }
  90. /**
  91. * @When I copy to the last selected folder in the file picker
  92. */
  93. public function iCopyToTheLastSelectedFolderInTheFilePicker() {
  94. $this->actor->find(self::copyButton(), 10)->click();
  95. }
  96. /**
  97. * @When I move to the last selected folder in the file picker
  98. */
  99. public function iMoveToTheLastSelectedFolderInTheFilePicker() {
  100. $this->actor->find(self::moveButton(), 10)->click();
  101. }
  102. /**
  103. * @When I choose the last selected file in the file picker
  104. */
  105. public function iChooseTheLastSelectedFileInTheFilePicker() {
  106. $this->actor->find(self::chooseButton(), 10)->click();
  107. }
  108. }