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