MDL-76542 behat: add step to go to user edit page directly

This commit is contained in:
Simey Lameze 2022-12-07 10:49:22 +08:00
parent d991b12d15
commit 64799f9ace
11 changed files with 68 additions and 43 deletions

View File

@ -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."

View File

@ -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 "jonest@example.com" "table_row"
And I am on the "jonest@example.com" "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 "reznor@example.com" "table_row"
And I am on the "reznor@example.com" "user > editing" page
And I should see "Classic"
@javascript

View File

@ -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 "s@example.com" "table_row"
And I am on the "s@example.com" "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"

View File

@ -1695,4 +1695,30 @@ EOF;
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;
}
}

View File

@ -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"

View File

@ -106,4 +106,31 @@ class behat_user extends behat_base {
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}'.");
}
}
}

View File

@ -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 "userwithinformation@example.com" "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 |

View File

@ -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"
@ -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"
@ -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"

View File

@ -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
@ -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 |

View File

@ -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 "unicorn@example.com" "table_row"
When I am on the "unicorn@example.com" "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"
@ -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"

View File

@ -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"