Skip to content

Commit

Permalink
MDL-76542 behat: add step to go to user edit page directly
Browse files Browse the repository at this point in the history
  • Loading branch information
lameze committed Feb 8, 2023
1 parent d991b12 commit 64799f9
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ Feature: Allowing multiple accounts to have the same email address
| username | firstname | lastname | email |
| s1 | John | Doe | s1@example.com |
| s2 | Jane | Doe | s2@example.com |
When I log in as "admin"
And I navigate to "Users > Accounts > Browse list of users" in site administration
And I click on "Edit" "link" in the "Jane Doe" "table_row"
When I am on the "s2" "user > editing" page logged in as "admin"
And I set the field "Email address" to "<email>"
And I press "Update profile"
Then I should <expect> "This email address is already registered."
Expand Down
6 changes: 2 additions & 4 deletions admin/tool/uploaduser/tests/behat/upload_users.feature
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,10 @@ Feature: Upload users
And I should see "Users created: 4"
And I press "Continue"
# Boost check.
And I navigate to "Users > Accounts > Browse list of users" in site administration
And I click on ".icon[title=Edit]" "css_element" in the "[email protected]" "table_row"
And I am on the "[email protected]" "user > editing" page
And I should see "Boost"
# Classic check.
And I navigate to "Users > Accounts > Browse list of users" in site administration
And I click on ".icon[title=Edit]" "css_element" in the "[email protected]" "table_row"
And I am on the "[email protected]" "user > editing" page
And I should see "Classic"

@javascript
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,8 @@ Feature: availability_profile
Given the following "custom profile fields" exist:
| datatype | shortname | name |
| text | superfield | Super field |
And I log in as "admin"

# Set field value for user.
And I navigate to "Users > Accounts > Browse list of users" in site administration
And I click on ".icon[title=Edit]" "css_element" in the "[email protected]" "table_row"
And I am on the "[email protected]" "user > editing" page logged in as "admin"
And I expand all fieldsets
And I set the field "Super field" to "Bananaman"
And I click on "Update profile" "button"
Expand Down
26 changes: 26 additions & 0 deletions lib/behat/classes/behat_session_trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -1695,4 +1695,30 @@ public static function scope_tags_match(HookScope $scope, callable $callback): b

return !empty($matches);
}

/**
* Get the user id from an identifier.
*
* The user username and email fields are checked.
*
* @param string $identifier The user's username or email.
* @return int|null The user id or null if not found.
*/
protected function get_user_id_by_identifier(string $identifier): ?int {
global $DB;

$sql = <<<EOF
SELECT id
FROM {user}
WHERE username = :username
OR email = :email
EOF;

$result = $DB->get_field_sql($sql, [
'username' => $identifier,
'email' => $identifier,
]);

return $result ?: null;
}
}
5 changes: 1 addition & 4 deletions user/tests/behat/addnewuser.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,5 @@ Feature: Manually create a user
Given the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | 1 | student1@example.com |
When I log in as "admin"
And I navigate to "Users > Accounts > Browse list of users" in site administration
And I follow "Student 1"
And I follow "Edit profile"
When I am on the "student1" "user > editing" page logged in as "admin"
Then I should not see "Preferred language"
27 changes: 27 additions & 0 deletions user/tests/behat/behat_user.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,31 @@ protected function resolve_page_url(string $page): moodle_url {
throw new Exception("Unrecognised core_user page type '{$page}'.");
}
}

/**
* Convert page names to URLs for steps like 'When I am on the "[identifier]" "[page type]" page'.
*
* Recognised page names are:
* | Page Type | Identifier meaning | Description |
* | editing | username or email | User editing page (/user/editadvanced.php) |
*
* @param string $type identifies which type of page this is, e.g. 'Editing'.
* @param string $identifier identifies the user, e.g. 'student1'.
* @return moodle_url the corresponding URL.
* @throws Exception with a meaningful error message if the specified page cannot be found.
*/
protected function resolve_page_instance_url(string $type, string $identifier): moodle_url {

switch (strtolower($type)) {
case 'editing':
$userid = $this->get_user_id_by_identifier($identifier);
if (!$userid) {
throw new Exception('The specified user with username or email "' .
$identifier . '" does not exist');
}
return new moodle_url('/user/editadvanced.php', ['id' => $userid]);
default:
throw new Exception("Unrecognised page type '{$type}'.");
}
}
}
4 changes: 1 addition & 3 deletions user/tests/behat/custom_profile_fields.feature
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ Feature: Custom profile fields should be visible and editable by those with the
| text | uservisible_field | uservisible_field | 1 | 1 |
| text | everyonevisible_field | everyonevisible_field | 0 | 2 |
| text | teachervisible_field | teachervisible_field | 1 | 3 |
And I log in as "admin"
And I navigate to "Users > Accounts > Browse list of users" in site administration
And I click on ".icon[title=Edit]" "css_element" in the "[email protected]" "table_row"
And I am on the "userwithinformation" "user > editing" page logged in as "admin"
And I set the following fields to these values:
| notvisible_field | notvisible_field_information |
| uservisible_field | uservisible_field_information |
Expand Down
10 changes: 3 additions & 7 deletions user/tests/behat/edit_profile_notification.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ Feature: Notification shown when user edit profile or preferences
@javascript
Scenario: Change own profile and has notification shown
Given I log in as "unicorn"
And I follow "Profile" in the user menu
When I click on "Edit profile" "link" in the "region-main" "region"
And I open my profile in edit mode
And I should see "Unicorn"
And I should see "1"
Then I set the field "Last name" to "Lil"
Expand All @@ -39,8 +38,7 @@ Feature: Notification shown when user edit profile or preferences
@javascript
Scenario: Do not show notification when cancel profile change
Given I log in as "unicorn"
And I follow "Profile" in the user menu
When I click on "Edit profile" "link" in the "region-main" "region"
And I open my profile in edit mode
And I should see "Unicorn"
And I should see "1"
Then I set the field "Last name" to "Lil"
Expand All @@ -49,9 +47,7 @@ Feature: Notification shown when user edit profile or preferences

@javascript
Scenario: Show notification after admin edited profile of another user
Given I log in as "admin"
And I navigate to "Users > Accounts > Browse list of users" in site administration
When I click on "Edit" "link" in the "Unicorn 1" "table_row"
Given I am on the "unicorn" "user > editing" page logged in as "admin"
And I expand all fieldsets
Then I set the field "Last name" to "Lil"
And I click on "Update profile" "button"
Expand Down
10 changes: 2 additions & 8 deletions user/tests/behat/edituserpassword.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ Feature: Edit a users password
Given the following "users" exist:
| username | firstname | lastname | email |
| user01 | User | One | user01@example.com |
And I log in as "admin"
When I navigate to "Users > Accounts > Browse list of users" in site administration
And I click on "User One" "link" in the "users" "table"
And I click on "Edit profile" "link"
When I am on the "user01" "user > editing" page logged in as "admin"
Then "Sign out everywhere" "field" should not exist

Scenario Outline: Sign out everywhere field is present based on expiry of active token
Expand All @@ -36,10 +33,7 @@ Feature: Edit a users password
And the following "core_webservice > Tokens" exist:
| user | service | validuntil |
| user01 | mytestservice | <validuntil> |
And I log in as "admin"
When I navigate to "Users > Accounts > Browse list of users" in site administration
And I click on "User One" "link" in the "users" "table"
And I click on "Edit profile" "link"
When I am on the "user01" "user > editing" page logged in as "admin"
Then "Sign out everywhere" "field" <shouldornot> exist
Examples:
| validuntil | shouldornot |
Expand Down
9 changes: 3 additions & 6 deletions user/tests/behat/input-purpose.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ Feature: The purpose of each input field collecting information about the user c

@javascript
Scenario: Fields for other users are not auto filled
When I log in as "admin"
And I navigate to "Users > Accounts > Browse list of users" in site administration
And I click on ".icon[title=Edit]" "css_element" in the "[email protected]" "table_row"
When I am on the "[email protected]" "user > editing" page logged in as "admin"
And I expand all fieldsets
Then the field "Username" should not have purpose "username"
And the field "First name" should not have purpose "given-name"
Expand All @@ -29,9 +27,8 @@ Feature: The purpose of each input field collecting information about the user c

@javascript
Scenario: My own user fields are auto filled
When I log in as "unicorn"
And I follow "Profile" in the user menu
And I click on "Edit profile" "link" in the "region-main" "region"
Given I log in as "unicorn"
When I open my profile in edit mode
And I expand all fieldsets
Then the field "First name" should have purpose "given-name"
And the field "Last name" should have purpose "family-name"
Expand Down
5 changes: 1 addition & 4 deletions user/tests/behat/name_fields.feature
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ Feature: Both first name and last name are always available for every user
Given the following "users" exist:
| username | firstname | lastname | email |
| foobar | Foo | Bar | foo@bar.com |
And I log in as "admin"
And I navigate to "Users > Accounts > Browse list of users" in site administration
And I follow "Foo Bar"
And I click on "Edit profile" "link" in the "region-main" "region"
And I am on the "foobar" "user > editing" page logged in as "admin"
When I set the field "First name" to " "
And I set the field "Last name" to " "
And I click on "Cancel" "button"
Expand Down

0 comments on commit 64799f9

Please sign in to comment.