behat_auth_emailrut.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. * Step definition for auth_emailrut
  18. *
  19. * @package auth_emailrut
  20. * @category test
  21. * @copyright 2018 Marina Glancy
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23. */
  24. require_once(__DIR__ . '/../../../../lib/behat/behat_base.php');
  25. /**
  26. * Step definition for auth_emailrut.
  27. *
  28. * @package auth_emailrut
  29. * @category test
  30. * @copyright 2018 Marina Glancy
  31. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  32. */
  33. class behat_auth_emailrut extends behat_base {
  34. /**
  35. * Emulate clicking on confirmation link from the email
  36. *
  37. * @When /^I confirm email for "(?P<username>(?:[^"]|\\")*)"$/
  38. *
  39. * @param string $username
  40. */
  41. public function i_confirm_email_for($username) {
  42. global $DB;
  43. $secret = $DB->get_field('user', 'secret', ['username' => $username], MUST_EXIST);
  44. $confirmationurl = new moodle_url('/login/confirm.php');
  45. $confirmationpath = $confirmationurl->out_as_local_url(false);
  46. $url = $confirmationpath . '?' . 'data='. $secret .'/'. $username;
  47. $this->execute('behat_general::i_visit', [$url]);
  48. }
  49. }