1 |
efrain |
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 steps definitions for drag and drop onto image.
|
|
|
19 |
*
|
|
|
20 |
* @package gradereport_grader
|
|
|
21 |
* @category test
|
|
|
22 |
* @copyright 2015 Oakland 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 |
|
|
|
28 |
require_once(__DIR__ . '/../../../../../lib/behat/behat_base.php');
|
|
|
29 |
|
|
|
30 |
use Behat\Mink\Exception\ExpectationException as ExpectationException,
|
|
|
31 |
Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
* Steps definitions related with the drag and drop onto image question type.
|
|
|
35 |
*
|
|
|
36 |
* @copyright 2015 Oakland University
|
|
|
37 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
38 |
*/
|
|
|
39 |
class behat_gradereport_grader extends behat_base {
|
|
|
40 |
|
|
|
41 |
/**
|
|
|
42 |
* Gets the user id from its name.
|
|
|
43 |
*
|
|
|
44 |
* @throws Exception
|
|
|
45 |
* @param string $name
|
|
|
46 |
* @return int
|
|
|
47 |
*/
|
|
|
48 |
protected function get_user_id($name) {
|
|
|
49 |
global $DB;
|
|
|
50 |
$names = explode(' ', $name);
|
|
|
51 |
|
|
|
52 |
if (!$id = $DB->get_field('user', 'id', array('firstname' => $names[0], 'lastname' => $names[1]))) {
|
|
|
53 |
throw new Exception('The specified user with username "' . $name . '" does not exist');
|
|
|
54 |
}
|
|
|
55 |
return $id;
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
/**
|
|
|
59 |
* Gets the grade item id from its name.
|
|
|
60 |
*
|
|
|
61 |
* @deprecated since 4.2
|
|
|
62 |
* @todo MDL-77107 This will be deleted in Moodle 4.6.
|
|
|
63 |
* @throws Exception
|
|
|
64 |
* @param string $itemname
|
|
|
65 |
* @return int
|
|
|
66 |
*/
|
|
|
67 |
protected function get_grade_item_id($itemname) {
|
|
|
68 |
|
|
|
69 |
global $DB;
|
|
|
70 |
|
|
|
71 |
debugging('behat_gradereport_grader::get_grade_item_id() is deprecated, please use' .
|
|
|
72 |
' behat_grades::get_grade_item_id() instead.', DEBUG_DEVELOPER);
|
|
|
73 |
|
|
|
74 |
if ($id = $DB->get_field('grade_items', 'id', array('itemname' => $itemname))) {
|
|
|
75 |
return $id;
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
// The course total is a special case.
|
|
|
79 |
if ($itemname === "Course total") {
|
|
|
80 |
if (!$id = $DB->get_field('grade_items', 'id', array('itemtype' => 'course'))) {
|
|
|
81 |
throw new Exception('The specified grade_item with name "' . $itemname . '" does not exist');
|
|
|
82 |
}
|
|
|
83 |
return $id;
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
// Find a category with the name.
|
|
|
87 |
if ($catid = $DB->get_field('grade_categories', 'id', array('fullname' => $itemname))) {
|
|
|
88 |
if ($id = $DB->get_field('grade_items', 'id', array('iteminstance' => $catid))) {
|
|
|
89 |
return $id;
|
|
|
90 |
}
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
throw new Exception('The specified grade_item with name "' . $itemname . '" does not exist');
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
/**
|
|
|
97 |
* Clicks on given user menu.
|
|
|
98 |
*
|
|
|
99 |
* @Given /^I click on user menu "([^"]*)"$/
|
|
|
100 |
* @param string $student
|
|
|
101 |
*/
|
|
|
102 |
public function i_click_on_user_menu(string $student) {
|
|
|
103 |
|
|
|
104 |
$xpath = $this->get_user_selector($student);
|
|
|
105 |
|
|
|
106 |
$this->execute("behat_general::i_click_on", array($this->escape($xpath), "xpath_element"));
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
/**
|
|
|
110 |
* Gets unique xpath selector for a user.
|
|
|
111 |
*
|
|
|
112 |
* @throws Exception
|
|
|
113 |
* @param string $student
|
|
|
114 |
* @return string
|
|
|
115 |
*/
|
|
|
116 |
protected function get_user_selector(string $student): string {
|
|
|
117 |
|
|
|
118 |
$userid = $this->get_user_id($student);
|
|
|
119 |
return "//table[@id='user-grades']//*[@data-type='user'][@data-id='" . $userid . "']";
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
/**
|
|
|
123 |
* Clicks on given user profile field menu.
|
|
|
124 |
*
|
|
|
125 |
* @Given /^I click on user profile field menu "([^"]*)"$/
|
|
|
126 |
* @param string $field
|
|
|
127 |
*/
|
|
|
128 |
public function i_click_on_user_profile_field_menu(string $field) {
|
|
|
129 |
|
|
|
130 |
$xpath = "//table[@id='user-grades']//*[@data-type='" . mb_strtolower($field) . "']";
|
|
|
131 |
$this->execute("behat_general::i_click_on", array($this->escape($xpath), "xpath_element"));
|
|
|
132 |
}
|
|
|
133 |
|
|
|
134 |
/**
|
|
|
135 |
* Return the list of partial named selectors.
|
|
|
136 |
*
|
|
|
137 |
* @return array
|
|
|
138 |
*/
|
|
|
139 |
public static function get_partial_named_selectors(): array {
|
|
|
140 |
return [
|
|
|
141 |
new behat_component_named_selector(
|
|
|
142 |
'collapse search',
|
|
|
143 |
[".//*[contains(concat(' ', @class, ' '), ' collapsecolumndropdown ')]"]
|
|
|
144 |
),
|
|
|
145 |
];
|
|
|
146 |
}
|
|
|
147 |
}
|