Commit | Line | Data |
---|---|---|
f0e4cf5e DM |
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 | /** | |
18 | * Enrolment steps definitions. | |
19 | * | |
20 | * @package core_enrol | |
21 | * @category test | |
22 | * @copyright 2013 David Monllaó | |
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 | ||
28 | require_once(__DIR__ . '/../../../lib/behat/behat_base.php'); | |
29 | ||
30 | use Behat\Behat\Context\Step\Given as Given, | |
31 | Behat\Gherkin\Node\TableNode as TableNode; | |
32 | ||
33 | /** | |
34 | * Steps definitions for general enrolment actions. | |
35 | * | |
36 | * @package core_enrol | |
37 | * @category test | |
38 | * @copyright 2013 David Monllaó | |
39 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
40 | */ | |
41 | class behat_enrol extends behat_base { | |
42 | ||
43 | /** | |
44 | * Adds the specified enrolment method to the current course filling the form with the provided data. | |
45 | * | |
46 | * @Given /^I add "(?P<enrolment_method_name_string>(?:[^"]|\\")*)" enrolment method with:$/ | |
47 | * @param string $enrolmethod | |
48 | * @param TableNode $table | |
49 | */ | |
50 | public function i_add_enrolment_method_with($enrolmethod, TableNode $table) { | |
f0e4cf5e | 51 | return array( |
dedb9738 DM |
52 | new Given('I expand "' . get_string('users', 'admin') . '" node'), |
53 | new Given('I follow "' . get_string('type_enrol_plural', 'plugin') . '"'), | |
e8cf6330 AN |
54 | new Given('I select "' . $this->escape($enrolmethod) . '" from the "' . |
55 | get_string('addinstance', 'enrol') . '" singleselect'), | |
f083d614 | 56 | new Given('I set the following fields to these values:', $table), |
e8cf6330 | 57 | new Given('I press "' . get_string('addinstance', 'enrol') . '"'), |
f0e4cf5e DM |
58 | ); |
59 | } | |
60 | ||
d46979ec DM |
61 | /** |
62 | * Enrols the specified user in the current course without options. | |
63 | * | |
64 | * This is a simple step, to set enrolment options would be better to | |
65 | * create a separate step as a TableNode will be required. | |
66 | * | |
67 | * @Given /^I enrol "(?P<user_fullname_string>(?:[^"]|\\")*)" user as "(?P<rolename_string>(?:[^"]|\\")*)"$/ | |
68 | * @param string $userfullname | |
69 | * @param string $rolename | |
70 | * @return Given[] | |
71 | */ | |
72 | public function i_enrol_user_as($userfullname, $rolename) { | |
73 | ||
74 | $steps = array( | |
75 | new Given('I follow "' . get_string('enrolledusers', 'enrol') . '"'), | |
76 | new Given('I press "' . get_string('enrolusers', 'enrol') . '"') | |
77 | ); | |
78 | ||
79 | if ($this->running_javascript()) { | |
80 | ||
81 | // We have a div here, not a tr. | |
82 | $userliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($userfullname); | |
83 | $userrowxpath = "//div[contains(concat(' ',normalize-space(@class),' '),' user ')][contains(., $userliteral)]"; | |
84 | ||
85 | $steps[] = new Given('I set the field "' . get_string('assignroles', 'role') . '" to "' . $rolename . '"'); | |
86 | $steps[] = new Given('I click on "' . get_string('enrol', 'enrol') . '" "button" in the "' . $userrowxpath . '" "xpath_element"'); | |
87 | $steps[] = new Given('I press "' . get_string('finishenrollingusers', 'enrol') . '"'); | |
88 | ||
89 | } else { | |
90 | ||
91 | $steps[] = new Given('I set the field "' . get_string('assignrole', 'role') . '" to "' . $rolename . '"'); | |
92 | $steps[] = new Given('I set the field "addselect" to "' . $userfullname . '"'); | |
93 | $steps[] = new Given('I press "add"'); | |
94 | } | |
95 | ||
96 | return $steps; | |
97 | } | |
98 | ||
f0e4cf5e | 99 | } |