Merge branch 'MDL-29261-402' of https://github.com/paulholden/moodle into MOODLE_402_STABLE
This commit is contained in:
@@ -1384,8 +1384,14 @@ class process {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ The example text file may also be used for testing, as you are able to preview u
|
||||
$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';
|
||||
|
||||
@@ -186,6 +186,26 @@ EOF;
|
||||
$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 = <<<EOF
|
||||
username,firstname,lastname,email,country
|
||||
student1,Student,One,[email protected],Wales
|
||||
EOF;
|
||||
|
||||
$output = $this->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']
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user