[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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 52 $userfullname = behat_context_helper::escape($userfullname); 53 54 // Using a xpath liternal to avoid problems with quotes and double quotes. 55 $groupname = behat_context_helper::escape($groupname); 56 57 // We don't know the option text as it contains the number of users in the group. 58 $select = $this->find_field('groups'); 59 $xpath = "//select[@id='groups']/descendant::option[contains(., $groupname)]"; 60 $groupoption = $this->find('xpath', $xpath); 61 $fulloption = $groupoption->getText(); 62 $select->selectOption($fulloption); 63 64 // This is needed by some drivers to ensure relevant event is triggred and button is enabled. 65 $script = "Syn.trigger('change', {}, {{ELEMENT}})"; 66 $this->getSession()->getDriver()->triggerSynScript($select->getXpath(), $script); 67 $this->getSession()->wait(self::TIMEOUT * 1000, self::PAGE_READY_JS); 68 69 // Here we don't need to wait for the AJAX response. 70 $this->find_button(get_string('adduserstogroup', 'group'))->click(); 71 72 // Wait for add/remove members page to be loaded. 73 $this->getSession()->wait(self::TIMEOUT * 1000, self::PAGE_READY_JS); 74 75 // Getting the option and selecting it. 76 $select = $this->find_field('addselect'); 77 $xpath = "//select[@id='addselect']/descendant::option[contains(., $userfullname)]"; 78 $memberoption = $this->find('xpath', $xpath); 79 $fulloption = $memberoption->getText(); 80 $select->selectOption($fulloption); 81 82 // Click add button. 83 $this->find_button(get_string('add'))->click(); 84 85 // Wait for the page to load. 86 $this->getSession()->wait(self::TIMEOUT * 1000, self::PAGE_READY_JS); 87 88 // Returning to the main groups page. 89 $this->find_button(get_string('backtogroups', 'group'))->click(); 90 } 91 92 /** 93 * A single or comma-separated list of groups expected within a grouping, on group overview page. 94 * 95 * @Given /^the group overview should include groups "(?P<groups_string>(?:[^"]|\\")*)" in grouping "(?P<grouping_string>(?:[^"]|\\")*)"$/ 96 * @param string $groups one or comma seperated list of groups. 97 * @param string $grouping grouping in which all group should be present. 98 */ 99 public function the_groups_overview_should_include_groups_in_grouping($groups, $grouping) { 100 101 $groups = array_map('trim', explode(',', $groups)); 102 103 foreach ($groups as $groupname) { 104 // Find the table after the H3 containing the grouping name, then look for the group name in the first column. 105 $xpath = "//h3[normalize-space(.) = '{$grouping}']/following-sibling::table//tr//". 106 "td[contains(concat(' ', normalize-space(@class), ' '), ' c0 ')][normalize-space(.) = '{$groupname}' ]"; 107 108 $this->execute('behat_general::should_exist', array($xpath, 'xpath_element')); 109 } 110 } 111 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |