[ticket/15905] Try it without auth

PHPBB3-15905
This commit is contained in:
mrgoldy 2018-12-10 00:10:27 +01:00 committed by Marc Alexander
parent eee00652e7
commit 133dfd0a84
No known key found for this signature in database
GPG key ID: 50E0D2423696F995
10 changed files with 10 additions and 83 deletions

View file

@ -37,7 +37,6 @@ services:
template.twig.extensions.phpbb: template.twig.extensions.phpbb:
class: phpbb\template\twig\extension class: phpbb\template\twig\extension
arguments: arguments:
- '@auth'
- '@template_context' - '@template_context'
- '@template.twig.environment' - '@template.twig.environment'
- '@language' - '@language'

View file

@ -15,9 +15,6 @@ namespace phpbb\template\twig;
class extension extends \Twig_Extension class extension extends \Twig_Extension
{ {
/** @var \phpbb\auth\auth */
protected $auth;
/** @var \phpbb\template\context */ /** @var \phpbb\template\context */
protected $context; protected $context;
@ -30,14 +27,12 @@ class extension extends \Twig_Extension
/** /**
* Constructor * Constructor
* *
* @param \phpbb\auth\auth $auth
* @param \phpbb\template\context $context * @param \phpbb\template\context $context
* @param \phpbb\template\twig\environment $environment * @param \phpbb\template\twig\environment $environment
* @param \phpbb\language\language $language * @param \phpbb\language\language $language
*/ */
public function __construct(\phpbb\auth\auth $auth, \phpbb\template\context $context, \phpbb\template\twig\environment $environment, $language) public function __construct(\phpbb\template\context $context, \phpbb\template\twig\environment $environment, $language)
{ {
$this->auth = $auth;
$this->context = $context; $this->context = $context;
$this->environment = $environment; $this->environment = $environment;
$this->language = $language; $this->language = $language;
@ -94,10 +89,6 @@ class extension extends \Twig_Extension
{ {
return array( return array(
new \Twig_SimpleFunction('lang', array($this, 'lang')), new \Twig_SimpleFunction('lang', array($this, 'lang')),
new \Twig_SimpleFunction('lang_defined', array($this, 'lang_defined')),
new \Twig_SimpleFunction('get_class', 'get_class'),
new \Twig_SimpleFunction('auth', array($this, 'get_auth')),
new \Twig_SimpleFunction('auth_global', array($this, 'get_auth_global')),
); );
} }
@ -195,52 +186,4 @@ class extension extends \Twig_Extension
return call_user_func_array(array($this->language, 'lang'), $args); return call_user_func_array(array($this->language, 'lang'), $args);
} }
/**
* Check if a language variable exists
*
* @return bool
*/
public function lang_defined($key)
{
return call_user_func_array([$this->language, 'is_set'], [$key]);
}
/**
* Look up permission option(s).
*
* How to use in a template:
* - {{ auth(options, forum_id) }}
*
* The options are required, either as a single string 'a_' or as a twig array ['a_', 'm_'].
* The forum identifier is optional.
*
* @return bool
*/
public function get_auth()
{
$args = func_get_args();
$options = $args[0];
$forum_id = isset($args[1]) ? (int) $args[1] : 0;
return is_array($options) ? $this->auth->acl_gets($options, $forum_id) : $this->auth->acl_get($options, $forum_id);
}
/**
* Look up permission option(s) for any forum
*
* How to use in a template:
* - {{ auth_global(options) }}
*
* The options are required, either as a single string 'a_' or as a twig array ['a_', 'm_'].
*
* @return bool
*/
public function get_auth_global()
{
$args = func_get_args();
return $this->auth->acl_getf_global($args);
}
} }

View file

@ -74,9 +74,7 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case
protected function generate_route_objects() protected function generate_route_objects()
{ {
global $request, $phpbb_root_path, $phpEx; global $request;
$auth = $this->getMock('\phpbb\auth\auth');
$this->request = new phpbb_mock_request(); $this->request = new phpbb_mock_request();
$this->request->overwrite('SCRIPT_NAME', $this->get_uri(), \phpbb\request\request_interface::SERVER); $this->request->overwrite('SCRIPT_NAME', $this->get_uri(), \phpbb\request\request_interface::SERVER);
@ -124,7 +122,7 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case
'autoescape' => false, 'autoescape' => false,
) )
); );
$this->template = new phpbb\template\twig\twig($this->phpbb_path_helper, $this->config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($auth, $context, $twig, $this->user))); $this->template = new phpbb\template\twig\twig($this->phpbb_path_helper, $this->config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $twig, $this->user)));
$twig->setLexer(new \phpbb\template\twig\lexer($twig)); $twig->setLexer(new \phpbb\template\twig\lexer($twig));
$this->extension_manager = new phpbb_mock_extension_manager( $this->extension_manager = new phpbb_mock_extension_manager(

View file

@ -66,9 +66,8 @@ class phpbb_email_parsing_test extends phpbb_test_case
); );
$phpbb_container->set('ext.manager', $extension_manager); $phpbb_container->set('ext.manager', $extension_manager);
$auth = $this->getMock('\phpbb\auth\auth');
$context = new \phpbb\template\context(); $context = new \phpbb\template\context();
$twig_extension = new \phpbb\template\twig\extension($auth, $context, $lang); $twig_extension = new \phpbb\template\twig\extension($context, $lang);
$phpbb_container->set('template.twig.extensions.phpbb', $twig_extension); $phpbb_container->set('template.twig.extensions.phpbb', $twig_extension);
$twig_extensions_collection = new \phpbb\di\service_collection($phpbb_container); $twig_extensions_collection = new \phpbb\di\service_collection($phpbb_container);

View file

@ -36,8 +36,6 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case
{ {
parent::setUp(); parent::setUp();
$auth = $this->getMock('\phpbb\auth\auth');
$this->config = new \phpbb\config\config(array( $this->config = new \phpbb\config\config(array(
'version' => '3.1.0', 'version' => '3.1.0',
)); ));
@ -113,7 +111,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case
$lang = new \phpbb\language\language($lang_loader); $lang = new \phpbb\language\language($lang_loader);
$this->user = new \phpbb\user($lang, '\phpbb\datetime'); $this->user = new \phpbb\user($lang, '\phpbb\datetime');
$this->template = new phpbb\template\twig\twig($phpbb_path_helper, $this->config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($auth, $context, $twig, $this->user))); $this->template = new phpbb\template\twig\twig($phpbb_path_helper, $this->config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $twig, $this->user)));
$twig->setLexer(new \phpbb\template\twig\lexer($twig)); $twig->setLexer(new \phpbb\template\twig\lexer($twig));
} }

View file

@ -26,8 +26,6 @@ class phpbb_template_allfolder_test extends phpbb_template_template_test_case
{ {
global $phpbb_root_path, $phpEx; global $phpbb_root_path, $phpEx;
$auth = $this->getMock('\phpbb\auth\auth');
$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));
$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
@ -77,7 +75,7 @@ class phpbb_template_allfolder_test extends phpbb_template_template_test_case
'autoescape' => false, 'autoescape' => false,
) )
); );
$this->template = new \phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($auth, $context, $twig, $this->user)), $this->extension_manager); $this->template = new \phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $twig, $this->user)), $this->extension_manager);
$twig->setLexer(new \phpbb\template\twig\lexer($twig)); $twig->setLexer(new \phpbb\template\twig\lexer($twig));
$this->template_path = $this->test_path . '/templates'; $this->template_path = $this->test_path . '/templates';

View file

@ -131,8 +131,6 @@ Zeta test event in all',
{ {
global $phpbb_root_path, $phpEx, $user; global $phpbb_root_path, $phpEx, $user;
$auth = $this->getMock('\phpbb\auth\auth');
$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));
@ -171,7 +169,7 @@ Zeta test event in all',
'autoescape' => false, 'autoescape' => false,
) )
); );
$this->template = new \phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($auth, $context, $twig, $this->user)), $this->extension_manager); $this->template = new \phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $twig, $this->user)), $this->extension_manager);
$twig->setLexer(new \phpbb\template\twig\lexer($twig)); $twig->setLexer(new \phpbb\template\twig\lexer($twig));
$this->template->set_custom_style(((!empty($style_names)) ? $style_names : 'silver'), array($this->template_path)); $this->template->set_custom_style(((!empty($style_names)) ? $style_names : 'silver'), array($this->template_path));

View file

@ -25,8 +25,6 @@ class phpbb_template_template_includecss_test extends phpbb_template_template_te
{ {
global $phpbb_root_path, $phpEx, $user; global $phpbb_root_path, $phpEx, $user;
$auth = $this->getMock('\phpbb\auth\auth');
$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));
@ -70,7 +68,7 @@ class phpbb_template_template_includecss_test extends phpbb_template_template_te
$twig, $twig,
$cache_path, $cache_path,
$this->user, $this->user,
array(new \phpbb\template\twig\extension($auth, $context, $twig, $this->user)), array(new \phpbb\template\twig\extension($context, $twig, $this->user)),
new phpbb_mock_extension_manager( new phpbb_mock_extension_manager(
dirname(__FILE__) . '/', dirname(__FILE__) . '/',
array( array(

View file

@ -73,8 +73,6 @@ class phpbb_template_template_test_case extends phpbb_test_case
{ {
global $phpbb_root_path, $phpEx; global $phpbb_root_path, $phpEx;
$auth = $this->getMock('\phpbb\auth\auth');
$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));
$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
@ -115,7 +113,7 @@ class phpbb_template_template_test_case extends phpbb_test_case
'autoescape' => false, 'autoescape' => false,
) )
); );
$this->template = new phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($auth, $context, $twig, $this->user))); $this->template = new phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $twig, $this->user)));
$twig->setLexer(new \phpbb\template\twig\lexer($twig)); $twig->setLexer(new \phpbb\template\twig\lexer($twig));
$this->template->set_custom_style('tests', $this->template_path); $this->template->set_custom_style('tests', $this->template_path);
} }

View file

@ -19,8 +19,6 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat
{ {
global $phpbb_root_path, $phpEx, $user; global $phpbb_root_path, $phpEx, $user;
$auth = $this->getMock('\phpbb\auth\auth');
$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));
@ -58,7 +56,7 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat
'autoescape' => false, 'autoescape' => false,
) )
); );
$this->template = new phpbb\template\twig\twig($this->phpbb_path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($auth, $context, $twig, $this->user))); $this->template = new phpbb\template\twig\twig($this->phpbb_path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $twig, $this->user)));
$twig->setLexer(new \phpbb\template\twig\lexer($twig)); $twig->setLexer(new \phpbb\template\twig\lexer($twig));
$this->template->set_custom_style('tests', array($this->template_path, $this->parent_template_path)); $this->template->set_custom_style('tests', array($this->template_path, $this->parent_template_path));
} }