Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
165 / 165 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| phpbb_console_user_base | |
100.00% |
165 / 165 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
| getDataSet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setUp | |
100.00% |
156 / 156 |
|
100.00% |
1 / 1 |
1 | |||
| get_user_id | |
100.00% |
8 / 8 |
|
100.00% |
1 / 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 | abstract class phpbb_console_user_base extends phpbb_database_test_case |
| 15 | { |
| 16 | protected $db; |
| 17 | protected $config; |
| 18 | protected $email; |
| 19 | protected $user; |
| 20 | protected $language; |
| 21 | protected $log; |
| 22 | protected $passwords_manager; |
| 23 | /** @var Symfony\Component\Console\Helper\QuestionHelper */ |
| 24 | protected $question; |
| 25 | protected $command_name; |
| 26 | protected $user_loader; |
| 27 | protected $phpbb_root_path; |
| 28 | protected $php_ext; |
| 29 | |
| 30 | public function getDataSet() |
| 31 | { |
| 32 | return $this->createXMLDataSet(__DIR__ . '/fixtures/config.xml'); |
| 33 | } |
| 34 | |
| 35 | protected function setUp(): void |
| 36 | { |
| 37 | global $auth, $db, $cache, $config, $user, $phpbb_dispatcher, $phpbb_container, $phpbb_root_path, $phpEx; |
| 38 | |
| 39 | $phpbb_dispatcher = new \phpbb\event\dispatcher(); |
| 40 | $phpbb_container = new phpbb_mock_container_builder(); |
| 41 | $phpbb_container->set('cache.driver', new phpbb_mock_cache()); |
| 42 | $phpbb_container->set('notification_manager', new phpbb_mock_notification_manager()); |
| 43 | |
| 44 | $auth = $this->createMock('\phpbb\auth\auth'); |
| 45 | |
| 46 | $cache = $phpbb_container->get('cache.driver'); |
| 47 | |
| 48 | $config = $this->config = new \phpbb\config\config(array( |
| 49 | 'board_timezone' => 'UTC', |
| 50 | 'default_lang' => 'en', |
| 51 | 'email_enable' => false, |
| 52 | 'min_name_chars' => 3, |
| 53 | 'max_name_chars' => 10, |
| 54 | 'min_pass_chars' => 3, |
| 55 | 'pass_complex' => 'PASS_TYPE_ANY', |
| 56 | )); |
| 57 | |
| 58 | $db = $this->db = $this->new_dbal(); |
| 59 | |
| 60 | $this->language = $this->getMockBuilder('\phpbb\language\language') |
| 61 | ->disableOriginalConstructor() |
| 62 | ->getMock(); |
| 63 | $this->language->expects($this->any()) |
| 64 | ->method('lang') |
| 65 | ->will($this->returnArgument(0)); |
| 66 | |
| 67 | $user = $this->user = $this->createMock('\phpbb\user', array(), array( |
| 68 | $this->language, |
| 69 | '\phpbb\datetime' |
| 70 | )); |
| 71 | $user->data['user_email'] = ''; |
| 72 | |
| 73 | $avatar_helper = $this->getMockBuilder('\phpbb\avatar\helper') |
| 74 | ->disableOriginalConstructor() |
| 75 | ->getMock(); |
| 76 | |
| 77 | $this->user_loader = new \phpbb\user_loader($avatar_helper, $db, $phpbb_root_path, $phpEx, USERS_TABLE); |
| 78 | |
| 79 | $driver_helper = new \phpbb\passwords\driver\helper($this->config); |
| 80 | $passwords_drivers = array( |
| 81 | 'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($this->config, $driver_helper), |
| 82 | 'passwords.driver.bcrypt' => new \phpbb\passwords\driver\bcrypt($this->config, $driver_helper), |
| 83 | 'passwords.driver.salted_md5' => new \phpbb\passwords\driver\salted_md5($this->config, $driver_helper), |
| 84 | 'passwords.driver.phpass' => new \phpbb\passwords\driver\phpass($this->config, $driver_helper), |
| 85 | ); |
| 86 | |
| 87 | $passwords_helper = new \phpbb\passwords\helper; |
| 88 | $this->passwords_manager = new \phpbb\passwords\manager($this->config, $passwords_drivers, $passwords_helper, array_keys($passwords_drivers)); |
| 89 | |
| 90 | $this->phpbb_root_path = $phpbb_root_path; |
| 91 | $this->php_ext = $phpEx; |
| 92 | |
| 93 | $this->log = $this->getMockBuilder('\phpbb\log\log') |
| 94 | ->disableOriginalConstructor() |
| 95 | ->getMock(); |
| 96 | |
| 97 | $phpbb_container->set('auth.provider.db', new phpbb_mock_auth_provider()); |
| 98 | $provider_collection = new \phpbb\auth\provider_collection($phpbb_container, $config); |
| 99 | $provider_collection->add('auth.provider.db'); |
| 100 | $phpbb_container->set( |
| 101 | 'auth.provider_collection', |
| 102 | $provider_collection |
| 103 | ); |
| 104 | $phpbb_container->setParameter('tables.auth_provider_oauth_token_storage', 'phpbb_oauth_tokens'); |
| 105 | $phpbb_container->setParameter('tables.auth_provider_oauth_states', 'phpbb_oauth_states'); |
| 106 | $phpbb_container->setParameter('tables.auth_provider_oauth_account_assoc', 'phpbb_oauth_accounts'); |
| 107 | |
| 108 | $phpbb_container->setParameter('tables.user_notifications', 'phpbb_user_notifications'); |
| 109 | |
| 110 | $assets_bag = new \phpbb\template\assets_bag(); |
| 111 | $phpbb_container->set('assets.bag', $assets_bag); |
| 112 | |
| 113 | $phpbb_container->set('dispatcher', $phpbb_dispatcher); |
| 114 | |
| 115 | $core_cache_dir = $phpbb_root_path . 'cache/' . PHPBB_ENVIRONMENT . '/'; |
| 116 | $phpbb_container->setParameter('core.cache_dir', $core_cache_dir); |
| 117 | |
| 118 | $core_messenger_queue_file = $core_cache_dir . 'queue.' . $phpEx; |
| 119 | $phpbb_container->setParameter('core.messenger_queue_file', $core_messenger_queue_file); |
| 120 | |
| 121 | $messenger_method_collection = new \phpbb\di\service_collection($phpbb_container); |
| 122 | $messenger_method_collection->add('messenger.method.email'); |
| 123 | $phpbb_container->set('messenger.method_collection', $messenger_method_collection); |
| 124 | |
| 125 | $messenger_queue = new \phpbb\messenger\queue($config, $phpbb_dispatcher, $messenger_method_collection, $core_messenger_queue_file); |
| 126 | $phpbb_container->set('messenger.queue', $messenger_queue); |
| 127 | |
| 128 | $request = new phpbb_mock_request; |
| 129 | $phpbb_container->set('request', $request); |
| 130 | |
| 131 | $symfony_request = new \phpbb\symfony_request( |
| 132 | $request |
| 133 | ); |
| 134 | |
| 135 | $phpbb_path_helper = new \phpbb\path_helper( |
| 136 | $symfony_request, |
| 137 | $request, |
| 138 | $phpbb_root_path, |
| 139 | $phpEx |
| 140 | ); |
| 141 | $phpbb_container->set('path_helper', $phpbb_path_helper); |
| 142 | |
| 143 | $factory = new \phpbb\db\tools\factory(); |
| 144 | $db_doctrine = $this->new_doctrine_dbal(); |
| 145 | $db_tools = $factory->get($db_doctrine); |
| 146 | $migrator = new \phpbb\db\migrator( |
| 147 | $phpbb_container, |
| 148 | $config, |
| 149 | $db, |
| 150 | $db_tools, |
| 151 | 'phpbb_migrations', |
| 152 | $phpbb_root_path, |
| 153 | $this->php_ext, |
| 154 | 'phpbb_', |
| 155 | self::get_core_tables(), |
| 156 | [], |
| 157 | new \phpbb\db\migration\helper() |
| 158 | ); |
| 159 | $phpbb_container->set('migrator', $migrator); |
| 160 | |
| 161 | $finder_factory = new \phpbb\finder\factory(null, false, $phpbb_root_path, $this->php_ext); |
| 162 | $extension_manager = new \phpbb\extension\manager( |
| 163 | $phpbb_container, |
| 164 | $db, |
| 165 | $config, |
| 166 | $finder_factory, |
| 167 | 'phpbb_ext', |
| 168 | __DIR__ . '/', |
| 169 | new \phpbb\cache\service(new phpbb_mock_cache(), $config, $db, $phpbb_dispatcher, $phpbb_root_path, $this->php_ext) |
| 170 | ); |
| 171 | $phpbb_container->set('ext.manager', $extension_manager); |
| 172 | |
| 173 | $context = new \phpbb\template\context(); |
| 174 | $cache_path = $phpbb_root_path . 'cache/' . PHPBB_ENVIRONMENT . '/twig'; |
| 175 | $phpbb_container->setParameter('core.template.cache_path', $cache_path); |
| 176 | $filesystem = new \phpbb\filesystem\filesystem(); |
| 177 | $phpbb_container->set('filesystem', $filesystem); |
| 178 | |
| 179 | $twig = new \phpbb\template\twig\environment( |
| 180 | $assets_bag, |
| 181 | $this->config, |
| 182 | $filesystem, |
| 183 | $phpbb_path_helper, |
| 184 | $cache_path, |
| 185 | null, |
| 186 | new \phpbb\template\twig\loader(''), |
| 187 | $phpbb_dispatcher, |
| 188 | [ |
| 189 | 'cache' => false, |
| 190 | 'debug' => false, |
| 191 | 'auto_reload' => true, |
| 192 | 'autoescape' => false, |
| 193 | ] |
| 194 | ); |
| 195 | $twig_extension = new \phpbb\template\twig\extension($context, $twig, $this->language); |
| 196 | $phpbb_container->set('template.twig.extensions.phpbb', $twig_extension); |
| 197 | |
| 198 | $twig_extensions_collection = new \phpbb\di\service_collection($phpbb_container); |
| 199 | $twig_extensions_collection->add('template.twig.extensions.phpbb'); |
| 200 | $phpbb_container->set('template.twig.extensions.collection', $twig_extensions_collection); |
| 201 | |
| 202 | $twig->addExtension($twig_extension); |
| 203 | $twig_lexer = new \phpbb\template\twig\lexer($twig); |
| 204 | $phpbb_container->set('template.twig.lexer', $twig_lexer); |
| 205 | |
| 206 | $this->email = new \phpbb\messenger\method\email( |
| 207 | $assets_bag, |
| 208 | $this->config, |
| 209 | $phpbb_dispatcher, |
| 210 | $this->language, |
| 211 | $messenger_queue, |
| 212 | $phpbb_path_helper, |
| 213 | $request, |
| 214 | $twig_extensions_collection, |
| 215 | $twig_lexer, |
| 216 | $user, |
| 217 | $phpbb_root_path, |
| 218 | $cache_path, |
| 219 | $extension_manager, |
| 220 | $this->log |
| 221 | ); |
| 222 | $phpbb_container->set('messenger.method.email', $this->email); |
| 223 | |
| 224 | parent::setUp(); |
| 225 | } |
| 226 | |
| 227 | public function get_user_id($username) |
| 228 | { |
| 229 | $sql = 'SELECT user_id |
| 230 | FROM ' . USERS_TABLE . ' |
| 231 | WHERE ' . 'username = ' . "'" . $username . "'"; |
| 232 | $result = $this->db->sql_query($sql); |
| 233 | $row = $this->db->sql_fetchrow($result); |
| 234 | $this->db->sql_freeresult($result); |
| 235 | |
| 236 | $user_id = $row ? $row['user_id'] : null; |
| 237 | return $user_id; |
| 238 | } |
| 239 | } |