mirror of
https://github.com/phpbb/phpbb.git
synced 2025-03-14 04:30:29 +01:00
[ticket/15886] Clean up services
PHPBB3-15886
This commit is contained in:
parent
d79eb72fc1
commit
e2e3d402a2
@ -129,8 +129,6 @@ services:
|
||||
- '@dispatcher'
|
||||
- '@path_helper'
|
||||
- '@user'
|
||||
- '%core.root_path%'
|
||||
- '%core.php_ext%'
|
||||
|
||||
log:
|
||||
class: phpbb\log\log
|
||||
|
@ -14,7 +14,7 @@
|
||||
namespace phpbb\group;
|
||||
|
||||
use phpbb\auth\auth;
|
||||
use phpbb\cache;
|
||||
use phpbb\cache\service as cache;
|
||||
use phpbb\config\config;
|
||||
use phpbb\language\language;
|
||||
use phpbb\event\dispatcher_interface;
|
||||
@ -26,7 +26,7 @@ class helper
|
||||
/** @var auth */
|
||||
protected $auth;
|
||||
|
||||
/** @var cache\service */
|
||||
/** @var cache */
|
||||
protected $cache;
|
||||
|
||||
/** @var config */
|
||||
@ -36,10 +36,10 @@ class helper
|
||||
protected $language;
|
||||
|
||||
/** @var dispatcher_interface */
|
||||
protected $phpbb_dispatcher;
|
||||
protected $dispatcher;
|
||||
|
||||
/** @var path_helper */
|
||||
protected $phpbb_path_helper;
|
||||
protected $path_helper;
|
||||
|
||||
/** @var user */
|
||||
protected $user;
|
||||
@ -47,40 +47,34 @@ class helper
|
||||
/** @var string phpBB root path */
|
||||
protected $phpbb_root_path;
|
||||
|
||||
/** @var string PHP file extension */
|
||||
protected $php_ext;
|
||||
|
||||
/** @var array Return templates for a group name string */
|
||||
protected $name_strings;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param auth $auth Authentication object
|
||||
* @param cache\service $cache Cache service object
|
||||
* @param config $config Configuration object
|
||||
* @param language $language Language object
|
||||
* @param dispatcher_interface $phpbb_dispatcher Event dispatcher object
|
||||
* @param path_helper $phpbb_path_helper Path helper object
|
||||
* @param user $user User object
|
||||
* @param string $phpbb_root_path phpBB root path
|
||||
* @param string $php_ext PHP file extension
|
||||
* @param auth $auth Authentication object
|
||||
* @param cache $cache Cache service object
|
||||
* @param config $config Configuration object
|
||||
* @param language $language Language object
|
||||
* @param dispatcher_interface $dispatcher Event dispatcher object
|
||||
* @param path_helper $path_helper Path helper object
|
||||
* @param user $user User object
|
||||
*/
|
||||
public function __construct(auth $auth, cache\service $cache, config $config, language $language, dispatcher_interface $phpbb_dispatcher, path_helper $phpbb_path_helper, user $user, $phpbb_root_path, $php_ext)
|
||||
public function __construct(auth $auth, cache $cache, config $config, language $language, dispatcher_interface $dispatcher, path_helper $path_helper, user $user)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
$this->cache = $cache;
|
||||
$this->config = $config;
|
||||
$this->language = $language;
|
||||
$this->phpbb_dispatcher = $phpbb_dispatcher;
|
||||
$this->phpbb_path_helper = $phpbb_path_helper;
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->path_helper = $path_helper;
|
||||
$this->user = $user;
|
||||
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
$this->php_ext = $php_ext;
|
||||
$this->phpbb_root_path = $path_helper->get_phpbb_root_path();
|
||||
|
||||
$this->name_strings = array(
|
||||
'base_url' => append_sid("{$phpbb_root_path}memberlist.{$php_ext}", 'mode=group&g={GROUP_ID}'),
|
||||
'base_url' => append_sid("{$path_helper->get_phpbb_root_path()}memberlist.{$path_helper->get_php_ext()}", 'mode=group&g={GROUP_ID}'),
|
||||
'tpl_noprofile' => '<span class="username">{GROUP_NAME}</span>',
|
||||
'tpl_noprofile_colour' => '<span class="username-coloured" style="color: {GROUP_COLOUR};">{GROUP_NAME}</span>',
|
||||
'tpl_profile' => '<a class="username" href="{PROFILE_URL}">{GROUP_NAME}</a>',
|
||||
@ -207,7 +201,7 @@ class helper
|
||||
'group_name_string',
|
||||
'name_strings',
|
||||
);
|
||||
extract($this->phpbb_dispatcher->trigger_event('core.modify_group_name_string', compact($vars)));
|
||||
extract($this->dispatcher->trigger_event('core.modify_group_name_string', compact($vars)));
|
||||
|
||||
return $group_name_string;
|
||||
}
|
||||
@ -237,7 +231,7 @@ class helper
|
||||
*/
|
||||
|
||||
$vars = array('group_data');
|
||||
extract($this->phpbb_dispatcher->trigger_event('core.get_group_rank_before', compact($vars)));
|
||||
extract($this->dispatcher->trigger_event('core.get_group_rank_before', compact($vars)));
|
||||
|
||||
if (!empty($group_data['group_rank']))
|
||||
{
|
||||
@ -250,7 +244,7 @@ class helper
|
||||
|
||||
$group_rank_data['title'] = $rank['rank_title'];
|
||||
|
||||
$group_rank_data['img_src'] = (!empty($rank['rank_image'])) ? $this->phpbb_path_helper->update_web_root_path($this->phpbb_root_path . $this->config['ranks_path'] . '/' . $rank['rank_image']) : '';
|
||||
$group_rank_data['img_src'] = (!empty($rank['rank_image'])) ? $this->path_helper->update_web_root_path($this->phpbb_root_path . $this->config['ranks_path'] . '/' . $rank['rank_image']) : '';
|
||||
|
||||
$group_rank_data['img'] = (!empty($rank['rank_image'])) ? '<img src="' . $group_rank_data['img_src'] . '" alt="' . $rank['rank_title'] . '" title="' . $rank['rank_title'] . '" />' : '';
|
||||
}
|
||||
@ -269,7 +263,7 @@ class helper
|
||||
'group_data',
|
||||
'group_rank_data',
|
||||
);
|
||||
extract($this->phpbb_dispatcher->trigger_event('core.get_group_rank_after', compact($vars)));
|
||||
extract($this->dispatcher->trigger_event('core.get_group_rank_after', compact($vars)));
|
||||
|
||||
return $group_rank_data;
|
||||
}
|
||||
|
@ -1,123 +1,123 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
class phpbb_group_helper_test_case extends phpbb_test_case
|
||||
{
|
||||
/** @var \phpbb\group\helper */
|
||||
protected $group_helper;
|
||||
|
||||
protected function config_defaults()
|
||||
{
|
||||
$defaults = array(
|
||||
'ranks_path' => 'images/ranks'
|
||||
);
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
protected function get_test_language_data_set()
|
||||
{
|
||||
return array(
|
||||
'G_BOTS' => 'Bots',
|
||||
'G_NEW_GROUP' => 'Some new group',
|
||||
'G_not_uppercase' => 'The key does not contain uppercase letters',
|
||||
'G_GROUP_WITH_ÜMLAUTS' => 'Should work',
|
||||
);
|
||||
}
|
||||
|
||||
protected function get_test_rank_data_set()
|
||||
{
|
||||
return array(
|
||||
'special' => array(
|
||||
1 => array(
|
||||
'rank_id' => 1,
|
||||
'rank_title' => 'Site admin',
|
||||
'rank_special' => 1,
|
||||
'rank_image' => 'siteadmin.png',
|
||||
),
|
||||
2 => array(
|
||||
'rank_id' => 2,
|
||||
'rank_title' => 'Test member',
|
||||
'rank_special' => 1,
|
||||
'rank_image' => '',
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected function setup_engine(array $new_config = array())
|
||||
{
|
||||
global $cache, $phpbb_dispatcher, $phpbb_root_path, $phpEx;
|
||||
|
||||
// Set up authentication data for testing
|
||||
$auth = $this->getMock('\phpbb\auth\auth');
|
||||
$auth->expects($this->any())
|
||||
->method('acl_get')
|
||||
->with($this->stringContains('_'), $this->anything())
|
||||
->will($this->returnValueMap(array(
|
||||
array('u_viewprofile', true),
|
||||
)));
|
||||
|
||||
// Set up cache service
|
||||
$cache_service = $this->getMockBuilder('\phpbb\cache\service')->disableOriginalConstructor()->getMock();
|
||||
$cache_service->expects($this->any())
|
||||
->method('obtain_ranks')
|
||||
->will($this->returnValue($this->get_test_rank_data_set()));
|
||||
|
||||
// Set up configuration
|
||||
$defaults = $this->config_defaults();
|
||||
$config = new \phpbb\config\config(array_merge($defaults, $new_config));
|
||||
|
||||
// Set up language service
|
||||
$lang = new \phpbb\language\language(
|
||||
new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)
|
||||
);
|
||||
|
||||
// Set up language data for testing
|
||||
$reflection_class = new ReflectionClass('\phpbb\language\language');
|
||||
|
||||
// Set default language files loaded flag to true
|
||||
$loaded_flag = $reflection_class->getProperty('common_language_files_loaded');
|
||||
$loaded_flag->setAccessible(true);
|
||||
$loaded_flag->setValue($lang, true);
|
||||
|
||||
// Set up test language data
|
||||
$lang_array = $reflection_class->getProperty('lang');
|
||||
$lang_array->setAccessible(true);
|
||||
$lang_array->setValue($lang, $this->get_test_language_data_set());
|
||||
|
||||
// Set up event dispatcher
|
||||
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
|
||||
|
||||
// Set up path helper
|
||||
$filesystem = new \phpbb\filesystem\filesystem();
|
||||
$path_helper = new \phpbb\path_helper(
|
||||
new \phpbb\symfony_request(
|
||||
new phpbb_mock_request()
|
||||
),
|
||||
$filesystem,
|
||||
$this->getMock('\phpbb\request\request'),
|
||||
$phpbb_root_path,
|
||||
$phpEx
|
||||
);
|
||||
|
||||
$user = new \phpbb\user($lang, '\phpbb\datetime');
|
||||
$user->data['user_id'] = ANONYMOUS;
|
||||
|
||||
$this->group_helper = new \phpbb\group\helper($auth, $cache_service, $config, $lang, $phpbb_dispatcher, $path_helper, $user, $phpbb_root_path, $phpEx);
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->setup_engine();
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
class phpbb_group_helper_test_case extends phpbb_test_case
|
||||
{
|
||||
/** @var \phpbb\group\helper */
|
||||
protected $group_helper;
|
||||
|
||||
protected function config_defaults()
|
||||
{
|
||||
$defaults = array(
|
||||
'ranks_path' => 'images/ranks'
|
||||
);
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
protected function get_test_language_data_set()
|
||||
{
|
||||
return array(
|
||||
'G_BOTS' => 'Bots',
|
||||
'G_NEW_GROUP' => 'Some new group',
|
||||
'G_not_uppercase' => 'The key does not contain uppercase letters',
|
||||
'G_GROUP_WITH_ÜMLAUTS' => 'Should work',
|
||||
);
|
||||
}
|
||||
|
||||
protected function get_test_rank_data_set()
|
||||
{
|
||||
return array(
|
||||
'special' => array(
|
||||
1 => array(
|
||||
'rank_id' => 1,
|
||||
'rank_title' => 'Site admin',
|
||||
'rank_special' => 1,
|
||||
'rank_image' => 'siteadmin.png',
|
||||
),
|
||||
2 => array(
|
||||
'rank_id' => 2,
|
||||
'rank_title' => 'Test member',
|
||||
'rank_special' => 1,
|
||||
'rank_image' => '',
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected function setup_engine(array $new_config = array())
|
||||
{
|
||||
global $phpbb_dispatcher, $phpbb_root_path, $phpEx;
|
||||
|
||||
// Set up authentication data for testing
|
||||
$auth = $this->getMock('\phpbb\auth\auth');
|
||||
$auth->expects($this->any())
|
||||
->method('acl_get')
|
||||
->with($this->stringContains('_'), $this->anything())
|
||||
->will($this->returnValueMap(array(
|
||||
array('u_viewprofile', true),
|
||||
)));
|
||||
|
||||
// Set up cache service
|
||||
$cache_service = $this->getMockBuilder('\phpbb\cache\service')->disableOriginalConstructor()->getMock();
|
||||
$cache_service->expects($this->any())
|
||||
->method('obtain_ranks')
|
||||
->will($this->returnValue($this->get_test_rank_data_set()));
|
||||
|
||||
// Set up configuration
|
||||
$defaults = $this->config_defaults();
|
||||
$config = new \phpbb\config\config(array_merge($defaults, $new_config));
|
||||
|
||||
// Set up language service
|
||||
$lang = new \phpbb\language\language(
|
||||
new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)
|
||||
);
|
||||
|
||||
// Set up language data for testing
|
||||
$reflection_class = new ReflectionClass('\phpbb\language\language');
|
||||
|
||||
// Set default language files loaded flag to true
|
||||
$loaded_flag = $reflection_class->getProperty('common_language_files_loaded');
|
||||
$loaded_flag->setAccessible(true);
|
||||
$loaded_flag->setValue($lang, true);
|
||||
|
||||
// Set up test language data
|
||||
$lang_array = $reflection_class->getProperty('lang');
|
||||
$lang_array->setAccessible(true);
|
||||
$lang_array->setValue($lang, $this->get_test_language_data_set());
|
||||
|
||||
// Set up event dispatcher
|
||||
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
|
||||
|
||||
// Set up path helper
|
||||
$filesystem = new \phpbb\filesystem\filesystem();
|
||||
$path_helper = new \phpbb\path_helper(
|
||||
new \phpbb\symfony_request(
|
||||
new phpbb_mock_request()
|
||||
),
|
||||
$filesystem,
|
||||
$this->getMock('\phpbb\request\request'),
|
||||
$phpbb_root_path,
|
||||
$phpEx
|
||||
);
|
||||
|
||||
$user = new \phpbb\user($lang, '\phpbb\datetime');
|
||||
$user->data['user_id'] = ANONYMOUS;
|
||||
|
||||
$this->group_helper = new \phpbb\group\helper($auth, $cache_service, $config, $lang, $phpbb_dispatcher, $path_helper, $user);
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->setup_engine();
|
||||
}
|
||||
}
|
||||
|
@ -65,9 +65,7 @@ class phpbb_notification_group_request_test extends phpbb_tests_notification_bas
|
||||
$phpbb_root_path,
|
||||
$phpEx
|
||||
),
|
||||
$this->user,
|
||||
$phpbb_root_path,
|
||||
$phpEx
|
||||
$this->user
|
||||
));
|
||||
$phpbb_dispatcher = new phpbb_mock_event_dispatcher;
|
||||
$phpbb_log = new \phpbb\log\dummy();
|
||||
|
Loading…
x
Reference in New Issue
Block a user