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
/**
18
 * Behat competency report definitions.
19
 *
20
 * @package    report_competency
21
 * @category   test
22
 * @copyright  2022 Noel De Martin
23
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
 
26
require_once(__DIR__ . '/../../../../lib/behat/behat_base.php');
27
 
28
/**
29
 * Competency report definitions.
30
 *
31
 * @package    report_competency
32
 * @category   test
33
 * @copyright  2022 Noel De Martin
34
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35
 */
36
class behat_report_competency extends behat_base {
37
 
38
    /**
39
     * Convert page names to URLs for steps like 'When I am on the "[identifier]" "[page type]" page'.
40
     *
41
     * Recognised page names are:
42
     * | pagetype  | name meaning | description                            |
43
     * | Breakdown | Course name  | The course competencies breakdown page |
44
     *
45
     * @param string $page identifies which type of page this is, e.g. 'Breakdown'.
46
     * @param string $identifier identifies the particular page, e.g. 'C1'.
47
     * @return moodle_url the corresponding URL.
48
     * @throws Exception with a meaningful error message if the specified page cannot be found.
49
     */
50
    protected function resolve_page_instance_url(string $page, string $identifier): moodle_url {
51
        switch (strtolower($page)) {
52
            case 'breakdown':
53
                $courseid = $this->get_course_id($identifier);
54
                return new moodle_url('/report/competency/index.php', [
55
                    'id' => $courseid,
56
                ]);
57
            default:
58
                throw new Exception("Unrecognised page type '{$page}'");
59
        }
60
    }
61
 
62
    /**
63
     * Return a list of the exact named selectors for the component.
64
     *
65
     * @return behat_component_named_selector[]
66
     */
67
    public static function get_exact_named_selectors(): array {
68
        return [
69
            new behat_component_named_selector('breakdown', [
70
                "//*[@data-region='competency-breakdown-report']//table".
71
                    "//tr[contains(., //a[@data-action='competency-dialogue'][contains(., %locator%)])]",
72
            ]),
73
            new behat_component_named_selector('breakdown rating', [
74
                "//td[position()=2][contains(., //a[@title='User competency summary'][contains(., %locator%)])]",
75
            ]),
76
        ];
77
    }
78
 
1441 ariadna 79
    /**
80
     * Set the value of a competency filter.
81
     *
82
     * @When /^I set the competency filter "([^"]*)" to "([^"]*)"$/
83
     * @param string $fieldlocator The field locator.
84
     * @param string $value The value to set.
85
     * @throws Exception
86
     */
87
    public function set_competency_filter(
88
        string $fieldlocator,
89
        string $value,
90
    ): void {
91
        $field = behat_field_manager::get_form_field_from_label($fieldlocator, $this)->get_node();
92
        $session = $this->getSession();
93
 
94
        $value = trim($value);
95
 
96
        // Click into the field.
97
        $field->click();
98
 
99
        // Remove any existing text.
100
        do {
101
            behat_base::type_keys($session, [behat_keys::BACKSPACE, behat_keys::DELETE]);
102
        } while (strlen($field->getValue()) > 0);
103
        $this->wait_for_pending_js();
104
 
105
        // Type in the new value.
106
        behat_base::type_keys($session, str_split($value));
107
        $this->wait_for_pending_js();
108
 
109
        // If the autocomplete found suggestions, then it will have:
110
        // 1) marked itself as expanded; and
111
        // 2) have an aria-selected suggestion in the list.
112
        $expanded = $field->getAttribute('aria-expanded');
113
        $suggestion = $field->getParent()->getParent()->find('css', '.form-autocomplete-suggestions > [aria-selected="true"]');
114
 
115
        if ($expanded && null !== $suggestion) {
116
            // A suggestion was found.
117
            // Click on the first item in the list.
118
            $suggestion->click();
119
        } else {
120
            throw new \InvalidArgumentException(
121
                "Unable to find '{$value}' in the list of options."
122
            );
123
        }
124
 
125
        $this->wait_for_pending_js();
126
    }
1 efrain 127
}