MDL-38958 behat: Step definition to add questions
[moodle.git] / question / tests / behat / behat_question.php
blobcb1e423f7a4b1990c1c25ab95acb59539424eede
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.
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/>.
17 /**
18 * Behat question-related steps definitions.
20 * @package core_question
21 * @category test
22 * @copyright 2013 David MonllaĆ³
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');
30 use Behat\Behat\Context\Step\Given as Given,
31 Behat\Gherkin\Node\TableNode as TableNode;
33 /**
34 * Steps definitions related with the question bank management.
36 * @package core_question
37 * @category test
38 * @copyright 2013 David MonllaĆ³
39 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
41 class behat_question extends behat_base {
43 /**
44 * Creates a question in the current course questions bank with the provided data. This step can only be used when creating question types composed by a single form.
46 * @Given /^I add a "(?P<question_type_name_string>(?:[^"]|\\")*)" question filling the form with:$/
47 * @param string $questiontypename The question type name
48 * @param TableNode $questiondata The data to fill the question type form
50 public function i_add_a_question_filling_the_form_with($questiontypename, TableNode $questiondata) {
52 $questiontypexpath = "//span[@class='qtypename'][.='" . $questiontypename . "']
53 /ancestor::div[@class='qtypeoption']/descendant::input";
55 return array(
56 new Given('I follow "' . get_string('questionbank', 'question') . '"'),
57 new Given('I press "' . get_string('createnewquestion', 'question') . '"'),
58 new Given('I click on "' . $questiontypexpath . '" "xpath_element"'),
59 new Given('I click on "Next" "button" in the "#qtypechoicecontainer" "css_element"'),
60 new Given('I fill the moodle form with:', $questiondata),
61 new Given('I press "Save changes"')