MDL-66280 core: Added unit tests for print_password_policy
author[Peter Burnett] <[peterburnett@catalyst-au.net]>
Tue, 30 Jul 2019 06:34:04 +0000 (16:34 +1000)
committer[Peter Burnett] <[peterburnett@catalyst-au.net]>
Fri, 2 Aug 2019 01:34:23 +0000 (11:34 +1000)
lib/tests/weblib_test.php

index 8e63d32..d3895a5 100644 (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());
+    }
 }