Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
47.37% |
18 / 38 |
|
57.14% |
4 / 7 |
CRAP | |
0.00% |
0 / 1 |
| phpbb_functions_validate_email_test | |
47.37% |
18 / 38 |
|
57.14% |
4 / 7 |
14.14 | |
0.00% |
0 / 1 |
| getDataSet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setUp | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| set_validation_prerequisites | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| validate_email_data | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| test_validate_email | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
| validate_email_mx_data | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| test_validate_email_mx | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * |
| 4 | * @package testing |
| 5 | * @copyright (c) 2014 phpBB Group |
| 6 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
| 7 | * |
| 8 | */ |
| 9 | |
| 10 | require_once __DIR__ . '/../../phpBB/includes/functions_user.php'; |
| 11 | require_once __DIR__ . '/../mock/user.php'; |
| 12 | require_once __DIR__ . '/validate_data_helper.php'; |
| 13 | |
| 14 | class phpbb_functions_validate_email_test extends phpbb_database_test_case |
| 15 | { |
| 16 | protected $db; |
| 17 | protected $user; |
| 18 | protected $helper; |
| 19 | |
| 20 | public function getDataSet() |
| 21 | { |
| 22 | return $this->createXMLDataSet(__DIR__ . '/fixtures/validate_email.xml'); |
| 23 | } |
| 24 | |
| 25 | protected function setUp(): void |
| 26 | { |
| 27 | parent::setUp(); |
| 28 | |
| 29 | $this->db = $this->new_dbal(); |
| 30 | $this->user = new phpbb_mock_user; |
| 31 | $this->helper = new phpbb_functions_validate_data_helper($this); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Get validation prerequesites |
| 36 | * |
| 37 | * @param bool $check_mx Whether mx records should be checked |
| 38 | */ |
| 39 | protected function set_validation_prerequisites($check_mx) |
| 40 | { |
| 41 | global $config, $db, $user; |
| 42 | |
| 43 | $config['email_check_mx'] = $check_mx; |
| 44 | $db = $this->db; |
| 45 | $user = $this->user; |
| 46 | $user->optionset('banned_users', array('banned@example.com')); |
| 47 | } |
| 48 | |
| 49 | public static function validate_email_data() |
| 50 | { |
| 51 | return array( |
| 52 | array('empty', array('EMAIL_INVALID'), ''), // email does not allow empty |
| 53 | array('allowed', array(), 'foobar@example.com'), |
| 54 | array('valid_complex', array(), "'%$~test@example.com"), |
| 55 | array('invalid', array('EMAIL_INVALID'), 'fööbar@example.com'), |
| 56 | array('taken', array(), 'admin@example.com'), // email does not check taken, should use user_email instead |
| 57 | array('banned', array(), 'banned@example.com'), // email does not check ban, should use user_email instead |
| 58 | ); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * @dataProvider validate_email_data |
| 63 | */ |
| 64 | public function test_validate_email($case, $errors, $email) |
| 65 | { |
| 66 | $this->set_validation_prerequisites(false); |
| 67 | |
| 68 | $this->helper->assert_valid_data(array( |
| 69 | $case => array( |
| 70 | $errors, |
| 71 | $email, |
| 72 | array('email'), |
| 73 | ), |
| 74 | )); |
| 75 | } |
| 76 | |
| 77 | public static function validate_email_mx_data() |
| 78 | { |
| 79 | return array( |
| 80 | array('valid', array(), 'foobar@phpbb.com'), |
| 81 | array('no_mx', array('DOMAIN_NO_MX_RECORD'), 'test@does-not-exist.phpbb.com'), |
| 82 | ); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * @dataProvider validate_email_mx_data |
| 87 | * @group slow |
| 88 | */ |
| 89 | public function test_validate_email_mx($case, $errors, $email) |
| 90 | { |
| 91 | $this->set_validation_prerequisites(true); |
| 92 | |
| 93 | $this->helper->assert_valid_data(array( |
| 94 | $case => array( |
| 95 | $errors, |
| 96 | $email, |
| 97 | array('email'), |
| 98 | ), |
| 99 | )); |
| 100 | } |
| 101 | } |