FilePickerContext.php 3.5 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. // File names in the file picker are split in two span elements, so
  45. // their texts need to be concatenated to get the full file name.
  46. return Locator::forThe()->xpath("//*[@id = 'picker-filestable']//*[contains(concat(' ', normalize-space(@class), ' '), ' filename-parts ') and concat(span[1], span[2]) = '$fileName']/ancestor::tr")->
  47. descendantOf(self::fileListContainer())->
  48. describedAs("Row for file $fileName in the file picker dialog");
  49. }
  50. /**
  51. * @return Locator
  52. */
  53. public static function buttonRow() {
  54. return Locator::forThe()->css(".oc-dialog-buttonrow")->
  55. descendantOf(self::dialog())->
  56. describedAs("Button row in the file picker dialog");
  57. }
  58. /**
  59. * @return Locator
  60. */
  61. private static function buttonFor($buttonText) {
  62. // "Copy" and "Move" buttons text is set to "Copy to XXX" and "Move to
  63. // XXX" when a folder is selected.
  64. return Locator::forThe()->xpath("//button[starts-with(normalize-space(), '$buttonText')]")->
  65. descendantOf(self::buttonRow())->
  66. describedAs($buttonText . " button in the file picker dialog");
  67. }
  68. /**
  69. * @return Locator
  70. */
  71. public static function copyButton() {
  72. return self::buttonFor("Copy");
  73. }
  74. /**
  75. * @return Locator
  76. */
  77. public static function moveButton() {
  78. return self::buttonFor("Move");
  79. }
  80. /**
  81. * @return Locator
  82. */
  83. public static function chooseButton() {
  84. return self::buttonFor("Choose");
  85. }
  86. /**
  87. * @When I select :fileName in the file picker
  88. */
  89. public function iSelectInTheFilePicker($fileName) {
  90. $this->actor->find(self::rowForFile($fileName), 10)->click();
  91. }
  92. /**
  93. * @When I copy to the last selected folder in the file picker
  94. */
  95. public function iCopyToTheLastSelectedFolderInTheFilePicker() {
  96. $this->actor->find(self::copyButton(), 10)->click();
  97. }
  98. /**
  99. * @When I move to the last selected folder in the file picker
  100. */
  101. public function iMoveToTheLastSelectedFolderInTheFilePicker() {
  102. $this->actor->find(self::moveButton(), 10)->click();
  103. }
  104. /**
  105. * @When I choose the last selected file in the file picker
  106. */
  107. public function iChooseTheLastSelectedFileInTheFilePicker() {
  108. $this->actor->find(self::chooseButton(), 10)->click();
  109. }
  110. }