aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--phpBB/phpbb/textformatter/s9e/parser.php28
-rw-r--r--phpBB/phpbb/textformatter/s9e/renderer.php2
-rw-r--r--tests/text_formatter/s9e/parser_test.php54
3 files changed, 82 insertions, 2 deletions
diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php
index 37900d3d7c..f220dd3e64 100644
--- a/phpBB/phpbb/textformatter/s9e/parser.php
+++ b/phpBB/phpbb/textformatter/s9e/parser.php
@@ -83,7 +83,33 @@ class parser implements \phpbb\textformatter\parser_interface
*/
public function parse($text)
{
- return $this->parser->parse($text);
+ $self = $this;
+
+ /**
+ * Modify a text before it is parsed
+ *
+ * @event core.text_formatter_s9e_parse_before
+ * @var \phpbb\textformatter\s9e\parser self This parser service
+ * @var string text The original text
+ * @since 3.2.0-a1
+ */
+ $vars = array('self', 'text');
+ extract($this->dispatcher->trigger_event('core.text_formatter_s9e_parse_before', compact($vars)));
+
+ $xml = $this->parser->parse($text);
+
+ /**
+ * Modify a parsed text in its XML form
+ *
+ * @event core.text_formatter_s9e_parse_after
+ * @var \phpbb\textformatter\s9e\parser self This parser service
+ * @var string xml The parsed text, in XML
+ * @since 3.2.0-a1
+ */
+ $vars = array('self', 'xml');
+ extract($this->dispatcher->trigger_event('core.text_formatter_s9e_parse_after', compact($vars)));
+
+ return $xml;
}
/**
diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php
index 484b067d47..272cc5e6f3 100644
--- a/phpBB/phpbb/textformatter/s9e/renderer.php
+++ b/phpBB/phpbb/textformatter/s9e/renderer.php
@@ -256,7 +256,7 @@ class renderer implements \phpbb\textformatter\renderer_interface
* Modify a rendered text
*
* @event core.text_formatter_s9e_render_after
- * @var string html The renderer text's HTML
+ * @var string html The rendered text's HTML
* @var \phpbb\textformatter\s9e\renderer self This renderer service
* @since 3.2.0-a1
*/
diff --git a/tests/text_formatter/s9e/parser_test.php b/tests/text_formatter/s9e/parser_test.php
index 03b29bef12..74182bda47 100644
--- a/tests/text_formatter/s9e/parser_test.php
+++ b/tests/text_formatter/s9e/parser_test.php
@@ -206,4 +206,58 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case
&& isset($vars['user'])
&& $vars['user'] instanceof \phpbb\user;
}
+
+ /**
+ * @testdox parse() triggers a core.text_formatter_s9e_parse_before and core.text_formatter_s9e_parse_after events
+ */
+ public function test_parse_event()
+ {
+ $container = $this->get_test_case_helpers()->set_s9e_services();
+ $dispatcher = $this->getMock('phpbb\\event\\dispatcher_interface');
+ $dispatcher
+ ->expects($this->any())
+ ->method('trigger_event')
+ ->will($this->returnArgument(1));
+ $dispatcher
+ ->expects($this->at(1))
+ ->method('trigger_event')
+ ->with(
+ 'core.text_formatter_s9e_parse_before',
+ $this->callback(array($this, 'parse_before_event_callback'))
+ )
+ ->will($this->returnArgument(1));
+ $dispatcher
+ ->expects($this->at(2))
+ ->method('trigger_event')
+ ->with(
+ 'core.text_formatter_s9e_parse_after',
+ $this->callback(array($this, 'parse_after_event_callback'))
+ )
+ ->will($this->returnArgument(1));
+
+ $parser = new \phpbb\textformatter\s9e\parser(
+ $container->get('cache.driver'),
+ '_foo_parser',
+ $container->get('user'),
+ $container->get('text_formatter.s9e.factory'),
+ $dispatcher
+ );
+ $parser->parse('...');
+ }
+
+ public function parse_before_event_callback($vars)
+ {
+ return isset($vars['self'])
+ && $vars['self'] instanceof \phpbb\textformatter\s9e\parser
+ && isset($vars['text'])
+ && $vars['text'] === '...';
+ }
+
+ public function parse_after_event_callback($vars)
+ {
+ return isset($vars['self'])
+ && $vars['self'] instanceof \phpbb\textformatter\s9e\parser
+ && isset($vars['xml'])
+ && $vars['xml'] === '<t>...</t>';
+ }
}