2 // This file is part of Stack - http://stack.bham.ac.uk/
4 // Stack 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.
9 // Stack 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.
14 // You should have received a copy of the GNU General Public License
15 // along with Stack. If not, see <http://www.gnu.org/licenses/>.
18 * Behat steps definitions for drag and drop onto image.
20 * @package qtype_ddimageortext
22 * @copyright 2015 The Open University
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 // NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
28 require_once(__DIR__ . '/../../../../../lib/behat/behat_base.php');
31 * Steps definitions related with the drag and drop onto image question type.
33 * @copyright 2015 The Open University
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 class behat_qtype_ddimageortext extends behat_base {
39 * Get the xpath for a given drag item.
40 * @param string $dragitem the text of the item to drag.
41 * @return string the xpath expression.
43 protected function drag_xpath($dragitem) {
44 return '//div[contains(@class, " drag ") and contains(normalize-space(.), "' . $this->escape($dragitem) . '")]';
48 * Get the xpath for a given drop box.
49 * @param string $dragitem the number of the drop box.
50 * @return string the xpath expression.
52 protected function drop_xpath($placenumber) {
53 return '//div[contains(@class, "dropzone ") and contains(@class, "place' . $placenumber . ' ")]';
57 * Drag the drag item with the given text to the given space.
59 * @param string $dragitem the text of the item to drag.
60 * @param int $placenumber the number of the place to drop into.
62 * @Given /^I drag "(?P<drag_item>[^"]*)" to place "(?P<place_number>\d+)" in the drag and drop onto image question$/
65 public function i_drag_to_place_in_the_drag_and_drop_onto_image_question($dragitem, $placenumber) {
66 $generalcontext = behat_context_helper::get('behat_general');
67 $generalcontext->i_drag_and_i_drop_it_in($this->drag_xpath($dragitem),
68 'xpath_element', $this->drop_xpath($placenumber), 'xpath_element');
72 * Type some characters while focussed on a given drop box.
74 * @param string $keys the characters to type.
75 * @param int $placenumber the number of the place to drop into.
77 * @Given /^I type "(?P<keys>[^"]*)" on place "(?P<place_number>\d+)" in the drag and drop onto image question$/
79 public function i_type_on_place_in_the_drag_and_drop_onto_image_question($keys, $placenumber) {
80 $generalcontext = behat_context_helper::get('behat_general');
81 $generalcontext->i_type_into_the($keys, $this->drop_xpath($placenumber), 'xpath_element');