| @@ 172-202 (lines=31) @@ | ||
| 169 | * |
|
| 170 | * @return array test results. |
|
| 171 | */ |
|
| 172 | public function run_tests( $password, $tests, $required_only = false ) { |
|
| 173 | $results = array( |
|
| 174 | 'passed' => array(), |
|
| 175 | 'failed' => array(), |
|
| 176 | ); |
|
| 177 | ||
| 178 | foreach ( $tests as $test_type => $section_tests ) { |
|
| 179 | foreach ( $section_tests as $test_name => $test_data ) { |
|
| 180 | // Skip non-required tests if required_only param is set. |
|
| 181 | if ( $required_only && ! $test_data['required'] ) { |
|
| 182 | continue; |
|
| 183 | } |
|
| 184 | ||
| 185 | $result = call_user_func_array( array( $this, 'test_' . $test_type ), array( $password, $test_data ) ); |
|
| 186 | if ( $result ) { |
|
| 187 | $results['passed'][] = array( 'test_name' => $test_name ); |
|
| 188 | } else { |
|
| 189 | $results['failed'][] = array( |
|
| 190 | 'test_name' => $test_name, |
|
| 191 | 'explanation' => $test_data['error'], |
|
| 192 | ); |
|
| 193 | ||
| 194 | if ( isset( $test_data['fail_immediately'] ) ) { |
|
| 195 | return $results; |
|
| 196 | } |
|
| 197 | } |
|
| 198 | } |
|
| 199 | } |
|
| 200 | ||
| 201 | return $results; |
|
| 202 | } |
|
| 203 | ||
| 204 | /** |
|
| 205 | * Returns an array of tests that need to be run on password strings. |
|
| @@ 176-211 (lines=36) @@ | ||
| 173 | * @param Boolean $required_only whether to run only required tests. |
|
| 174 | * @return array test results. |
|
| 175 | */ |
|
| 176 | protected function run_tests( $tests, $required_only = false ) { |
|
| 177 | ||
| 178 | $results = array( |
|
| 179 | 'passed' => array(), |
|
| 180 | 'failed' => array(), |
|
| 181 | ); |
|
| 182 | ||
| 183 | foreach ( $tests as $test_type => $section_tests ) { |
|
| 184 | foreach ( $section_tests as $test_name => $test_data ) { |
|
| 185 | ||
| 186 | // Skip non-required tests if required_only param is set. |
|
| 187 | if ( $required_only && ! $test_data['required'] ) { |
|
| 188 | continue; |
|
| 189 | } |
|
| 190 | ||
| 191 | $test_function = 'test_' . $test_type; |
|
| 192 | ||
| 193 | $result = call_user_func( array( $this, $test_function ), $test_data ); |
|
| 194 | ||
| 195 | if ( $result ) { |
|
| 196 | $results['passed'][] = array( 'test_name' => $test_name ); |
|
| 197 | } else { |
|
| 198 | $results['failed'][] = array( |
|
| 199 | 'test_name' => $test_name, |
|
| 200 | 'explanation' => $test_data['error'], |
|
| 201 | ); |
|
| 202 | ||
| 203 | if ( isset( $test_data['fail_immediately'] ) ) { |
|
| 204 | return $results; |
|
| 205 | } |
|
| 206 | } |
|
| 207 | } |
|
| 208 | } |
|
| 209 | ||
| 210 | return $results; |
|
| 211 | } |
|
| 212 | ||
| 213 | /** |
|
| 214 | * Returns a list of tests that need to be run on password strings. |
|