[ticket/9687] Fix tests

PHPBB3-9687
This commit is contained in:
Marc Alexander 2023-07-04 14:49:31 +02:00
parent 7739eb2cfe
commit 8bdda472bf
No known key found for this signature in database
GPG key ID: 50E0D2423696F995
3 changed files with 56 additions and 11 deletions

View file

@ -28,18 +28,39 @@ class phpbb_functions_validate_user_email_test extends phpbb_database_test_case
protected function setUp(): void protected function setUp(): void
{ {
global $cache, $phpbb_dispatcher, $phpbb_root_path, $phpEx; global $cache, $phpbb_container, $phpbb_dispatcher, $phpbb_root_path, $phpEx;
parent::setUp(); parent::setUp();
$cache = new \phpbb\cache\driver\file(); $phpbb_container = new phpbb_mock_container_builder();
$cache->purge(); $config = new \phpbb\config\config([]);
$this->db = $this->new_dbal(); $this->db = $this->new_dbal();
$phpbb_dispatcher = new phpbb_mock_event_dispatcher(); $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
$language = new phpbb\language\language(new phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); $language = new phpbb\language\language(new phpbb\language\language_file_loader($phpbb_root_path, $phpEx));
$this->user = new phpbb\user($language, '\phpbb\datetime'); $this->user = new phpbb\user($language, '\phpbb\datetime');
$this->user->data['user_email'] = ''; $this->user->data['user_email'] = '';
$this->helper = new phpbb_functions_validate_data_helper($this); $this->helper = new phpbb_functions_validate_data_helper($this);
$cache = new \phpbb\cache\service(
new \phpbb\cache\driver\dummy(),
$config,
$this->db,
$phpbb_dispatcher,
$phpbb_root_path,
$phpEx
);
$cache->get_driver()->purge();
$ban_type_email = new \phpbb\ban\type\email($this->db, 'phpbb_users', 'phpbb_sessions', 'phpbb_sessions_keys');
$ban_type_user = new \phpbb\ban\type\user($this->db, 'phpbb_users', 'phpbb_sessions', 'phpbb_sessions_keys');
$phpbb_container->set('ban.type.email', $ban_type_email);
$phpbb_container->set('ban.type.user', $ban_type_user);
$collection = new \phpbb\di\service_collection($phpbb_container);
$collection->add('ban.type.email');
$collection->add('ban.type.user');
$ban_manager = new \phpbb\ban\manager($collection, $cache, $this->db, 'phpbb_bans', 'phpbb_users');
$phpbb_container->set('ban.manager', $ban_manager);
} }
/** /**

View file

@ -38,7 +38,7 @@ class phpbb_session_testable_factory
public function __construct() public function __construct()
{ {
// default configuration values // default configuration values
$this->config_data = array( $this->config_data = [
'allow_autologin' => false, 'allow_autologin' => false,
'auth_method' => 'db', 'auth_method' => 'db',
'forwarded_for_check' => true, 'forwarded_for_check' => true,
@ -53,13 +53,14 @@ class phpbb_session_testable_factory
'limit_search_load' => 0, 'limit_search_load' => 0,
'ip_check' => 3, 'ip_check' => 3,
'browser_check' => 1, 'browser_check' => 1,
); ];
$this->cache_data = array( $this->cache_data = [
'_bots' => array(), '_bots' => [],
); '_ban_info' => [],
];
$this->cookies = array(); $this->cookies = [];
$this->server_data = $_SERVER; $this->server_data = $_SERVER;
} }
@ -73,7 +74,8 @@ class phpbb_session_testable_factory
public function get_session(\phpbb\db\driver\driver_interface $dbal) public function get_session(\phpbb\db\driver\driver_interface $dbal)
{ {
// set up all the global variables used by session // set up all the global variables used by session
global $SID, $_SID, $db, $config, $cache, $request, $phpbb_container, $phpbb_root_path; global $SID, $_SID, $db, $config, $cache, $request, $phpbb_container, $phpbb_dispatcher;
global $phpbb_root_path, $phpEx;
$request = $this->request = new phpbb_mock_request( $request = $this->request = new phpbb_mock_request(
array(), array(),
@ -103,6 +105,28 @@ class phpbb_session_testable_factory
$provider_collection $provider_collection
); );
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
$cache_service = new \phpbb\cache\service(
$cache,
$config,
$db,
$phpbb_dispatcher,
$phpbb_root_path,
$phpEx
);
$ban_type_email = new \phpbb\ban\type\email($db, 'phpbb_users', 'phpbb_sessions', 'phpbb_sessions_keys');
$ban_type_user = new \phpbb\ban\type\user($db, 'phpbb_users', 'phpbb_sessions', 'phpbb_sessions_keys');
$phpbb_container->set('ban.type.email', $ban_type_email);
$phpbb_container->set('ban.type.user', $ban_type_user);
$collection = new \phpbb\di\service_collection($phpbb_container);
$collection->add('ban.type.email');
$collection->add('ban.type.user');
$ban_manager = new \phpbb\ban\manager($collection, $cache_service, $db, 'phpbb_bans', 'phpbb_users');
$phpbb_container->set('ban.manager', $ban_manager);
$session = new phpbb_mock_session_testable; $session = new phpbb_mock_session_testable;
return $session; return $session;
} }

View file

@ -29,7 +29,7 @@ abstract class phpbb_session_test_case extends phpbb_database_test_case
{ {
parent::setUp(); parent::setUp();
global $symfony_request, $phpbb_path_helper, $request, $phpbb_root_path, $phpEx; global $symfony_request, $phpbb_path_helper, $phpbb_root_path, $phpEx;
$symfony_request = new \phpbb\symfony_request( $symfony_request = new \phpbb\symfony_request(
new phpbb_mock_request() new phpbb_mock_request()
); );