Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
50.82% covered (warning)
50.82%
31 / 61
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
phpbb_functions_validate_password_test
50.82% covered (warning)
50.82%
31 / 61
66.67% covered (warning)
66.67%
2 / 3
4.07
0.00% covered (danger)
0.00%
0 / 1
 setUp
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 validate_password_data
0.00% covered (danger)
0.00%
0 / 30
0.00% covered (danger)
0.00%
0 / 1
2
 test_validate_password
100.00% covered (success)
100.00%
29 / 29
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13
14require_once __DIR__ . '/../../phpBB/includes/functions_user.php';
15require_once __DIR__ . '/validate_data_helper.php';
16
17class phpbb_functions_validate_password_test extends phpbb_test_case
18{
19    protected $helper;
20
21    protected function setUp(): void
22    {
23        parent::setUp();
24
25        $this->helper = new phpbb_functions_validate_data_helper($this);
26    }
27
28    public static function validate_password_data()
29    {
30        return array(
31            array('PASS_TYPE_ANY', array(
32                'empty'            => array(),
33                'foobar_any'        => array(),
34                'foobar_mixed'        => array(),
35                'foobar_alpha'        => array(),
36                'foobar_symbol'        => array(),
37            )),
38            array('PASS_TYPE_CASE', array(
39                'empty'            => array(),
40                'foobar_any'        => array('INVALID_CHARS'),
41                'foobar_mixed'        => array(),
42                'foobar_alpha'        => array(),
43                'foobar_symbol'        => array(),
44            )),
45            array('PASS_TYPE_ALPHA', array(
46                'empty'            => array(),
47                'foobar_any'        => array('INVALID_CHARS'),
48                'foobar_mixed'        => array('INVALID_CHARS'),
49                'foobar_alpha'        => array(),
50                'foobar_symbol'        => array(),
51            )),
52            array('PASS_TYPE_SYMBOL', array(
53                'empty'            => array(),
54                'foobar_any'        => array('INVALID_CHARS'),
55                'foobar_mixed'        => array('INVALID_CHARS'),
56                'foobar_alpha'        => array('INVALID_CHARS'),
57                'foobar_symbol'        => array(),
58            )),
59        );
60    }
61
62    /**
63    * @dataProvider validate_password_data
64    */
65    public function test_validate_password($pass_complexity, $expected)
66    {
67        global $config;
68
69        // Set complexity to mixed case letters, numbers and symbols
70        $config['pass_complex'] = $pass_complexity;
71
72        $this->helper->assert_valid_data(array(
73            'empty'            => array(
74                $expected['empty'],
75                '',
76                array('password'),
77            ),
78            'foobar_any'        => array(
79                $expected['foobar_any'],
80                'foobar',
81                array('password'),
82            ),
83            'foobar_mixed'        => array(
84                $expected['foobar_mixed'],
85                'FooBar',
86                array('password'),
87            ),
88            'foobar_alpha'        => array(
89                $expected['foobar_alpha'],
90                'F00bar',
91                array('password'),
92            ),
93            'foobar_symbol'        => array(
94                $expected['foobar_symbol'],
95                'fooBar123*',
96                array('password'),
97            ),
98        ));
99    }
100}