This commit is contained in:
Andrew Nicols 2019-08-07 10:22:04 +08:00
commit 638097810d
2 changed files with 42 additions and 2 deletions

View file

@ -830,4 +830,39 @@ EXPECTED;
$extracteddraftareas = extract_draft_file_urls_from_text($html, false, 5, 'user', 'draft');
$this->assertEquals($draftareas, $extracteddraftareas);
}
public function test_print_password_policy() {
$this->resetAfterTest(true);
global $CFG;
$policydisabled = '';
// Set password policy to disabled.
$CFG->passwordpolicy = false;
// Check for empty response.
$this->assertEquals($policydisabled, print_password_policy());
// Now set the policy to enabled with every control disabled.
$CFG->passwordpolicy = true;
$CFG->minpasswordlength = 0;
$CFG->minpassworddigits = 0;
$CFG->minpasswordlower = 0;
$CFG->minpasswordupper = 0;
$CFG->minpasswordnonalphanum = 0;
$CFG->maxconsecutiveidentchars = 0;
// Check for empty response.
$this->assertEquals($policydisabled, print_password_policy());
// Now enable some controls, and check that the policy responds with policy text.
$CFG->minpasswordlength = 8;
$CFG->minpassworddigits = 1;
$CFG->minpasswordlower = 1;
$CFG->minpasswordupper = 1;
$CFG->minpasswordnonalphanum = 1;
$CFG->maxconsecutiveidentchars = 1;
$this->assertNotEquals($policydisabled, print_password_policy());
}
}

View file

@ -3615,7 +3615,9 @@ function print_password_policy() {
$message = '';
if (!empty($CFG->passwordpolicy)) {
$messages = array();
$messages[] = get_string('informminpasswordlength', 'auth', $CFG->minpasswordlength);
if (!empty($CFG->minpasswordlength)) {
$messages[] = get_string('informminpasswordlength', 'auth', $CFG->minpasswordlength);
}
if (!empty($CFG->minpassworddigits)) {
$messages[] = get_string('informminpassworddigits', 'auth', $CFG->minpassworddigits);
}
@ -3630,7 +3632,10 @@ function print_password_policy() {
}
$messages = join(', ', $messages); // This is ugly but we do not have anything better yet...
$message = get_string('informpasswordpolicy', 'auth', $messages);
// Check if messages is empty before outputting any text.
if ($messages != '') {
$message = get_string('informpasswordpolicy', 'auth', $messages);
}
}
return $message;
}