Merge branch 'wip-mdl-56348' of https://github.com/rajeshtaneja/moodle
[moodle.git] / auth / tests / behat / behat_auth.php
blobd5ddb59e71627d92e0b6f1f30f0f26d35d6bdae9
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * Basic authentication steps definitions.
21 * @package core_auth
22 * @category test
23 * @copyright 2012 David MonllaĆ³
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 // NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
29 require_once(__DIR__ . '/../../../lib/behat/behat_base.php');
31 /**
32 * Log in log out steps definitions.
34 * @package core_auth
35 * @category test
36 * @copyright 2012 David MonllaĆ³
37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39 class behat_auth extends behat_base {
41 /**
42 * Logs in the user. There should exist a user with the same value as username and password.
44 * @Given /^I log in as "(?P<username_string>(?:[^"]|\\")*)"$/
46 public function i_log_in_as($username) {
47 // Visit login page.
48 $this->getSession()->visit($this->locate_path('login/index.php'));
50 // Enter username and password.
51 $this->execute('behat_forms::i_set_the_field_to', array('Username', $this->escape($username)));
52 $this->execute('behat_forms::i_set_the_field_to', array('Password', $this->escape($username)));
54 // Press log in button, no need to check for exceptions as it will checked after this step execution.
55 $this->execute('behat_forms::press_button', get_string('login'));
58 /**
59 * Logs out of the system.
61 * @Given /^I log out$/
63 public function i_log_out() {
64 // There is no longer any need to worry about whether the navigation
65 // bar needs to be expanded; user_menu now lives outside the
66 // hamburger.
68 // However, the user menu *always* needs to be expanded. if running JS.
69 if ($this->running_javascript()) {
70 $xpath = "//div[@class='usermenu']//a[contains(concat(' ', @class, ' '), ' toggle-display ')]";
72 $this->execute('behat_general::i_click_on', array($xpath, "xpath_element"));
75 // No need to check for exceptions as it will checked after this step execution.
76 $this->execute('behat_general::click_link', get_string('logout'));