diff --git a/admin/tool/uploaduser/classes/process.php b/admin/tool/uploaduser/classes/process.php index 6d9cdc53bb1ab..c3820a4fa1241 100644 --- a/admin/tool/uploaduser/classes/process.php +++ b/admin/tool/uploaduser/classes/process.php @@ -1384,8 +1384,14 @@ public function process_line(array $line) { } } } + + // Warn user about invalid data values. if (($invalid = \core_user::validate($user)) !== true) { - $this->upt->track('status', get_string('invaliduserdata', 'tool_uploaduser', s($user->username)), 'warning'); + $listseparator = get_string('listsep', 'langconfig') . ' '; + $this->upt->track('status', get_string('invaliduserdatavalues', 'tool_uploaduser', [ + 'username' => s($user->username), + 'values' => implode($listseparator, array_keys($invalid)), + ]), 'warning'); } } diff --git a/admin/tool/uploaduser/lang/en/tool_uploaduser.php b/admin/tool/uploaduser/lang/en/tool_uploaduser.php index 7c480398eb1f8..e0c8987d82c85 100644 --- a/admin/tool/uploaduser/lang/en/tool_uploaduser.php +++ b/admin/tool/uploaduser/lang/en/tool_uploaduser.php @@ -50,6 +50,7 @@ $string['infoprefix'] = 'Info:'; $string['invalidupdatetype'] = 'This option cannot be selected with the chosen upload type.'; $string['invaliduserdata'] = 'Invalid data detected for user {$a} and it has been automatically cleaned.'; +$string['invaliduserdatavalues'] = 'Invalid data detected for user \'{$a->username}\' ({$a->values}), which has been automatically cleaned.'; $string['invalidtheme'] = 'Theme "{$a}" is not installed and will be ignored.'; $string['linex'] = 'Line {$a}'; $string['matchemail'] = 'Match on email address'; diff --git a/admin/tool/uploaduser/tests/upload_users_test.php b/admin/tool/uploaduser/tests/upload_users_test.php index 49e204e716f37..559f19ca4c682 100644 --- a/admin/tool/uploaduser/tests/upload_users_test.php +++ b/admin/tool/uploaduser/tests/upload_users_test.php @@ -186,6 +186,26 @@ public function test_user_can_upload_with_course_enrolment_default_role(): void $this->assertEquals('student1', reset($usersasdefaultrole)->username); } + /** + * Test that invalid data contained in uploaded CSV triggers appropriate warnings + */ + public function test_user_upload_user_validate(): void { + $this->resetAfterTest(); + $this->setAdminUser(); + + $csv = <<process_csv_upload($csv, ['--uutype=' . UU_USER_ADDNEW]); + + // We should get the debugging from the user class itself, as well as warning in the output regarding the same. + $this->assertDebuggingCalled('The property \'country\' has invalid data and has been cleaned.'); + $this->assertStringContainsString('Invalid data detected for user \'student1\' (country), ' . + 'which has been automatically cleaned.', $output); + } + /** * Generate cli_helper and mock $_SERVER['argv'] *