Proyectos de Subversion Moodle

Rev

| 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 groups-related steps definitions.
19
 *
20
 * @package    core_group
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\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
31
 
32
/**
33
 * Groups-related steps definitions.
34
 *
35
 * @package    core_group
36
 * @category   test
37
 * @copyright  2013 David Monllaó
38
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39
 */
40
class behat_groups extends behat_base {
41
 
42
    /**
43
     * Add the specified user to the group. You should be in the groups page when running this step. The user should be specified like "Firstname Lastname (user@example.com)".
44
     *
45
     * @Given /^I add "(?P<user_fullname_string>(?:[^"]|\\")*)" user to "(?P<group_name_string>(?:[^"]|\\")*)" group members$/
46
     * @throws ElementNotFoundException Thrown by behat_base::find
47
     * @param string $username
48
     * @param string $groupname
49
     */
50
    public function i_add_user_to_group_members($userfullname, $groupname) {
51
        // Select the group in the select.
52
        $this->execute('behat_forms::i_set_the_field_to', [get_string('groups', 'core'), $this->escape($groupname)]);
53
 
54
        // Press "Add/remove users".
55
        $this->execute('behat_general::i_click_on', [get_string('adduserstogroup', 'group'), "button"]);
56
 
57
        // Select the user.
58
        $this->execute('behat_forms::i_set_the_field_to', ["addselect", $this->escape($userfullname)]);
59
 
60
        // Click add button.
61
        $this->execute('behat_general::i_click_on', [get_string('add', 'core'), "button"]);
62
 
63
        // Returning to the main groups page.
64
        $this->execute('behat_general::i_click_on', [get_string('backtogroups', 'group'), "button"]);
65
    }
66
 
67
    /**
68
     * A single or comma-separated list of groups expected within a grouping, on group overview page.
69
     *
70
     * @Given /^the group overview should include groups "(?P<groups_string>(?:[^"]|\\")*)" in grouping "(?P<grouping_string>(?:[^"]|\\")*)"$/
71
     * @param string $groups one or comma seperated list of groups.
72
     * @param string $grouping grouping in which all group should be present.
73
     */
74
    public function the_groups_overview_should_include_groups_in_grouping($groups, $grouping) {
75
 
76
        $groups = array_map('trim', explode(',', $groups));
77
 
78
        foreach ($groups as $groupname) {
79
            // Find the table after the H3 containing the grouping name, then look for the group name in the first column.
80
            $xpath = "//h3[normalize-space(.) = '{$grouping}']/following-sibling::div[contains(@class, 'table-responsive')]" .
81
                "/table//tr//td[contains(concat(' ', normalize-space(@class), ' '), ' c0 ')][normalize-space(.) = '{$groupname}' ]";
82
 
83
            $this->execute('behat_general::should_exist', array($xpath, 'xpath_element'));
84
        }
85
    }
86
}