MDL-52335 tool_uploaduser: php7 compatibility in variable syntax
authorMarina Glancy <marina@moodle.com>
Thu, 3 Dec 2015 01:28:08 +0000 (09:28 +0800)
committerMarina Glancy <marina@moodle.com>
Thu, 3 Dec 2015 01:31:25 +0000 (09:31 +0800)
admin/tool/uploaduser/index.php
admin/tool/uploaduser/tests/behat/upload_users.feature [moved from admin/tests/behat/upload_users.feature with 58% similarity]
lib/tests/fixtures/upload_users_profile.csv [new file with mode: 0644]

index ad36657..e687fe3 100644 (file)
@@ -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);
                 }
@@ -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 (file)
index 0000000..b15db76
--- /dev/null
@@ -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