From a7ac52538e7e020f2cc7f9fa125dd148e854b423 Mon Sep 17 00:00:00 2001 From: sangnguyen Date: Tue, 15 Dec 2020 14:55:38 +0700 Subject: [PATCH] MDL-51287 Profile: Should notify users that changes are saved --- user/calendar.php | 2 +- user/course.php | 2 +- user/edit.php | 2 +- user/editadvanced.php | 4 +- user/editor.php | 2 +- user/forum.php | 2 +- user/language.php | 2 +- .../behat/edit_profile_notification.feature | 58 +++++++++++++++++++ 8 files changed, 66 insertions(+), 8 deletions(-) create mode 100644 user/tests/behat/edit_profile_notification.feature diff --git a/user/calendar.php b/user/calendar.php index ef810f4dd54..5f7ec2bef13 100644 --- a/user/calendar.php +++ b/user/calendar.php @@ -85,7 +85,7 @@ if ($calendarform->is_cancelled()) { $USER->calendartype = $calendartype; } - redirect($redirect); + redirect($redirect, get_string('changessaved'), null, \core\output\notification::NOTIFY_SUCCESS); } // Display page header. diff --git a/user/course.php b/user/course.php index 66cb0b52ea2..236365d4f58 100644 --- a/user/course.php +++ b/user/course.php @@ -44,7 +44,7 @@ if ($courseform->is_cancelled()) { useredit_update_user_preference(['id' => $user->id, 'preference_usemodchooser' => $data->enableactivitychooser]); - redirect($redirect); + redirect($redirect, get_string('changessaved'), null, \core\output\notification::NOTIFY_SUCCESS); } // Display page header. diff --git a/user/edit.php b/user/edit.php index ec1a81fba18..0f3f559f64a 100644 --- a/user/edit.php +++ b/user/edit.php @@ -299,7 +299,7 @@ if ($userform->is_cancelled()) { } if (!$emailchanged || !$CFG->emailchangeconfirmation) { - redirect($returnurl); + redirect($returnurl, get_string('changessaved'), null, \core\output\notification::NOTIFY_SUCCESS); } } diff --git a/user/editadvanced.php b/user/editadvanced.php index fea54a6bf08..0bdbe43c5d9 100644 --- a/user/editadvanced.php +++ b/user/editadvanced.php @@ -306,11 +306,11 @@ if ($userform->is_cancelled()) { // Somebody double clicked when editing admin user during install. redirect("$CFG->wwwroot/$CFG->admin/"); } else { - redirect($returnurl); + redirect($returnurl, get_string('changessaved'), null, \core\output\notification::NOTIFY_SUCCESS); } } else { \core\session\manager::gc(); // Remove stale sessions. - redirect("$CFG->wwwroot/$CFG->admin/user.php"); + redirect("$CFG->wwwroot/$CFG->admin/user.php", get_string('changessaved'), null, \core\output\notification::NOTIFY_SUCCESS); } // Never reached.. } diff --git a/user/editor.php b/user/editor.php index b1030681914..660d1c693ec 100644 --- a/user/editor.php +++ b/user/editor.php @@ -52,7 +52,7 @@ if ($editorform->is_cancelled()) { // Trigger event. \core\event\user_updated::create_from_userid($user->id)->trigger(); - redirect($redirect); + redirect($redirect, get_string('changessaved'), null, \core\output\notification::NOTIFY_SUCCESS); } // Display page header. diff --git a/user/forum.php b/user/forum.php index f0b7da24152..ce637916226 100644 --- a/user/forum.php +++ b/user/forum.php @@ -72,7 +72,7 @@ if ($forumform->is_cancelled()) { } } - redirect($redirect); + redirect($redirect, get_string('changessaved'), null, \core\output\notification::NOTIFY_SUCCESS); } // Display page header. diff --git a/user/language.php b/user/language.php index ef2b09fd9d4..61cacddb967 100644 --- a/user/language.php +++ b/user/language.php @@ -60,7 +60,7 @@ if ($languageform->is_cancelled()) { $USER->lang = $lang; } - redirect($redirect); + redirect($redirect, get_string('changessaved'), null, \core\output\notification::NOTIFY_SUCCESS); } // Display page header. diff --git a/user/tests/behat/edit_profile_notification.feature b/user/tests/behat/edit_profile_notification.feature new file mode 100644 index 00000000000..2fb174b8258 --- /dev/null +++ b/user/tests/behat/edit_profile_notification.feature @@ -0,0 +1,58 @@ +@core @core_user +Feature: Notification shown when user edit profile or preferences + In order to show notification + As a user + I press update profile button after make some changes in edit profile page + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | unicorn | Unicorn | 1 | unicorn@example.com | + And the following "courses" exist: + | fullname | shortname | category | groupmode | + | Course 1 | C1 | 0 | 1 | + And the following "course enrolments" exist: + | user | course | role | + | unicorn | C1 | student | + + @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 should see "Unicorn" + And I should see "1" + Then I set the field "Surname" to "Lil" + And I click on "Update profile" "button" + And I should see "Changes saved" + And I click on ".close" "css_element" in the "div.alert-block" "css_element" + And I should not see "Changes saved" + And I follow "Preferences" in the user menu + And I follow "Preferred language" + And I click on "Save changes" "button" + And I should see "Changes saved" + And I follow "Forum preferences" + And I set the field "Use experimental nested discussion view" to "Yes" + And I click on "Save changes" "button" + And I should see "Changes saved" + + @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 should see "Unicorn" + And I should see "1" + Then I set the field "Surname" to "Lil" + And I click on "Cancel" "button" + And I should not see "Changes saved" + + @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" + And I expand all fieldsets + Then I set the field "Surname" to "Lil" + And I click on "Update profile" "button" + And I should see "Changes saved"