PageRenderTime 51ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/auth/tests/behat/behat_auth.php

https://bitbucket.org/moodle/moodle
PHP | 76 lines | 20 code | 9 blank | 47 comment | 2 complexity | 68fdedb461b5433cca1cc2d2ff7b4d00 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1, BSD-3-Clause, MIT, GPL-3.0
  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. * Basic authentication steps definitions.
  18. *
  19. * @package core_auth
  20. * @category test
  21. * @copyright 2012 David MonllaĆ³
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23. */
  24. // NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
  25. require_once(__DIR__ . '/../../../lib/behat/behat_base.php');
  26. /**
  27. * Log in log out steps definitions.
  28. *
  29. * @package core_auth
  30. * @category test
  31. * @copyright 2012 David MonllaĆ³
  32. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33. */
  34. class behat_auth extends behat_base {
  35. /**
  36. * Logs in the user. There should exist a user with the same value as username and password.
  37. *
  38. * @Given /^I log in as "(?P<username_string>(?:[^"]|\\")*)"$/
  39. * @Given I am logged in as :username
  40. * @param string $username the user to log in as.
  41. * @param moodle_url|null $wantsurl optional, URL to go to after logging in.
  42. */
  43. public function i_log_in_as(string $username, moodle_url $wantsurl = null) {
  44. // In the mobile app the required tasks are different (does not support $wantsurl).
  45. if ($this->is_in_app()) {
  46. $this->execute('behat_app::login', [$username]);
  47. return;
  48. }
  49. $loginurl = new moodle_url('/auth/tests/behat/login.php', [
  50. 'username' => $username,
  51. ]);
  52. if ($wantsurl !== null) {
  53. $loginurl->param('wantsurl', $wantsurl->out_as_local_url());
  54. }
  55. // Visit login page.
  56. $this->execute('behat_general::i_visit', [$loginurl]);
  57. }
  58. /**
  59. * Logs out of the system.
  60. *
  61. * @Given /^I log out$/
  62. * @Given I am not logged in
  63. */
  64. public function i_log_out() {
  65. $this->execute('behat_general::i_visit', [new moodle_url('/auth/tests/behat/logout.php')]);
  66. }
  67. }