From d82b6004bfd0b716e5211134acea71eef7f3cb11 Mon Sep 17 00:00:00 2001 From: "[Peter Burnett]" <[peterburnett@catalyst-au.net]> Date: Tue, 30 Jul 2019 16:34:04 +1000 Subject: [PATCH] MDL-66280 core: Added unit tests for print_password_policy --- lib/tests/weblib_test.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/lib/tests/weblib_test.php b/lib/tests/weblib_test.php index 8e63d32cd20..d3895a534dc 100644 --- a/lib/tests/weblib_test.php +++ b/lib/tests/weblib_test.php @@ -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()); + } }