Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
68.57% |
48 / 70 |
|
57.14% |
4 / 7 |
CRAP | |
0.00% |
0 / 1 |
| phpbb_functions_validate_user_email_test | |
68.57% |
48 / 70 |
|
57.14% |
4 / 7 |
8.52 | |
0.00% |
0 / 1 |
| getDataSet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setUp | |
100.00% |
34 / 34 |
|
100.00% |
1 / 1 |
1 | |||
| set_validation_prerequisites | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| validate_user_email_data | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
| test_validate_user_email | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
1 | |||
| validate_user_email_mx_data | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| test_validate_user_email_mx | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
| 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 | |
| 14 | require_once __DIR__ . '/../../phpBB/includes/functions_user.php'; |
| 15 | require_once __DIR__ . '/../mock/user.php'; |
| 16 | require_once __DIR__ . '/validate_data_helper.php'; |
| 17 | |
| 18 | class phpbb_functions_validate_user_email_test extends phpbb_database_test_case |
| 19 | { |
| 20 | protected $db; |
| 21 | protected $user; |
| 22 | protected $helper; |
| 23 | |
| 24 | public function getDataSet() |
| 25 | { |
| 26 | return $this->createXMLDataSet(__DIR__ . '/fixtures/validate_email.xml'); |
| 27 | } |
| 28 | |
| 29 | protected function setUp(): void |
| 30 | { |
| 31 | global $cache, $phpbb_container, $phpbb_dispatcher, $phpbb_root_path, $phpEx, $config; |
| 32 | |
| 33 | parent::setUp(); |
| 34 | |
| 35 | $phpbb_container = new phpbb_mock_container_builder(); |
| 36 | $config = new \phpbb\config\config([ |
| 37 | 'allow_emailreuse' => 0, |
| 38 | ]); |
| 39 | $this->db = $this->new_dbal(); |
| 40 | $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); |
| 41 | $language = new phpbb\language\language(new phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); |
| 42 | $this->user = new phpbb\user($language, '\phpbb\datetime'); |
| 43 | $this->user->data['user_email'] = ''; |
| 44 | $this->helper = new phpbb_functions_validate_data_helper($this); |
| 45 | |
| 46 | $cache = new \phpbb\cache\service( |
| 47 | new \phpbb\cache\driver\dummy(), |
| 48 | $config, |
| 49 | $this->db, |
| 50 | $phpbb_dispatcher, |
| 51 | $phpbb_root_path, |
| 52 | $phpEx |
| 53 | ); |
| 54 | $cache->get_driver()->purge(); |
| 55 | |
| 56 | $ban_type_email = new \phpbb\ban\type\email($this->db, 'phpbb_bans', 'phpbb_users', 'phpbb_sessions', 'phpbb_sessions_keys'); |
| 57 | $ban_type_user = new \phpbb\ban\type\user($this->db, 'phpbb_bans', 'phpbb_users', 'phpbb_sessions', 'phpbb_sessions_keys'); |
| 58 | $ban_type_ip = new \phpbb\ban\type\ip($this->db, 'phpbb_bans', 'phpbb_users', 'phpbb_sessions', 'phpbb_sessions_keys'); |
| 59 | $phpbb_container->set('ban.type.email', $ban_type_email); |
| 60 | $phpbb_container->set('ban.type.user', $ban_type_user); |
| 61 | $phpbb_container->set('ban.type.ip', $ban_type_ip); |
| 62 | $collection = new \phpbb\di\service_collection($phpbb_container); |
| 63 | $collection->add('ban.type.email'); |
| 64 | $collection->add('ban.type.user'); |
| 65 | $collection->add('ban.type.ip'); |
| 66 | $phpbb_log = new \phpbb\log\dummy(); |
| 67 | |
| 68 | $ban_manager = new \phpbb\ban\manager($collection, $cache->get_driver(), $this->db, $language, $phpbb_log, $this->user, 'phpbb_bans', 'phpbb_users'); |
| 69 | $phpbb_container->set('ban.manager', $ban_manager); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Get validation prerequesites |
| 74 | * |
| 75 | * @param bool $check_mx Whether mx records should be checked |
| 76 | */ |
| 77 | protected function set_validation_prerequisites($check_mx) |
| 78 | { |
| 79 | global $config, $db, $user; |
| 80 | |
| 81 | $config['email_check_mx'] = $check_mx; |
| 82 | $db = $this->db; |
| 83 | $user = $this->user; |
| 84 | } |
| 85 | |
| 86 | public static function validate_user_email_data() |
| 87 | { |
| 88 | return array( |
| 89 | array('empty', array(), ''), |
| 90 | array('allowed', array(), 'foobar@example.com'), |
| 91 | array('valid_complex', array(), "'%$~test@example.com"), |
| 92 | array('invalid', array('EMAIL_INVALID'), 'fööbar@example.com'), |
| 93 | array('taken', array('EMAIL_TAKEN'), 'admin@example.com'), |
| 94 | array('banned', ['just because'], 'banned2@example.com'), |
| 95 | array('banned', ['EMAIL_BANNED'], 'banned@example.com') |
| 96 | ); |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * @dataProvider validate_user_email_data |
| 101 | */ |
| 102 | public function test_validate_user_email($case, $errors, $email) |
| 103 | { |
| 104 | global $config, $db, $user; |
| 105 | |
| 106 | $this->set_validation_prerequisites(false); |
| 107 | |
| 108 | $this->helper->assert_valid_data(array( |
| 109 | $case => array( |
| 110 | $errors, |
| 111 | $email, |
| 112 | array('user_email'), |
| 113 | ), |
| 114 | )); |
| 115 | } |
| 116 | |
| 117 | public static function validate_user_email_mx_data() |
| 118 | { |
| 119 | return array( |
| 120 | array('valid', array(), 'foobar@phpbb.com'), |
| 121 | array('no_mx', array('DOMAIN_NO_MX_RECORD'), 'test@does-not-exist.phpbb.com'), |
| 122 | ); |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * @dataProvider validate_user_email_mx_data |
| 127 | * @group slow |
| 128 | */ |
| 129 | public function test_validate_user_email_mx($case, $errors, $email) |
| 130 | { |
| 131 | global $config, $db, $user; |
| 132 | |
| 133 | $this->set_validation_prerequisites(true); |
| 134 | |
| 135 | $this->helper->assert_valid_data(array( |
| 136 | $case => array( |
| 137 | $errors, |
| 138 | $email, |
| 139 | array('user_email'), |
| 140 | ), |
| 141 | )); |
| 142 | } |
| 143 | } |