aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJoshyPHP <s9e.dev@gmail.com>2018-01-22 03:34:47 +0100
committerJoshyPHP <s9e.dev@gmail.com>2018-01-22 03:34:47 +0100
commit531d9dfa1f0dddfe765a92ca40c77015091ecc5e (patch)
tree071817862fb1559727816d8c18c3fc5eccbe1dab /tests
parentd0143bec8830e709047443f73f79c0dce438e3fc (diff)
downloadforums-531d9dfa1f0dddfe765a92ca40c77015091ecc5e.tar
forums-531d9dfa1f0dddfe765a92ca40c77015091ecc5e.tar.gz
forums-531d9dfa1f0dddfe765a92ca40c77015091ecc5e.tar.bz2
forums-531d9dfa1f0dddfe765a92ca40c77015091ecc5e.tar.xz
forums-531d9dfa1f0dddfe765a92ca40c77015091ecc5e.zip
[ticket/15531] Log malformed BBCodes
PHPBB3-15531
Diffstat (limited to 'tests')
-rw-r--r--tests/test_framework/phpbb_test_case_helpers.php7
-rw-r--r--tests/text_formatter/s9e/factory_test.php18
-rw-r--r--tests/text_formatter/s9e/fixtures/malformed_bbcode.xml28
3 files changed, 51 insertions, 2 deletions
diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php
index 7fb9a740b8..c792976b1e 100644
--- a/tests/test_framework/phpbb_test_case_helpers.php
+++ b/tests/test_framework/phpbb_test_case_helpers.php
@@ -385,7 +385,7 @@ class phpbb_test_case_helpers
$mb = $this->test_case->getMockBuilder('phpbb\\textformatter\\data_access');
$mb->setMethods(array('get_bbcodes', 'get_censored_words', 'get_smilies', 'get_styles'));
$mb->setConstructorArgs(array(
- $this->test_case->getMock('phpbb\\db\\driver\\driver'),
+ $this->test_case->getMockBuilder('phpbb\\db\\driver\\driver')->getMock(),
'phpbb_bbcodes',
'phpbb_smilies',
'phpbb_styles',
@@ -489,8 +489,11 @@ class phpbb_test_case_helpers
$request = new phpbb_mock_request;
}
+ // Get a log interface
+ $log = ($container->has('log')) ? $container->get('log') : $this->test_case->getMockBuilder('phpbb\\log\\log_interface')->getMock();
+
// Create and register the text_formatter.s9e.factory service
- $factory = new \phpbb\textformatter\s9e\factory($dal, $cache, $dispatcher, $config, new \phpbb\textformatter\s9e\link_helper, $cache_dir, $cache_key_parser, $cache_key_renderer);
+ $factory = new \phpbb\textformatter\s9e\factory($dal, $cache, $dispatcher, $config, new \phpbb\textformatter\s9e\link_helper, $log, $cache_dir, $cache_key_parser, $cache_key_renderer);
$container->set('text_formatter.s9e.factory', $factory);
// Create a user if none was provided, and add the common lang strings
diff --git a/tests/text_formatter/s9e/factory_test.php b/tests/text_formatter/s9e/factory_test.php
index d35330a975..0d780a19a9 100644
--- a/tests/text_formatter/s9e/factory_test.php
+++ b/tests/text_formatter/s9e/factory_test.php
@@ -56,6 +56,7 @@ class phpbb_textformatter_s9e_factory_test extends phpbb_database_test_case
$this->dispatcher,
new \phpbb\config\config(array('allowed_schemes_links' => 'http,https,ftp')),
new \phpbb\textformatter\s9e\link_helper,
+ $this->getMockBuilder('phpbb\\log\\log_interface')->getMock(),
$this->get_cache_dir(),
'_foo_parser',
'_foo_renderer'
@@ -264,6 +265,23 @@ class phpbb_textformatter_s9e_factory_test extends phpbb_database_test_case
}
/**
+ * @testdox Logs malformed BBCodes
+ */
+ public function test_malformed_bbcodes()
+ {
+ $log = $this->getMockBuilder('phpbb\\log\\log_interface')->getMock();
+ $log->expects($this->once())
+ ->method('add')
+ ->with('critical', null, null, 'LOG_BBCODE_CONFIGURATION_ERROR', false, ['[x !x]{TEXT}[/x]', 'Cannot interpret the BBCode definition']);
+
+ $container = new phpbb_mock_container_builder;
+ $container->set('log', $log);
+
+ $fixture = __DIR__ . '/fixtures/malformed_bbcode.xml';
+ $this->get_test_case_helpers()->set_s9e_services($container, $fixture);
+ }
+
+ /**
* @testdox get_configurator() triggers events before and after configuration
*/
public function test_configure_events()
diff --git a/tests/text_formatter/s9e/fixtures/malformed_bbcode.xml b/tests/text_formatter/s9e/fixtures/malformed_bbcode.xml
new file mode 100644
index 0000000000..7e7aa1a39c
--- /dev/null
+++ b/tests/text_formatter/s9e/fixtures/malformed_bbcode.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_bbcodes">
+ <column>bbcode_id</column>
+ <column>bbcode_tag</column>
+ <column>bbcode_helpline</column>
+ <column>display_on_posting</column>
+ <column>bbcode_match</column>
+ <column>bbcode_tpl</column>
+ <column>first_pass_match</column>
+ <column>first_pass_replace</column>
+ <column>second_pass_match</column>
+ <column>second_pass_replace</column>
+
+ <row>
+ <value>13</value>
+ <value>x</value>
+ <value></value>
+ <value>1</value>
+ <value>[x !x]{TEXT}[/x]</value>
+ <value>...</value>
+ <value/>
+ <value/>
+ <value/>
+ <value/>
+ </row>
+ </table>
+</dataset>