Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
18
 
19
require_once(__DIR__ . '/../../../../../lib/behat/behat_base.php');
20
 
21
/**
1441 ariadna 22
 * Behat step definitions for the grader report
1 efrain 23
 *
1441 ariadna 24
 * @package   gradereport_grader
25
 * @category  test
1 efrain 26
 * @copyright 2015 Oakland University
27
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28
 */
29
class behat_gradereport_grader extends behat_base {
30
 
31
    /**
32
     * Gets the user id from its name.
33
     *
34
     * @throws Exception
35
     * @param string $name
36
     * @return int
37
     */
38
    protected function get_user_id($name) {
39
        global $DB;
40
        $names = explode(' ', $name);
41
 
42
        if (!$id = $DB->get_field('user', 'id', array('firstname' => $names[0], 'lastname' => $names[1]))) {
43
            throw new Exception('The specified user with username "' . $name . '" does not exist');
44
        }
45
        return $id;
46
    }
47
 
48
    /**
49
     * @deprecated since 4.2
50
     */
1441 ariadna 51
    #[\core\attribute\deprecated('behat_grades::get_grade_item_id', since: '4.2', mdl: 'MDL-77033', final: true)]
52
    protected function get_grade_item_id() {
53
        \core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
1 efrain 54
    }
55
 
56
    /**
57
     * Clicks on given user menu.
58
     *
59
     * @Given /^I click on user menu "([^"]*)"$/
60
     * @param string $student
61
     */
62
    public function i_click_on_user_menu(string $student) {
63
 
64
        $xpath = $this->get_user_selector($student);
65
 
66
        $this->execute("behat_general::i_click_on", array($this->escape($xpath), "xpath_element"));
67
    }
68
 
69
    /**
70
     * Gets unique xpath selector for a user.
71
     *
72
     * @throws Exception
73
     * @param string $student
74
     * @return string
75
     */
76
    protected function get_user_selector(string $student): string {
77
 
78
        $userid = $this->get_user_id($student);
79
        return "//table[@id='user-grades']//*[@data-type='user'][@data-id='" . $userid . "']";
80
    }
81
 
82
    /**
83
     * Clicks on given user profile field menu.
84
     *
85
     * @Given /^I click on user profile field menu "([^"]*)"$/
86
     * @param string $field
87
     */
88
    public function i_click_on_user_profile_field_menu(string $field) {
89
 
90
        $xpath = "//table[@id='user-grades']//*[@data-type='" . mb_strtolower($field) . "']";
91
        $this->execute("behat_general::i_click_on", array($this->escape($xpath), "xpath_element"));
92
    }
93
 
94
    /**
95
     * Return the list of partial named selectors.
96
     *
97
     * @return array
98
     */
99
    public static function get_partial_named_selectors(): array {
100
        return [
101
            new behat_component_named_selector(
102
                'collapse search',
103
                [".//*[contains(concat(' ', @class, ' '), ' collapsecolumndropdown ')]"]
104
            ),
105
        ];
106
    }
107
}