Merge branch 'MDL-47340-master' of git://github.com/jethac/moodle
[moodle.git] / grade / tests / behat / behat_grade.php
CommitLineData
4f5eaa55
MN
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 * Behat grade related steps definitions.
19 *
20 * @package core_grades
21 * @category test
22 * @copyright 2014 Mark Nelson <markn@moodle.com>
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
d06aec10
MG
30use Behat\Behat\Context\Step\Given as Given,
31 Behat\Gherkin\Node\TableNode as TableNode;
4f5eaa55
MN
32
33class behat_grade extends behat_base {
34
35 /**
36 * Enters a grade via the gradebook for a specific grade item and user when viewing the 'Grader report' with editing mode turned on.
37 *
38 * @Given /^I give the grade "(?P<grade_number>(?:[^"]|\\")*)" to the user "(?P<username_string>(?:[^"]|\\")*)" for the grade item "(?P<grade_activity_string>(?:[^"]|\\")*)"$/
39 * @param int $grade
40 * @param string $userfullname the user's fullname as returned by fullname()
41 * @param string $itemname
42 * @return Given
43 */
44 public function i_give_the_grade($grade, $userfullname, $itemname) {
45 $gradelabel = $userfullname . ' ' . $itemname;
46 $fieldstr = get_string('useractivitygrade', 'gradereport_grader', $gradelabel);
47
f083d614 48 return new Given('I set the field "' . $this->escape($fieldstr) . '" to "' . $grade . '"');
4f5eaa55 49 }
d06aec10
MG
50
51 /**
52 * Changes the settings of a grade item or category or the course.
53 *
54 * Teacher must be either on the grade setup page or on the Grader report page with editing mode turned on.
55 *
56 * @Given /^I set the following settings for grade item "(?P<grade_item_string>(?:[^"]|\\")*)":$/
57 * @param string $gradeitem
58 * @param TableNode $data
59 * @return Given[]
60 */
61 public function i_set_the_following_settings_for_grade_item($gradeitem, TableNode $data) {
62 $savechanges = get_string('savechanges', 'grades');
63 $edit = $this->getSession()->getSelectorsHandler()->xpathLiteral(get_string('edit') . ' ');
64 $gradeitem = $this->getSession()->getSelectorsHandler()->xpathLiteral($gradeitem);
65 $linkxpath = "//a[./img[starts-with(@title,$edit) and contains(@title,$gradeitem)]]";
66 return array(
67 new Given('I click on "' . $this->escape($linkxpath) . '" "xpath_element"'),
68 new Given('I set the following fields to these values:', $data),
69 new Given('I press "' . $this->escape($savechanges) . '"'),
70 );
71 }
4f5eaa55 72}