behat_blocks.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Steps definitions related with blocks.
  18. *
  19. * @package core_block
  20. * @category test
  21. * @copyright 2012 David Monllaó
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23. */
  24. // NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
  25. require_once(__DIR__ . '/../../../lib/behat/behat_base.php');
  26. /**
  27. * Blocks management steps definitions.
  28. *
  29. * @package core_block
  30. * @category test
  31. * @copyright 2012 David Monllaó
  32. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33. */
  34. class behat_blocks extends behat_base {
  35. /**
  36. * Adds the selected block. Editing mode must be previously enabled.
  37. *
  38. * @Given /^I add the "(?P<block_name_string>(?:[^"]|\\")*)" block$/
  39. * @param string $blockname
  40. */
  41. public function i_add_the_block($blockname) {
  42. $this->execute('behat_forms::i_set_the_field_to',
  43. array("bui_addblock", $this->escape($blockname))
  44. );
  45. // If we are running without javascript we need to submit the form.
  46. if (!$this->running_javascript()) {
  47. $this->execute('behat_general::i_click_on_in_the',
  48. array(get_string('go'), "button", "#add_block", "css_element")
  49. );
  50. }
  51. }
  52. /**
  53. * Docks a block. Editing mode should be previously enabled.
  54. *
  55. * @Given /^I dock "(?P<block_name_string>(?:[^"]|\\")*)" block$/
  56. * @param string $blockname
  57. */
  58. public function i_dock_block($blockname) {
  59. // Looking for both title and alt.
  60. $xpath = "//input[@type='image'][@title='" . get_string('dockblock', 'block', $blockname) . "' or @alt='" . get_string('addtodock', 'block') . "']";
  61. $this->execute('behat_general::i_click_on_in_the',
  62. array($xpath, "xpath_element", $this->escape($blockname), "block")
  63. );
  64. }
  65. /**
  66. * Opens a block's actions menu if it is not already opened.
  67. *
  68. * @Given /^I open the "(?P<block_name_string>(?:[^"]|\\")*)" blocks action menu$/
  69. * @throws DriverException The step is not available when Javascript is disabled
  70. * @param string $blockname
  71. */
  72. public function i_open_the_blocks_action_menu($blockname) {
  73. if (!$this->running_javascript()) {
  74. // Action menu does not need to be open if Javascript is off.
  75. return;
  76. }
  77. // If it is already opened we do nothing.
  78. $blocknode = $this->get_text_selector_node('block', $blockname);
  79. if ($blocknode->hasClass('action-menu-shown')) {
  80. return;
  81. }
  82. $this->execute('behat_general::i_click_on_in_the',
  83. array("a[role='menuitem']", "css_element", $this->escape($blockname), "block")
  84. );
  85. }
  86. /**
  87. * Clicks on Configure block for specified block. Page must be in editing mode.
  88. *
  89. * Argument block_name may be either the name of the block or CSS class of the block.
  90. *
  91. * @Given /^I configure the "(?P<block_name_string>(?:[^"]|\\")*)" block$/
  92. * @param string $blockname
  93. */
  94. public function i_configure_the_block($blockname) {
  95. // Note that since $blockname may be either block name or CSS class, we can not use the exact label of "Configure" link.
  96. $this->execute("behat_blocks::i_open_the_blocks_action_menu", $this->escape($blockname));
  97. $this->execute('behat_general::i_click_on_in_the',
  98. array("Configure", "link", $this->escape($blockname), "block")
  99. );
  100. }
  101. }