From c3b548479bec2e24c783c841e77fcb3af7177b8a Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Thu, 15 Mar 2018 16:16:00 +0800 Subject: [PATCH] MDL-61477 auth_email: behat tests for sign up --- auth/email/tests/behat/behat_auth_email.php | 54 +++++++++++++++++ auth/email/tests/behat/signup.feature | 65 +++++++++++++++++++++ 2 files changed, 119 insertions(+) create mode 100644 auth/email/tests/behat/behat_auth_email.php create mode 100644 auth/email/tests/behat/signup.feature diff --git a/auth/email/tests/behat/behat_auth_email.php b/auth/email/tests/behat/behat_auth_email.php new file mode 100644 index 00000000000..b3fe2fbbca1 --- /dev/null +++ b/auth/email/tests/behat/behat_auth_email.php @@ -0,0 +1,54 @@ +. + +/** + * Step definition for auth_email + * + * @package auth_email + * @category test + * @copyright 2018 Marina Glancy + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once(__DIR__ . '/../../../../lib/behat/behat_base.php'); + +/** + * Step definition for auth_email. + * + * @package auth_email + * @category test + * @copyright 2018 Marina Glancy + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class behat_auth_email extends behat_base { + + /** + * Emulate clicking on confirmation link from the email + * + * @When /^I confirm email for "(?P(?:[^"]|\\")*)"$/ + * + * @param string $username + */ + public function i_confirm_email_for($username) { + global $DB; + $secret = $DB->get_field('user', 'secret', ['username' => $username], MUST_EXIST); + $confirmationurl = new moodle_url('/login/confirm.php'); + $confirmationpath = $confirmationurl->out_as_local_url(false); + $url = $confirmationpath . '?' . 'data='. $secret .'/'. $username; + + $this->getSession()->visit($this->locate_path($url)); + } +} diff --git a/auth/email/tests/behat/signup.feature b/auth/email/tests/behat/signup.feature new file mode 100644 index 00000000000..7934510729a --- /dev/null +++ b/auth/email/tests/behat/signup.feature @@ -0,0 +1,65 @@ +@auth @auth_email +Feature: User must accept policy when logging in and signing up + In order to record user agreement to use the site + As a user + I need to be able to accept site policy during sign up + + Scenario: Accept policy on sign up, no site policy + Given the following config values are set as admin: + | registerauth | email | + | passwordpolicy | 0 | + And I am on site homepage + And I follow "Log in" + When I press "Create new account" + Then I should not see "I understand and agree" + And I set the following fields to these values: + | Username | user1 | + | Password | user1 | + | Email address | user1@address.invalid | + | Email (again) | user1@address.invalid | + | First name | User1 | + | Surname | L1 | + And I press "Create my new account" + And I should see "Confirm your account" + And I should see "An email should have been sent to your address at user1@address.invalid" + And I confirm email for "user1" + And I should see "Thanks, User1 L1" + And I should see "Your registration has been confirmed" + And I open my profile in edit mode + And the field "First name" matches value "User1" + And I log out + # Confirm that user can login and browse the site (edit their profile). + And I log in as "user1" + And I open my profile in edit mode + And the field "First name" matches value "User1" + + Scenario: Accept policy on sign up, with site policy + Given the following config values are set as admin: + | registerauth | email | + | passwordpolicy | 0 | + | sitepolicy | https://moodle.org | + And I am on site homepage + And I follow "Log in" + When I press "Create new account" + Then the field "I understand and agree" matches value "0" + And I set the following fields to these values: + | Username | user1 | + | Password | user1 | + | Email address | user1@address.invalid | + | Email (again) | user1@address.invalid | + | First name | User1 | + | Surname | L1 | + | I understand and agree | 1 | + And I press "Create my new account" + And I should see "Confirm your account" + And I should see "An email should have been sent to your address at user1@address.invalid" + And I confirm email for "user1" + And I should see "Thanks, User1 L1" + And I should see "Your registration has been confirmed" + And I open my profile in edit mode + And the field "First name" matches value "User1" + And I log out + # Confirm that user is not asked to agree to site policy again after the next login. + And I log in as "user1" + And I open my profile in edit mode + And the field "First name" matches value "User1"