aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoshyPHP <s9e.dev@gmail.com>2015-03-25 01:39:19 +0100
committerJoshyPHP <s9e.dev@gmail.com>2015-04-02 19:16:04 +0200
commita7a53d5a30d4736f8114721c0d7019d64d24cda2 (patch)
treecfdde13f487f2c95e6aea89a39ac465691ac4242
parent2a462bb7e43b848d0277bd27e14ca4d645230eeb (diff)
downloadforums-a7a53d5a30d4736f8114721c0d7019d64d24cda2.tar
forums-a7a53d5a30d4736f8114721c0d7019d64d24cda2.tar.gz
forums-a7a53d5a30d4736f8114721c0d7019d64d24cda2.tar.bz2
forums-a7a53d5a30d4736f8114721c0d7019d64d24cda2.tar.xz
forums-a7a53d5a30d4736f8114721c0d7019d64d24cda2.zip
[ticket/11768] Added core.text_formatter_s9e_parser_setup event
PHPBB3-11768
-rw-r--r--phpBB/phpbb/textformatter/s9e/parser.php33
-rw-r--r--tests/test_framework/phpbb_test_case_helpers.php5
-rw-r--r--tests/text_formatter/s9e/parser_test.php47
3 files changed, 76 insertions, 9 deletions
diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php
index 6fda94d7ba..37900d3d7c 100644
--- a/phpBB/phpbb/textformatter/s9e/parser.php
+++ b/phpBB/phpbb/textformatter/s9e/parser.php
@@ -22,6 +22,11 @@ use s9e\TextFormatter\Parser\Logger;
class parser implements \phpbb\textformatter\parser_interface
{
/**
+ * @var \phpbb\event\dispatcher_interface
+ */
+ protected $dispatcher;
+
+ /**
* @var \s9e\TextFormatter\Parser
*/
protected $parser;
@@ -38,19 +43,39 @@ class parser implements \phpbb\textformatter\parser_interface
* @param string $key Cache key
* @param \phpbb\user $user
* @param factory $factory
+ * @param \phpbb\event\dispatcher_interface $dispatcher
*/
- public function __construct(\phpbb\cache\driver\driver_interface $cache, $key, \phpbb\user $user, factory $factory)
+ public function __construct(\phpbb\cache\driver\driver_interface $cache, $key, \phpbb\user $user, factory $factory, \phpbb\event\dispatcher_interface $dispatcher)
{
- $this->user = $user;
-
$parser = $cache->get($key);
if (!$parser)
{
$objects = $factory->regenerate();
$parser = $objects['parser'];
}
-
+ $self = $this;
+
+ /**
+ * Configure the parser service
+ *
+ * Can be used to:
+ * - toggle features according to the user's preferences,
+ * - toggle BBCodes according to the user's permissions,
+ * - register variables or custom parsers in the s9e\TextFormatter
+ * - configure the s9e\TextFormatter parser
+ *
+ * @event core.text_formatter_s9e_parser_setup
+ * @var \s9e\TextFormatter\Parser parser s9e\TextFormatter parser instance
+ * @var \phpbb\textformatter\s9e\parser self This parser service
+ * @var \phpbb\user user Current user
+ * @since 3.2.0-a1
+ */
+ $vars = array('parser', 'self', 'user');
+ extract($dispatcher->trigger_event('core.text_formatter_s9e_parser_setup', compact($vars)));
+
+ $this->dispatcher = $dispatcher;
$this->parser = $parser;
+ $this->user = $user;
}
/**
diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php
index 5c6da94014..d43138d780 100644
--- a/tests/test_framework/phpbb_test_case_helpers.php
+++ b/tests/test_framework/phpbb_test_case_helpers.php
@@ -425,6 +425,7 @@ class phpbb_test_case_helpers
$prefix = '_s9e_' . md5(serialize(func_get_args()));
$cache_key_parser = $prefix . '_parser';
$cache_key_renderer = $prefix . '_renderer';
+ $container->set('cache.driver', $cache);
// Create a path_helper
if (!$container->has('path_helper'))
@@ -473,6 +474,7 @@ class phpbb_test_case_helpers
$user->optionset('viewflash', true);
$user->optionset('viewimg', true);
$user->optionset('viewsmilies', true);
+ $container->set('user', $user);
}
$user->add_lang('common');
@@ -486,7 +488,8 @@ class phpbb_test_case_helpers
$cache,
$cache_key_parser,
$user,
- $factory
+ $factory,
+ $dispatcher
);
$container->set('text_formatter.parser', $parser);
diff --git a/tests/text_formatter/s9e/parser_test.php b/tests/text_formatter/s9e/parser_test.php
index 71433e209f..03b29bef12 100644
--- a/tests/text_formatter/s9e/parser_test.php
+++ b/tests/text_formatter/s9e/parser_test.php
@@ -36,7 +36,8 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case
$cache,
'_foo_parser',
$this->getMockBuilder('phpbb\\user')->disableOriginalConstructor()->getMock(),
- $factory
+ $factory,
+ new phpbb_mock_event_dispatcher
);
}
@@ -63,7 +64,8 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case
$cache,
'_foo_parser',
$this->getMockBuilder('phpbb\\user')->disableOriginalConstructor()->getMock(),
- $factory
+ $factory,
+ new phpbb_mock_event_dispatcher
);
$this->assertSame('<t>test</t>', $parser->parse('test'));
@@ -91,7 +93,8 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case
new phpbb_mock_cache,
'_foo_parser',
$this->getMockBuilder('phpbb\\user')->disableOriginalConstructor()->getMock(),
- $factory
+ $factory,
+ new phpbb_mock_event_dispatcher
);
$this->assertSame('<t>test</t>', $parser->parse('test'));
@@ -124,7 +127,8 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case
$cache,
'_foo_parser',
$this->getMockBuilder('phpbb\\user')->disableOriginalConstructor()->getMock(),
- $factory
+ $factory,
+ new phpbb_mock_event_dispatcher
);
call_user_func_array(array($parser, $adapter_method), (array) $adapter_arg);
@@ -167,4 +171,39 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case
)
);
}
+
+ /**
+ * @testdox The constructor triggers a core.text_formatter_s9e_parser_setup event
+ */
+ public function test_setup_event()
+ {
+ $container = $this->get_test_case_helpers()->set_s9e_services();
+ $dispatcher = $this->getMock('phpbb\\event\\dispatcher_interface');
+ $dispatcher
+ ->expects($this->once())
+ ->method('trigger_event')
+ ->with(
+ 'core.text_formatter_s9e_parser_setup',
+ $this->callback(array($this, 'setup_event_callback'))
+ )
+ ->will($this->returnArgument(1));
+
+ new \phpbb\textformatter\s9e\parser(
+ $container->get('cache.driver'),
+ '_foo_parser',
+ $container->get('user'),
+ $container->get('text_formatter.s9e.factory'),
+ $dispatcher
+ );
+ }
+
+ public function setup_event_callback($vars)
+ {
+ return isset($vars['parser'])
+ && $vars['parser'] instanceof \s9e\TextFormatter\Parser
+ && isset($vars['self'])
+ && $vars['self'] instanceof \phpbb\textformatter\s9e\parser
+ && isset($vars['user'])
+ && $vars['user'] instanceof \phpbb\user;
+ }
}