diff --git a/admin/tool/uploaduser/index.php b/admin/tool/uploaduser/index.php index ad36657a213..e687fe32214 100644 --- a/admin/tool/uploaduser/index.php +++ b/admin/tool/uploaduser/index.php @@ -232,8 +232,8 @@ if ($formdata = $mform2->is_cancelled()) { if (isset($USER->$key) and is_array($USER->$key)) { // this must be some hacky field that is abusing arrays to store content and format $user->$key = array(); - $user->$key['text'] = $value; - $user->$key['format'] = FORMAT_MOODLE; + $user->{$key['text']} = $value; + $user->{$key['format']} = FORMAT_MOODLE; } else { $user->$key = trim($value); } diff --git a/admin/tests/behat/upload_users.feature b/admin/tool/uploaduser/tests/behat/upload_users.feature similarity index 58% rename from admin/tests/behat/upload_users.feature rename to admin/tool/uploaduser/tests/behat/upload_users.feature index 0c4b1dafe07..32aa9631c35 100644 --- a/admin/tests/behat/upload_users.feature +++ b/admin/tool/uploaduser/tests/behat/upload_users.feature @@ -1,4 +1,4 @@ -@core @core_admin @_file_upload +@tool @tool_uploaduser @_file_upload Feature: Upload users In order to add users to the system As an admin @@ -39,3 +39,25 @@ Feature: Upload users And I follow "Groups" And I set the field "groups" to "Section 1 (1)" And the "members" select box should contain "Tom Jones" + + @javascript + Scenario: Upload users with custom profile fields + # Create user profile field. + Given I log in as "admin" + And I navigate to "User profile fields" node in "Site administration > Users > Accounts" + And I set the field "datatype" to "Text area" + And I set the following fields to these values: + | Short name | superfield | + | Name | Super field | + And I click on "Save changes" "button" + # Upload users. + When I navigate to "Upload users" node in "Site administration > Users > Accounts" + And I upload "lib/tests/fixtures/upload_users_profile.csv" file to "File" filemanager + And I press "Upload users" + And I press "Upload users" + # Check that users were created and the superfield is filled. + And I navigate to "Browse list of users" node in "Site administration > Users > Accounts" + And I follow "Tom Jones" + And I should see "Super field" + And I should see "The big guy" + And I log out diff --git a/lib/tests/fixtures/upload_users_profile.csv b/lib/tests/fixtures/upload_users_profile.csv new file mode 100644 index 00000000000..b15db768103 --- /dev/null +++ b/lib/tests/fixtures/upload_users_profile.csv @@ -0,0 +1,3 @@ +username,password,firstname,lastname,email,profile_field_superfield +jonest,verysecret,Tom,Jones,jonest@someplace.edu,The big guy +reznort,somesecret,Trent,Reznor,reznort@someplace.edu,Loves cats