MDL-70153 qtype_essay: Add behat test for attachments max size
[moodle.git] / question / type / ddimageortext / tests / behat / behat_qtype_ddimageortext.php
CommitLineData
42865c84 1<?php
bf47ddbd 2// This file is part of Moodle - http://moodle.org/
42865c84 3//
e3b03886 4// Moodle is free software: you can redistribute it and/or modify
42865c84
TH
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//
e3b03886 9// Moodle is distributed in the hope that it will be useful,
42865c84
TH
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
e3b03886 15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
42865c84
TH
16
17/**
18 * Behat steps definitions for drag and drop onto image.
19 *
20 * @package qtype_ddimageortext
21 * @category test
22 * @copyright 2015 The Open University
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
26// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
27
28require_once(__DIR__ . '/../../../../../lib/behat/behat_base.php');
29
30/**
31 * Steps definitions related with the drag and drop onto image question type.
32 *
33 * @copyright 2015 The Open University
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35 */
36class behat_qtype_ddimageortext extends behat_base {
37
38 /**
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.
42 */
43 protected function drag_xpath($dragitem) {
a05ef130
HN
44 return '//div[contains(concat(" ", @class, " "), " draghome ") and ' .
45 'contains(normalize-space(.), "' . $this->escape($dragitem) . '") and not(contains(@class, "dragplaceholder"))]';
42865c84
TH
46 }
47
48 /**
49 * Get the xpath for a given drop box.
8bc1d28b 50 * @param string $placenumber the number of the drop box.
42865c84
TH
51 * @return string the xpath expression.
52 */
53 protected function drop_xpath($placenumber) {
ebf91776
TH
54 return '//div[contains(concat(" ", @class, " "), " dropzone ") and ' .
55 'contains(concat(" ", @class, " "), " place' . $placenumber . ' ")]';
42865c84
TH
56 }
57
58 /**
59 * Drag the drag item with the given text to the given space.
60 *
61 * @param string $dragitem the text of the item to drag.
62 * @param int $placenumber the number of the place to drop into.
63 *
64 * @Given /^I drag "(?P<drag_item>[^"]*)" to place "(?P<place_number>\d+)" in the drag and drop onto image question$/
42865c84
TH
65 */
66 public function i_drag_to_place_in_the_drag_and_drop_onto_image_question($dragitem, $placenumber) {
67 $generalcontext = behat_context_helper::get('behat_general');
68 $generalcontext->i_drag_and_i_drop_it_in($this->drag_xpath($dragitem),
69 'xpath_element', $this->drop_xpath($placenumber), 'xpath_element');
70 }
71
72 /**
73 * Type some characters while focussed on a given drop box.
74 *
75 * @param string $keys the characters to type.
76 * @param int $placenumber the number of the place to drop into.
77 *
78 * @Given /^I type "(?P<keys>[^"]*)" on place "(?P<place_number>\d+)" in the drag and drop onto image question$/
79 */
80 public function i_type_on_place_in_the_drag_and_drop_onto_image_question($keys, $placenumber) {
d804067d
TH
81 $node = $this->get_selected_node('xpath_element', $this->drop_xpath($placenumber));
82 $this->ensure_node_is_visible($node);
83 foreach (str_split($keys) as $key) {
84 $node->keyDown($key);
85 $node->keyPress($key);
86 $node->keyUp($key);
a05ef130 87 $this->wait_for_pending_js();
d804067d 88 }
42865c84
TH
89 }
90}