aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors9e <s9e.dev@gmail.com>2014-11-22 20:00:58 +0100
committerJoshyPHP <s9e.dev@gmail.com>2015-04-02 19:16:01 +0200
commit147a713cc066d493b50b82a9d475aa9af940e2b4 (patch)
tree602a17f1928dc4a7c94a4d8fb6349cd702422d2b
parenteb7e6d7c23db65530a46dd62432039c19792d564 (diff)
downloadforums-147a713cc066d493b50b82a9d475aa9af940e2b4.tar
forums-147a713cc066d493b50b82a9d475aa9af940e2b4.tar.gz
forums-147a713cc066d493b50b82a9d475aa9af940e2b4.tar.bz2
forums-147a713cc066d493b50b82a9d475aa9af940e2b4.tar.xz
forums-147a713cc066d493b50b82a9d475aa9af940e2b4.zip
[ticket/11768] This commit integrates s9e\TextFormatter
This commit integrates s9e\TextFormatter as outlined in http://area51.phpbb.com/phpBB/viewtopic.php?f=108&t=44467 PHPBB3-11768
-rw-r--r--phpBB/composer.lock108
-rw-r--r--phpBB/config/default/container/services.yml2
-rw-r--r--phpBB/config/default/container/services_text_formatter.yml58
-rw-r--r--phpBB/config/default/container/tables.yml4
-rw-r--r--phpBB/includes/acp/acp_bbcodes.php2
-rw-r--r--phpBB/includes/acp/acp_icons.php6
-rw-r--r--phpBB/includes/acp/acp_main.php5
-rw-r--r--phpBB/includes/acp/acp_words.php2
-rw-r--r--phpBB/includes/functions_content.php121
-rw-r--r--phpBB/includes/message_parser.php129
-rw-r--r--phpBB/phpbb/textformatter/cache.php37
-rw-r--r--phpBB/phpbb/textformatter/data_access.php233
-rw-r--r--phpBB/phpbb/textformatter/parser.php121
-rw-r--r--phpBB/phpbb/textformatter/renderer.php136
-rw-r--r--phpBB/phpbb/textformatter/s9e/factory.php493
-rw-r--r--phpBB/phpbb/textformatter/s9e/parser.php335
-rw-r--r--phpBB/phpbb/textformatter/s9e/renderer.php228
-rw-r--r--phpBB/phpbb/textformatter/s9e/utils.php67
-rw-r--r--phpBB/phpbb/textformatter/utils.php62
-rw-r--r--tests/notification/group_request_test.php1
-rw-r--r--tests/test_framework/phpbb_test_case_helpers.php210
-rw-r--r--tests/text_formatter/s9e/default_formatting_test.php200
-rw-r--r--tests/text_formatter/s9e/factory_test.php182
-rw-r--r--tests/text_formatter/s9e/fixtures/default_formatting.xml466
-rw-r--r--tests/text_formatter/s9e/fixtures/default_lang.xml20
-rw-r--r--tests/text_formatter/s9e/fixtures/factory.xml115
-rw-r--r--tests/text_formatter/s9e/fixtures/inttext_token.xml27
-rw-r--r--tests/text_formatter/s9e/fixtures/local_url.xml28
-rw-r--r--tests/text_formatter/s9e/fixtures/smilies_special_chars.xml23
-rw-r--r--tests/text_formatter/s9e/fixtures/style_inheritance.xml66
-rw-r--r--tests/text_formatter/s9e/fixtures/styles.xml36
-rw-r--r--tests/text_formatter/s9e/fixtures/styles/bar/template/bbcode.html40
-rw-r--r--tests/text_formatter/s9e/fixtures/styles/barplus/template/bbcode.html40
-rw-r--r--tests/text_formatter/s9e/fixtures/styles/foo/template/bbcode.html40
-rw-r--r--tests/text_formatter/s9e/parser_test.php162
-rw-r--r--tests/text_formatter/s9e/renderer_test.php355
-rw-r--r--tests/text_formatter/s9e/utils_test.php157
-rw-r--r--tests/text_processing/decode_message_test.php87
-rw-r--r--tests/text_processing/fixtures/empty.xml3
-rw-r--r--tests/text_processing/fixtures/smilies.xml443
-rw-r--r--tests/text_processing/generate_text_for_display_test.php172
-rw-r--r--tests/text_processing/generate_text_for_edit_test.php90
-rw-r--r--tests/text_processing/generate_text_for_storage_test.php70
-rw-r--r--tests/text_processing/message_parser_test.php532
-rw-r--r--tests/text_processing/smilies_test.php48
-rw-r--r--tests/text_processing/strip_bbcode_test.php38
-rw-r--r--tests/text_processing/tickets_data/PHPBB3-10002.html2
-rw-r--r--tests/text_processing/tickets_data/PHPBB3-10002.txt2
-rw-r--r--tests/text_processing/tickets_data/PHPBB3-10425.html3
-rw-r--r--tests/text_processing/tickets_data/PHPBB3-10425.txt3
-rw-r--r--tests/text_processing/tickets_data/PHPBB3-10587.html2
-rw-r--r--tests/text_processing/tickets_data/PHPBB3-10587.txt2
-rw-r--r--tests/text_processing/tickets_data/PHPBB3-10922.html1
-rw-r--r--tests/text_processing/tickets_data/PHPBB3-10922.txt1
-rw-r--r--tests/text_processing/tickets_data/PHPBB3-10989.html8
-rw-r--r--tests/text_processing/tickets_data/PHPBB3-10989.txt8
-rw-r--r--tests/text_processing/tickets_data/PHPBB3-11153.html1
-rw-r--r--tests/text_processing/tickets_data/PHPBB3-11153.txt1
-rw-r--r--tests/text_processing/tickets_data/PHPBB3-11153.xml28
-rw-r--r--tests/text_processing/tickets_data/PHPBB3-12195.html1
-rw-r--r--tests/text_processing/tickets_data/PHPBB3-12195.txt1
-rw-r--r--tests/text_processing/tickets_data/PHPBB3-3981.before.php17
-rw-r--r--tests/text_processing/tickets_data/PHPBB3-3981.html1
-rw-r--r--tests/text_processing/tickets_data/PHPBB3-3981.txt1
-rw-r--r--tests/text_processing/tickets_data/PHPBB3-7187.html1
-rw-r--r--tests/text_processing/tickets_data/PHPBB3-7187.txt1
-rw-r--r--tests/text_processing/tickets_data/PHPBB3-7187.xml33
-rw-r--r--tests/text_processing/tickets_data/PHPBB3-7275.after.php15
-rw-r--r--tests/text_processing/tickets_data/PHPBB3-7275.html1
-rw-r--r--tests/text_processing/tickets_data/PHPBB3-7275.txt1
-rw-r--r--tests/text_processing/tickets_data/PHPBB3-7275.xml49
-rw-r--r--tests/text_processing/tickets_data/PHPBB3-9377.html1
-rw-r--r--tests/text_processing/tickets_data/PHPBB3-9377.txt1
-rw-r--r--tests/text_processing/tickets_data/PHPBB3-9377.xml41
-rw-r--r--tests/text_processing/tickets_test.php91
75 files changed, 5962 insertions, 156 deletions
diff --git a/phpBB/composer.lock b/phpBB/composer.lock
index b6957aa667..e6dd12e8f0 100644
--- a/phpBB/composer.lock
+++ b/phpBB/composer.lock
@@ -145,7 +145,7 @@
"Psr\\Log\\": ""
}
},
- "notification-url": "https://packagist.org/downloads/",
+ "notification-url": "http://packagist.org/downloads/",
"license": [
"MIT"
],
@@ -164,6 +164,63 @@
"time": "2012-12-21 11:40:51"
},
{
+ "name": "s9e/text-formatter",
+ "version": "dev-release/php5.3",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/s9e/TextFormatter.git",
+ "reference": "872ed9d9204986668afc0b3e633be99e397e201b"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/s9e/TextFormatter/zipball/872ed9d9204986668afc0b3e633be99e397e201b",
+ "reference": "872ed9d9204986668afc0b3e633be99e397e201b",
+ "shasum": ""
+ },
+ "require": {
+ "ext-dom": "*",
+ "ext-filter": "*",
+ "php": ">=5.3.3"
+ },
+ "suggest": {
+ "ext-intl": "Allows international URLs to be accepted by the URL filter",
+ "ext-json": "Enables the generation of a JavaScript parser",
+ "ext-mbstring": "Enables some optimizations in the PHP renderer",
+ "ext-tokenizer": "Enables optimizations in the PHP renderer",
+ "ext-xsl": "Enables the XSLT renderer",
+ "ext-zlib": "Enables gzip compression when scraping content via the MediaEmbed plugin"
+ },
+ "type": "library",
+ "autoload": {
+ "psr-4": {
+ "s9e\\TextFormatter\\": "src"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "description": "Multi-purpose text formatting and markup library. Plugins offer support for BBCodes, Markdown, emoticons, HTML, embedding media (YouTube, etc...), enhanced typography and more.",
+ "keywords": [
+ "bbcode",
+ "bbcodes",
+ "blog",
+ "censor",
+ "embed",
+ "emoji",
+ "emoticons",
+ "engine",
+ "forum",
+ "html",
+ "markdown",
+ "markup",
+ "media",
+ "parser",
+ "shortcodes"
+ ],
+ "time": "2014-11-22 14:23:43"
+ },
+ {
"name": "symfony/config",
"version": "2.7.x-dev",
"target-dir": "Symfony/Component/Config",
@@ -960,16 +1017,14 @@
"Twig_": "lib/"
}
},
- "notification-url": "https://packagist.org/downloads/",
+ "notification-url": "http://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Fabien Potencier",
- "email": "fabien@symfony.com",
- "homepage": "http://fabien.potencier.org",
- "role": "Lead Developer"
+ "email": "fabien@symfony.com"
},
{
"name": "Armin Ronacher",
@@ -993,21 +1048,21 @@
"packages-dev": [
{
"name": "fabpot/goutte",
- "version": "v1.0.7",
+ "version": "v1.0.3",
"source": {
"type": "git",
- "url": "https://github.com/FriendsOfPHP/Goutte.git",
- "reference": "794b196e76bdd37b5155cdecbad311f0a3b07625"
+ "url": "https://github.com/fabpot/Goutte.git",
+ "reference": "75c9f23c4122caf4ea3e87a42a00b471366e707f"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/FriendsOfPHP/Goutte/zipball/794b196e76bdd37b5155cdecbad311f0a3b07625",
- "reference": "794b196e76bdd37b5155cdecbad311f0a3b07625",
+ "url": "https://api.github.com/repos/fabpot/Goutte/zipball/75c9f23c4122caf4ea3e87a42a00b471366e707f",
+ "reference": "75c9f23c4122caf4ea3e87a42a00b471366e707f",
"shasum": ""
},
"require": {
"ext-curl": "*",
- "guzzle/http": "~3.1",
+ "guzzle/http": ">=3.0.5,<3.8-dev",
"php": ">=5.3.0",
"symfony/browser-kit": "~2.1",
"symfony/css-selector": "~2.1",
@@ -1016,8 +1071,8 @@
"symfony/process": "~2.1"
},
"require-dev": {
- "guzzle/plugin-history": "~3.1",
- "guzzle/plugin-mock": "~3.1"
+ "guzzle/plugin-history": ">=3.0.5,<3.8-dev",
+ "guzzle/plugin-mock": ">=3.0.5,<3.8-dev"
},
"type": "application",
"extra": {
@@ -1037,7 +1092,9 @@
"authors": [
{
"name": "Fabien Potencier",
- "email": "fabien@symfony.com"
+ "email": "fabien@symfony.com",
+ "homepage": "http://fabien.potencier.org",
+ "role": "Lead Developer"
}
],
"description": "A simple PHP Web Scraper",
@@ -1045,7 +1102,7 @@
"keywords": [
"scraper"
],
- "time": "2014-10-09 15:52:51"
+ "time": "2013-08-16 06:03:22"
},
{
"name": "guzzle/common",
@@ -1376,8 +1433,7 @@
"authors": [
{
"name": "Michiel Rook",
- "email": "mrook@php.net",
- "role": "Lead"
+ "email": "mrook@php.net"
},
{
"name": "Phing Community",
@@ -1881,16 +1937,16 @@
},
{
"name": "sami/sami",
- "version": "v1.4",
+ "version": "v1.3",
"source": {
"type": "git",
- "url": "https://github.com/FriendsOfPHP/Sami.git",
- "reference": "70f29c781f7bef30181c814b9471b2ceac694454"
+ "url": "https://github.com/fabpot/Sami.git",
+ "reference": "76f2ed80b3420f7e2f6dcd5b7218b5a5781f4110"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/FriendsOfPHP/Sami/zipball/70f29c781f7bef30181c814b9471b2ceac694454",
- "reference": "70f29c781f7bef30181c814b9471b2ceac694454",
+ "url": "https://api.github.com/repos/fabpot/Sami/zipball/76f2ed80b3420f7e2f6dcd5b7218b5a5781f4110",
+ "reference": "76f2ed80b3420f7e2f6dcd5b7218b5a5781f4110",
"shasum": ""
},
"require": {
@@ -1911,7 +1967,7 @@
"type": "application",
"extra": {
"branch-alias": {
- "dev-master": "1.4-dev"
+ "dev-master": "1.3-dev"
}
},
"autoload": {
@@ -1926,7 +1982,9 @@
"authors": [
{
"name": "Fabien Potencier",
- "email": "fabien@symfony.com"
+ "email": "fabien@symfony.com",
+ "homepage": "http://fabien.potencier.org",
+ "role": "Lead Developer"
}
],
"description": "Sami, an API documentation generator",
@@ -1934,7 +1992,7 @@
"keywords": [
"phpdoc"
],
- "time": "2014-06-25 11:24:03"
+ "time": "2013-11-30 17:16:25"
},
{
"name": "sebastian/comparator",
diff --git a/phpBB/config/default/container/services.yml b/phpBB/config/default/container/services.yml
index 36f22d72d6..2b4aa52571 100644
--- a/phpBB/config/default/container/services.yml
+++ b/phpBB/config/default/container/services.yml
@@ -13,9 +13,9 @@ imports:
- { resource: services_notification.yml }
- { resource: services_password.yml }
- { resource: services_profilefield.yml }
+ - { resource: services_text_formatter.yml }
- { resource: services_twig.yml }
- { resource: services_user.yml }
-
- { resource: tables.yml }
- { resource: parameters.yml }
diff --git a/phpBB/config/default/container/services_text_formatter.yml b/phpBB/config/default/container/services_text_formatter.yml
new file mode 100644
index 0000000000..7d21e4498e
--- /dev/null
+++ b/phpBB/config/default/container/services_text_formatter.yml
@@ -0,0 +1,58 @@
+parameters:
+ text_formatter.cache.dir: %core.root_path%cache/
+ text_formatter.cache.parser.key: _text_formatter_parser
+ text_formatter.cache.renderer.key: _text_formatter_renderer
+
+services:
+ text_formatter.cache:
+ alias: text_formatter.s9e.factory
+
+ text_formatter.data_access:
+ class: phpbb\textformatter\data_access
+ arguments:
+ - @dbal.conn
+ - %tables.bbcodes%
+ - %tables.smilies%
+ - %tables.styles%
+ - %tables.words%
+ - %core.root_path%styles/
+
+ text_formatter.parser:
+ alias: text_formatter.s9e.parser
+
+ text_formatter.renderer:
+ alias: text_formatter.s9e.renderer
+
+ text_formatter.utils:
+ alias: text_formatter.s9e.utils
+
+ text_formatter.s9e.factory:
+ class: phpbb\textformatter\s9e\factory
+ arguments:
+ - @text_formatter.data_access
+ - @cache.driver
+ - %text_formatter.cache.dir%
+ - %text_formatter.cache.parser.key%
+ - %text_formatter.cache.renderer.key%
+
+ text_formatter.s9e.parser:
+ class: phpbb\textformatter\s9e\parser
+ arguments:
+ - @cache.driver
+ - %text_formatter.cache.parser.key%
+ - @user
+ - @service_container
+
+ text_formatter.s9e.renderer:
+ class: phpbb\textformatter\s9e\renderer
+ arguments:
+ - @cache.driver
+ - %text_formatter.cache.dir%
+ - %text_formatter.cache.renderer.key%
+ - @service_container
+ calls:
+ - [configure_smilies_path, [@config, @path_helper]]
+ - [configure_user, [@user, @config, @auth]]
+
+ text_formatter.s9e.utils:
+ class: phpbb\textformatter\s9e\utils
diff --git a/phpBB/config/default/container/tables.yml b/phpBB/config/default/container/tables.yml
index 2fe2a33be8..00067d5abe 100644
--- a/phpBB/config/default/container/tables.yml
+++ b/phpBB/config/default/container/tables.yml
@@ -1,6 +1,7 @@
parameters:
tables.auth_provider_oauth_token_storage: %core.table_prefix%oauth_tokens
tables.auth_provider_oauth_account_assoc: %core.table_prefix%oauth_accounts
+ tables.bbcodes: %core.table_prefix%bbcodes
tables.captcha_qa_questions: %core.table_prefix%captcha_questions
tables.captcha_qa_answers: %core.table_prefix%captcha_answers
tables.captcha_qa_confirm: %core.table_prefix%qa_confirm
@@ -18,6 +19,9 @@ parameters:
tables.profile_fields_options_language: %core.table_prefix%profile_fields_lang
tables.profile_fields_language: %core.table_prefix%profile_lang
tables.posts: %core.table_prefix%posts
+ tables.smilies: %core.table_prefix%smilies
+ tables.styles: %core.table_prefix%styles
tables.topics: %core.table_prefix%topics
tables.user_notifications: %core.table_prefix%user_notifications
tables.users: %core.table_prefix%users
+ tables.words: %core.table_prefix%words
diff --git a/phpBB/includes/acp/acp_bbcodes.php b/phpBB/includes/acp/acp_bbcodes.php
index a5cd48c444..327af0e0bc 100644
--- a/phpBB/includes/acp/acp_bbcodes.php
+++ b/phpBB/includes/acp/acp_bbcodes.php
@@ -269,6 +269,7 @@ class acp_bbcodes
$db->sql_query('INSERT INTO ' . BBCODES_TABLE . $db->sql_build_array('INSERT', $sql_ary));
$cache->destroy('sql', BBCODES_TABLE);
+ $phpbb_container->get('text_formatter.cache')->invalidate();
$lang = 'BBCODE_ADDED';
$log_action = 'LOG_BBCODE_ADD';
@@ -280,6 +281,7 @@ class acp_bbcodes
WHERE bbcode_id = ' . $bbcode_id;
$db->sql_query($sql);
$cache->destroy('sql', BBCODES_TABLE);
+ $phpbb_container->get('text_formatter.cache')->invalidate();
$lang = 'BBCODE_EDITED';
$log_action = 'LOG_BBCODE_EDIT';
diff --git a/phpBB/includes/acp/acp_icons.php b/phpBB/includes/acp/acp_icons.php
index fdf366097a..5d1756de45 100644
--- a/phpBB/includes/acp/acp_icons.php
+++ b/phpBB/includes/acp/acp_icons.php
@@ -28,7 +28,7 @@ class acp_icons
function main($id, $mode)
{
- global $db, $user, $auth, $template, $cache;
+ global $db, $user, $auth, $template, $cache, $phpbb_container;
global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
global $request, $phpbb_container;
@@ -486,6 +486,7 @@ class acp_icons
$cache->destroy('_icons');
$cache->destroy('sql', $table);
+ $phpbb_container->get('text_formatter.cache')->invalidate();
$level = ($icons_updated) ? E_USER_NOTICE : E_USER_WARNING;
$errormsgs = '';
@@ -661,6 +662,7 @@ class acp_icons
$cache->destroy('_icons');
$cache->destroy('sql', $table);
+ $phpbb_container->get('text_formatter.cache')->invalidate();
trigger_error($user->lang[$lang . '_IMPORT_SUCCESS'] . adm_back_link($this->u_action));
}
@@ -783,6 +785,7 @@ class acp_icons
$cache->destroy('_icons');
$cache->destroy('sql', $table);
+ $phpbb_container->get('text_formatter.cache')->invalidate();
if ($request->is_ajax())
{
@@ -848,6 +851,7 @@ class acp_icons
$cache->destroy('_icons');
$cache->destroy('sql', $table);
+ $phpbb_container->get('text_formatter.cache')->invalidate();
if ($request->is_ajax())
{
diff --git a/phpBB/includes/acp/acp_main.php b/phpBB/includes/acp/acp_main.php
index c49ccdf479..9a99666c75 100644
--- a/phpBB/includes/acp/acp_main.php
+++ b/phpBB/includes/acp/acp_main.php
@@ -352,6 +352,11 @@ class acp_main
$config->increment('assets_version', 1);
$cache->purge();
+ // Remove old renderers from the text_formatter service. Since this
+ // operation is performed after the cache is purged, there is not "current"
+ // renderer and in effect all renderers will be purged
+ $phpbb_container->get('text_formatter.cache')->tidy();
+
// Clear permissions
$auth->acl_clear_prefetch();
phpbb_cache_moderators($db, $cache, $auth);
diff --git a/phpBB/includes/acp/acp_words.php b/phpBB/includes/acp/acp_words.php
index d28aa8e60b..1ba247be4d 100644
--- a/phpBB/includes/acp/acp_words.php
+++ b/phpBB/includes/acp/acp_words.php
@@ -115,6 +115,7 @@ class acp_words
}
$cache->destroy('_word_censors');
+ $phpbb_container->get('text_formatter.cache')->invalidate();
$log_action = ($word_id) ? 'LOG_WORD_EDIT' : 'LOG_WORD_ADD';
@@ -148,6 +149,7 @@ class acp_words
$db->sql_query($sql);
$cache->destroy('_word_censors');
+ $phpbb_container->get('text_formatter.cache')->invalidate();
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_WORD_DELETE', false, array($deleted_word));
diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php
index bdbc8a92fa..60511d89a4 100644
--- a/phpBB/includes/functions_content.php
+++ b/phpBB/includes/functions_content.php
@@ -389,46 +389,68 @@ function phpbb_clean_search_string($search_string)
/**
* Decode text whereby text is coming from the db and expected to be pre-parsed content
* We are placing this outside of the message parser because we are often in need of it...
+*
+* NOTE: special chars are kept encoded
+*
+* @param string &$message Original message, passed by reference
+* @param string $bbcode_uid BBCode UID
+* @return null
*/
function decode_message(&$message, $bbcode_uid = '')
{
- global $config;
+ global $phpbb_container;
- if ($bbcode_uid)
+ if (preg_match('#^<[rt][ >]#', $message))
{
- $match = array('<br />', "[/*:m:$bbcode_uid]", ":u:$bbcode_uid", ":o:$bbcode_uid", ":$bbcode_uid");
- $replace = array("\n", '', '', '', '');
+ $message = htmlspecialchars($phpbb_container->get('text_formatter.utils')->unparse($message), ENT_COMPAT);
}
else
{
- $match = array('<br />');
- $replace = array("\n");
- }
+ if ($bbcode_uid)
+ {
+ $match = array('<br />', "[/*:m:$bbcode_uid]", ":u:$bbcode_uid", ":o:$bbcode_uid", ":$bbcode_uid");
+ $replace = array("\n", '', '', '', '');
+ }
+ else
+ {
+ $match = array('<br />');
+ $replace = array("\n");
+ }
- $message = str_replace($match, $replace, $message);
+ $message = str_replace($match, $replace, $message);
- $match = get_preg_expression('bbcode_htm');
- $replace = array('\1', '\1', '\2', '\1', '', '');
+ $match = get_preg_expression('bbcode_htm');
+ $replace = array('\1', '\1', '\2', '\1', '', '');
- $message = preg_replace($match, $replace, $message);
+ $message = preg_replace($match, $replace, $message);
+ }
}
/**
-* Strips all bbcode from a text and returns the plain content
+* Strips all bbcode from a text in place
*/
function strip_bbcode(&$text, $uid = '')
{
- if (!$uid)
+ global $phpbb_container;
+
+ if (preg_match('#^<[rt][ >]#', $text))
{
- $uid = '[0-9a-z]{5,}';
+ $text = $phpbb_container->get('text_formatter.utils')->clean_formatting($text);
}
+ else
+ {
+ if (!$uid)
+ {
+ $uid = '[0-9a-z]{5,}';
+ }
- $text = preg_replace("#\[\/?[a-z0-9\*\+\-]+(?:=(?:&quot;.*&quot;|[^\]]*))?(?::[a-z])?(\:$uid)\]#", ' ', $text);
+ $text = preg_replace("#\[\/?[a-z0-9\*\+\-]+(?:=(?:&quot;.*&quot;|[^\]]*))?(?::[a-z])?(\:$uid)\]#", ' ', $text);
- $match = get_preg_expression('bbcode_htm');
- $replace = array('\1', '\1', '\2', '\1', '', '');
+ $match = get_preg_expression('bbcode_htm');
+ $replace = array('\1', '\1', '\2', '\1', '', '');
- $text = preg_replace($match, $replace, $text);
+ $text = preg_replace($match, $replace, $text);
+ }
}
/**
@@ -438,7 +460,7 @@ function strip_bbcode(&$text, $uid = '')
function generate_text_for_display($text, $uid, $bitfield, $flags, $censor_text = true)
{
static $bbcode;
- global $phpbb_dispatcher;
+ global $phpbb_dispatcher, $phpbb_container;
if ($text === '')
{
@@ -459,34 +481,56 @@ function generate_text_for_display($text, $uid, $bitfield, $flags, $censor_text
$vars = array('text', 'uid', 'bitfield', 'flags', 'censor_text');
extract($phpbb_dispatcher->trigger_event('core.modify_text_for_display_before', compact($vars)));
- if ($censor_text)
+ if (preg_match('#^<[rt][ >]#', $text))
{
- $text = censor_text($text);
- }
+ $renderer = $phpbb_container->get('text_formatter.renderer');
- // Parse bbcode if bbcode uid stored and bbcode enabled
- if ($uid && ($flags & OPTION_FLAG_BBCODE))
- {
- if (!class_exists('bbcode'))
+ // Temporarily switch off viewcensors if applicable
+ $old_censor = $renderer->get_viewcensors();
+ if ($old_censor !== $censor_text)
{
- global $phpbb_root_path, $phpEx;
- include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
+ $renderer->set_viewcensors($censor_text);
}
- if (empty($bbcode))
+ $text = $renderer->render($text);
+
+ // Restore the previous value
+ if ($old_censor !== $censor_text)
{
- $bbcode = new bbcode($bitfield);
+ $renderer->set_viewcensors($old_censor);
}
- else
+ }
+ else
+ {
+ if ($censor_text)
{
- $bbcode->bbcode($bitfield);
+ $text = censor_text($text);
}
- $bbcode->bbcode_second_pass($text, $uid);
- }
+ // Parse bbcode if bbcode uid stored and bbcode enabled
+ if ($uid && ($flags & OPTION_FLAG_BBCODE))
+ {
+ if (!class_exists('bbcode'))
+ {
+ global $phpbb_root_path, $phpEx;
+ include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
+ }
+
+ if (empty($bbcode))
+ {
+ $bbcode = new bbcode($bitfield);
+ }
+ else
+ {
+ $bbcode->bbcode($bitfield);
+ }
- $text = bbcode_nl2br($text);
- $text = smiley_text($text, !($flags & OPTION_FLAG_SMILIES));
+ $bbcode->bbcode_second_pass($text, $uid);
+ }
+
+ $text = bbcode_nl2br($text);
+ $text = smiley_text($text, !($flags & OPTION_FLAG_SMILIES));
+ }
/**
* Use this event to modify the text after it is parsed
@@ -550,11 +594,6 @@ function generate_text_for_storage(&$text, &$uid, &$bitfield, &$flags, $allow_bb
$uid = $bitfield = '';
$flags = (($allow_bbcode) ? OPTION_FLAG_BBCODE : 0) + (($allow_smilies) ? OPTION_FLAG_SMILIES : 0) + (($allow_urls) ? OPTION_FLAG_LINKS : 0);
- if ($text === '')
- {
- return;
- }
-
if (!class_exists('parse_message'))
{
include($phpbb_root_path . 'includes/message_parser.' . $phpEx);
diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php
index ccb953adbe..e4c35f8bca 100644
--- a/phpBB/includes/message_parser.php
+++ b/phpBB/includes/message_parser.php
@@ -1094,7 +1094,7 @@ class parse_message extends bbcode_firstpass
function parse_message($message = '')
{
// Init BBCode UID
- $this->bbcode_uid = substr(base_convert(unique_id(), 16, 36), 0, BBCODE_UID_LEN);
+ $this->bbcode_uid = '';
$this->message = $message;
}
@@ -1103,7 +1103,7 @@ class parse_message extends bbcode_firstpass
*/
function parse($allow_bbcode, $allow_magic_url, $allow_smilies, $allow_img_bbcode = true, $allow_flash_bbcode = true, $allow_quote_bbcode = true, $allow_url_bbcode = true, $update_this_message = true, $mode = 'post')
{
- global $config, $db, $user, $phpbb_dispatcher;
+ global $config, $db, $user, $phpbb_dispatcher, $phpbb_container;
$this->mode = $mode;
@@ -1132,12 +1132,6 @@ class parse_message extends bbcode_firstpass
$this->decode_message();
}
- // Do some general 'cleanup' first before processing message,
- // e.g. remove excessive newlines(?), smilies(?)
- $match = array('#(script|about|applet|activex|chrome):#i');
- $replace = array("\\1&#058;");
- $this->message = preg_replace($match, $replace, trim($this->message));
-
// Store message length...
$message_length = ($mode == 'post') ? utf8_strlen($this->message) : utf8_strlen(preg_replace('#\[\/?[a-z\*\+\-]+(=[\S]+)?\]#ius', ' ', $this->message));
@@ -1210,47 +1204,29 @@ class parse_message extends bbcode_firstpass
return (!$update_this_message) ? $return_message : $this->warn_msg;
}
- // Prepare BBcode (just prepares some tags for better parsing)
- if ($allow_bbcode && strpos($this->message, '[') !== false)
- {
- $this->bbcode_init();
- $disallow = array('img', 'flash', 'quote', 'url');
- foreach ($disallow as $bool)
- {
- if (!${'allow_' . $bool . '_bbcode'})
- {
- $this->bbcodes[$bool]['disabled'] = true;
- }
- }
-
- $this->prepare_bbcodes();
- }
-
- // Parse smilies
- if ($allow_smilies)
- {
- $this->smilies($config['max_' . $mode . '_smilies']);
- }
-
- $num_urls = 0;
+ // Get the parser
+ $parser = $phpbb_container->get('text_formatter.parser');
- // Parse BBCode
- if ($allow_bbcode && strpos($this->message, '[') !== false)
- {
- $this->parse_bbcode();
- $num_urls += $this->parsed_items['url'];
- }
+ // Set the parser's options
+ ($allow_bbcode) ? $parser->enable_bbcodes() : $parser->disable_bbcodes();
+ ($allow_magic_url) ? $parser->enable_magic_url() : $parser->disable_magic_url();
+ ($allow_smilies) ? $parser->enable_smilies() : $parser->disable_smilies();
+ ($allow_img_bbcode) ? $parser->enable_bbcode('img') : $parser->disable_bbcode('img');
+ ($allow_flash_bbcode) ? $parser->enable_bbcode('flash') : $parser->disable_bbcode('flash');
+ ($allow_quote_bbcode) ? $parser->enable_bbcode('quote') : $parser->disable_bbcode('quote');
+ ($allow_url_bbcode) ? $parser->enable_bbcode('url') : $parser->disable_bbcode('url');
- // Parse URL's
- if ($allow_magic_url)
- {
- $this->magic_url(generate_board_url());
+ // Set some config values
+ $parser->set_vars(array(
+ 'max_font_size' => $config['max_' . $this->mode . '_font_size'],
+ 'max_img_height' => $config['max_' . $this->mode . '_img_height'],
+ 'max_img_width' => $config['max_' . $this->mode . '_img_width'],
+ 'max_smilies' => $config['max_' . $this->mode . '_smilies'],
+ 'max_urls' => $config['max_' . $this->mode . '_urls']
+ ));
- if ($config['max_' . $mode . '_urls'])
- {
- $num_urls += preg_match_all('#\<!-- ([lmwe]) --\>.*?\<!-- \1 --\>#', $this->message, $matches);
- }
- }
+ // Parse this message
+ $this->message = $parser->parse(htmlspecialchars_decode($this->message, ENT_QUOTES));
// Check for out-of-bounds characters that are currently
// not supported by utf8_bin in MySQL
@@ -1269,10 +1245,12 @@ class parse_message extends bbcode_firstpass
return (!$update_this_message) ? $return_message : $this->warn_msg;
}
- // Check number of links
- if ($config['max_' . $mode . '_urls'] && $num_urls > $config['max_' . $mode . '_urls'])
+ // Check for errors
+ $errors = $parser->get_errors();
+ if ($errors)
{
- $this->warn_msg[] = sprintf($user->lang['TOO_MANY_URLS'], $config['max_' . $mode . '_urls']);
+ $this->warn_msg = array_merge($this->warn_msg, $errors);
+
return (!$update_this_message) ? $return_message : $this->warn_msg;
}
@@ -1292,7 +1270,7 @@ class parse_message extends bbcode_firstpass
*/
function format_display($allow_bbcode, $allow_magic_url, $allow_smilies, $update_this_message = true)
{
- global $phpbb_dispatcher;
+ global $phpbb_container, $phpbb_dispatcher;
// If false, then the parsed message get returned but internal message not processed.
if (!$update_this_message)
@@ -1301,26 +1279,25 @@ class parse_message extends bbcode_firstpass
$return_message = &$this->message;
}
- if ($this->message_status == 'plain')
+ // NOTE: message_status is unreliable for detecting unparsed text because some callers
+ // change $this->message without resetting $this->message_status to 'plain' so we
+ // inspect the message instead
+ //if ($this->message_status == 'plain')
+ if (!preg_match('/^<[rt][ >]/', $this->message))
{
// Force updating message - of course.
$this->parse($allow_bbcode, $allow_magic_url, $allow_smilies, $this->allow_img_bbcode, $this->allow_flash_bbcode, $this->allow_quote_bbcode, $this->allow_url_bbcode, true);
}
- // Replace naughty words such as farty pants
- $this->message = censor_text($this->message);
-
- // Parse BBcode
- if ($allow_bbcode)
+ // There's a bug when previewing a topic with no poll, because the empty title of the poll
+ // gets parsed but $this->message still ends up empty. This fixes it, until a proper fix is
+ // devised
+ if ($this->message === '')
{
- $this->bbcode_cache_init();
-
- // We are giving those parameters to be able to use the bbcode class on its own
- $this->bbcode_second_pass($this->message, $this->bbcode_uid);
+ $this->message = $phpbb_container->get('text_formatter.parser')->parse($this->message);
}
- $this->message = bbcode_nl2br($this->message);
- $this->message = smiley_text($this->message, !$allow_smilies);
+ $this->message = $phpbb_container->get('text_formatter.renderer')->render($this->message);
$text = $this->message;
$uid = $this->bbcode_uid;
@@ -1784,24 +1761,22 @@ class parse_message extends bbcode_firstpass
$poll_max_options = $poll['poll_max_options'];
- // Parse Poll Option text ;)
+ // Parse Poll Option text
$tmp_message = $this->message;
- $this->message = $poll['poll_option_text'];
- $bbcode_bitfield = $this->bbcode_bitfield;
- $poll['poll_option_text'] = $this->parse($poll['enable_bbcode'], ($config['allow_post_links']) ? $poll['enable_urls'] : false, $poll['enable_smilies'], $poll['img_status'], false, false, $config['allow_post_links'], false, 'poll');
+ $poll['poll_options'] = explode("\n", trim($poll['poll_option_text']));
+ $poll['poll_options_size'] = sizeof($poll['poll_options']);
- $bbcode_bitfield = base64_encode(base64_decode($bbcode_bitfield) | base64_decode($this->bbcode_bitfield));
- $this->message = $tmp_message;
+ foreach ($poll['poll_options'] as &$poll_option)
+ {
+ $this->message = $poll_option;
+ $poll_option = $this->parse($poll['enable_bbcode'], ($config['allow_post_links']) ? $poll['enable_urls'] : false, $poll['enable_smilies'], $poll['img_status'], false, false, $config['allow_post_links'], false, 'poll');
+ }
+ unset($poll_option);
+ $poll['poll_option_text'] = implode("\n", $poll['poll_options']);
// Parse Poll Title
- $tmp_message = $this->message;
$this->message = $poll['poll_title'];
- $this->bbcode_bitfield = $bbcode_bitfield;
-
- $poll['poll_options'] = explode("\n", trim($poll['poll_option_text']));
- $poll['poll_options_size'] = sizeof($poll['poll_options']);
-
if (!$poll['poll_title'] && $poll['poll_options_size'])
{
$this->warn_msg[] = $user->lang['NO_POLL_TITLE'];
@@ -1819,10 +1794,6 @@ class parse_message extends bbcode_firstpass
}
}
- $this->bbcode_bitfield = base64_encode(base64_decode($bbcode_bitfield) | base64_decode($this->bbcode_bitfield));
- $this->message = $tmp_message;
- unset($tmp_message);
-
if (sizeof($poll['poll_options']) == 1)
{
$this->warn_msg[] = $user->lang['TOO_FEW_POLL_OPTIONS'];
@@ -1837,6 +1808,8 @@ class parse_message extends bbcode_firstpass
}
$poll['poll_max_options'] = ($poll['poll_max_options'] < 1) ? 1 : (($poll['poll_max_options'] > $config['max_poll_options']) ? $config['max_poll_options'] : $poll['poll_max_options']);
+
+ $this->message = $tmp_message;
}
/**
diff --git a/phpBB/phpbb/textformatter/cache.php b/phpBB/phpbb/textformatter/cache.php
new file mode 100644
index 0000000000..c92683217e
--- /dev/null
+++ b/phpBB/phpbb/textformatter/cache.php
@@ -0,0 +1,37 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+namespace phpbb\textformatter;
+
+/**
+* text_formatter.cache service
+*
+* Currently only used to signal that something that could effect the rendering has changed.
+* BBCodes, smilies, censored words, templates, etc...
+*
+* @todo functionality should be moved to data_access
+*
+* @package phpBB3
+*/
+interface cache
+{
+ /**
+ * Invalidate and/or regenerate this text formatter's cache(s)
+ */
+ public function invalidate();
+
+ /**
+ * Tidy/prune this text formatter's cache(s)
+ */
+ public function tidy();
+}
diff --git a/phpBB/phpbb/textformatter/data_access.php b/phpBB/phpbb/textformatter/data_access.php
new file mode 100644
index 0000000000..ec6bf9f88e
--- /dev/null
+++ b/phpBB/phpbb/textformatter/data_access.php
@@ -0,0 +1,233 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+namespace phpbb\textformatter;
+
+/**
+* text_formatter.data_access service
+*
+* Data access layer that fetchs BBCodes, smilies and censored words from the database.
+* To be extended to include insert/update/delete operations.
+*
+* Also used to get templates.
+*
+* @package phpBB3
+*/
+class data_access
+{
+ /**
+ * @var string Name of the BBCodes table
+ */
+ protected $bbcodes_table;
+
+ /**
+ * @var phpbb_db_driver
+ */
+ protected $db;
+
+ /**
+ * @var string Name of the smilies table
+ */
+ protected $smilies_table;
+
+ /**
+ * @var string Name of the styles table
+ */
+ protected $styles_table;
+
+ /**
+ * @var string Path to the styles dir
+ */
+ protected $styles_path;
+
+ /**
+ * @var string Name of the words table
+ */
+ protected $words_table;
+
+ /**
+ * Constructor
+ *
+ * @param \phpbb\db\driver\driver_interface $db Database connection
+ * @param string $bbcodes_table Name of the BBCodes table
+ * @param string $smilies_table Name of the smilies table
+ * @param string $styles_table Name of the styles table
+ * @param string $words_table Name of the words table
+ * @param string $styles_path Path to the styles dir
+ * @return null
+ */
+ public function __construct(\phpbb\db\driver\driver_interface $db, $bbcodes_table, $smilies_table, $styles_table, $words_table, $styles_path)
+ {
+ $this->db = $db;
+
+ $this->bbcodes_table = $bbcodes_table;
+ $this->smilies_table = $smilies_table;
+ $this->styles_table = $styles_table;
+ $this->words_table = $words_table;
+
+ $this->styles_path = $styles_path;
+ }
+
+ /**
+ * Return the list of custom BBCodes
+ *
+ * @return array
+ */
+ public function get_bbcodes()
+ {
+ $sql = 'SELECT bbcode_match, bbcode_tpl FROM ' . $this->bbcodes_table;
+ $result = $this->db->sql_query($sql);
+ $rows = $this->db->sql_fetchrowset($result);
+ $this->db->sql_freeresult($result);
+
+ return $rows;
+ }
+
+ /**
+ * Return the list of smilies
+ *
+ * @return array
+ */
+ public function get_smilies()
+ {
+ // NOTE: smilies that are displayed on the posting page are processed first because they're
+ // typically the most used smilies and it ends up producing a slightly more efficient
+ // renderer
+ $sql = 'SELECT code, emotion, smiley_url, smiley_width, smiley_height
+ FROM ' . $this->smilies_table . '
+ ORDER BY display_on_posting DESC';
+ $result = $this->db->sql_query($sql);
+ $rows = $this->db->sql_fetchrowset($result);
+ $this->db->sql_freeresult($result);
+
+ return $rows;
+ }
+
+ /**
+ * Return the list of installed styles
+ *
+ * @return array
+ */
+ protected function get_styles()
+ {
+ $sql = 'SELECT style_id, style_path, bbcode_bitfield FROM ' . $this->styles_table;
+ $result = $this->db->sql_query($sql);
+ $rows = $this->db->sql_fetchrowset($result);
+ $this->db->sql_freeresult($result);
+
+ return $rows;
+ }
+
+ /**
+ * Return the bbcode.html template for every installed style
+ *
+ * @return array 2D array. style_id as keys, each element is an array with a "template" element that contains the style's bbcode.html and a "bbcodes" element that contains the name of each BBCode that is to be stylised
+ */
+ public function get_styles_templates()
+ {
+ $templates = array();
+
+ $bbcode_ids = array(
+ 'quote' => 0,
+ 'b' => 1,
+ 'i' => 2,
+ 'url' => 3,
+ 'img' => 4,
+ 'size' => 5,
+ 'color' => 6,
+ 'u' => 7,
+ 'code' => 8,
+ 'list' => 9,
+ '*' => 9,
+ 'email' => 10,
+ 'flash' => 11,
+ 'attachment' => 12,
+ );
+
+ $styles = array();
+ foreach ($this->get_styles() as $row)
+ {
+ $styles[$row['style_id']] = $row;
+ }
+
+ foreach ($styles as $style_id => $style)
+ {
+ $bbcodes = array();
+
+ // Collect the name of the BBCodes whose bit is set in the style's bbcode_bitfield
+ $template_bitfield = new \bitfield($style['bbcode_bitfield']);
+ foreach ($bbcode_ids as $bbcode_name => $bit)
+ {
+ if ($template_bitfield->get($bit))
+ {
+ $bbcodes[] = $bbcode_name;
+ }
+ }
+
+ $filename = $this->resolve_style_filename($styles, $style);
+ if ($filename === false)
+ {
+ // Ignore this style, it will use the default templates
+ continue;
+ }
+
+ $templates[$style_id] = array(
+ 'bbcodes' => $bbcodes,
+ 'template' => file_get_contents($filename),
+ );
+ }
+
+ return $templates;
+ }
+
+ /**
+ * Resolve inheritance for given style and return the path to their bbcode.html file
+ *
+ * @param array $styles Associative array of [style_id => style] containing all styles
+ * @param array $style Style for which we resolve
+ * @return string|bool Path to this style's bbcode.html, or FALSE
+ */
+ protected function resolve_style_filename(array $styles, array $style)
+ {
+ // Look for a bbcode.html in this style's dir
+ $filename = $this->styles_path . $style['style_path'] . '/template/bbcode.html';
+ if (file_exists($filename))
+ {
+ return $filename;
+ }
+
+ // Resolve using this style's parent
+ $parent_id = $style['style_parent_id'];
+ if ($parent_id && !empty($styles[$parent_id]))
+ {
+ return $this->resolve_style_filename($styles, $styles[$parent_id]);
+ }
+
+ return false;
+ }
+
+ /**
+ * Return the list of censored words
+ *
+ * @return array
+ */
+ public function get_words()
+ {
+ $sql = 'SELECT word, replacement FROM ' . $this->words_table;
+ $result = $this->db->sql_query($sql);
+ $rows = $this->db->sql_fetchrowset($result);
+ $this->db->sql_freeresult($result);
+
+ return $rows;
+ }
+}
diff --git a/phpBB/phpbb/textformatter/parser.php b/phpBB/phpbb/textformatter/parser.php
new file mode 100644
index 0000000000..c595a459bd
--- /dev/null
+++ b/phpBB/phpbb/textformatter/parser.php
@@ -0,0 +1,121 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+namespace phpbb\textformatter;
+
+/**
+* text_formatter.parser service
+* @package phpBB3
+*/
+abstract class parser
+{
+ /**
+ * Parse given text
+ *
+ * @param string $text
+ * @return string
+ */
+ abstract public function parse($text);
+
+ /**
+ * Disable a specific BBCode
+ *
+ * @param string $name BBCode name
+ * @return null
+ */
+ abstract public function disable_bbcode($name);
+
+ /**
+ * Disable BBCodes in general
+ */
+ abstract public function disable_bbcodes();
+
+ /**
+ * Disable the censor
+ */
+ abstract public function disable_censor();
+
+ /**
+ * Disable magic URLs
+ */
+ abstract public function disable_magic_url();
+
+ /**
+ * Disable smilies
+ */
+ abstract public function disable_smilies();
+
+ /**
+ * Enable a specific BBCode
+ *
+ * @param string $name BBCode name
+ * @return null
+ */
+ abstract public function enable_bbcode($name);
+
+ /**
+ * Enable BBCodes in general
+ */
+ abstract public function enable_bbcodes();
+
+ /**
+ * Enable the censor
+ */
+ abstract public function enable_censor();
+
+ /**
+ * Enable magic URLs
+ */
+ abstract public function enable_magic_url();
+
+ /**
+ * Enable smilies
+ */
+ abstract public function enable_smilies();
+
+ /**
+ * Get the list of errors that were generated during last parsing
+ *
+ * @return array
+ */
+ abstract public function get_errors();
+
+ /**
+ * Set a variable to be used by the parser
+ *
+ * - max_font_size
+ * - max_img_height
+ * - max_img_width
+ * - max_smilies
+ * - max_urls
+ *
+ * @param string $name
+ * @param mixed $value
+ * @return null
+ */
+ abstract public function set_var($name, $value);
+
+ /**
+ * Set multiple variables to be used by the parser
+ *
+ * @param array Associative array of [name => value]
+ * @return null
+ */
+ public function set_vars(array $vars)
+ {
+ foreach ($vars as $name => $value)
+ {
+ $this->set_var($name, $value);
+ }
+ }
+}
diff --git a/phpBB/phpbb/textformatter/renderer.php b/phpBB/phpbb/textformatter/renderer.php
new file mode 100644
index 0000000000..fb731a5294
--- /dev/null
+++ b/phpBB/phpbb/textformatter/renderer.php
@@ -0,0 +1,136 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+namespace phpbb\textformatter;
+
+/**
+* text_formatter.renderer service
+* @package phpBB3
+*/
+abstract class renderer
+{
+ /**
+ * Render given text
+ *
+ * @param string $text Text, as parsed by the text_formatter.parser service
+ * @return string
+ */
+ abstract public function render($text);
+
+ /**
+ * Automatically set the smilies path based on config
+ *
+ * Called by the service container
+ *
+ * @param phpbb\config\config $config
+ * @param phpbb\path_helper $path_helper
+ * @return null
+ */
+ public function configure_smilies_path(\phpbb\config\config $config, \phpbb\path_helper $path_helper)
+ {
+ /**
+ * @see smiley_text()
+ */
+ $root_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? generate_board_url() . '/' : $path_helper->get_web_root_path();
+
+ $this->set_smilies_path($root_path . $config['smilies_path']);
+ }
+
+ /**
+ * Configure this renderer as per the user's settings
+ *
+ * Should set the locale as well as the viewcensor/viewflash/viewimg/viewsmilies options.
+ * Called by the service container
+ *
+ * @param phpbb\user $user
+ * @param phpbb\config\config $config
+ * @param phpbb\auth\auth $auth
+ * @return null
+ */
+ public function configure_user(\phpbb\user $user, \phpbb\config\config $config, \phpbb\auth\auth $auth)
+ {
+ $censor = $user->optionget('viewcensors') || !$config['allow_nocensors'] || !$auth->acl_get('u_chgcensors');
+
+ $this->set_viewcensors($censor);
+ $this->set_viewflash($user->optionget('viewflash'));
+ $this->set_viewimg($user->optionget('viewimg'));
+ $this->set_viewsmilies($user->optionget('viewsmilies'));
+ }
+
+ /**
+ * Set the smilies' path
+ *
+ * @return null
+ */
+ abstract public function set_smilies_path($path);
+
+ /**
+ * Return the value of the "viewcensors" option
+ *
+ * @return bool Option's value
+ */
+ abstract public function get_viewcensors();
+
+ /**
+ * Return the value of the "viewflash" option
+ *
+ * @return bool Option's value
+ */
+ abstract public function get_viewflash();
+
+ /**
+ * Return the value of the "viewimg" option
+ *
+ * @return bool Option's value
+ */
+ abstract public function get_viewimg();
+
+ /**
+ * Return the value of the "viewsmilies" option
+ *
+ * @return bool Option's value
+ */
+ abstract public function get_viewsmilies();
+
+ /**
+ * Set the "viewcensors" option
+ *
+ * @param bool $value Option's value
+ * @return null
+ */
+ abstract public function set_viewcensors($value);
+
+ /**
+ * Set the "viewflash" option
+ *
+ * @param bool $value Option's value
+ * @return null
+ */
+ abstract public function set_viewflash($value);
+
+ /**
+ * Set the "viewimg" option
+ *
+ * @param bool $value Option's value
+ * @return null
+ */
+ abstract public function set_viewimg($value);
+
+ /**
+ * Set the "viewsmilies" option
+ *
+ * @param bool $value Option's value
+ * @return null
+ */
+ abstract public function set_viewsmilies($value);
+}
diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php
new file mode 100644
index 0000000000..8d61f2caac
--- /dev/null
+++ b/phpBB/phpbb/textformatter/s9e/factory.php
@@ -0,0 +1,493 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+namespace phpbb\textformatter\s9e;
+
+use s9e\TextFormatter\Configurator;
+use s9e\TextFormatter\Configurator\Items\AttributeFilters\Regexp as RegexpFilter;
+
+/**
+* Creates s9e\TextFormatter objects
+* @package phpBB3
+*/
+class factory implements \phpbb\textformatter\cache
+{
+ /**
+ * @var phpbb_cache_driver_interface $cache
+ */
+ protected $cache;
+
+ /**
+ * @var string Path to the cache dir
+ */
+ protected $cache_dir;
+
+ /**
+ * @var string Cache key used for the parser
+ */
+ protected $cache_key_parser;
+
+ /**
+ * @var string Cache key used for the renderer
+ */
+ protected $cache_key_renderer;
+
+ /**
+ * @var array Custom tokens used in bbcode.html and their corresponding token from the definition
+ */
+ protected $custom_tokens = array(
+ 'email' => array('{DESCRIPTION}' => '{TEXT}'),
+ 'flash' => array('{WIDTH}' => '{NUMBER1}', '{HEIGHT}' => '{NUMBER2}'),
+ 'img' => array('{URL}' => '{IMAGEURL}'),
+ 'list' => array('{LIST_TYPE}' => '{HASHMAP}'),
+ 'quote' => array('{USERNAME}' => '{TEXT1}'),
+ 'size' => array('{SIZE}' => '{FONTSIZE}'),
+ 'url' => array('{DESCRIPTION}' => '{TEXT}'),
+ );
+
+ /**
+ * @var \phpbb\textformatter\data_access
+ */
+ protected $dal;
+
+ /**
+ * @var array Default BBCode definitions
+ */
+ protected $default_definitions = array(
+ 'attachment' => '[ATTACHMENT index={NUMBER} filename={TEXT;useContent}]',
+ 'b' => '[B]{TEXT}[/B]',
+ 'code' => '[CODE]{TEXT}[/CODE]',
+ 'color' => '[COLOR={COLOR}]{TEXT}[/COLOR]',
+ 'email' => '[EMAIL={EMAIL;useContent}]{TEXT}[/EMAIL]',
+ 'flash' => '[FLASH={NUMBER1},{NUMBER2} width={NUMBER1;postFilter=#flashwidth} height={NUMBER2;postFilter=#flashheight} url={URL;useContent} /]',
+ 'i' => '[I]{TEXT}[/I]',
+ 'img' => '[IMG src={IMAGEURL;useContent}]',
+ 'list' => '[LIST type={HASHMAP=1:decimal,a:lower-alpha,A:upper-alpha,i:lower-roman,I:upper-roman;optional;postFilter=#simpletext}]{TEXT}[/LIST]',
+ 'li' => '[* $tagName=LI]{TEXT}[/*]',
+ 'quote' => '[QUOTE author={TEXT1;optional}]{TEXT2}[/QUOTE]',
+ 'size' => '[SIZE={FONTSIZE}]{TEXT}[/SIZE]',
+ 'u' => '[U]{TEXT}[/U]',
+ 'url' => '[URL={URL;useContent}]{TEXT}[/URL]',
+ );
+
+ /**
+ * @var array Default templates, taken from bbcode::bbcode_tpl()
+ */
+ protected $default_templates = array(
+ 'b' => '<span style="font-weight: bold"><xsl:apply-templates/></span>',
+ 'i' => '<span style="font-style: italic"><xsl:apply-templates/></span>',
+ 'u' => '<span style="text-decoration: underline"><xsl:apply-templates/></span>',
+ 'img' => '<img src="{IMAGEURL}" alt="{L_IMAGE}"/>',
+ 'size' => '<span style="font-size: {FONTSIZE}%; line-height: normal"><xsl:apply-templates/></span>',
+ 'color' => '<span style="color: {COLOR}"><xsl:apply-templates/></span>',
+ 'email' => '<a href="mailto:{EMAIL}"><xsl:apply-templates/></a>',
+ );
+
+ /**
+ * Constructor
+ *
+ * @param phpbb\textformatter\data_access $dal
+ * @param phpbb\cache\driver\driver_interface $cache
+ * @param string $cache_dir Path to the cache dir
+ * @param string $cache_key_parser Cache key used for the parser
+ * @param string $cache_key_renderer Cache key used for the renderer
+ * @return null
+ */
+ public function __construct(\phpbb\textformatter\data_access $dal, \phpbb\cache\driver\driver_interface $cache, $cache_dir, $cache_key_parser, $cache_key_renderer)
+ {
+ $this->cache = $cache;
+ $this->cache_dir = $cache_dir;
+ $this->cache_key_parser = $cache_key_parser;
+ $this->cache_key_renderer = $cache_key_renderer;
+
+ $this->dal = $dal;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function invalidate()
+ {
+ $this->regenerate();
+ }
+
+ /**
+ * {@inheritdoc}
+ *
+ * Will remove old renderers from the cache dir but won't touch the current renderer
+ */
+ public function tidy()
+ {
+ // Get the name of current renderer
+ $renderer_data = $this->cache->get($this->cache_key_renderer);
+ $renderer_file = ($renderer_data) ? $renderer_data['class'] . '.php' : null;
+
+ foreach (glob($this->cache_dir . 's9e_*') as $filename)
+ {
+ // Only remove the file if it's not the current renderer
+ if (!$renderer_file || substr($filename, -strlen($renderer_file)) !== $renderer_file)
+ {
+ unlink($filename);
+ }
+ }
+ }
+
+ /**
+ * Generate and return a new configured instance of s9e\TextFormatter\Configurator
+ *
+ * @return s9e\TextFormatter\Configurator
+ */
+ public function get_configurator()
+ {
+ // Create a new Configurator
+ $configurator = new Configurator;
+
+ // Convert newlines to br elements by default
+ $configurator->rootRules->enableAutoLineBreaks();
+
+ // Set the rendering engine and configure it to save to the cache dir
+ $configurator->rendering->engine = 'PHP';
+ $configurator->rendering->engine->cacheDir = $this->cache_dir;
+ $configurator->rendering->engine->defaultClassPrefix = 's9e_renderer_';
+ $configurator->rendering->engine->enableQuickRenderer = true;
+
+ // Create custom filters for BBCode tokens that are supported in phpBB but not in
+ // s9e\TextFormatter
+ $filter = new RegexpFilter('#^' . get_preg_expression('relative_url') . '$#D');
+ $configurator->attributeFilters->add('#local_url', $filter);
+ $configurator->attributeFilters->add('#relative_url', $filter);
+
+ $regexp = (phpbb_pcre_utf8_support())
+ ? '!^([\p{L}\p{N}\-+,_. ]+)$!uD'
+ : '!^([a-zA-Z0-9\-+,_. ]+)$!uD';
+ $configurator->attributeFilters->add('#inttext', new RegexpFilter($regexp));
+
+ // Create custom filters for Flash restrictions, which use the same values as the image
+ // restrictions but have their own error message
+ $configurator->attributeFilters
+ ->add('#flashheight', __NAMESPACE__ . '\\parser::filter_flash_height')
+ ->addParameterByName('max_img_height')
+ ->addParameterByName('logger');
+
+ $configurator->attributeFilters
+ ->add('#flashwidth', __NAMESPACE__ . '\\parser::filter_flash_width')
+ ->addParameterByName('max_img_width')
+ ->addParameterByName('logger');
+
+ // Create a custom filter for phpBB's per-mode font size limits
+ $configurator->attributeFilters
+ ->add('#fontsize', __NAMESPACE__ . '\\parser::filter_font_size')
+ ->addParameterByName('max_font_size')
+ ->addParameterByName('logger')
+ ->markAsSafeInCSS();
+
+ // Create a custom filter for image URLs
+ $configurator->attributeFilters
+ ->add('#imageurl', __NAMESPACE__ . '\\parser::filter_img_url')
+ ->addParameterByName('urlConfig')
+ ->addParameterByName('logger')
+ ->addParameterByName('max_img_height')
+ ->addParameterByName('max_img_width')
+ ->markAsSafeAsURL();
+
+ // Add default BBCodes
+ foreach ($this->get_default_bbcodes($configurator) as $bbcode)
+ {
+ $configurator->BBCodes->addCustom($bbcode['usage'], $bbcode['template']);
+ }
+
+ // Modify the template to disable images/flash depending on user's settings
+ foreach (array('FLASH', 'IMG') as $name)
+ {
+ $tag = $configurator->tags[$name];
+ $tag->template = '<xsl:choose><xsl:when test="$S_VIEW' . $name . '">' . $tag->template . '</xsl:when><xsl:otherwise><xsl:apply-templates/></xsl:otherwise></xsl:choose>';
+ }
+
+ // Load custom BBCodes
+ foreach ($this->dal->get_bbcodes() as $row)
+ {
+ // Insert the board's URL before {LOCAL_URL} tokens
+ $tpl = preg_replace_callback(
+ '#\\{LOCAL_URL\\d*\\}#',
+ function ($m)
+ {
+ return generate_board_url() . '/' . $m[0];
+ },
+ $row['bbcode_tpl']
+ );
+
+ try
+ {
+ $configurator->BBCodes->addCustom($row['bbcode_match'], $tpl);
+ }
+ catch (\Exception $e)
+ {
+ /**
+ * @todo log an error?
+ */
+ }
+ }
+
+ // Load smilies
+ foreach ($this->dal->get_smilies() as $row)
+ {
+ $configurator->Emoticons->add(
+ $row['code'],
+ '<img class="smilies" src="{$T_SMILIES_PATH}/' . htmlspecialchars($row['smiley_url']) . '" alt="{.}" title="' . htmlspecialchars($row['emotion']) . '"/>'
+ );
+ }
+
+ if (isset($configurator->Emoticons))
+ {
+ // Force emoticons to be rendered as text if $S_VIEWSMILIES is not set
+ $configurator->Emoticons->notIfCondition = 'not($S_VIEWSMILIES)';
+
+ // Only parse emoticons at the beginning of the text or if they're preceded by any
+ // one of: a new line, a space, a dot, or a right square bracket
+ $configurator->Emoticons->notAfter = '[^\\n .\\]]';
+ }
+
+ // Load the censored words
+ foreach ($this->dal->get_words() as $row)
+ {
+ $configurator->Censor->add($row['word'], $row['replacement']);
+ }
+
+ if (isset($configurator->Censor))
+ {
+ // Replace the template with a template that applies only when $S_VIEWCENSORS is set
+ $tag = $configurator->Censor->getTag();
+ $tag->template =
+ '<xsl:choose>
+ <xsl:when test="not($S_VIEWCENSORS)">
+ <xsl:value-of select="."/>
+ </xsl:when>
+ <xsl:when test="@with">
+ <xsl:value-of select="@with"/>
+ </xsl:when>
+ <xsl:otherwise>****</xsl:otherwise>
+ </xsl:choose>';
+ }
+
+ // Load the magic links plugins. We do that after BBCodes so that they use the same tags
+ $configurator->plugins->load('Autoemail');
+ $configurator->plugins->load('Autolink');
+
+ // Register some vars with a default value. Those should be set at runtime by whatever calls
+ // the parser
+ $configurator->registeredVars['max_font_size'] = 0;
+ $configurator->registeredVars['max_img_height'] = 0;
+ $configurator->registeredVars['max_img_width'] = 0;
+
+ return $configurator;
+ }
+
+ /**
+ * Regenerate and cache a new parser and renderer
+ *
+ * @return array Array with two elements: an instance of the parser, an instance of the renderer
+ */
+ public function regenerate()
+ {
+ $configurator = $this->get_configurator();
+
+ // Create $parser and $renderer
+ extract($configurator->finalize());
+
+ // Cache the parser as-is
+ $this->cache->put($this->cache_key_parser, $parser);
+
+ // We need to cache the name of the renderer's generated class so that we can load the class
+ // before the renderer is unserialized. That's why we save them together, with the renderer
+ // in serialized form
+ $renderer_data = array(
+ 'class' => get_class($renderer),
+ 'renderer' => serialize($renderer)
+ );
+ $this->cache->put($this->cache_key_renderer, $renderer_data);
+
+ return array($parser, $renderer);
+ }
+
+ /**
+ * Return the default BBCodes configuration
+ *
+ * @return array 2D array. Each element has a 'usage' key, a 'template' key, and an optional 'options' key
+ */
+ protected function get_default_bbcodes($configurator)
+ {
+ // For each BBCode, build an associative array matching style_ids to their template
+ $templates = array();
+ foreach ($this->dal->get_styles_templates() as $style_id => $data)
+ {
+ foreach ($this->extract_templates($data['template']) as $bbcode_name => $template)
+ {
+ $templates[$bbcode_name][$style_id] = $template;
+ }
+
+ // Add default templates wherever missing, or for BBCodes that were not specified in
+ // this template's bitfield. For instance, prosilver has a custom template for b but its
+ // bitfield does not enable it so the default template is used instead
+ foreach ($this->default_templates as $bbcode_name => $template)
+ {
+ if (!isset($templates[$bbcode_name][$style_id]) || !in_array($bbcode_name, $data['bbcodes'], true))
+ {
+ $templates[$bbcode_name][$style_id] = $template;
+ }
+ }
+ }
+
+ // Replace custom tokens and normalize templates
+ foreach ($templates as $bbcode_name => &$style_templates)
+ {
+ foreach ($style_templates as &$template)
+ {
+ if (isset($this->custom_tokens[$bbcode_name]))
+ {
+ $template = strtr($template, $this->custom_tokens[$bbcode_name]);
+ }
+
+ $template = $configurator->templateNormalizer->normalizeTemplate($template);
+ }
+ unset($template);
+ }
+ unset($style_templates);
+
+ $bbcodes = array();
+ foreach ($this->default_definitions as $bbcode_name => $usage)
+ {
+ $bbcodes[$bbcode_name] = array(
+ 'usage' => $usage,
+ 'template' => $this->merge_templates($templates[$bbcode_name]),
+ );
+ }
+
+ return $bbcodes;
+ }
+
+ /**
+ * Extract and recompose individual BBCode templates from a style's template file
+ *
+ * @param string $template Style template (bbcode.html)
+ * @return array Associative array matching BBCode names to their template
+ */
+ protected function extract_templates($template)
+ {
+ // Capture the template fragments
+ preg_match_all('#<!-- BEGIN (.*?) -->(.*?)<!-- END .*? -->#s', $template, $matches, PREG_SET_ORDER);
+
+ $fragments = array();
+ foreach ($matches as $match)
+ {
+ // Normalize the whitespace
+ $fragment = preg_replace('#>\\n\\t*<#', '><', trim($match[2]));
+
+ $fragments[$match[1]] = $fragment;
+ }
+
+ // Automatically recompose templates split between *_open and *_close
+ foreach ($fragments as $fragment_name => $fragment)
+ {
+ if (preg_match('#^(\\w+)_close$#', $fragment_name, $match))
+ {
+ $bbcode_name = $match[1];
+
+ if (isset($fragments[$bbcode_name . '_open']))
+ {
+ $templates[$bbcode_name] = $fragments[$bbcode_name . '_open'] . '<xsl:apply-templates/>' . $fragment;
+ }
+ }
+ }
+
+ // Manually recompose and overwrite irregular templates
+ $templates['list'] =
+ '<xsl:choose>
+ <xsl:when test="not(@type)">
+ ' . $fragments['ulist_open_default'] . '<xsl:apply-templates/>' . $fragments['ulist_close'] . '
+ </xsl:when>
+ <xsl:when test="contains(\'upperlowerdecim\',substring(@type,1,5))">
+ ' . $fragments['olist_open'] . '<xsl:apply-templates/>' . $fragments['olist_close'] . '
+ </xsl:when>
+ <xsl:otherwise>
+ ' . $fragments['ulist_open'] . '<xsl:apply-templates/>' . $fragments['ulist_close'] . '
+ </xsl:otherwise>
+ </xsl:choose>';
+
+ $templates['li'] = $fragments['listitem'] . '<xsl:apply-templates/>' . $fragments['listitem_close'];
+
+ $templates['quote'] =
+ '<xsl:choose>
+ <xsl:when test="@author">
+ ' . $fragments['quote_username_open'] . '<xsl:apply-templates/>' . $fragments['quote_close'] . '
+ </xsl:when>
+ <xsl:otherwise>
+ ' . $fragments['quote_open'] . '<xsl:apply-templates/>' . $fragments['quote_close'] . '
+ </xsl:otherwise>
+ </xsl:choose>';
+
+ // The [attachment] BBCode uses the inline_attachment template to output a comment that
+ // is post-processed by parse_attachments()
+ $templates['attachment'] = $fragments['inline_attachment_open'] . '<xsl:comment> ia<xsl:value-of select="@index"/> </xsl:comment><xsl:value-of select="@filename"/><xsl:comment> ia<xsl:value-of select="@index"/> </xsl:comment>' . $fragments['inline_attachment_close'];
+
+ // Finally save fragments whose names look like the name of a BBCode, e.g. "flash"
+ foreach ($fragments as $fragment_name => $fragment)
+ {
+ if (preg_match('#^\\w+$#', $fragment_name))
+ {
+ $templates[$fragment_name] = $fragment;
+ }
+ }
+
+ return $templates;
+ }
+
+ /**
+ * Merge the templates from any number of styles into one BBCode template
+ *
+ * @param array $style_templates Associative array matching style_ids to their template
+ * @return string
+ */
+ protected function merge_templates(array $style_templates)
+ {
+ // Group identical templates together
+ $grouped_templates = array();
+ foreach ($style_templates as $style_id => $style_template)
+ {
+ $grouped_templates[$style_template][] = $style_id;
+ }
+
+ if (count($grouped_templates) === 1)
+ {
+ return $style_template;
+ }
+
+ // Sort templates by frequency descending
+ $templates_cnt = array_map('sizeof', $grouped_templates);
+ array_multisort($grouped_templates, $templates_cnt);
+
+ // Remove the most frequent template from the list; It becomes the default
+ reset($grouped_templates);
+ $default_template = key($grouped_templates);
+ unset($grouped_templates[$default_template]);
+
+ // Build an xsl:choose switch
+ $template = '<xsl:choose>';
+ foreach ($grouped_templates as $style_template => $style_ids)
+ {
+ $template .= '<xsl:when test="$STYLE_ID=' . implode(' or $STYLE_ID=', $style_ids) . '">' . $style_template . '</xsl:when>';
+ }
+ $template .= '<xsl:otherwise>' . $default_template . '</xsl:otherwise></xsl:choose>';
+
+ return $template;
+ }
+}
diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php
new file mode 100644
index 0000000000..10e33f47e6
--- /dev/null
+++ b/phpBB/phpbb/textformatter/s9e/parser.php
@@ -0,0 +1,335 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+namespace phpbb\textformatter\s9e;
+
+use Symfony\Component\DependencyInjection\ContainerInterface;
+use s9e\TextFormatter\Parser\BuiltInFilters;
+use s9e\TextFormatter\Parser\Logger;
+
+/**
+* s9e\TextFormatter\Parser adapter
+* @package phpBB3
+*/
+class parser extends \phpbb\textformatter\parser
+{
+ /**
+ * @var s9e\TextFormatter\Parser
+ */
+ protected $parser;
+
+ /**
+ * @var phpbb\user User object, used for translating errors
+ */
+ protected $user;
+
+ /**
+ * Constructor
+ *
+ * @param phpbb\cache\driver_interface $cache
+ * @param string $key Cache key
+ * @param phpbb\user $user
+ * @param Symfony\Component\DependencyInjection\ContainerInterface $container
+ * @return null
+ */
+ public function __construct(\phpbb\cache\driver\driver_interface $cache, $key, \phpbb\user $user, ContainerInterface $container)
+ {
+ $this->user = $user;
+
+ $parser = $cache->get($key);
+ if (!$parser)
+ {
+ list($parser) = $container->get('text_formatter.s9e.factory')->regenerate();
+ }
+
+ $this->parser = $parser;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function parse($text)
+ {
+ return $this->parser->parse($text);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function disable_bbcode($name)
+ {
+ $this->parser->disableTag(strtoupper($name));
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function disable_bbcodes()
+ {
+ $this->parser->disablePlugin('BBCodes');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function disable_censor()
+ {
+ $this->parser->disablePlugin('Censor');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function disable_magic_url()
+ {
+ $this->parser->disablePlugin('Autoemail');
+ $this->parser->disablePlugin('Autolink');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function disable_smilies()
+ {
+ $this->parser->disablePlugin('Emoticons');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function enable_bbcode($name)
+ {
+ $this->parser->enableTag(strtoupper($name));
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function enable_bbcodes()
+ {
+ $this->parser->enablePlugin('BBCodes');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function enable_censor()
+ {
+ $this->parser->enablePlugin('Censor');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function enable_magic_url()
+ {
+ $this->parser->enablePlugin('Autoemail');
+ $this->parser->enablePlugin('Autolink');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function enable_smilies()
+ {
+ $this->parser->enablePlugin('Emoticons');
+ }
+
+ /**
+ * {@inheritdoc}
+ *
+ * This will translate the log entries found in s9e\TextFormatter's logger into phpBB error
+ * messages
+ */
+ public function get_errors()
+ {
+ $errors = array();
+
+ foreach ($this->parser->getLogger()->get() as $entry)
+ {
+ list($type, $msg, $context) = $entry;
+
+ if ($msg === 'Tag limit exceeded')
+ {
+ if ($context['tagName'] === 'E')
+ {
+ $errors[] = $this->user->lang('TOO_MANY_SMILIES', $context['tagLimit']);
+ }
+ else if ($context['tagName'] === 'URL')
+ {
+ $errors[] = $this->user->lang('TOO_MANY_URLS', $context['tagLimit']);
+ }
+ }
+ else if ($msg === 'MAX_FONT_SIZE_EXCEEDED')
+ {
+ $errors[] = $this->user->lang($msg, $context['max_size']);
+ }
+ else if (preg_match('/^MAX_(?:FLASH|IMG)_(HEIGHT|WIDTH)_EXCEEDED$/D', $msg, $m))
+ {
+ $errors[] = $this->user->lang($msg, $context['max_' . strtolower($m[1])]);
+ }
+ else if ($msg === 'Tag is disabled')
+ {
+ $name = strtolower($context['tag']->getName());
+ $errors[] = $this->user->lang('UNAUTHORISED_BBCODE', '[' . $name . ']');
+ }
+ else if ($msg === 'UNABLE_GET_IMAGE_SIZE')
+ {
+ $errors[] = $this->user->lang[$msg];
+ }
+ }
+
+ return array_unique($errors);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function set_var($name, $value)
+ {
+ if ($name === 'max_smilies')
+ {
+ $this->parser->setTagLimit('E', $value ?: PHP_INT_MAX);
+ }
+ else if ($name === 'max_urls')
+ {
+ $this->parser->setTagLimit('URL', $value ?: PHP_INT_MAX);
+ }
+ else
+ {
+ $this->parser->registeredVars[$name] = $value;
+ }
+ }
+
+ /**
+ * Filter a flash object's height
+ *
+ * @see bbcode_firstpass::bbcode_flash()
+ *
+ * @param string $height
+ * @param integer $max_height
+ * @param s9e\TextFormatter\Parser\Logger $logger
+ * @return mixed Original value if valid, FALSE otherwise
+ */
+ static public function filter_flash_height($height, $max_height, Logger $logger)
+ {
+ if ($max_height && $height > $max_height)
+ {
+ $logger->err('MAX_FLASH_HEIGHT_EXCEEDED', array('max_height' => $max_height));
+
+ return false;
+ }
+
+ return $height;
+ }
+
+ /**
+ * Filter a flash object's width
+ *
+ * @see bbcode_firstpass::bbcode_flash()
+ *
+ * @param string $width
+ * @param integer $max_width
+ * @param s9e\TextFormatter\Parser\Logger $logger
+ * @return mixed Original value if valid, FALSE otherwise
+ */
+ static public function filter_flash_width($width, $max_width, Logger $logger)
+ {
+ if ($max_width && $width > $max_width)
+ {
+ $logger->err('MAX_FLASH_WIDTH_EXCEEDED', array('max_width' => $max_width));
+
+ return false;
+ }
+
+ return $width;
+ }
+
+ /**
+ * Filter the value used in a [size] BBCode
+ *
+ * @see bbcode_firstpass::bbcode_size()
+ *
+ * @param string $size Original size
+ * @param integer $max_size Maximum allowed size
+ * @param s9e\TextFormatter\Parser\Logger $logger
+ * @return mixed Original value if valid, FALSE otherwise
+ */
+ static public function filter_font_size($size, $max_size, Logger $logger)
+ {
+ if ($max_size && $size > $max_size)
+ {
+ $logger->err('MAX_FONT_SIZE_EXCEEDED', array('max_size' => $max_size));
+
+ return false;
+ }
+
+ if ($size < 1)
+ {
+ return false;
+ }
+
+ return $size;
+ }
+
+ /**
+ * Filter an image's URL to enforce restrictions on its dimensions
+ *
+ * @see bbcode_firstpass::bbcode_img()
+ *
+ * @param string $url Original URL
+ * @param array $url_config Config used by the URL filter
+ * @param s9e\TextFormatter\Parser\Logger $logger
+ * @param integer $max_height Maximum height allowed
+ * @param integer $max_width Maximum width allowed
+ * @return string|bool Original value if valid, FALSE otherwise
+ */
+ static public function filter_img_url($url, array $url_config, Logger $logger, $max_height, $max_width)
+ {
+ // Validate the URL
+ $url = BuiltInFilters::filterUrl($url, $url_config, $logger);
+
+ if ($url === false)
+ {
+ return false;
+ }
+
+ if ($max_height || $max_width)
+ {
+ $stats = @getimagesize($url);
+
+ if ($stats === false)
+ {
+ $logger->err('UNABLE_GET_IMAGE_SIZE');
+
+ return false;
+ }
+
+ if ($max_height && $max_height < $stats[1])
+ {
+ $logger->err('MAX_IMG_HEIGHT_EXCEEDED', array('max_height' => $max_height));
+
+ return false;
+ }
+
+ if ($max_width && $max_width < $stats[0])
+ {
+ $logger->err('MAX_IMG_WIDTH_EXCEEDED', array('max_width' => $max_width));
+
+ return false;
+ }
+ }
+
+ return $url;
+ }
+}
diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php
new file mode 100644
index 0000000000..2c8412f961
--- /dev/null
+++ b/phpBB/phpbb/textformatter/s9e/renderer.php
@@ -0,0 +1,228 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+namespace phpbb\textformatter\s9e;
+
+use Symfony\Component\DependencyInjection\ContainerInterface;
+
+/**
+* s9e\TextFormatter\Renderer adapter
+* @package phpBB3
+*/
+class renderer extends \phpbb\textformatter\renderer
+{
+ /**
+ * @var s9e\TextFormatter\Renderer
+ */
+ protected $renderer;
+
+ /**
+ * @var bool Status of the viewcensors option
+ */
+ protected $viewcensors = false;
+
+ /**
+ * @var bool Status of the viewflash option
+ */
+ protected $viewflash = false;
+
+ /**
+ * @var bool Status of the viewimg option
+ */
+ protected $viewimg = false;
+
+ /**
+ * @var bool Status of the viewsmilies option
+ */
+ protected $viewsmilies = false;
+
+ /**
+ * Constructor
+ *
+ * @param phpbb\cache\driver\driver_interface $cache
+ * @param string $cache_dir Path to the cache dir
+ * @param string $key Cache key
+ * @param Symfony\Component\DependencyInjection\ContainerInterface $container
+ * @return null
+ */
+ public function __construct(\phpbb\cache\driver\driver_interface $cache, $cache_dir, $key, ContainerInterface $container)
+ {
+ $renderer_data = $cache->get($key);
+
+ if ($renderer_data)
+ {
+ $class = $renderer_data['class'];
+
+ if (!class_exists($class, false))
+ {
+ // Try to load the renderer class from its cache file
+ $cache_file = $cache_dir . $class . '.php';
+
+ if (file_exists($cache_file))
+ {
+ include($cache_file);
+ }
+ }
+
+ if (class_exists($class, false))
+ {
+ $renderer = unserialize($renderer_data['renderer']);
+ }
+ }
+
+ if (!isset($renderer))
+ {
+ list(, $renderer) = $container->get('text_formatter.s9e.factory')->regenerate();
+ }
+
+ $this->renderer = $renderer;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function configure_user(\phpbb\user $user, \phpbb\config\config $config, \phpbb\auth\auth $auth)
+ {
+ parent::configure_user($user, $config, $auth);
+
+ // Set the stylesheet parameters
+ foreach (array_keys($this->renderer->getParameters()) as $param_name)
+ {
+ if (substr($param_name, 0, 2) === 'L_')
+ {
+ // L_FOO is set to $user->lang('FOO')
+ $this->renderer->setParameter($param_name, $user->lang(substr($param_name, 2)));
+ }
+ }
+
+ // Set the style id
+ $this->renderer->setParameter('STYLE_ID', $user->style['style_id']);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function get_viewcensors()
+ {
+ return $this->viewcensors;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function get_viewflash()
+ {
+ return $this->viewflash;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function get_viewimg()
+ {
+ return $this->viewimg;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function get_viewsmilies()
+ {
+ return $this->viewsmilies;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function render($text)
+ {
+ $html = $this->renderer->render($text);
+
+ /**
+ * @see bbcode::bbcode_second_pass_code()
+ */
+ $html = preg_replace_callback(
+ '#(<code>)(.*?)(</code>)#is',
+ function ($captures)
+ {
+ $code = $captures[2];
+
+ $code = str_replace("\t", '&nbsp; &nbsp;', $code);
+ $code = str_replace(' ', '&nbsp; ', $code);
+ $code = str_replace(' ', ' &nbsp;', $code);
+ $code = str_replace("\n ", "\n&nbsp;", $code);
+
+ // keep space at the beginning
+ if (!empty($code) && $code[0] == ' ')
+ {
+ $code = '&nbsp;' . substr($code, 1);
+ }
+
+ // remove newline at the beginning
+ if (!empty($code) && $code[0] == "\n")
+ {
+ $code = substr($code, 1);
+ }
+
+ return $captures[1] . $code . $captures[3];
+ },
+ $html
+ );
+
+ return $html;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function set_smilies_path($path)
+ {
+ $this->renderer->setParameter('T_SMILIES_PATH', $path);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function set_viewcensors($value)
+ {
+ $this->viewcensors = $value;
+ $this->renderer->setParameter('S_VIEWCENSORS', $value);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function set_viewflash($value)
+ {
+ $this->viewflash = $value;
+ $this->renderer->setParameter('S_VIEWFLASH', $value);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function set_viewimg($value)
+ {
+ $this->viewimg = $value;
+ $this->renderer->setParameter('S_VIEWIMG', $value);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function set_viewsmilies($value)
+ {
+ $this->viewsmilies = $value;
+ $this->renderer->setParameter('S_VIEWSMILIES', $value);
+ }
+}
diff --git a/phpBB/phpbb/textformatter/s9e/utils.php b/phpBB/phpbb/textformatter/s9e/utils.php
new file mode 100644
index 0000000000..19cd3a11c8
--- /dev/null
+++ b/phpBB/phpbb/textformatter/s9e/utils.php
@@ -0,0 +1,67 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+namespace phpbb\textformatter\s9e;
+
+/**
+* Text manipulation utilities
+* @package phpBB3
+*/
+class utils extends \phpbb\textformatter\utils
+{
+ /**
+ * {@inheritdoc}
+ */
+ public function clean_formatting($text)
+ {
+ // Insert a space before <s> and <e> then remove formatting
+ $text = preg_replace('#<[es]>#', ' $0', $text);
+
+ return \s9e\TextFormatter\Unparser::removeFormatting($text);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function remove_bbcode($text, $bbcode_name, $depth = 0)
+ {
+ $dom = new \DOMDocument;
+ $dom->loadXML($text);
+
+ $xpath = new \DOMXPath($dom);
+ $nodes = $xpath->query(str_repeat('//' . strtoupper($bbcode_name), 1 + $depth));
+
+ foreach ($nodes as $node)
+ {
+ $node->parentNode->removeChild($node);
+ }
+
+ return $dom->saveXML($dom->documentElement);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function remove_formatting($text)
+ {
+ return \s9e\TextFormatter\Unparser::removeFormatting($text);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function unparse($text)
+ {
+ return \s9e\TextFormatter\Unparser::unparse($text);
+ }
+}
diff --git a/phpBB/phpbb/textformatter/utils.php b/phpBB/phpbb/textformatter/utils.php
new file mode 100644
index 0000000000..c9bed94553
--- /dev/null
+++ b/phpBB/phpbb/textformatter/utils.php
@@ -0,0 +1,62 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+namespace phpbb\textformatter;
+
+/**
+* text_formatter.utils service
+*
+* Used to manipulate a parsed text
+*
+* @package phpBB3
+*/
+abstract class utils
+{
+ /**
+ * Replace BBCodes and other formatting elements with whitespace
+ *
+ * NOTE: preserves smilies as text
+ *
+ * @param string $text
+ * @return string
+ */
+ abstract public function clean_formatting($text);
+
+ /**
+ * Remove given BBCode at given nesting depth
+ *
+ * @param string $text Parsed text
+ * @param string $bbcode_name BBCode's name
+ * @param integer $depth Minimum nesting depth (number of parents of the same name)
+ * @return string
+ */
+ abstract public function remove_bbcode($text, $bbcode_name, $depth = 0);
+
+ /**
+ * Remove BBCodes and other formatting from a parsed text
+ *
+ * NOTE: preserves smilies as text
+ *
+ * @param string $text
+ * @return string
+ */
+ abstract public function remove_formatting($text);
+
+ /**
+ * Return a parsed text to its original form
+ *
+ * @param string $text
+ * @return string
+ */
+ abstract public function unparse($text);
+}
diff --git a/tests/notification/group_request_test.php b/tests/notification/group_request_test.php
index 0d532882c6..6a56a38c45 100644
--- a/tests/notification/group_request_test.php
+++ b/tests/notification/group_request_test.php
@@ -51,6 +51,7 @@ class phpbb_notification_group_request_test extends phpbb_tests_notification_bas
));
$phpbb_dispatcher = new phpbb_mock_event_dispatcher;
$phpbb_log = new \phpbb\log\null();
+ $this->get_test_case_helpers()->set_s9e_services();
// Now on to the actual test
diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php
index dee70ad016..d0b1573e61 100644
--- a/tests/test_framework/phpbb_test_case_helpers.php
+++ b/tests/test_framework/phpbb_test_case_helpers.php
@@ -11,6 +11,8 @@
*
*/
+use Symfony\Component\DependencyInjection\ContainerInterface;
+
class phpbb_test_case_helpers
{
protected $expectedTriggerError = false;
@@ -298,4 +300,212 @@ class phpbb_test_case_helpers
}
}
}
+
+ /**
+ * Set working instances of the text_formatter.* services
+ *
+ * If no container is passed, the global $phpbb_container will be used and/or
+ * created if applicable
+ *
+ * @param ContainerInterface $container Service container
+ * @param string $fixture Path to the XML fixture
+ * @param string $styles_path Path to the styles dir
+ * @return ContainerInterface
+ */
+ public function set_s9e_services(ContainerInterface $container = null, $fixture = null, $styles_path = null)
+ {
+ static $first_run;
+ global $phpbb_container, $phpbb_root_path, $phpEx;
+
+ $cache_dir = __DIR__ . '/../tmp/';
+
+ // Remove old cache files on first run
+ if (!isset($first_run))
+ {
+ $first_run = 1;
+
+ array_map('unlink', array_merge(
+ glob($cache_dir . 'data_s9e_*'),
+ glob($cache_dir . 's9e_*')
+ ));
+ }
+
+ if (!isset($container))
+ {
+ if (!isset($phpbb_container))
+ {
+ $phpbb_container = new phpbb_mock_container_builder;
+ }
+
+ $container = $phpbb_container;
+ }
+
+ if (!isset($fixture))
+ {
+ $fixture = __DIR__ . '/../text_formatter/s9e/fixtures/default_formatting.xml';
+ }
+
+ if (!isset($styles_path))
+ {
+ $styles_path = $phpbb_root_path . 'styles/';
+ }
+
+ $dataset = new DOMDocument;
+ $dataset->load($fixture);
+
+ $tables = array(
+ 'phpbb_bbcodes' => array(),
+ 'phpbb_smilies' => array(),
+ 'phpbb_styles' => array(),
+ 'phpbb_words' => array()
+ );
+ foreach ($dataset->getElementsByTagName('table') as $table)
+ {
+ $name = $table->getAttribute('name');
+ $columns = array();
+
+ foreach ($table->getElementsByTagName('column') as $column)
+ {
+ $columns[] = $column->textContent;
+ }
+
+ foreach ($table->getElementsByTagName('row') as $row)
+ {
+ $values = array();
+
+ foreach ($row->getElementsByTagName('value') as $value)
+ {
+ $values[] = $value->textContent;
+ }
+
+ $tables[$name][] = array_combine($columns, $values);
+ }
+ }
+
+ // Set up a default style if there's none set
+ if (empty($tables['phpbb_styles']))
+ {
+ $tables['phpbb_styles'][] = array(
+ 'style_id' => 1,
+ 'style_path' => 'prosilver',
+ 'bbcode_bitfield' => 'kNg='
+ );
+ }
+
+ // Mock the DAL, make it return data from the fixture
+ $mb = $this->test_case->getMockBuilder('phpbb\\textformatter\\data_access');
+ $mb->setMethods(array('get_bbcodes', 'get_smilies', 'get_styles', 'get_words'));
+ $mb->setConstructorArgs(array(
+ $this->test_case->getMock('phpbb\\db\\driver\\driver'),
+ 'phpbb_bbcodes',
+ 'phpbb_smilies',
+ 'phpbb_styles',
+ 'phpbb_words',
+ $styles_path
+ ));
+
+ $dal = $mb->getMock();
+ $container->set('text_formatter.data_access', $dal);
+
+ $dal->expects($this->test_case->any())
+ ->method('get_bbcodes')
+ ->will($this->test_case->returnValue($tables['phpbb_bbcodes']));
+ $dal->expects($this->test_case->any())
+ ->method('get_smilies')
+ ->will($this->test_case->returnValue($tables['phpbb_smilies']));
+ $dal->expects($this->test_case->any())
+ ->method('get_styles')
+ ->will($this->test_case->returnValue($tables['phpbb_styles']));
+ $dal->expects($this->test_case->any())
+ ->method('get_words')
+ ->will($this->test_case->returnValue($tables['phpbb_words']));
+
+ // Cache the parser and renderer with a key based on this method's arguments
+ $cache = new \phpbb\cache\driver\file($cache_dir);
+ $prefix = '_s9e_' . md5(serialize(func_get_args()));
+ $cache_key_parser = $prefix . '_parser';
+ $cache_key_renderer = $prefix . '_renderer';
+
+ // Create a path_helper
+ if (!$container->has('path_helper'))
+ {
+ $container->set(
+ 'path_helper',
+ new \phpbb\path_helper(
+ new \phpbb\symfony_request(
+ new phpbb_mock_request()
+ ),
+ new \phpbb\filesystem(),
+ $this->test_case->getMock('\phpbb\request\request'),
+ $phpbb_root_path,
+ $phpEx
+ )
+ );
+ }
+
+ // Create and register the text_formatter.s9e.factory service
+ $factory = new \phpbb\textformatter\s9e\factory($dal, $cache, $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
+ if ($container->has('user'))
+ {
+ $user = $container->get('user');
+ }
+ else
+ {
+ $user = new \phpbb\user('\phpbb\datetime');
+ $user->optionset('viewcensors', true);
+ $user->optionset('viewflash', true);
+ $user->optionset('viewimg', true);
+ $user->optionset('viewsmilies', true);
+ }
+ $user->add_lang('common');
+
+ if (!isset($user->style))
+ {
+ $user->style = array('style_id' => 1);
+ }
+
+ // Create and register the text_formatter.s9e.parser service and its alias
+ $parser = new \phpbb\textformatter\s9e\parser(
+ $cache,
+ $cache_key_parser,
+ $user,
+ $container
+ );
+
+ $container->set('text_formatter.parser', $parser);
+ $container->set('text_formatter.s9e.parser', $parser);
+
+ // Create and register the text_formatter.s9e.renderer service and its alias
+ $renderer = new \phpbb\textformatter\s9e\renderer(
+ $cache,
+ $cache_dir,
+ $cache_key_renderer,
+ $container
+ );
+
+ $root_path = ($container->hasParameter('core.root_path'))
+ ? $container->getParameter('core.root_path')
+ : './';
+ $config = ($container->has('config'))
+ ? $container->get('config')
+ : new \phpbb\config\config(array('smilies_path' => 'images/smilies', 'allow_nocensors' => false));
+ $auth = ($container->has('auth')) ? $container->get('auth') : new \phpbb\auth\auth;
+
+ // Calls configured in services.yml
+ $renderer->configure_smilies_path($config, $container->get('path_helper'));
+ $renderer->configure_user($user, $config, $auth);
+
+ $container->set('text_formatter.renderer', $renderer);
+ $container->set('text_formatter.s9e.renderer', $renderer);
+
+ // Create and register the text_formatter.s9e.utils service and its alias
+ $utils = new \phpbb\textformatter\s9e\utils;
+ $container->set('text_formatter.utils', $utils);
+ $container->set('text_formatter.s9e.utils', $utils);
+
+ return $container;
+ }
}
diff --git a/tests/text_formatter/s9e/default_formatting_test.php b/tests/text_formatter/s9e/default_formatting_test.php
new file mode 100644
index 0000000000..be258868dd
--- /dev/null
+++ b/tests/text_formatter/s9e/default_formatting_test.php
@@ -0,0 +1,200 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2013 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+require_once __DIR__ . '/../../../phpBB/includes/functions.php';
+require_once __DIR__ . '/../../../phpBB/includes/functions_content.php';
+
+class phpbb_textformatter_s9e_default_formatting_test extends phpbb_test_case
+{
+ /**
+ * @dataProvider get_default_formatting_tests
+ */
+ public function test_default_formatting($original, $expected)
+ {
+ $fixture = __DIR__ . '/fixtures/default_formatting.xml';
+ $container = $this->get_test_case_helpers()->set_s9e_services(null, $fixture);
+
+ $parser = $container->get('text_formatter.parser');
+ $renderer = $container->get('text_formatter.renderer');
+
+ $parsed_text = $parser->parse($original);
+
+ $this->assertSame($expected, $renderer->render($parsed_text));
+ }
+
+ public function get_default_formatting_tests()
+ {
+ return array(
+ array(
+ '[b]bold[/b]',
+ '<span style="font-weight: bold">bold</span>'
+ ),
+ array(
+ '[u]underlined[/u]',
+ '<span style="text-decoration: underline">underlined</span>'
+ ),
+ array(
+ '[i]italic[/i]',
+ '<span style="font-style: italic">italic</span>'
+ ),
+ array(
+ '[color=#FF0000]colored[/color]',
+ '<span style="color: #FF0000">colored</span>'
+ ),
+ array(
+ '[color=red]colored[/color]',
+ '<span style="color: red">colored</span>'
+ ),
+ array(
+ '[size=75]smaller[/size]',
+ '<span style="font-size: 75%; line-height: normal">smaller</span>'
+ ),
+ array(
+ '[quote]quoted[/quote]',
+ '<blockquote class="uncited"><div>quoted</div></blockquote>'
+ ),
+ array(
+ '[quote="username"]quoted[/quote]',
+ '<blockquote><div><cite>username wrote:</cite>quoted</div></blockquote>'
+ ),
+ array(
+ '[code]unparsed code[/code]',
+ '<div class="codebox"><p>CODE: <a href="#" onclick="selectCode(this); return false;">Select all</a></p><code>unparsed code</code></div>'
+ ),
+ array(
+ '[list]no item[/list]',
+ '<ul></ul>'
+ ),
+ array(
+ '[*]unparsed',
+ '[*]unparsed'
+ ),
+ array(
+ '[list][*]item[/list]',
+ '<ul><li>item</li></ul>'
+ ),
+ array(
+ '[list][*]item[/*][/list]',
+ '<ul><li>item</li></ul>'
+ ),
+ array(
+ '[list=1][*]item[/list]',
+ '<ol style="list-style-type: decimal"><li>item</li></ol>'
+ ),
+ array(
+ '[list=a][*]item[/list]',
+ '<ol style="list-style-type: lower-alpha"><li>item</li></ol>'
+ ),
+ array(
+ '[list=i][*]item[/list]',
+ '<ol style="list-style-type: lower-roman"><li>item</li></ol>'
+ ),
+ array(
+ '[list=I][*]item[/list]',
+ '<ol style="list-style-type: upper-roman"><li>item</li></ol>'
+ ),
+ array(
+ '[list=disc][*]item[/list]',
+ '<ul style="list-style-type: disc"><li>item</li></ul>'
+ ),
+ array(
+ '[list=circle][*]item[/list]',
+ '<ul style="list-style-type: circle"><li>item</li></ul>'
+ ),
+ array(
+ '[list=square][*]item[/list]',
+ '<ul style="list-style-type: square"><li>item</li></ul>'
+ ),
+ array(
+ '[img]https://area51.phpbb.com/images/area51.png[/img]',
+ '<img src="https://area51.phpbb.com/images/area51.png" alt="Image">'
+ ),
+ array(
+ '[url]https://area51.phpbb.com/[/url]',
+ '<a href="https://area51.phpbb.com/" class="postlink">https://area51.phpbb.com/</a>'
+ ),
+ array(
+ '[url=https://area51.phpbb.com/]Area51[/url]',
+ '<a href="https://area51.phpbb.com/" class="postlink">Area51</a>'
+ ),
+ array(
+ '[email]bbcode-test@phpbb.com[/email]',
+ '<a href="mailto:bbcode-test@phpbb.com">bbcode-test@phpbb.com</a>'
+ ),
+ array(
+ '[email=bbcode-test@phpbb.com]Email[/email]',
+ '<a href="mailto:bbcode-test@phpbb.com">Email</a>'
+ ),
+ array(
+ '[attachment=0]filename[/attachment]',
+ '<div class="inline-attachment"><!-- ia0 -->filename<!-- ia0 --></div>'
+ ),
+ array(
+ // PHPBB3-1401 - correct: parsed
+ '[quote="[test]test"]test [ test[/quote]',
+ '<blockquote><div><cite>[test]test wrote:</cite>test [ test</div></blockquote>'
+ ),
+ array(
+ // PHPBB3-6117 - correct: parsed
+ '[quote]test[/quote] test ] and [ test [quote]test[/quote]',
+ '<blockquote class="uncited"><div>test</div></blockquote> test ] and [ test <blockquote class="uncited"><div>test</div></blockquote>'
+ ),
+ array(
+ // PHPBB3-6200 - correct: parsed
+ '[quote="["]test[/quote]',
+ '<blockquote><div><cite>[ wrote:</cite>test</div></blockquote>'
+ ),
+ array(
+ // PHPBB3-9364 - quoted: "test[/[/b]quote] test" / non-quoted: "[/quote] test" - also failed if layout distorted
+ '[quote]test[/[/b]quote] test [/quote][/quote] test',
+ '<blockquote class="uncited"><div>test[/[/b]quote] test </div></blockquote>[/quote] test'
+ ),
+ array(
+ // PHPBB3-8096 - first quote tag parsed, second quote tag unparsed
+ '[quote="a"]a[/quote][quote="a]a[/quote]',
+ '<blockquote><div><cite>a wrote:</cite>a</div></blockquote>[quote="a]a[/quote]'
+ ),
+ array(
+ // Allow textual bbcodes in textual bbcodes
+ '[b]bold [i]bold + italic[/i][/b]',
+ '<span style="font-weight: bold">bold <span style="font-style: italic">bold + italic</span></span>'
+ ),
+ array(
+ // Allow textual bbcodes in url with description
+ '[url=https://area51.phpbb.com/]Area51 [i]italic[/i][/url]',
+ '<a href="https://area51.phpbb.com/" class="postlink">Area51 <span style="font-style: italic">italic</span></a>'
+ ),
+ array(
+ // Allow url with description in textual bbcodes
+ '[i]italic [url=https://area51.phpbb.com/]Area51[/url][/i]',
+ '<span style="font-style: italic">italic <a href="https://area51.phpbb.com/" class="postlink">Area51</a></span>'
+ ),
+ array(
+ // Do not parse textual bbcodes in code
+ '[code]unparsed code [b]bold [i]bold + italic[/i][/b][/code]',
+ '<div class="codebox"><p>CODE: <a href="#" onclick="selectCode(this); return false;">Select all</a></p><code>unparsed code [b]bold [i]bold + italic[/i][/b]</code></div>'
+ ),
+ array(
+ // Do not parse quote bbcodes in code
+ '[code]unparsed code [quote="username"]quoted[/quote][/code]',
+ '<div class="codebox"><p>CODE: <a href="#" onclick="selectCode(this); return false;">Select all</a></p><code>unparsed code [quote="username"]quoted[/quote]</code></div>'
+ ),
+/*
+ array(
+ // Textual bbcode nesting into textual bbcode
+ '[b]bold [i]bold + italic[/b] italic[/i]',
+ '<span style="font-weight: bold">bold <span style="font-style: italic">bold + italic</span></span><span style="font-style: italic"> italic</span>'
+ ),
+*/
+ array(
+ "[code]\tline1\n line2[/code]",
+ '<div class="codebox"><p>CODE: <a href="#" onclick="selectCode(this); return false;">Select all</a></p><code>&nbsp; &nbsp;line1<br>' . "\n" . '&nbsp; line2</code></div>'
+ ),
+ );
+ }
+}
diff --git a/tests/text_formatter/s9e/factory_test.php b/tests/text_formatter/s9e/factory_test.php
new file mode 100644
index 0000000000..2ea4b3031b
--- /dev/null
+++ b/tests/text_formatter/s9e/factory_test.php
@@ -0,0 +1,182 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2013 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+require_once __DIR__ . '/../../../phpBB/includes/functions.php';
+require_once __DIR__ . '/../../../phpBB/includes/functions_content.php';
+require_once __DIR__ . '/../../mock/user.php';
+require_once __DIR__ . '/../../mock/cache.php';
+require_once __DIR__ . '/../../test_framework/phpbb_database_test_case.php';
+
+class phpbb_textformatter_s9e_factory_test extends phpbb_database_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(__DIR__ . '/fixtures/factory.xml');
+ }
+
+ public function get_cache_dir()
+ {
+ return __DIR__ . '/../../tmp/';
+ }
+
+ public function get_factory()
+ {
+ global $phpbb_root_path;
+
+ $this->cache = new phpbb_mock_cache;
+
+ $dal = new \phpbb\textformatter\data_access(
+ $this->new_dbal(),
+ 'phpbb_bbcodes',
+ 'phpbb_smilies',
+ 'phpbb_styles',
+ 'phpbb_words',
+ $phpbb_root_path . 'styles/'
+ );
+
+ $factory = new \phpbb\textformatter\s9e\factory(
+ $dal,
+ $this->cache,
+ $this->get_cache_dir(),
+ '_foo_parser',
+ '_foo_renderer'
+ );
+
+ return $factory;
+ }
+
+ public function test_get_configurator()
+ {
+ $configurator = $this->get_factory()->get_configurator();
+
+ $this->assertInstanceOf('s9e\\TextFormatter\\Configurator', $configurator);
+
+ $this->assertTrue(isset($configurator->plugins['Autoemail']));
+ $this->assertTrue(isset($configurator->plugins['Autolink']));
+
+ $this->assertTrue(isset($configurator->BBCodes['B']));
+ $this->assertTrue(isset($configurator->BBCodes['CODE']));
+ $this->assertTrue(isset($configurator->BBCodes['COLOR']));
+ $this->assertTrue(isset($configurator->BBCodes['EMAIL']));
+ $this->assertTrue(isset($configurator->BBCodes['FLASH']));
+ $this->assertTrue(isset($configurator->BBCodes['I']));
+ $this->assertTrue(isset($configurator->BBCodes['IMG']));
+ $this->assertTrue(isset($configurator->BBCodes['LIST']));
+ $this->assertTrue(isset($configurator->BBCodes['*']));
+ $this->assertTrue(isset($configurator->BBCodes['QUOTE']));
+ $this->assertTrue(isset($configurator->BBCodes['SIZE']));
+ $this->assertTrue(isset($configurator->BBCodes['U']));
+ $this->assertTrue(isset($configurator->BBCodes['URL']));
+
+ // This custom BBCode should be set
+ $this->assertTrue(isset($configurator->BBCodes['CUSTOM']));
+
+ // This unsafe custom BBCode will trigger an exception and should be ignored
+ $this->assertFalse(isset($configurator->BBCodes['UNSAFE']));
+
+ $this->assertTrue(isset($configurator->Emoticons[':D']));
+ }
+
+ public function test_regenerate()
+ {
+ list($parser, $renderer) = $this->get_factory()->regenerate();
+
+ $this->assertInstanceOf('s9e\\TextFormatter\\Parser', $parser);
+ $this->assertInstanceOf('s9e\\TextFormatter\\Renderer', $renderer);
+
+ $this->assertEquals($parser, $this->cache->get('_foo_parser'), 'The parser was not cached');
+ $this->assertEquals(
+ array(
+ 'class' => get_class($renderer),
+ 'renderer' => serialize($renderer)
+ ),
+ $this->cache->get('_foo_renderer'),
+ 'The renderer was not cached'
+ );
+
+ $file = $this->get_cache_dir() . get_class($renderer) . '.php';
+ $this->assertFileExists($file);
+ unlink($file);
+ }
+
+ public function test_tidy()
+ {
+ $factory = $this->get_factory();
+
+ // Create a fake "old" cache file
+ $old_file = $this->get_cache_dir() . 's9e_foo.php';
+ touch($old_file);
+
+ // Create a current renderer
+ list($parser, $renderer) = $factory->regenerate();
+ $new_file = $this->get_cache_dir() . get_class($renderer) . '.php';
+
+ // Tidy the cache
+ $factory->tidy();
+
+ $this->assertFileExists($new_file, 'The current renderer has been deleted');
+ $this->assertFileNotExists($old_file, 'The old renderer has not been deleted');
+
+ unlink($new_file);
+ }
+
+ public function test_local_url()
+ {
+ global $config, $user, $request;
+
+ $config = array(
+ 'force_server_vars' => true,
+ 'server_protocol' => 'http://',
+ 'server_name' => 'path',
+ 'server_port' => 80,
+ 'script_path' => '/to',
+ 'cookie_secure' => false
+ );
+ $user = new phpbb_mock_user;
+ $request = new phpbb_mock_request;
+
+ $fixture = __DIR__ . '/fixtures/local_url.xml';
+ $renderer = $this->get_test_case_helpers()->set_s9e_services(null, $fixture)->get('text_formatter.renderer');
+
+ $this->assertSame(
+ '<a href="http://path/to/foo">http://path/to/foo</a>',
+ $renderer->render('<r><LOCAL content="foo"><s>[local]</s>foo<e>[/local]</e></LOCAL></r>')
+ );
+ }
+
+ public function test_smilies_special_chars()
+ {
+ // Use a smiley that contains every special chars in every field
+ $fixture = __DIR__ . '/fixtures/smilies_special_chars.xml';
+ $renderer = $this->get_test_case_helpers()->set_s9e_services(null, $fixture)->get('text_formatter.renderer');
+
+ $this->assertSame(
+ '<img class="smilies" src="phpBB/images/smilies/%22%27%3C&amp;%3E.png" alt="&quot;\'&lt;&amp;&gt;" title="&quot;\'&lt;&amp;&gt;">',
+ $renderer->render('<r><E>"\'&lt;&amp;&gt;</E></r>')
+ );
+ }
+
+ /**
+ * @testdox {INTTEXT} is supported in custom BBCodes
+ */
+ public function test_inttext_token()
+ {
+ $fixture = __DIR__ . '/fixtures/inttext_token.xml';
+ $container = $this->get_test_case_helpers()->set_s9e_services(null, $fixture);
+ $parser = $container->get('text_formatter.parser');
+ $renderer = $container->get('text_formatter.renderer');
+
+ $original = '[spoiler=ɎɆS]text[/spoiler]';
+ $expected = '<div class="spoiler"><div class="title">ɎɆS</div><div class="content">text</div></div>';
+ $this->assertSame($expected, $renderer->render($parser->parse($original)));
+
+ $original = '[spoiler=N:O:P:E]text[/spoiler]';
+ $expected = $original;
+ $this->assertSame($expected, $renderer->render($parser->parse($original)));
+ }
+}
diff --git a/tests/text_formatter/s9e/fixtures/default_formatting.xml b/tests/text_formatter/s9e/fixtures/default_formatting.xml
new file mode 100644
index 0000000000..2b7236fb30
--- /dev/null
+++ b/tests/text_formatter/s9e/fixtures/default_formatting.xml
@@ -0,0 +1,466 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_smilies">
+ <column>smiley_id</column>
+ <column>code</column>
+ <column>emotion</column>
+ <column>smiley_url</column>
+ <column>smiley_width</column>
+ <column>smiley_height</column>
+ <column>smiley_order</column>
+ <column>display_on_posting</column>
+ <row>
+ <value>1</value>
+ <value>:D</value>
+ <value>Very Happy</value>
+ <value>icon_e_biggrin.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>1</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>:-D</value>
+ <value>Very Happy</value>
+ <value>icon_e_biggrin.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>2</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>:grin:</value>
+ <value>Very Happy</value>
+ <value>icon_e_biggrin.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>3</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>:)</value>
+ <value>Smile</value>
+ <value>icon_e_smile.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>4</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>5</value>
+ <value>:-)</value>
+ <value>Smile</value>
+ <value>icon_e_smile.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>5</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>6</value>
+ <value>:smile:</value>
+ <value>Smile</value>
+ <value>icon_e_smile.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>6</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>7</value>
+ <value>;)</value>
+ <value>Wink</value>
+ <value>icon_e_wink.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>7</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>8</value>
+ <value>;-)</value>
+ <value>Wink</value>
+ <value>icon_e_wink.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>8</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>9</value>
+ <value>:wink:</value>
+ <value>Wink</value>
+ <value>icon_e_wink.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>9</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>10</value>
+ <value>:(</value>
+ <value>Sad</value>
+ <value>icon_e_sad.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>10</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>11</value>
+ <value>:-(</value>
+ <value>Sad</value>
+ <value>icon_e_sad.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>11</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>12</value>
+ <value>:sad:</value>
+ <value>Sad</value>
+ <value>icon_e_sad.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>12</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>13</value>
+ <value>:o</value>
+ <value>Surprised</value>
+ <value>icon_e_surprised.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>13</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>14</value>
+ <value>:-o</value>
+ <value>Surprised</value>
+ <value>icon_e_surprised.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>14</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>15</value>
+ <value>:eek:</value>
+ <value>Surprised</value>
+ <value>icon_e_surprised.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>15</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>16</value>
+ <value>:shock:</value>
+ <value>Shocked</value>
+ <value>icon_eek.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>16</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>17</value>
+ <value>:?</value>
+ <value>Confused</value>
+ <value>icon_e_confused.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>17</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>18</value>
+ <value>:-?</value>
+ <value>Confused</value>
+ <value>icon_e_confused.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>18</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>19</value>
+ <value>:???:</value>
+ <value>Confused</value>
+ <value>icon_e_confused.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>19</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>20</value>
+ <value>8-)</value>
+ <value>Cool</value>
+ <value>icon_cool.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>20</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>21</value>
+ <value>:cool:</value>
+ <value>Cool</value>
+ <value>icon_cool.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>21</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>22</value>
+ <value>:lol:</value>
+ <value>Laughing</value>
+ <value>icon_lol.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>22</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>23</value>
+ <value>:x</value>
+ <value>Mad</value>
+ <value>icon_mad.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>23</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>24</value>
+ <value>:-x</value>
+ <value>Mad</value>
+ <value>icon_mad.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>24</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>25</value>
+ <value>:mad:</value>
+ <value>Mad</value>
+ <value>icon_mad.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>25</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>26</value>
+ <value>:P</value>
+ <value>Razz</value>
+ <value>icon_razz.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>26</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>27</value>
+ <value>:-P</value>
+ <value>Razz</value>
+ <value>icon_razz.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>27</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>28</value>
+ <value>:razz:</value>
+ <value>Razz</value>
+ <value>icon_razz.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>28</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>29</value>
+ <value>:oops:</value>
+ <value>Embarrassed</value>
+ <value>icon_redface.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>29</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>30</value>
+ <value>:cry:</value>
+ <value>Crying or Very Sad</value>
+ <value>icon_cry.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>30</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>31</value>
+ <value>:evil:</value>
+ <value>Evil or Very Mad</value>
+ <value>icon_evil.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>31</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>32</value>
+ <value>:twisted:</value>
+ <value>Twisted Evil</value>
+ <value>icon_twisted.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>32</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>33</value>
+ <value>:roll:</value>
+ <value>Rolling Eyes</value>
+ <value>icon_rolleyes.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>33</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>34</value>
+ <value>:!:</value>
+ <value>Exclamation</value>
+ <value>icon_exclaim.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>34</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>35</value>
+ <value>:?:</value>
+ <value>Question</value>
+ <value>icon_question.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>35</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>36</value>
+ <value>:idea:</value>
+ <value>Idea</value>
+ <value>icon_idea.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>36</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>37</value>
+ <value>:arrow:</value>
+ <value>Arrow</value>
+ <value>icon_arrow.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>37</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>38</value>
+ <value>:|</value>
+ <value>Neutral</value>
+ <value>icon_neutral.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>38</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>39</value>
+ <value>:-|</value>
+ <value>Neutral</value>
+ <value>icon_neutral.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>39</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>40</value>
+ <value>:mrgreen:</value>
+ <value>Mr. Green</value>
+ <value>icon_mrgreen.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>40</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>41</value>
+ <value>:geek:</value>
+ <value>Geek</value>
+ <value>icon_e_geek.gif</value>
+ <value>17</value>
+ <value>17</value>
+ <value>41</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>42</value>
+ <value>:ugeek:</value>
+ <value>Uber Geek</value>
+ <value>icon_e_ugeek.gif</value>
+ <value>17</value>
+ <value>18</value>
+ <value>42</value>
+ <value>1</value>
+ </row>
+ </table>
+
+ <table name="phpbb_styles">
+ <column>style_id</column>
+ <column>style_name</column>
+ <column>style_copyright</column>
+ <column>style_active</column>
+ <column>style_path</column>
+ <column>bbcode_bitfield</column>
+ <column>style_parent_id</column>
+ <column>style_parent_tree</column>
+ <row>
+ <value>1</value>
+ <value>prosilver</value>
+ <value>&amp;copy; phpBB Group</value>
+ <value>1</value>
+ <value>prosilver</value>
+ <value>kNg=</value>
+ <value>0</value>
+ <value></value>
+ </row>
+ </table>
+
+ <table name="phpbb_words">
+ <column>word_id</column>
+ <column>word</column>
+ <column>replacement</column>
+
+ <row>
+ <value>1</value>
+ <value>apple</value>
+ <value>banana</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/text_formatter/s9e/fixtures/default_lang.xml b/tests/text_formatter/s9e/fixtures/default_lang.xml
new file mode 100644
index 0000000000..2cfde4aab2
--- /dev/null
+++ b/tests/text_formatter/s9e/fixtures/default_lang.xml
@@ -0,0 +1,20 @@
+<?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>
+
+ <row>
+ <value>13</value>
+ <value>foo</value>
+ <value></value>
+ <value>1</value>
+ <value>[foo]{TEXT}[/foo]</value>
+ <value>{L_FOO_BAR}</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/text_formatter/s9e/fixtures/factory.xml b/tests/text_formatter/s9e/fixtures/factory.xml
new file mode 100644
index 0000000000..9ae52e9747
--- /dev/null
+++ b/tests/text_formatter/s9e/fixtures/factory.xml
@@ -0,0 +1,115 @@
+<?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>custom</value>
+ <value></value>
+ <value>1</value>
+ <value>[custom]{TEXT}[/custom]</value>
+ <value>&lt;span style=&quot;color:red&quot;&gt;{TEXT}&lt;/span&gt;</value>
+ <value>!\[custom\](.*?)\[/custom\]!ies</value>
+ <value>'[custom:$uid]'.str_replace(array(&quot;\r\n&quot;, '\&quot;', '\'', '(', ')'), array(&quot;\n&quot;, '&quot;', '&amp;#39;', '&amp;#40;', '&amp;#41;'), trim('${1}')).'[/custom:$uid]'</value>
+ <value>!\[custom:$uid\](.*?)\[/custom:$uid\]!s</value>
+ <value>&lt;span style=&quot;color:red&quot;&gt;${1}&lt;/span&gt;</value>
+ </row>
+ <row>
+ <value>14</value>
+ <value>unsafe</value>
+ <value></value>
+ <value>1</value>
+ <value>[unsafe]{TEXT}[/unsafe]</value>
+ <value>&lt;script&gt;{TEXT}&lt;/script&gt;</value>
+ <value>!\[unsafe\](.*?)\[/unsafe\]!ies</value>
+ <value>'[unsafe:$uid]'.str_replace(array(&quot;\r\n&quot;, '\&quot;', '\'', '(', ')'), array(&quot;\n&quot;, '&quot;', '&amp;#39;', '&amp;#40;', '&amp;#41;'), trim('${1}')).'[/unsafe:$uid]'</value>
+ <value>!\[unsafe:$uid\](.*?)\[/unsafe:$uid\]!s</value>
+ <value>&lt;script&gt;${1}&lt;/script&gt;</value>
+ </row>
+ </table>
+
+ <table name="phpbb_smilies">
+ <column>smiley_id</column>
+ <column>code</column>
+ <column>emotion</column>
+ <column>smiley_url</column>
+ <column>smiley_width</column>
+ <column>smiley_height</column>
+ <column>smiley_order</column>
+ <column>display_on_posting</column>
+ <row>
+ <value>1</value>
+ <value>:D</value>
+ <value>Very Happy</value>
+ <value>icon_e_biggrin.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>2</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>:)</value>
+ <value>Smile</value>
+ <value>icon_e_smile.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>4</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>10</value>
+ <value>:(</value>
+ <value>Sad</value>
+ <value>icon_e_sad.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>10</value>
+ <value>1</value>
+ </row>
+ </table>
+
+ <table name="phpbb_styles">
+ <column>style_id</column>
+ <column>style_name</column>
+ <column>style_copyright</column>
+ <column>style_active</column>
+ <column>style_path</column>
+ <column>bbcode_bitfield</column>
+ <column>style_parent_id</column>
+ <column>style_parent_tree</column>
+
+ <row>
+ <value>1</value>
+ <value>prosilver</value>
+ <value>&amp;copy; phpBB Group</value>
+ <value>1</value>
+ <value>prosilver</value>
+ <value>kNg=</value>
+ <value>0</value>
+ <value></value>
+ </row>
+ </table>
+
+ <table name="phpbb_words">
+ <column>word_id</column>
+ <column>word</column>
+ <column>replacement</column>
+
+ <row>
+ <value>1</value>
+ <value>apple</value>
+ <value>banana</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/text_formatter/s9e/fixtures/inttext_token.xml b/tests/text_formatter/s9e/fixtures/inttext_token.xml
new file mode 100644
index 0000000000..30b971f315
--- /dev/null
+++ b/tests/text_formatter/s9e/fixtures/inttext_token.xml
@@ -0,0 +1,27 @@
+<?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>spoiler=</value>
+ <value></value>
+ <value>1</value>
+ <value>[spoiler={INTTEXT}]{TEXT}[/spoiler]</value>
+ <value><![CDATA[<div class="spoiler"><div class="title">{INTTEXT}</div><div class="content">{TEXT}</div></div>]]></value>
+ <value><![CDATA[!\[spoiler\=([\p{L}\p{N}\-+,_. ]+)\](.*?)\[/spoiler\]!iues]]></value>
+ <value><![CDATA['[spoiler=${1}:$uid]'.str_replace(array("\r\n", '\"', '\'', '(', ')'), array("\n", '"', '&#39;', '&#40;', '&#41;'), trim('${2}')).'[/spoiler:$uid]']]></value>
+ <value><![CDATA[!\[spoiler\=([\p{L}\p{N}\-+,_. ]+):$uid\](.*?)\[/spoiler:$uid\]!su]]></value><value><![CDATA[<div class="spoiler"><div class="title">${1}</div><div class="content">${2}</div></div>]]></value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/text_formatter/s9e/fixtures/local_url.xml b/tests/text_formatter/s9e/fixtures/local_url.xml
new file mode 100644
index 0000000000..9db2bf4710
--- /dev/null
+++ b/tests/text_formatter/s9e/fixtures/local_url.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>local</value>
+ <value></value>
+ <value>1</value>
+ <value>[local]{LOCAL_URL}[/local]</value>
+ <value><![CDATA[<a href="{LOCAL_URL}">{LOCAL_URL}</a>]]></value>
+ <value><![CDATA[!\[local\]((?:[a-z0-9\-._~\!$&'()*+,;=:@|]+|%[\dA-F]{2})*(?:/(?:[a-z0-9\-._~\!$&'()*+,;=:@|]+|%[\dA-F]{2})*)*(?:\?(?:[a-z0-9\-._~\!$&'()*+,;=:@/?|]+|%[\dA-F]{2})*)?(?:#(?:[a-z0-9\-._~\!$&'()*+,;=:@/?|]+|%[\dA-F]{2})*)?)\[/local\]!ie]]></value>
+ <value><![CDATA['[local:$uid]'.$this->bbcode_specialchars('${1}').'[/local:$uid]']]></value>
+ <value><![CDATA[!\[local:$uid\](?i)((?:[a-z0-9\-._~\!$&'()*+,;=:@|]+|%[\dA-F]{2})*(?:/(?:[a-z0-9\-._~\!$&'()*+,;=:@|]+|%[\dA-F]{2})*)*(?:\?(?:[a-z0-9\-._~\!$&'()*+,;=:@/?|]+|%[\dA-F]{2})*)?(?:#(?:[a-z0-9\-._~\!$&'()*+,;=:@/?|]+|%[\dA-F]{2})*)?)(?-i)\[/local:$uid\]!s]]></value>
+ <value><![CDATA[<a href="http://path/to/phpBB/${1}">http://path/to/phpBB/${1}</a>]]></value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/text_formatter/s9e/fixtures/smilies_special_chars.xml b/tests/text_formatter/s9e/fixtures/smilies_special_chars.xml
new file mode 100644
index 0000000000..d3a7cfa4f7
--- /dev/null
+++ b/tests/text_formatter/s9e/fixtures/smilies_special_chars.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_smilies">
+ <column>smiley_id</column>
+ <column>code</column>
+ <column>emotion</column>
+ <column>smiley_url</column>
+ <column>smiley_width</column>
+ <column>smiley_height</column>
+ <column>smiley_order</column>
+ <column>display_on_posting</column>
+ <row>
+ <value>1</value>
+ <value>"'&lt;&amp;&gt;</value>
+ <value>"'&lt;&amp;&gt;</value>
+ <value>"'&lt;&amp;&gt;.png</value>
+ <value>15</value>
+ <value>17</value>
+ <value>2</value>
+ <value>1</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/text_formatter/s9e/fixtures/style_inheritance.xml b/tests/text_formatter/s9e/fixtures/style_inheritance.xml
new file mode 100644
index 0000000000..a692d0ef2d
--- /dev/null
+++ b/tests/text_formatter/s9e/fixtures/style_inheritance.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_styles">
+ <column>style_id</column>
+ <column>style_name</column>
+ <column>style_copyright</column>
+ <column>style_active</column>
+ <column>style_path</column>
+ <column>bbcode_bitfield</column>
+ <column>style_parent_id</column>
+ <column>style_parent_tree</column>
+
+ <row>
+ <value>1</value>
+ <value>foo</value>
+ <value></value>
+ <value>1</value>
+ <value>foo</value>
+ <!-- Bitfield for "b" only -->
+ <value>QA==</value>
+ <value>0</value>
+ <value></value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>fooplus</value>
+ <value></value>
+ <value>1</value>
+ <value>fooplus</value>
+ <value>QA==</value>
+ <value>1</value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>fooplusplus</value>
+ <value></value>
+ <value>1</value>
+ <value>fooplusplus</value>
+ <value>QA==</value>
+ <value>2</value>
+ <value></value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>bar</value>
+ <value></value>
+ <value>1</value>
+ <value>bar</value>
+ <!-- Bitfield for "b" only -->
+ <value>QA==</value>
+ <value>0</value>
+ <value></value>
+ </row>
+ <row>
+ <value>5</value>
+ <value>barplus</value>
+ <value></value>
+ <value>1</value>
+ <value>barplus</value>
+ <value>QA==</value>
+ <value>4</value>
+ <value></value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/text_formatter/s9e/fixtures/styles.xml b/tests/text_formatter/s9e/fixtures/styles.xml
new file mode 100644
index 0000000000..8004412aea
--- /dev/null
+++ b/tests/text_formatter/s9e/fixtures/styles.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_styles">
+ <column>style_id</column>
+ <column>style_name</column>
+ <column>style_copyright</column>
+ <column>style_active</column>
+ <column>style_path</column>
+ <column>bbcode_bitfield</column>
+ <column>style_parent_id</column>
+ <column>style_parent_tree</column>
+
+ <row>
+ <value>1</value>
+ <value>foo</value>
+ <value></value>
+ <value>1</value>
+ <value>foo</value>
+ <!-- Bitfield for "b" only -->
+ <value>QA==</value>
+ <value>0</value>
+ <value></value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>bar</value>
+ <value></value>
+ <value>1</value>
+ <value>bar</value>
+ <!-- Bitfield for "b" only -->
+ <value>QA==</value>
+ <value>0</value>
+ <value></value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/text_formatter/s9e/fixtures/styles/bar/template/bbcode.html b/tests/text_formatter/s9e/fixtures/styles/bar/template/bbcode.html
new file mode 100644
index 0000000000..a17446581a
--- /dev/null
+++ b/tests/text_formatter/s9e/fixtures/styles/bar/template/bbcode.html
@@ -0,0 +1,40 @@
+<!-- BEGIN ulist_open --><ul style="list-style-type: {LIST_TYPE}"><!-- END ulist_open -->
+<!-- BEGIN ulist_open_default --><ul><!-- END ulist_open_default -->
+<!-- BEGIN ulist_close --></ul><!-- END ulist_close -->
+
+<!-- BEGIN olist_open --><ol style="list-style-type: {LIST_TYPE}"><!-- END olist_open -->
+<!-- BEGIN olist_close --></ol><!-- END olist_close -->
+
+<!-- BEGIN listitem --><li><!-- END listitem -->
+<!-- BEGIN listitem_close --></li><!-- END listitem_close -->
+
+<!-- BEGIN quote_username_open --><blockquote><div><cite>{USERNAME} {L_WROTE}{L_COLON}</cite><!-- END quote_username_open -->
+<!-- BEGIN quote_open --><blockquote class="uncited"><div><!-- END quote_open -->
+<!-- BEGIN quote_close --></div></blockquote><!-- END quote_close -->
+
+<!-- BEGIN code_open --><div class="codebox"><p>{L_CODE}{L_COLON} <a href="#" onclick="selectCode(this); return false;">{L_SELECT_ALL_CODE}</a></p><code><!-- END code_open -->
+<!-- BEGIN code_close --></code></div><!-- END code_close -->
+
+<!-- BEGIN inline_attachment_open --><div class="inline-attachment"><!-- END inline_attachment_open -->
+<!-- BEGIN inline_attachment_close --></div><!-- END inline_attachment_close -->
+
+<!-- BEGIN b_open --><b><!-- END b_open -->
+<!-- BEGIN b_close --></b><!-- END b_close -->
+
+<!-- BEGIN u_open --><span style="text-decoration: underline"><!-- END u_open -->
+<!-- BEGIN u_close --></span><!-- END u_close -->
+
+<!-- BEGIN i_open --><em><!-- END i_open -->
+<!-- BEGIN i_close --></em><!-- END i_close -->
+
+<!-- BEGIN color --><span style="color: {COLOR}">{TEXT}</span><!-- END color -->
+
+<!-- BEGIN size --><span style="font-size: {SIZE}%; line-height: 116%;">{TEXT}</span><!-- END size -->
+
+<!-- BEGIN img --><img src="{URL}" alt="{L_IMAGE}" /><!-- END img -->
+
+<!-- BEGIN url --><a href="{URL}" class="postlink">{DESCRIPTION}</a><!-- END url -->
+
+<!-- BEGIN email --><a href="mailto:{EMAIL}">{DESCRIPTION}</a><!-- END email -->
+
+<!-- BEGIN flash --><object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=5,0,0,0" width="{WIDTH}" height="{HEIGHT}"><param name="movie" value="{URL}" /><param name="play" value="false" /><param name="loop" value="false" /><param name="quality" value="high" /><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /><embed src="{URL}" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" width="{WIDTH}" height="{HEIGHT}" play="false" loop="false" quality="high" allowscriptaccess="never" allownetworking="internal"></embed></object><!-- END flash -->
diff --git a/tests/text_formatter/s9e/fixtures/styles/barplus/template/bbcode.html b/tests/text_formatter/s9e/fixtures/styles/barplus/template/bbcode.html
new file mode 100644
index 0000000000..cd2f0acae3
--- /dev/null
+++ b/tests/text_formatter/s9e/fixtures/styles/barplus/template/bbcode.html
@@ -0,0 +1,40 @@
+<!-- BEGIN ulist_open --><ul style="list-style-type: {LIST_TYPE}"><!-- END ulist_open -->
+<!-- BEGIN ulist_open_default --><ul><!-- END ulist_open_default -->
+<!-- BEGIN ulist_close --></ul><!-- END ulist_close -->
+
+<!-- BEGIN olist_open --><ol style="list-style-type: {LIST_TYPE}"><!-- END olist_open -->
+<!-- BEGIN olist_close --></ol><!-- END olist_close -->
+
+<!-- BEGIN listitem --><li><!-- END listitem -->
+<!-- BEGIN listitem_close --></li><!-- END listitem_close -->
+
+<!-- BEGIN quote_username_open --><blockquote><div><cite>{USERNAME} {L_WROTE}{L_COLON}</cite><!-- END quote_username_open -->
+<!-- BEGIN quote_open --><blockquote class="uncited"><div><!-- END quote_open -->
+<!-- BEGIN quote_close --></div></blockquote><!-- END quote_close -->
+
+<!-- BEGIN code_open --><div class="codebox"><p>{L_CODE}{L_COLON} <a href="#" onclick="selectCode(this); return false;">{L_SELECT_ALL_CODE}</a></p><code><!-- END code_open -->
+<!-- BEGIN code_close --></code></div><!-- END code_close -->
+
+<!-- BEGIN inline_attachment_open --><div class="inline-attachment"><!-- END inline_attachment_open -->
+<!-- BEGIN inline_attachment_close --></div><!-- END inline_attachment_close -->
+
+<!-- BEGIN b_open --><b class="barplus"><!-- END b_open -->
+<!-- BEGIN b_close --></b><!-- END b_close -->
+
+<!-- BEGIN u_open --><span style="text-decoration: underline"><!-- END u_open -->
+<!-- BEGIN u_close --></span><!-- END u_close -->
+
+<!-- BEGIN i_open --><em><!-- END i_open -->
+<!-- BEGIN i_close --></em><!-- END i_close -->
+
+<!-- BEGIN color --><span style="color: {COLOR}">{TEXT}</span><!-- END color -->
+
+<!-- BEGIN size --><span style="font-size: {SIZE}%; line-height: 116%;">{TEXT}</span><!-- END size -->
+
+<!-- BEGIN img --><img src="{URL}" alt="{L_IMAGE}" /><!-- END img -->
+
+<!-- BEGIN url --><a href="{URL}" class="postlink">{DESCRIPTION}</a><!-- END url -->
+
+<!-- BEGIN email --><a href="mailto:{EMAIL}">{DESCRIPTION}</a><!-- END email -->
+
+<!-- BEGIN flash --><object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=5,0,0,0" width="{WIDTH}" height="{HEIGHT}"><param name="movie" value="{URL}" /><param name="play" value="false" /><param name="loop" value="false" /><param name="quality" value="high" /><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /><embed src="{URL}" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" width="{WIDTH}" height="{HEIGHT}" play="false" loop="false" quality="high" allowscriptaccess="never" allownetworking="internal"></embed></object><!-- END flash -->
diff --git a/tests/text_formatter/s9e/fixtures/styles/foo/template/bbcode.html b/tests/text_formatter/s9e/fixtures/styles/foo/template/bbcode.html
new file mode 100644
index 0000000000..909c09df5a
--- /dev/null
+++ b/tests/text_formatter/s9e/fixtures/styles/foo/template/bbcode.html
@@ -0,0 +1,40 @@
+<!-- BEGIN ulist_open --><ul style="list-style-type: {LIST_TYPE}"><!-- END ulist_open -->
+<!-- BEGIN ulist_open_default --><ul><!-- END ulist_open_default -->
+<!-- BEGIN ulist_close --></ul><!-- END ulist_close -->
+
+<!-- BEGIN olist_open --><ol style="list-style-type: {LIST_TYPE}"><!-- END olist_open -->
+<!-- BEGIN olist_close --></ol><!-- END olist_close -->
+
+<!-- BEGIN listitem --><li><!-- END listitem -->
+<!-- BEGIN listitem_close --></li><!-- END listitem_close -->
+
+<!-- BEGIN quote_username_open --><blockquote><div><cite>{USERNAME} {L_WROTE}{L_COLON}</cite><!-- END quote_username_open -->
+<!-- BEGIN quote_open --><blockquote class="uncited"><div><!-- END quote_open -->
+<!-- BEGIN quote_close --></div></blockquote><!-- END quote_close -->
+
+<!-- BEGIN code_open --><div class="codebox"><p>{L_CODE}{L_COLON} <a href="#" onclick="selectCode(this); return false;">{L_SELECT_ALL_CODE}</a></p><code><!-- END code_open -->
+<!-- BEGIN code_close --></code></div><!-- END code_close -->
+
+<!-- BEGIN inline_attachment_open --><div class="inline-attachment"><!-- END inline_attachment_open -->
+<!-- BEGIN inline_attachment_close --></div><!-- END inline_attachment_close -->
+
+<!-- BEGIN b_open --><strong><!-- END b_open -->
+<!-- BEGIN b_close --></strong><!-- END b_close -->
+
+<!-- BEGIN u_open --><span style="text-decoration: underline"><!-- END u_open -->
+<!-- BEGIN u_close --></span><!-- END u_close -->
+
+<!-- BEGIN i_open --><em><!-- END i_open -->
+<!-- BEGIN i_close --></em><!-- END i_close -->
+
+<!-- BEGIN color --><span style="color: {COLOR}">{TEXT}</span><!-- END color -->
+
+<!-- BEGIN size --><span style="font-size: {SIZE}%; line-height: 116%;">{TEXT}</span><!-- END size -->
+
+<!-- BEGIN img --><img src="{URL}" alt="{L_IMAGE}" /><!-- END img -->
+
+<!-- BEGIN url --><a href="{URL}" class="postlink">{DESCRIPTION}</a><!-- END url -->
+
+<!-- BEGIN email --><a href="mailto:{EMAIL}">{DESCRIPTION}</a><!-- END email -->
+
+<!-- BEGIN flash --><object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=5,0,0,0" width="{WIDTH}" height="{HEIGHT}"><param name="movie" value="{URL}" /><param name="play" value="false" /><param name="loop" value="false" /><param name="quality" value="high" /><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /><embed src="{URL}" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" width="{WIDTH}" height="{HEIGHT}" play="false" loop="false" quality="high" allowscriptaccess="never" allownetworking="internal"></embed></object><!-- END flash -->
diff --git a/tests/text_formatter/s9e/parser_test.php b/tests/text_formatter/s9e/parser_test.php
new file mode 100644
index 0000000000..528305a11c
--- /dev/null
+++ b/tests/text_formatter/s9e/parser_test.php
@@ -0,0 +1,162 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2013 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+require_once __DIR__ . '/../../../phpBB/includes/functions.php';
+require_once __DIR__ . '/../../mock/user.php';
+require_once __DIR__ . '/../../mock/cache.php';
+
+class phpbb_textformatter_s9e_parser_test extends phpbb_test_case
+{
+ public function test_load_from_cache()
+ {
+ $mock = $this->getMockBuilder('s9e\\TextFormatter\\Parser')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $cache = $this->getMock('phpbb_mock_cache');
+ $cache->expects($this->once())
+ ->method('get')
+ ->with('_foo_parser')
+ ->will($this->returnValue($mock));
+
+ $parser = new \phpbb\textformatter\s9e\parser(
+ $cache,
+ '_foo_parser',
+ $this->getMockBuilder('phpbb\\user')->disableOriginalConstructor()->getMock(),
+ new phpbb_mock_container_builder
+ );
+ }
+
+ public function test_use_from_cache()
+ {
+ $mock = $this->getMockBuilder('s9e\\TextFormatter\\Parser')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $mock->expects($this->once())
+ ->method('parse')
+ ->with('test')
+ ->will($this->returnValue('<t>test</t>'));
+
+ $cache = new phpbb_mock_cache;
+ $cache->put('_foo_parser', $mock);
+
+ $parser = new \phpbb\textformatter\s9e\parser(
+ $cache,
+ '_foo_parser',
+ $this->getMockBuilder('phpbb\\user')->disableOriginalConstructor()->getMock(),
+ new phpbb_mock_container_builder
+ );
+
+ $this->assertSame('<t>test</t>', $parser->parse('test'));
+ }
+
+ public function test_regenerate_on_cache_miss()
+ {
+ $mock = $this->getMockBuilder('s9e\\TextFormatter\\Parser')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $mock->expects($this->once())
+ ->method('parse')
+ ->with('test')
+ ->will($this->returnValue('<t>test</t>'));
+
+ $factory = $this->getMock('stdClass', array('regenerate'));
+ $factory->expects($this->once())
+ ->method('regenerate')
+ ->will($this->returnValue(array($mock, false)));
+
+ $container = new phpbb_mock_container_builder;
+ $container->set('text_formatter.s9e.factory', $factory);
+
+ $parser = new \phpbb\textformatter\s9e\parser(
+ new phpbb_mock_cache,
+ '_foo_parser',
+ $this->getMockBuilder('phpbb\\user')->disableOriginalConstructor()->getMock(),
+ $container
+ );
+
+ $this->assertSame('<t>test</t>', $parser->parse('test'));
+ }
+
+ /**
+ * @dataProvider get_options_tests()
+ */
+ public function test_options($adapter_method, $adapter_arg, $concrete_method, $concrete_arg)
+ {
+ $mock = $this->getMockBuilder('s9e\\TextFormatter\\Parser')
+ ->setMethods(array($concrete_method))
+ ->disableOriginalConstructor()
+ ->getMock();
+ foreach ((array) $concrete_arg as $i => $concrete_arg)
+ {
+ $mock->expects($this->at($i))
+ ->method($concrete_method)
+ ->with($concrete_arg);
+ }
+
+ $cache = new phpbb_mock_cache;
+ $cache->put('_foo_parser', $mock);
+
+ $parser = new \phpbb\textformatter\s9e\parser(
+ $cache,
+ '_foo_parser',
+ $this->getMockBuilder('phpbb\\user')->disableOriginalConstructor()->getMock(),
+ new phpbb_mock_container_builder
+ );
+
+ call_user_func_array(array($parser, $adapter_method), (array) $adapter_arg);
+ }
+
+ public function get_options_tests()
+ {
+ return array(
+ array(
+ 'disable_bbcode', 'url',
+ 'disableTag', 'URL'
+ ),
+ array(
+ 'disable_bbcodes', null,
+ 'disablePlugin', 'BBCodes'
+ ),
+ array(
+ 'disable_censor', null,
+ 'disablePlugin', 'Censor'
+ ),
+ array(
+ 'disable_magic_url', null,
+ 'disablePlugin', array('Autoemail', 'Autolink')
+ ),
+ array(
+ 'disable_smilies', null,
+ 'disablePlugin', 'Emoticons'
+ ),
+ array(
+ 'enable_bbcode', 'url',
+ 'enableTag', 'URL'
+ ),
+ array(
+ 'enable_bbcodes', null,
+ 'enablePlugin', 'BBCodes'
+ ),
+ array(
+ 'enable_censor', null,
+ 'enablePlugin', 'Censor'
+ ),
+ array(
+ 'enable_magic_url', null,
+ 'enablePlugin', array('Autoemail', 'Autolink')
+ ),
+ array(
+ 'enable_smilies', null,
+ 'enablePlugin', 'Emoticons'
+ )
+ );
+ }
+}
diff --git a/tests/text_formatter/s9e/renderer_test.php b/tests/text_formatter/s9e/renderer_test.php
new file mode 100644
index 0000000000..76babbfdf3
--- /dev/null
+++ b/tests/text_formatter/s9e/renderer_test.php
@@ -0,0 +1,355 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2013 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+require_once __DIR__ . '/../../../phpBB/includes/functions.php';
+require_once __DIR__ . '/../../../phpBB/includes/functions_content.php';
+require_once __DIR__ . '/../../mock/cache.php';
+
+class phpbb_textformatter_s9e_renderer_test extends phpbb_test_case
+{
+ public function get_cache_dir()
+ {
+ return __DIR__ . '/../../tmp/';
+ }
+
+ public function test_load_from_cache()
+ {
+ // Save a fake renderer class in the cache dir
+ file_put_contents(
+ $this->get_cache_dir() . 'renderer_foo.php',
+ '<?php class renderer_foo { public function setParameter() {} }'
+ );
+
+ $mock = $this->getMockForAbstractClass('s9e\\TextFormatter\\Renderer');
+
+ $cache = $this->getMock('phpbb_mock_cache');
+ $cache->expects($this->once())
+ ->method('get')
+ ->with('_foo_renderer')
+ ->will($this->returnValue(array('class' => 'renderer_foo', 'renderer' => serialize($mock))));
+
+ $container = new phpbb_mock_container_builder;
+ $container->set('text_formatter.s9e.factory', $factory);
+
+ $renderer = new \phpbb\textformatter\s9e\renderer(
+ $cache,
+ $this->get_cache_dir(),
+ '_foo_renderer',
+ $container
+ );
+ }
+
+ public function test_regenerate_on_cache_miss()
+ {
+ $mock = $this->getMockForAbstractClass('s9e\\TextFormatter\\Renderer');
+
+ $cache = $this->getMock('phpbb_mock_cache');
+ $cache->expects($this->once())
+ ->method('get')
+ ->with('_foo_renderer')
+ ->will($this->returnValue(false));
+
+ $factory = $this->getMock('stdClass', array('regenerate'));
+ $factory->expects($this->once())
+ ->method('regenerate')
+ ->will($this->returnValue(array($mock, false)));
+
+ $container = new phpbb_mock_container_builder;
+ $container->set('text_formatter.s9e.factory', $factory);
+
+ $renderer = new \phpbb\textformatter\s9e\renderer(
+ $cache,
+ $this->get_cache_dir(),
+ '_foo_renderer',
+ $container
+ );
+ }
+
+ /**
+ * @dataProvider get_options_cases
+ */
+ public function test_options($original, $expected, $calls)
+ {
+ $container = new phpbb_mock_container_builder;
+ $this->get_test_case_helpers()->set_s9e_services($container);
+
+ $renderer = $container->get('text_formatter.renderer');
+
+ foreach ($calls as $method => $arg)
+ {
+ $renderer->$method($arg);
+ }
+
+ $this->assertSame($expected, $renderer->render($original));
+ }
+
+ public function get_options_cases()
+ {
+ return array(
+ array(
+ '<r><CENSOR with="banana">apple</CENSOR></r>',
+ 'banana',
+ array('set_viewcensors' => true)
+ ),
+ array(
+ '<r><CENSOR with="banana">apple</CENSOR></r>',
+ 'apple',
+ array('set_viewcensors' => false)
+ ),
+ array(
+ '<r><FLASH height="456" url="http://example.org/foo.swf" width="123"><s>[flash=123,456]</s><URL url="http://example.org/foo.swf">http://example.org/foo.swf</URL><e>[/flash]</e></FLASH></r>',
+ '<object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=5,0,0,0" width="123" height="456"><param name="movie" value="http://example.org/foo.swf"><param name="play" value="false"><param name="loop" value="false"><param name="quality" value="high"><param name="allowScriptAccess" value="never"><param name="allowNetworking" value="internal"><embed src="http://example.org/foo.swf" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" width="123" height="456" play="false" loop="false" quality="high" allowscriptaccess="never" allownetworking="internal"></object>',
+ array('set_viewflash' => true)
+ ),
+ array(
+ '<r><IMG src="http://example.org/foo.png"><s>[img]</s>http://example.org/foo.png<e>[/img]</e></IMG></r>',
+ '<img src="http://example.org/foo.png" alt="Image">',
+ array('set_viewimg' => true)
+ ),
+ array(
+ '<r><E>:)</E></r>',
+ '<img class="smilies" src="phpBB/images/smilies/icon_e_smile.gif" alt=":)" title="Smile">',
+ array('set_viewsmilies' => true)
+ ),
+ array(
+ '<r><E>:)</E></r>',
+ ':)',
+ array('set_viewsmilies' => false)
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider get_default_options_cases
+ */
+ public function test_default_options($original, $expected, $setup = null)
+ {
+ $container = new phpbb_mock_container_builder;
+
+ if (isset($setup))
+ {
+ $setup($container, $this);
+ }
+
+ $this->get_test_case_helpers()->set_s9e_services($container);
+
+ $this->assertSame($expected, $container->get('text_formatter.renderer')->render($original));
+ }
+
+ public function get_default_options_cases()
+ {
+ return array(
+ array(
+ '<r><CENSOR with="banana">apple</CENSOR></r>',
+ 'banana'
+ ),
+ array(
+ '<r><CENSOR with="banana">apple</CENSOR></r>',
+ 'banana',
+ function ($phpbb_container)
+ {
+ $user = new \phpbb\user('\\phpbb\\datetime');
+ $user->optionset('viewcensors', false);
+
+ $phpbb_container->set('user', $user);
+ }
+ ),
+ array(
+ '<r><CENSOR with="banana">apple</CENSOR></r>',
+ 'banana',
+ function ($phpbb_container)
+ {
+ $user = new \phpbb\user('\\phpbb\\datetime');
+ $user->optionset('viewcensors', false);
+
+ $config = new \phpbb\config\config(array('allow_nocensors' => true));
+
+ $phpbb_container->set('user', $user);
+ $phpbb_container->set('config', $config);
+ }
+ ),
+ array(
+ '<r><CENSOR with="banana">apple</CENSOR></r>',
+ 'apple',
+ function ($phpbb_container, $test)
+ {
+ $user = new \phpbb\user('\\phpbb\\datetime');
+ $user->optionset('viewcensors', false);
+
+ $config = new \phpbb\config\config(array('allow_nocensors' => true));
+
+ $auth = $test->getMock('phpbb\\auth\\auth');
+ $auth->expects($test->any())
+ ->method('acl_get')
+ ->with('u_chgcensors')
+ ->will($test->returnValue(true));
+
+ $phpbb_container->set('user', $user);
+ $phpbb_container->set('config', $config);
+ $phpbb_container->set('auth', $auth);
+ }
+ ),
+ array(
+ '<r><FLASH url="http://localhost/foo.swf" width="123" height="456"><s>[flash=123,456]</s>http://localhost/foo.swf<e>[/flash]</e></FLASH></r>',
+ '<object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=5,0,0,0" width="123" height="456"><param name="movie" value="http://localhost/foo.swf"><param name="play" value="false"><param name="loop" value="false"><param name="quality" value="high"><param name="allowScriptAccess" value="never"><param name="allowNetworking" value="internal"><embed src="http://localhost/foo.swf" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" width="123" height="456" play="false" loop="false" quality="high" allowscriptaccess="never" allownetworking="internal"></object>'
+ ),
+ array(
+ '<r><FLASH url="http://localhost/foo.swf" width="123" height="456"><s>[flash=123,456]</s>http://localhost/foo.swf<e>[/flash]</e></FLASH></r>',
+ 'http://localhost/foo.swf',
+ function ($phpbb_container)
+ {
+ $user = new \phpbb\user('\\phpbb\\datetime');
+ $user->optionset('viewflash', false);
+
+ $phpbb_container->set('user', $user);
+ }
+ ),
+ array(
+ '<r><IMG src="http://localhost/mrgreen.gif"><s>[img]</s><URL url="http://localhost/mrgreen.gif">http://localhost/mrgreen.gif</URL><e>[/img]</e></IMG></r>',
+ '<img src="http://localhost/mrgreen.gif" alt="Image">'
+ ),
+ array(
+ '<r><IMG src="http://localhost/mrgreen.gif"><s>[img]</s><URL url="http://localhost/mrgreen.gif">http://localhost/mrgreen.gif</URL><e>[/img]</e></IMG></r>',
+ '<a href="http://localhost/mrgreen.gif" class="postlink">http://localhost/mrgreen.gif</a>',
+ function ($phpbb_container)
+ {
+ $user = new \phpbb\user('\\phpbb\\datetime');
+ $user->optionset('viewimg', false);
+
+ $phpbb_container->set('user', $user);
+ }
+ ),
+ array(
+ '<r><E>:)</E></r>',
+ '<img class="smilies" src="phpBB/images/smilies/icon_e_smile.gif" alt=":)" title="Smile">'
+ ),
+ array(
+ '<r><E>:)</E></r>',
+ ':)',
+ function ($phpbb_container)
+ {
+ $user = new \phpbb\user('\\phpbb\\datetime');
+ $user->optionset('smilies', false);
+
+ $phpbb_container->set('user', $user);
+ }
+ ),
+ );
+ }
+
+ public function test_default_lang()
+ {
+ global $phpbb_container;
+ $this->get_test_case_helpers()->set_s9e_services($phpbb_container, __DIR__ . '/fixtures/default_lang.xml');
+
+ $renderer = $phpbb_container->get('text_formatter.renderer');
+
+ $this->assertSame('FOO_BAR', $renderer->render('<r><FOO/></r>'));
+ }
+
+ /**
+ * @dataProvider get_option_names
+ */
+ public function test_get_option($option_name)
+ {
+ global $phpbb_container;
+ $this->get_test_case_helpers()->set_s9e_services();
+
+ $renderer = $phpbb_container->get('text_formatter.renderer');
+
+ $renderer->{'set_' . $option_name}(false);
+ $this->assertFalse($renderer->{'get_' . $option_name}());
+ $renderer->{'set_' . $option_name}(true);
+ $this->assertTrue($renderer->{'get_' . $option_name}());
+ }
+
+ public function get_option_names()
+ {
+ return array(
+ array('viewcensors'),
+ array('viewflash'),
+ array('viewimg'),
+ array('viewsmilies')
+ );
+ }
+
+ public function test_styles()
+ {
+ global $phpbb_container;
+
+ $tests = array(
+ 1 => '<strong>bold</strong>',
+ 2 => '<b>bold</b>'
+ );
+
+ foreach ($tests as $style_id => $expected)
+ {
+ $user = new \phpbb\user('\\phpbb\\datetime');
+ $user->style = array('style_id' => $style_id);
+
+ $phpbb_container = new phpbb_mock_container_builder;
+ $phpbb_container->set('user', $user);
+
+ $this->get_test_case_helpers()->set_s9e_services($phpbb_container, __DIR__ . '/fixtures/styles.xml', __DIR__ . '/fixtures/styles/');
+
+ $renderer = $phpbb_container->get('text_formatter.renderer');
+ $this->assertSame(
+ $expected,
+ $renderer->render('<r><B><s>[b]</s>bold<e>[/b]</e></B></r>')
+ );
+ }
+ }
+
+ public function test_style_inheritance1()
+ {
+ global $phpbb_container;
+
+ // Style 3 inherits from 2 which inherits from 1. Only style 1 has a bbcode.html
+ $user = new \phpbb\user('\\phpbb\\datetime');
+ $user->style = array('style_id' => 3);
+
+ $phpbb_container = new phpbb_mock_container_builder;
+ $phpbb_container->set('user', $user);
+
+ $this->get_test_case_helpers()->set_s9e_services($phpbb_container, __DIR__ . '/fixtures/style_inheritance.xml', __DIR__ . '/fixtures/styles/');
+
+ $renderer = $phpbb_container->get('text_formatter.renderer');
+ $this->assertSame(
+ '<strong>bold</strong>',
+ $renderer->render('<r><B><s>[b]</s>bold<e>[/b]</e></B></r>')
+ );
+ }
+
+ public function test_style_inheritance2()
+ {
+ global $phpbb_container;
+
+ // Style 5 inherits from 4, but both have a bbcode.html
+ $tests = array(
+ 4 => '<b>bold</b>',
+ 5 => '<b class="barplus">bold</b>'
+ );
+
+ foreach ($tests as $style_id => $expected)
+ {
+ $user = new \phpbb\user('\\phpbb\\datetime');
+ $user->style = array('style_id' => $style_id);
+
+ $phpbb_container = new phpbb_mock_container_builder;
+ $phpbb_container->set('user', $user);
+
+ $this->get_test_case_helpers()->set_s9e_services($phpbb_container, __DIR__ . '/fixtures/style_inheritance.xml', __DIR__ . '/fixtures/styles/');
+
+ $renderer = $phpbb_container->get('text_formatter.renderer');
+ $this->assertSame(
+ $expected,
+ $renderer->render('<r><B><s>[b]</s>bold<e>[/b]</e></B></r>')
+ );
+ }
+ }
+}
diff --git a/tests/text_formatter/s9e/utils_test.php b/tests/text_formatter/s9e/utils_test.php
new file mode 100644
index 0000000000..510beba817
--- /dev/null
+++ b/tests/text_formatter/s9e/utils_test.php
@@ -0,0 +1,157 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2013 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once __DIR__ . '/../../../phpBB/includes/functions.php';
+require_once __DIR__ . '/../../../phpBB/includes/functions_content.php';
+
+class phpbb_textformatter_s9e_utils_test extends phpbb_test_case
+{
+ /**
+ * @dataProvider get_unparse_tests
+ */
+ public function test_unparse($original, $expected)
+ {
+ $container = $this->get_test_case_helpers()->set_s9e_services();
+ $utils = $container->get('text_formatter.utils');
+
+ $this->assertSame($expected, $utils->unparse($original));
+ }
+
+ public function get_unparse_tests()
+ {
+ return array(
+ array(
+ '<t>Plain text</t>',
+ 'Plain text'
+ ),
+ array(
+ "<t>Multi<br/>\nline</t>",
+ "Multi\nline"
+ ),
+ array(
+ '<r><B><s>[b]</s>bold<e>[/b]</e></B></r>',
+ '[b]bold[/b]'
+ )
+ );
+ }
+
+ /**
+ * @dataProvider get_remove_formatting_tests
+ */
+ public function test_remove_formatting($original, $expected)
+ {
+ $container = $this->get_test_case_helpers()->set_s9e_services();
+ $utils = $container->get('text_formatter.utils');
+
+ $this->assertSame($expected, $utils->remove_formatting($original));
+ }
+
+ public function get_remove_formatting_tests()
+ {
+ return array(
+ array(
+ '<t>Plain text</t>',
+ 'Plain text'
+ ),
+ array(
+ "<t>Multi<br/>\nline</t>",
+ "Multi\nline"
+ ),
+ array(
+ '<r><B><s>[b]</s>bold<e>[/b]</e></B></r>',
+ 'bold'
+ )
+ );
+ }
+
+ /**
+ * @dataProvider get_clean_formatting_tests
+ */
+ public function test_clean_formatting($original, $expected)
+ {
+ $container = $this->get_test_case_helpers()->set_s9e_services();
+ $utils = $container->get('text_formatter.utils');
+
+ $this->assertSame($expected, $utils->clean_formatting($original));
+ }
+
+ public function get_clean_formatting_tests()
+ {
+ return array(
+ array(
+ '<t>Plain text</t>',
+ 'Plain text'
+ ),
+ array(
+ "<t>Multi<br/>\nline</t>",
+ "Multi\nline"
+ ),
+ array(
+ '<r><B><s>[b]</s>bold<e>[/b]</e></B></r>',
+ ' bold '
+ )
+ );
+ }
+
+ /**
+ * @dataProvider get_remove_bbcode_tests
+ */
+ public function test_remove_bbcode($original, $name, $depth, $expected)
+ {
+ $container = $this->get_test_case_helpers()->set_s9e_services();
+ $utils = $container->get('text_formatter.utils');
+
+ $this->assertSame($expected, $utils->remove_bbcode($original, $name, $depth));
+ }
+
+ public function get_remove_bbcode_tests()
+ {
+ return array(
+ array(
+ '<t>Plain text</t>',
+ 'b',
+ 1,
+ '<t>Plain text</t>'
+ ),
+ array(
+ '<r><QUOTE author="u0"><s>[quote="u0"]</s><QUOTE author="u1"><s>[quote="u1"]</s><QUOTE author="u2"><s>[quote="u2"]</s>q2<e>[/quote]</e></QUOTE>
+q1<e>[/quote]</e></QUOTE>
+q0<e>[/quote]</e></QUOTE>
+<B><s>[b]</s>bold<e>[/b]</e></B></r>',
+ 'quote',
+ 0,
+ '<r>
+<B><s>[b]</s>bold<e>[/b]</e></B></r>'
+ ),
+ array(
+ '<r><QUOTE author="u0"><s>[quote="u0"]</s><QUOTE author="u1"><s>[quote="u1"]</s><QUOTE author="u2"><s>[quote="u2"]</s>q2<e>[/quote]</e></QUOTE>
+q1<e>[/quote]</e></QUOTE>
+q0<e>[/quote]</e></QUOTE>
+<B><s>[b]</s>bold<e>[/b]</e></B></r>',
+ 'quote',
+ 1,
+ '<r><QUOTE author="u0"><s>[quote="u0"]</s>
+q0<e>[/quote]</e></QUOTE>
+<B><s>[b]</s>bold<e>[/b]</e></B></r>'
+ ),
+ array(
+ '<r><QUOTE author="u0"><s>[quote="u0"]</s><QUOTE author="u1"><s>[quote="u1"]</s><QUOTE author="u2"><s>[quote="u2"]</s>q2<e>[/quote]</e></QUOTE>
+q1<e>[/quote]</e></QUOTE>
+q0<e>[/quote]</e></QUOTE>
+<B><s>[b]</s>bold<e>[/b]</e></B></r>',
+ 'quote',
+ 2,
+ '<r><QUOTE author="u0"><s>[quote="u0"]</s><QUOTE author="u1"><s>[quote="u1"]</s>
+q1<e>[/quote]</e></QUOTE>
+q0<e>[/quote]</e></QUOTE>
+<B><s>[b]</s>bold<e>[/b]</e></B></r>'
+ ),
+ );
+ }
+}
diff --git a/tests/text_processing/decode_message_test.php b/tests/text_processing/decode_message_test.php
new file mode 100644
index 0000000000..855b3c6c57
--- /dev/null
+++ b/tests/text_processing/decode_message_test.php
@@ -0,0 +1,87 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php';
+
+class phpbb_text_processing_decode_message_test extends phpbb_test_case
+{
+ /**
+ * @dataProvider get_legacy_tests
+ */
+ public function test_legacy($original, $expected, $bbcode_uid = '')
+ {
+ $actual = $original;
+ decode_message($actual, $bbcode_uid);
+
+ $this->assertSame($expected, $actual);
+ }
+
+ public function get_legacy_tests()
+ {
+ return array(
+ array(
+ "&amp;&lt;&gt;&quot;'",
+ "&amp;&lt;&gt;&quot;'"
+ ),
+ array(
+ '<!-- s:) --><img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile" /><!-- s:) -->',
+ ':)'
+ ),
+ /**
+ * Fails as per PHPBB3-8420
+ * @link http://tracker.phpbb.com/browse/PHPBB3-8420
+ *
+ array(
+ '[url=http://example.com:2cpxwbdy]<!-- s:arrow: --><img src="{SMILIES_PATH}/icon_arrow.gif" alt=":arrow:" title="Arrow" /><!-- s:arrow: --> here[/url:2cpxwbdy]',
+ '[url=http://example.com] :arrow: here[/url]',
+ '2cpxwbdy'
+ ),
+ */
+ );
+ }
+
+ /**
+ * @dataProvider get_text_formatter_tests
+ */
+ public function test_text_formatter($original, $expected)
+ {
+ $this->get_test_case_helpers()->set_s9e_services();
+
+ $actual = $original;
+ decode_message($actual);
+
+ $this->assertSame($expected, $actual);
+ }
+
+ public function get_text_formatter_tests()
+ {
+ return array(
+ array(
+ "<t>&amp;&lt;&gt;\"'",
+ "&amp;&lt;&gt;&quot;'"
+ ),
+ array(
+ '<r><E>:)</E></r>',
+ ':)'
+ ),
+ array(
+ "<t>a<br/>\nb</t>",
+ "a\nb"
+ ),
+ /**
+ * @link http://tracker.phpbb.com/browse/PHPBB3-8420
+ */
+ array(
+ '<r><URL url="http://example.com"><s>[url=http://example.com]</s> <E>:arrow:</E> here<e>[/url]</e></URL></r>',
+ '[url=http://example.com] :arrow: here[/url]'
+ ),
+ );
+ }
+}
diff --git a/tests/text_processing/fixtures/empty.xml b/tests/text_processing/fixtures/empty.xml
new file mode 100644
index 0000000000..d8206ad124
--- /dev/null
+++ b/tests/text_processing/fixtures/empty.xml
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+</dataset>
diff --git a/tests/text_processing/fixtures/smilies.xml b/tests/text_processing/fixtures/smilies.xml
new file mode 100644
index 0000000000..25b2e60836
--- /dev/null
+++ b/tests/text_processing/fixtures/smilies.xml
@@ -0,0 +1,443 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_smilies">
+ <column>smiley_id</column>
+ <column>code</column>
+ <column>emotion</column>
+ <column>smiley_url</column>
+ <column>smiley_width</column>
+ <column>smiley_height</column>
+ <column>smiley_order</column>
+ <column>display_on_posting</column>
+ <row>
+ <value>1</value>
+ <value>:D</value>
+ <value>Very Happy</value>
+ <value>icon_e_biggrin.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>1</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>:-D</value>
+ <value>Very Happy</value>
+ <value>icon_e_biggrin.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>2</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>:grin:</value>
+ <value>Very Happy</value>
+ <value>icon_e_biggrin.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>3</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>:)</value>
+ <value>Smile</value>
+ <value>icon_e_smile.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>4</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>5</value>
+ <value>:-)</value>
+ <value>Smile</value>
+ <value>icon_e_smile.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>5</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>6</value>
+ <value>:smile:</value>
+ <value>Smile</value>
+ <value>icon_e_smile.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>6</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>7</value>
+ <value>;)</value>
+ <value>Wink</value>
+ <value>icon_e_wink.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>7</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>8</value>
+ <value>;-)</value>
+ <value>Wink</value>
+ <value>icon_e_wink.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>8</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>9</value>
+ <value>:wink:</value>
+ <value>Wink</value>
+ <value>icon_e_wink.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>9</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>10</value>
+ <value>:(</value>
+ <value>Sad</value>
+ <value>icon_e_sad.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>10</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>11</value>
+ <value>:-(</value>
+ <value>Sad</value>
+ <value>icon_e_sad.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>11</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>12</value>
+ <value>:sad:</value>
+ <value>Sad</value>
+ <value>icon_e_sad.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>12</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>13</value>
+ <value>:o</value>
+ <value>Surprised</value>
+ <value>icon_e_surprised.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>13</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>14</value>
+ <value>:-o</value>
+ <value>Surprised</value>
+ <value>icon_e_surprised.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>14</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>15</value>
+ <value>:eek:</value>
+ <value>Surprised</value>
+ <value>icon_e_surprised.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>15</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>16</value>
+ <value>:shock:</value>
+ <value>Shocked</value>
+ <value>icon_eek.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>16</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>17</value>
+ <value>:?</value>
+ <value>Confused</value>
+ <value>icon_e_confused.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>17</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>18</value>
+ <value>:-?</value>
+ <value>Confused</value>
+ <value>icon_e_confused.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>18</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>19</value>
+ <value>:???:</value>
+ <value>Confused</value>
+ <value>icon_e_confused.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>19</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>20</value>
+ <value>8-)</value>
+ <value>Cool</value>
+ <value>icon_cool.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>20</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>21</value>
+ <value>:cool:</value>
+ <value>Cool</value>
+ <value>icon_cool.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>21</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>22</value>
+ <value>:lol:</value>
+ <value>Laughing</value>
+ <value>icon_lol.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>22</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>23</value>
+ <value>:x</value>
+ <value>Mad</value>
+ <value>icon_mad.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>23</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>24</value>
+ <value>:-x</value>
+ <value>Mad</value>
+ <value>icon_mad.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>24</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>25</value>
+ <value>:mad:</value>
+ <value>Mad</value>
+ <value>icon_mad.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>25</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>26</value>
+ <value>:P</value>
+ <value>Razz</value>
+ <value>icon_razz.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>26</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>27</value>
+ <value>:-P</value>
+ <value>Razz</value>
+ <value>icon_razz.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>27</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>28</value>
+ <value>:razz:</value>
+ <value>Razz</value>
+ <value>icon_razz.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>28</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>29</value>
+ <value>:oops:</value>
+ <value>Embarrassed</value>
+ <value>icon_redface.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>29</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>30</value>
+ <value>:cry:</value>
+ <value>Crying or Very Sad</value>
+ <value>icon_cry.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>30</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>31</value>
+ <value>:evil:</value>
+ <value>Evil or Very Mad</value>
+ <value>icon_evil.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>31</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>32</value>
+ <value>:twisted:</value>
+ <value>Twisted Evil</value>
+ <value>icon_twisted.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>32</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>33</value>
+ <value>:roll:</value>
+ <value>Rolling Eyes</value>
+ <value>icon_rolleyes.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>33</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>34</value>
+ <value>:!:</value>
+ <value>Exclamation</value>
+ <value>icon_exclaim.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>34</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>35</value>
+ <value>:?:</value>
+ <value>Question</value>
+ <value>icon_question.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>35</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>36</value>
+ <value>:idea:</value>
+ <value>Idea</value>
+ <value>icon_idea.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>36</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>37</value>
+ <value>:arrow:</value>
+ <value>Arrow</value>
+ <value>icon_arrow.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>37</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>38</value>
+ <value>:|</value>
+ <value>Neutral</value>
+ <value>icon_neutral.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>38</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>39</value>
+ <value>:-|</value>
+ <value>Neutral</value>
+ <value>icon_neutral.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>39</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>40</value>
+ <value>:mrgreen:</value>
+ <value>Mr. Green</value>
+ <value>icon_mrgreen.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>40</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>41</value>
+ <value>:geek:</value>
+ <value>Geek</value>
+ <value>icon_e_geek.gif</value>
+ <value>17</value>
+ <value>17</value>
+ <value>41</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>42</value>
+ <value>:ugeek:</value>
+ <value>Uber Geek</value>
+ <value>icon_e_ugeek.gif</value>
+ <value>17</value>
+ <value>18</value>
+ <value>42</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>43</value>
+ <value>8)</value>
+ <value>8)</value>
+ <value>custom.gif</value>
+ <value>17</value>
+ <value>18</value>
+ <value>42</value>
+ <value>1</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/text_processing/generate_text_for_display_test.php b/tests/text_processing/generate_text_for_display_test.php
index 057416da33..fe83938c0b 100644
--- a/tests/text_processing/generate_text_for_display_test.php
+++ b/tests/text_processing/generate_text_for_display_test.php
@@ -11,10 +11,8 @@
*
*/
-require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
-require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php';
-require_once dirname(__FILE__) . '/../mock/user.php';
-require_once dirname(__FILE__) . '/../mock/cache.php';
+require_once __DIR__ . '/../../phpBB/includes/functions.php';
+require_once __DIR__ . '/../../phpBB/includes/functions_content.php';
class phpbb_text_processing_generate_text_for_display_test extends phpbb_test_case
{
@@ -24,21 +22,175 @@ class phpbb_text_processing_generate_text_for_display_test extends phpbb_test_ca
parent::setUp();
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher;
+ $config = new \phpbb\config\config(array());
+ set_config(null, null, null, $config);
+ }
+
+ /**
+ * @dataProvider get_legacy_tests
+ */
+ public function test_legacy($original, $expected, $uid = '', $bitfield = '', $flags = 0, $censor_text = true)
+ {
+ global $cache, $user;
+
$cache = new phpbb_mock_cache;
+ $user = new \phpbb\user('\\phpbb\\datetime');
+ $user->optionset('viewcensors', true);
+ $user->optionset('viewflash', true);
+ $user->optionset('viewimg', true);
+ $user->optionset('viewsmilies', true);
+
+ $actual = generate_text_for_display($original, $uid, $bitfield, $flags, $censor_text);
+
+ $this->assertSame($expected, $actual);
+ }
+
+ public function get_legacy_tests()
+ {
+ return array(
+ array(
+ '',
+ ''
+ ),
+ array(
+ '0',
+ '0'
+ ),
+ );
+ }
+
+ public function test_censor_is_restored()
+ {
+ global $phpbb_container;
+
+ $phpbb_container = new phpbb_mock_container_builder;
- $user = new phpbb_mock_user;
+ $user = new \phpbb\user('\\phpbb\\datetime');
$user->optionset('viewcensors', false);
- $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+ $config = new \phpbb\config\config(array('allow_nocensors' => true));
+
+ $auth = $this->getMock('phpbb\\auth\\auth');
+ $auth->expects($this->any())
+ ->method('acl_get')
+ ->with('u_chgcensors')
+ ->will($this->returnValue(true));
+
+ $phpbb_container->set('user', $user);
+ $phpbb_container->set('config', $config);
+ $phpbb_container->set('auth', $auth);
+
+ $this->get_test_case_helpers()->set_s9e_services($phpbb_container);
+ $renderer = $phpbb_container->get('text_formatter.renderer');
+
+ $original = '<r><CENSOR with="banana">apple</CENSOR></r>';
+
+ $renderer->set_viewcensors(false);
+ $this->assertSame('apple', $renderer->render($original));
+ $renderer->set_viewcensors(true);
+ $this->assertSame('banana', $renderer->render($original));
+ $this->assertSame('apple', generate_text_for_display($original, '', '', 0, false));
+ $this->assertSame('banana', $renderer->render($original), 'The original setting was not restored');
+
+ $renderer->set_viewcensors(false);
+ $this->assertSame('apple', $renderer->render($original));
+ $this->assertSame('banana', generate_text_for_display($original, '', '', 0, truee));
+ $this->assertSame('apple', $renderer->render($original), 'The original setting was not restored');
}
- public function test_empty_string()
+ /**
+ * @dataProvider get_text_formatter_tests
+ */
+ public function test_text_formatter($original, $expected, $censor_text = true, $setup = null)
{
- $this->assertSame('', generate_text_for_display('', '', '', 0));
+ global $phpbb_container;
+
+ $phpbb_container = new phpbb_mock_container_builder;
+
+ if (isset($setup))
+ {
+ $setup($phpbb_container, $this);
+ }
+
+ $this->get_test_case_helpers()->set_s9e_services($phpbb_container);
+
+ $this->assertSame($expected, generate_text_for_display($original, '', '', 0, $censor_text));
}
- public function test_zero_string()
+ public function get_text_formatter_tests()
{
- $this->assertSame('0', generate_text_for_display('0', '', '', 0));
+ return array(
+ array(
+ '<t>Plain text</t>',
+ 'Plain text'
+ ),
+ array(
+ '<r>Hello <URL url="http://example.org"><s>[url=http://example.org]</s>world<e>[/url]</e></URL></r>',
+ 'Hello <a href="http://example.org" class="postlink">world</a>'
+ ),
+ array(
+ '<t>&amp;&lt;&gt;"\'</t>',
+ '&amp;&lt;&gt;"\''
+ ),
+ array(
+ '<r><CENSOR with="banana">apple</CENSOR></r>',
+ 'banana',
+ true
+ ),
+ array(
+ '<r><CENSOR with="banana">apple</CENSOR></r>',
+ 'apple',
+ false
+ ),
+ array(
+ '<r><FLASH url="http://localhost/foo.swf" width="123" height="456"><s>[flash=123,456]</s>http://localhost/foo.swf<e>[/flash]</e></FLASH></r>',
+ '<object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=5,0,0,0" width="123" height="456"><param name="movie" value="http://localhost/foo.swf"><param name="play" value="false"><param name="loop" value="false"><param name="quality" value="high"><param name="allowScriptAccess" value="never"><param name="allowNetworking" value="internal"><embed src="http://localhost/foo.swf" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" width="123" height="456" play="false" loop="false" quality="high" allowscriptaccess="never" allownetworking="internal"></object>'
+ ),
+ array(
+ '<r><FLASH url="http://localhost/foo.swf" width="123" height="456"><s>[flash=123,456]</s>http://localhost/foo.swf<e>[/flash]</e></FLASH></r>',
+ 'http://localhost/foo.swf',
+ true,
+ function ($phpbb_container)
+ {
+ $user = new \phpbb\user('\\phpbb\\datetime');
+ $user->optionset('viewflash', false);
+
+ $phpbb_container->set('user', $user);
+ }
+ ),
+ array(
+ '<r><IMG src="http://localhost/mrgreen.gif"><s>[img]</s><URL url="http://localhost/mrgreen.gif">http://localhost/mrgreen.gif</URL><e>[/img]</e></IMG></r>',
+ '<img src="http://localhost/mrgreen.gif" alt="Image">'
+ ),
+ array(
+ '<r><IMG src="http://localhost/mrgreen.gif"><s>[img]</s><URL url="http://localhost/mrgreen.gif">http://localhost/mrgreen.gif</URL><e>[/img]</e></IMG></r>',
+ '<a href="http://localhost/mrgreen.gif" class="postlink">http://localhost/mrgreen.gif</a>',
+ true,
+ function ($phpbb_container)
+ {
+ $user = new \phpbb\user('\\phpbb\\datetime');
+ $user->optionset('viewimg', false);
+
+ $phpbb_container->set('user', $user);
+ }
+ ),
+ array(
+ '<r><E>:)</E></r>',
+ '<img class="smilies" src="phpBB/images/smilies/icon_e_smile.gif" alt=":)" title="Smile">'
+ ),
+ array(
+ '<r><E>:)</E></r>',
+ ':)',
+ true,
+ function ($phpbb_container)
+ {
+ $user = new \phpbb\user('\\phpbb\\datetime');
+ $user->optionset('smilies', false);
+
+ $phpbb_container->set('user', $user);
+ }
+ ),
+ );
}
}
diff --git a/tests/text_processing/generate_text_for_edit_test.php b/tests/text_processing/generate_text_for_edit_test.php
new file mode 100644
index 0000000000..85b3a6a0ab
--- /dev/null
+++ b/tests/text_processing/generate_text_for_edit_test.php
@@ -0,0 +1,90 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2013 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once __DIR__ . '/../../phpBB/includes/functions.php';
+require_once __DIR__ . '/../../phpBB/includes/functions_content.php';
+require_once __DIR__ . '/../mock/user.php';
+require_once __DIR__ . '/../mock/cache.php';
+
+class phpbb_text_processing_generate_text_for_edit_test extends phpbb_test_case
+{
+ /**
+ * @dataProvider get_legacy_tests
+ */
+ public function test_legacy($original, $expected, $uid = '', $flags = 0)
+ {
+ global $cache, $user, $phpbb_dispatcher;
+
+ $cache = new phpbb_mock_cache;
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher;
+
+ $user = new phpbb_mock_user;
+ $user->optionset('viewcensors', false);
+
+ $return = generate_text_for_edit($original, $uid, $flags);
+
+ $this->assertSame($expected, $return['text']);
+ }
+
+ public function get_legacy_tests()
+ {
+ return array(
+ array(
+ '',
+ ''
+ ),
+ array(
+ '0',
+ '0'
+ ),
+ array(
+ 'Hello [url=http&#58;//example&#46;org:1f4coh9x]world[/url:1f4coh9x] <!-- s:) --><img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile" /><!-- s:) -->',
+ 'Hello [url=http&#58;//example&#46;org]world[/url] :)',
+ '1f4coh9x',
+ 0
+ ),
+ array(
+ "&amp;&lt;&gt;&quot;'",
+ "&amp;&lt;&gt;&quot;'"
+ )
+ );
+ }
+
+ /**
+ * @dataProvider get_text_formatter_tests
+ */
+ public function test_text_formatter($original, $expected)
+ {
+ global $phpbb_dispatcher;
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher;
+ $this->get_test_case_helpers()->set_s9e_services();
+
+ $return = generate_text_for_edit($original, '', 0);
+
+ $this->assertSame($expected, $return['text']);
+ }
+
+ public function get_text_formatter_tests()
+ {
+ return array(
+ array(
+ '<t>Plain text</t>',
+ 'Plain text'
+ ),
+ array(
+ '<r>Hello <URL url="http://example.org"><s>[url=http://example.org]</s>world<e>[/url]</e></URL> <E>:)</E></r>',
+ 'Hello [url=http://example.org]world[/url] :)'
+ ),
+ array(
+ '<t>&amp;&lt;&gt;"\'</t>',
+ "&amp;&lt;&gt;&quot;'"
+ )
+ );
+ }
+}
diff --git a/tests/text_processing/generate_text_for_storage_test.php b/tests/text_processing/generate_text_for_storage_test.php
new file mode 100644
index 0000000000..0bacaacfb8
--- /dev/null
+++ b/tests/text_processing/generate_text_for_storage_test.php
@@ -0,0 +1,70 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2013 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once __DIR__ . '/../../phpBB/includes/functions.php';
+require_once __DIR__ . '/../../phpBB/includes/functions_content.php';
+require_once __DIR__ . '/../../phpBB/includes/utf/utf_tools.php';
+require_once __DIR__ . '/../mock/container_builder.php';
+
+class phpbb_text_processing_generate_text_for_storage_test extends phpbb_test_case
+{
+ public function setUp()
+ {
+ global $config, $phpbb_container, $phpbb_dispatcher;
+
+ parent::setUp();
+
+ $config = new \phpbb\config\config(array());
+ set_config(null, null, null, $config);
+
+ $phpbb_container = new phpbb_mock_container_builder;
+ $phpbb_container->set('config', $config);
+ $this->get_test_case_helpers()->set_s9e_services($phpbb_container);
+
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher;
+ }
+
+ /**
+ * @dataProvider get_text_formatter_tests
+ */
+ public function test_text_formatter($original, $expected, $allow_bbcode = true, $allow_urls = true, $allow_smilies = true, $setup = null)
+ {
+ $actual = $original;
+ $uid = '';
+ $bitfield = '';
+ $flags = 0;
+
+ if (isset($setup))
+ {
+ $setup();
+ }
+
+ generate_text_for_storage($actual, $uid, $bitfield, $flags, $allow_bbcode, $allow_urls, $allow_smilies);
+
+ $this->assertSame($expected, $actual);
+ }
+
+ public function get_text_formatter_tests()
+ {
+ return array(
+ array(
+ 'Hello world',
+ '<t>Hello world</t>'
+ ),
+ array(
+ 'Hello [url=http://example.org]world[/url] :)',
+ '<r>Hello <URL url="http://example.org"><s>[url=http://example.org]</s>world<e>[/url]</e></URL> <E>:)</E></r>'
+ ),
+ array(
+ '&<>"\'',
+ '<t>&amp;&lt;&gt;"\'</t>'
+ ),
+ );
+ }
+}
diff --git a/tests/text_processing/message_parser_test.php b/tests/text_processing/message_parser_test.php
new file mode 100644
index 0000000000..59af2553f8
--- /dev/null
+++ b/tests/text_processing/message_parser_test.php
@@ -0,0 +1,532 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once __DIR__ . '/../../phpBB/includes/bbcode.php';
+require_once __DIR__ . '/../../phpBB/includes/functions.php';
+require_once __DIR__ . '/../../phpBB/includes/functions_content.php';
+require_once __DIR__ . '/../../phpBB/includes/message_parser.php';
+require_once __DIR__ . '/../../phpBB/includes/utf/utf_tools.php';
+
+class phpbb_text_processing_message_parser_test extends phpbb_test_case
+{
+ public static function setUpBeforeClass()
+ {
+ parent::setUpBeforeClass();
+
+ // Set up an intercepting proxy for getimagesize() calls
+ stream_wrapper_unregister('http');
+ stream_wrapper_register('http', __CLASS__ . '_proxy');
+ }
+
+ public static function tearDownAfterClass()
+ {
+ parent::tearDownAfterClass();
+ stream_wrapper_restore('http');
+ }
+
+ protected function prepare_s9e_services($setup = null)
+ {
+ global $config, $phpbb_container, $user;
+
+ $config = new \phpbb\config\config(array('max_poll_options' => 999));
+
+ $map = array(
+ array('MAX_FLASH_HEIGHT_EXCEEDED', 123, 'Your flash files may only be up to 123 pixels high.'),
+ array('MAX_FLASH_WIDTH_EXCEEDED', 456, 'Your flash files may only be up to 456 pixels wide.'),
+ array('MAX_FONT_SIZE_EXCEEDED', 120, 'You may only use fonts up to size 120.'),
+ array('MAX_FONT_SIZE_EXCEEDED', 200, 'You may only use fonts up to size 200.'),
+ array('MAX_IMG_HEIGHT_EXCEEDED', 12, 'Your images may only be up to 12 pixels high.'),
+ array('MAX_IMG_WIDTH_EXCEEDED', 34, 'Your images may only be up to 34 pixels wide.'),
+ array('TOO_MANY_SMILIES', 3, 'Your message contains too many smilies. The maximum number of smilies allowed is 3.'),
+ array('TOO_MANY_URLS', 2, 'Your message contains too many URLs. The maximum number of URLs allowed is 2.'),
+ array('UNAUTHORISED_BBCODE', '[flash]', 'You cannot use certain BBCodes: [flash].'),
+ array('UNAUTHORISED_BBCODE', '[img]', 'You cannot use certain BBCodes: [img].'),
+ array('UNAUTHORISED_BBCODE', '[quote]', 'You cannot use certain BBCodes: [quote].'),
+ array('UNAUTHORISED_BBCODE', '[url]', 'You cannot use certain BBCodes: [url].'),
+ );
+
+ $user = $this->getMockBuilder('phpbb\\user')->disableOriginalConstructor()->getMock();
+ $user->expects($this->any())
+ ->method('lang')
+ ->will($this->returnValueMap($map));
+
+ $user->lang = array(
+ 'NO_POLL_TITLE' => 'You have to enter a poll title.',
+ 'POLL_TITLE_TOO_LONG' => 'The poll title must contain fewer than 100 characters.',
+ 'POLL_TITLE_COMP_TOO_LONG' => 'The parsed size of your poll title is too large, consider removing BBCodes or smilies.',
+ 'TOO_FEW_POLL_OPTIONS' => 'You must enter at least two poll options.',
+ 'TOO_MANY_POLL_OPTIONS' => 'You have tried to enter too many poll options.',
+ 'TOO_MANY_USER_OPTIONS' => 'You cannot specify more options per user than existing poll options.',
+ 'UNABLE_GET_IMAGE_SIZE' => 'It was not possible to determine the dimensions of the image.'
+ );
+
+ $phpbb_container = new phpbb_mock_container_builder;
+ $phpbb_container->set('user', $user);
+ $phpbb_container->set('config', $config);
+
+ if (isset($setup))
+ {
+ $setup($parser, $phpbb_container, $this);
+ }
+
+ $this->get_test_case_helpers()->set_s9e_services($phpbb_container);
+ }
+
+ /**
+ * @dataProvider get_test_polls
+ */
+ public function test_parse_poll($poll, $expected, $warn_msg = array())
+ {
+ $this->prepare_s9e_services();
+
+ $message_parser = new parse_message('Me[i]s[/i]sage');
+
+ // Add some default values
+ $poll += array(
+ 'poll_length' => 123,
+ 'poll_start' => 123,
+ 'poll_last_vote' => 123,
+ 'poll_vote_change' => true,
+ 'enable_bbcode' => true,
+ 'enable_urls' => true,
+ 'enable_smilies' => true,
+ 'img_status' => true
+ );
+
+ $message_parser->parse_poll($poll);
+ $this->assertSame($expected, array_intersect_key($poll, $expected));
+
+ $this->assertSame(
+ '<r>Me<I><s>[i]</s>s<e>[/i]</e></I>sage</r>',
+ $message_parser->parse(true, true, true, true, true, true, true, false)
+ );
+
+ $this->assertSame($warn_msg, $message_parser->warn_msg);
+ }
+
+ public function get_test_polls()
+ {
+ return array(
+ array(
+ array(
+ 'poll_title' => 'foo [b]bar[/b] baz',
+ 'poll_option_text' => "[i]foo[/i]\nbar\n[i]baz[/i]",
+ 'poll_max_options' => 3,
+ 'poll_options_size' => 3
+ ),
+ array(
+ 'poll_title' => '<r>foo <B><s>[b]</s>bar<e>[/b]</e></B> baz</r>',
+ 'poll_option_text' => "<r><I><s>[i]</s>foo<e>[/i]</e></I></r>\n<t>bar</t>\n<r><I><s>[i]</s>baz<e>[/i]</e></I></r>",
+ 'poll_options' => array(
+ '<r><I><s>[i]</s>foo<e>[/i]</e></I></r>',
+ '<t>bar</t>',
+ '<r><I><s>[i]</s>baz<e>[/i]</e></I></r>'
+ )
+ )
+ ),
+ array(
+ array(
+ 'poll_title' => 'xxx',
+ 'poll_option_text' => "[quote]quote[/quote]\n:)",
+ 'poll_max_options' => 2,
+ 'poll_options_size' => 2
+ ),
+ array(
+ 'poll_title' => '<t>xxx</t>',
+ 'poll_option_text' => "<t>[quote]quote[/quote]</t>\n<r><E>:)</E></r>",
+ 'poll_options' => array(
+ '<t>[quote]quote[/quote]</t>',
+ '<r><E>:)</E></r>'
+ )
+ ),
+ array('You cannot use certain BBCodes: [quote].')
+ ),
+ array(
+ array(
+ 'poll_title' => 'xxx',
+ 'poll_option_text' => "[flash=12,34]http://example.org/x.swf[/flash]\n:)",
+ 'poll_max_options' => 2,
+ 'poll_options_size' => 2
+ ),
+ array(
+ 'poll_title' => '<t>xxx</t>',
+ 'poll_option_text' => "<t>[flash=12,34]http://example.org/x.swf[/flash]</t>\n<r><E>:)</E></r>",
+ 'poll_options' => array(
+ '<t>[flash=12,34]http://example.org/x.swf[/flash]</t>',
+ '<r><E>:)</E></r>'
+ )
+ ),
+ array('You cannot use certain BBCodes: [flash].')
+ ),
+ array(
+ array(
+ 'poll_title' => 'xxx',
+ 'poll_option_text' => "[b]x\ny[/b]",
+ 'poll_max_options' => 2,
+ 'poll_options_size' => 2
+ ),
+ array(
+ 'poll_title' => '<t>xxx</t>',
+ 'poll_option_text' => "<r><B><s>[b]</s>x</B></r>\n<t>y[/b]</t>",
+ 'poll_options' => array(
+ '<r><B><s>[b]</s>x</B></r>',
+ '<t>y[/b]</t>',
+ )
+ )
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider get_test_cases
+ */
+ public function test_options($original, $expected, array $args, $setup = null, $warn_msg = array())
+ {
+ $this->prepare_s9e_services($setup);
+
+ $message_parser = new parse_message($original);
+ call_user_func_array(array($message_parser, 'parse'), $args);
+
+ $this->assertSame($expected, $message_parser->message);
+ $this->assertSame($warn_msg, $message_parser->warn_msg);
+ }
+
+ public function get_test_cases()
+ {
+ return array(
+ array(
+ '[b]bold[/b]',
+ '<r><B><s>[b]</s>bold<e>[/b]</e></B></r>',
+ array(true, true, true, true, true, true, true)
+ ),
+ array(
+ '[b]bold[/b]',
+ '<t>[b]bold[/b]</t>',
+ array(false, true, true, true, true, true, true)
+ ),
+ array(
+ 'http://example.org',
+ '<r><URL url="http://example.org">http://example.org</URL></r>',
+ array(true, true, true, true, true, true, true)
+ ),
+ array(
+ 'http://example.org',
+ '<t>http://example.org</t>',
+ array(true, false, true, true, true, true, true)
+ ),
+ array(
+ ':)',
+ '<r><E>:)</E></r>',
+ array(true, true, true, true, true, true, true)
+ ),
+ array(
+ ':)',
+ '<t>:)</t>',
+ array(true, true, false, true, true, true, true)
+ ),
+ array(
+ '[url=http://example.org][img]http://example.org/img.png[/img][/url]',
+ '<r><URL url="http://example.org"><s>[url=http://example.org]</s><IMG src="http://example.org/img.png"><s>[img]</s>http://example.org/img.png<e>[/img]</e></IMG><e>[/url]</e></URL></r>',
+ array(true, true, true, true, true, true, true)
+ ),
+ array(
+ '[url=http://example.org][img]http://example.org/img.png[/img][/url]',
+ '<r><URL url="http://example.org"><s>[url=http://example.org]</s>[img]http://example.org/img.png[/img]<e>[/url]</e></URL></r>',
+ array(true, true, true, false, true, true, true),
+ null,
+ array('You cannot use certain BBCodes: [img].')
+ ),
+ array(
+ '[flash=12,34]http://example.org/foo.swf[/flash]',
+ '<r><FLASH height="34" url="http://example.org/foo.swf" width="12"><s>[flash=12,34]</s><URL url="http://example.org/foo.swf">http://example.org/foo.swf</URL><e>[/flash]</e></FLASH></r>',
+ array(true, true, true, true, true, true, true)
+ ),
+ array(
+ '[flash=12,34]http://example.org/foo.swf[/flash]',
+ '<r>[flash=12,34]<URL url="http://example.org/foo.swf">http://example.org/foo.swf</URL>[/flash]</r>',
+ array(true, true, true, true, false, true, true),
+ null,
+ array('You cannot use certain BBCodes: [flash].')
+ ),
+ array(
+ '[quote="foo"]bar :)[/quote]',
+ '<r><QUOTE author="foo"><s>[quote="foo"]</s>bar <E>:)</E><e>[/quote]</e></QUOTE></r>',
+ array(true, true, true, true, true, true, true)
+ ),
+ array(
+ '[quote="foo"]bar :)[/quote]',
+ '<r>[quote="foo"]bar <E>:)</E>[/quote]</r>',
+ array(true, true, true, true, true, false, true),
+ null,
+ array('You cannot use certain BBCodes: [quote].')
+ ),
+ array(
+ '[url=http://example.org][img]http://example.org/img.png[/img][/url]',
+ '<r><URL url="http://example.org"><s>[url=http://example.org]</s><IMG src="http://example.org/img.png"><s>[img]</s>http://example.org/img.png<e>[/img]</e></IMG><e>[/url]</e></URL></r>',
+ array(true, true, true, true, true, true, true)
+ ),
+ array(
+ '[url=http://example.org][img]http://example.org/img.png[/img][/url]',
+ '<r>[url=http://example.org]<IMG src="http://example.org/img.png"><s>[img]</s>http://example.org/img.png<e>[/img]</e></IMG>[/url]</r>',
+ array(true, true, true, true, true, true, false),
+ null,
+ array('You cannot use certain BBCodes: [url].')
+ ),
+ array(
+ '[size=200]200[/size]',
+ '<r><SIZE size="200"><s>[size=200]</s>200<e>[/size]</e></SIZE></r>',
+ array(true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_post_font_size', 200);
+ }
+ ),
+ array(
+ '[size=200]200[/size]',
+ '<r><SIZE size="200"><s>[size=200]</s>200<e>[/size]</e></SIZE></r>',
+ array(true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_post_font_size', 0);
+ }
+ ),
+ array(
+ '[size=2000]2000[/size]',
+ '<t>[size=2000]2000[/size]</t>',
+ array(true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_post_font_size', 200);
+ },
+ array('You may only use fonts up to size 200.')
+ ),
+ array(
+ '[size=0]0[/size]',
+ '<t>[size=0]0[/size]</t>',
+ array(true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_post_font_size', 200);
+ }
+ ),
+ array(
+ '[size=200]200[/size]',
+ '<r><SIZE size="200"><s>[size=200]</s>200<e>[/size]</e></SIZE></r>',
+ array(true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_sig_font_size', 200);
+ }
+ ),
+ array(
+ '[size=200]200[/size]',
+ '<t>[size=200]200[/size]</t>',
+ array(true, true, true, true, true, true, true, true, 'sig'),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_sig_font_size', 120);
+ },
+ array('You may only use fonts up to size 120.')
+ ),
+ array(
+ '[img]http://example.org/100x100.png[/img]',
+ '<r>[img]<URL url="http://example.org/100x100.png">http://example.org/100x100.png</URL>[/img]</r>',
+ array(true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_post_img_height', 12);
+ },
+ array('Your images may only be up to 12 pixels high.')
+ ),
+ array(
+ '[img]http://example.org/100x100.png[/img]',
+ '<r>[img]<URL url="http://example.org/100x100.png">http://example.org/100x100.png</URL>[/img]</r>',
+ array(true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_post_img_width', 34);
+ },
+ array('Your images may only be up to 34 pixels wide.')
+ ),
+ array(
+ '[img]http://example.org/100x100.png[/img]',
+ '<r><IMG src="http://example.org/100x100.png"><s>[img]</s><URL url="http://example.org/100x100.png">http://example.org/100x100.png</URL><e>[/img]</e></IMG></r>',
+ array(true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_post_img_height', 0);
+ $phpbb_container->get('config')->set('max_post_img_width', 0);
+ }
+ ),
+ array(
+ '[img]http://example.org/100x100.png[/img]',
+ '<r><IMG src="http://example.org/100x100.png"><s>[img]</s><URL url="http://example.org/100x100.png">http://example.org/100x100.png</URL><e>[/img]</e></IMG></r>',
+ array(true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_post_img_height', 100);
+ $phpbb_container->get('config')->set('max_post_img_width', 100);
+ }
+ ),
+ array(
+ '[img]http://example.org/100x100.png[/img]',
+ '<r><IMG src="http://example.org/100x100.png"><s>[img]</s><URL url="http://example.org/100x100.png">http://example.org/100x100.png</URL><e>[/img]</e></IMG></r>',
+ array(true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_sig_img_height', 12);
+ $phpbb_container->get('config')->set('max_sig_img_width', 34);
+ }
+ ),
+ array(
+ '[img]http://example.org/404.png[/img]',
+ '<r>[img]<URL url="http://example.org/404.png">http://example.org/404.png</URL>[/img]</r>',
+ array(true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_post_img_height', 12);
+ },
+ array('It was not possible to determine the dimensions of the image.')
+ ),
+ array(
+ '[flash=999,999]http://example.org/foo.swf[/flash]',
+ '<r>[flash=999,999]<URL url="http://example.org/foo.swf">http://example.org/foo.swf</URL>[/flash]</r>',
+ array(true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_post_img_height', 123);
+ },
+ array('Your flash files may only be up to 123 pixels high.')
+ ),
+ array(
+ '[flash=999,999]http://example.org/foo.swf[/flash]',
+ '<r>[flash=999,999]<URL url="http://example.org/foo.swf">http://example.org/foo.swf</URL>[/flash]</r>',
+ array(true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_post_img_width', 456);
+ },
+ array('Your flash files may only be up to 456 pixels wide.')
+ ),
+ array(
+ ':) :) :)',
+ '<r><E>:)</E> <E>:)</E> <E>:)</E></r>',
+ array(true, true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_post_smilies', 3);
+ }
+ ),
+ array(
+ ':) :) :) :)',
+ '<r><E>:)</E> <E>:)</E> <E>:)</E> :)</r>',
+ array(true, true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_post_smilies', 3);
+ },
+ array('Your message contains too many smilies. The maximum number of smilies allowed is 3.')
+ ),
+ array(
+ ':) :) :) :)',
+ '<r><E>:)</E> <E>:)</E> <E>:)</E> <E>:)</E></r>',
+ array(true, true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_post_smilies', 0);
+ }
+ ),
+ array(
+ ':) :) :) :)',
+ '<r><E>:)</E> <E>:)</E> <E>:)</E> <E>:)</E></r>',
+ array(true, true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_sig_smilies', 3);
+ }
+ ),
+ array(
+ ':) :) :) :)',
+ '<r><E>:)</E> <E>:)</E> <E>:)</E> :)</r>',
+ array(true, true, true, true, true, true, true, true, 'sig'),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_sig_smilies', 3);
+ },
+ array('Your message contains too many smilies. The maximum number of smilies allowed is 3.')
+ ),
+ array(
+ 'http://example.org http://example.org http://example.org',
+ '<r><URL url="http://example.org">http://example.org</URL> <URL url="http://example.org">http://example.org</URL> http://example.org</r>',
+ array(true, true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_post_urls', 2);
+ },
+ array('Your message contains too many URLs. The maximum number of URLs allowed is 2.')
+ ),
+ array(
+ 'http://example.org http://example.org http://example.org',
+ '<r><URL url="http://example.org">http://example.org</URL> <URL url="http://example.org">http://example.org</URL> <URL url="http://example.org">http://example.org</URL></r>',
+ array(true, true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_post_urls', 0);
+ }
+ ),
+ array(
+ 'http://example.org http://example.org http://example.org',
+ '<r><URL url="http://example.org">http://example.org</URL> <URL url="http://example.org">http://example.org</URL> <URL url="http://example.org">http://example.org</URL></r>',
+ array(true, true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_sig_urls', 2);
+ }
+ ),
+ );
+ }
+}
+
+class phpbb_text_processing_message_parser_test_proxy
+{
+ protected $response;
+
+ public function stream_open($url)
+ {
+ if (strpos($url, '100x100'))
+ {
+ // Return a 100 x 100 PNG image
+ $this->response = base64_decode('iVBORw0KGgoAAAANSUhEUgAAAGQAAABkAQAAAABYmaj5AAAAE0lEQVR4AWOgKxgFo2AUjIJRAAAFeAABHs0ozQAAAABJRU5ErkJggg==');
+ }
+ else
+ {
+ $this->response = '404 not found';
+ }
+
+ return true;
+ }
+
+ public function stream_stat()
+ {
+ return false;
+ }
+
+ public function stream_read($len)
+ {
+ $chunk = substr($this->response, 0, $len);
+ $this->response = substr($this->response, $len);
+
+ return $chunk;
+ }
+
+ public function stream_eof()
+ {
+ return ($this->response === false);
+ }
+}
diff --git a/tests/text_processing/smilies_test.php b/tests/text_processing/smilies_test.php
new file mode 100644
index 0000000000..cd35c25525
--- /dev/null
+++ b/tests/text_processing/smilies_test.php
@@ -0,0 +1,48 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2013 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once __DIR__ . '/../../phpBB/includes/functions.php';
+require_once __DIR__ . '/../../phpBB/includes/functions_content.php';
+
+class phpbb_text_processing_smilies_test extends phpbb_test_case
+{
+ /**
+ * @dataProvider get_text_formatter_tests
+ */
+ public function test_text_formatter($original, $expected)
+ {
+ $container = $this->get_test_case_helpers()->set_s9e_services(null, __DIR__ . '/fixtures/smilies.xml');
+ $parser = $container->get('text_formatter.parser');
+ $renderer = $container->get('text_formatter.renderer');
+
+ $this->assertSame($expected, $renderer->render($parser->parse($original)));
+ }
+
+ public function get_text_formatter_tests()
+ {
+ return array(
+ array(
+ ':) beginning',
+ '<img class="smilies" src="phpBB/images/smilies/icon_e_smile.gif" alt=":)" title="Smile"> beginning'
+ ),
+ array(
+ 'end :)',
+ 'end <img class="smilies" src="phpBB/images/smilies/icon_e_smile.gif" alt=":)" title="Smile">'
+ ),
+ array(
+ ':)',
+ '<img class="smilies" src="phpBB/images/smilies/icon_e_smile.gif" alt=":)" title="Smile">'
+ ),
+ array(
+ 'xx (18) 8) xx',
+ 'xx (18) <img class="smilies" src="phpBB/images/smilies/custom.gif" alt="8)" title="8)"> xx'
+ ),
+ );
+ }
+}
diff --git a/tests/text_processing/strip_bbcode_test.php b/tests/text_processing/strip_bbcode_test.php
new file mode 100644
index 0000000000..d0dda89167
--- /dev/null
+++ b/tests/text_processing/strip_bbcode_test.php
@@ -0,0 +1,38 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php';
+
+class phpbb_text_processing_strip_bbcode_test extends phpbb_test_case
+{
+ public function test_legacy()
+ {
+ $original = '[b:20m4ill1]bold[/b:20m4ill1]';
+ $expected = ' bold ';
+
+ $actual = $original;
+ strip_bbcode($actual);
+
+ $this->assertSame($expected, $actual, '20m4ill1');
+ }
+
+ public function test_s9e()
+ {
+ $phpbb_container = $this->get_test_case_helpers()->set_s9e_services();
+
+ $original = '<r><B><s>[b]</s>bold<e>[/b]</e></B></r>';
+ $expected = ' bold ';
+
+ $actual = $original;
+ strip_bbcode($actual);
+
+ $this->assertSame($expected, $actual);
+ }
+}
diff --git a/tests/text_processing/tickets_data/PHPBB3-10002.html b/tests/text_processing/tickets_data/PHPBB3-10002.html
new file mode 100644
index 0000000000..82990b2253
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-10002.html
@@ -0,0 +1,2 @@
+<blockquote class="uncited"><div><ul><li>one
+<blockquote class="uncited"><div><ul><li>two</li></ul></div></blockquote></li></ul></div></blockquote> \ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-10002.txt b/tests/text_processing/tickets_data/PHPBB3-10002.txt
new file mode 100644
index 0000000000..fe2f29073f
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-10002.txt
@@ -0,0 +1,2 @@
+[quote][list][*]one
+[quote][list][*]two[/list][/quote] \ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-10425.html b/tests/text_processing/tickets_data/PHPBB3-10425.html
new file mode 100644
index 0000000000..522b2f8858
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-10425.html
@@ -0,0 +1,3 @@
+<a href="http://ar.wikipedia.org/wiki/%D8%A7%D9%84%D8%B5%D9%81%D8%AD%D8%A9_%D8%A7%D9%84%D8%B1%D8%A6%D9%8A%D8%B3%D9%8A%D8%A9" class="postlink">http://ar.wikipedia.org/wiki/الصفحة_الرئيسية</a><br>
+<a href="http://ar.wikipedia.org/wiki/%D8%A7%D9%84%D8%B5%D9%81%D8%AD%D8%A9_%D8%A7%D9%84%D8%B1%D8%A6%D9%8A%D8%B3%D9%8A%D8%A9" class="postlink">http://ar.wikipedia.org/wiki/الصفحة_الرئيسية</a><br>
+<a href="http://ar.wikipedia.org/wiki/%D8%A7%D9%84%D8%B5%D9%81%D8%AD%D8%A9_%D8%A7%D9%84%D8%B1%D8%A6%D9%8A%D8%B3%D9%8A%D8%A9" class="postlink">link</a> \ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-10425.txt b/tests/text_processing/tickets_data/PHPBB3-10425.txt
new file mode 100644
index 0000000000..d93c0446b6
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-10425.txt
@@ -0,0 +1,3 @@
+http://ar.wikipedia.org/wiki/الصفحة_الرئيسية
+[url]http://ar.wikipedia.org/wiki/الصفحة_الرئيسية[/url]
+[url=http://ar.wikipedia.org/wiki/الصفحة_الرئيسية]link[/url] \ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-10587.html b/tests/text_processing/tickets_data/PHPBB3-10587.html
new file mode 100644
index 0000000000..dd0a483244
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-10587.html
@@ -0,0 +1,2 @@
+<a href="http://www.tx-gaming.net/warzone/tournament.php?tourney%5Bid%5D=34&amp;action=brackets" class="postlink">http://www.tx-gaming.net/warzone/tournament.php?tourney[id]=34&amp;action=brackets</a><br>
+<a href="http://www.tx-gaming.net/warzone/tournament.php?tourney%5Bid%5D=34&amp;action=brackets" class="postlink">link</a> \ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-10587.txt b/tests/text_processing/tickets_data/PHPBB3-10587.txt
new file mode 100644
index 0000000000..f81a35eb5f
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-10587.txt
@@ -0,0 +1,2 @@
+[url]http://www.tx-gaming.net/warzone/tournament.php?tourney[id]=34&action=brackets[/url]
+[url="http://www.tx-gaming.net/warzone/tournament.php?tourney[id]=34&action=brackets"]link[/url] \ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-10922.html b/tests/text_processing/tickets_data/PHPBB3-10922.html
new file mode 100644
index 0000000000..cdf8316df0
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-10922.html
@@ -0,0 +1 @@
+<a href="mailto:user@example.org">user@example.org</a><a href="mailto:user@example.org">...</a> \ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-10922.txt b/tests/text_processing/tickets_data/PHPBB3-10922.txt
new file mode 100644
index 0000000000..348f8a1541
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-10922.txt
@@ -0,0 +1 @@
+[email]user@example.org[/email][email=user@example.org]...[/email] \ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-10989.html b/tests/text_processing/tickets_data/PHPBB3-10989.html
new file mode 100644
index 0000000000..f003ad3dfa
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-10989.html
@@ -0,0 +1,8 @@
+<blockquote><div><cite>Lorem wrote:</cite>[quote="Lorem"<blockquote class="uncited"><div> Suspendisse iaculis porta tempor. Nulla.</div></blockquote>
+ Nullam a tortor sit amet.</div></blockquote>
+ Proin ac mi eget magna.
+
+<blockquote><div><cite>Lorem wrote:</cite>Quisque fermentum tortor quis odio scelerisque consequat fermentum urna gravida. In semper vehicula condimentum. Donec suscipit ante imperdiet augue rhoncus.</div></blockquote>
+
+<br>
+Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Maecenas quis odio orci, sit amet semper. \ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-10989.txt b/tests/text_processing/tickets_data/PHPBB3-10989.txt
new file mode 100644
index 0000000000..dc2430f210
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-10989.txt
@@ -0,0 +1,8 @@
+[quote="Lorem"][quote="Lorem"[quote] Suspendisse iaculis porta tempor. Nulla.[/quote]
+ Nullam a tortor sit amet.[/quote]
+ Proin ac mi eget magna.
+
+[quote="Lorem"]Quisque fermentum tortor quis odio scelerisque consequat fermentum urna gravida. In semper vehicula condimentum. Donec suscipit ante imperdiet augue rhoncus.[/quote]
+
+
+Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Maecenas quis odio orci, sit amet semper. \ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-11153.html b/tests/text_processing/tickets_data/PHPBB3-11153.html
new file mode 100644
index 0000000000..0f67ac4bc0
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-11153.html
@@ -0,0 +1 @@
+<a href="mailto:user@example.org">...</a> \ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-11153.txt b/tests/text_processing/tickets_data/PHPBB3-11153.txt
new file mode 100644
index 0000000000..d2794978d9
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-11153.txt
@@ -0,0 +1 @@
+[myemail=user@example.org]...[/myemail] \ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-11153.xml b/tests/text_processing/tickets_data/PHPBB3-11153.xml
new file mode 100644
index 0000000000..a7fc69520b
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-11153.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>myemail</value>
+ <value></value>
+ <value>1</value>
+ <value>[myemail={EMAIL}]{TEXT}[/myemail]</value>
+ <value><![CDATA[<a href="mailto:{EMAIL}">{TEXT}</a>]]></value>
+ <value><![CDATA[!\[myemail\=(([\w\!\#$\%\&'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*(?:[\w\!\#$\%'\*\+\-\/\=\?\^\`{\|\}\~]|&amp;)+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,63})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?))\](.*?)\[/myemail\]!ies]]></value>
+ <value><![CDATA['[myemail='.$this->bbcode_specialchars('${1}').':$uid]'.str_replace(array("\r\n", '\"', '\'', '(', ')'), array("\n", '"', '&#39;', '&#40;', '&#41;'), trim('${2}')).'[/myemail:$uid]']]></value>
+ <value><![CDATA[!\[myemail\=(([\w\!\#$\%\&'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*(?:[\w\!\#$\%'\*\+\-\/\=\?\^\`{\|\}\~]|&amp;)+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,63})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)):$uid\](.*?)\[/myemail:$uid\]!s]]></value>
+ <value><![CDATA[<a href="mailto:${1}">${2}</a>]]></value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/text_processing/tickets_data/PHPBB3-12195.html b/tests/text_processing/tickets_data/PHPBB3-12195.html
new file mode 100644
index 0000000000..d8e0f8d523
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-12195.html
@@ -0,0 +1 @@
+<a href="//example.org/" class="postlink"><img src="//example.org/img.png" alt="Image"></a> \ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-12195.txt b/tests/text_processing/tickets_data/PHPBB3-12195.txt
new file mode 100644
index 0000000000..b66dbd5d96
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-12195.txt
@@ -0,0 +1 @@
+[url=//example.org/][img]//example.org/img.png[/img][/url] \ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-3981.before.php b/tests/text_processing/tickets_data/PHPBB3-3981.before.php
new file mode 100644
index 0000000000..20c96d163c
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-3981.before.php
@@ -0,0 +1,17 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2013 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+function before_assert_phpbb3_3981($vars)
+{
+ if (!function_exists('idn_to_ascii'))
+ {
+ extract($vars);
+ $test->markTestSkipped('International URLs need idn_to_ascii()');
+ }
+}
diff --git a/tests/text_processing/tickets_data/PHPBB3-3981.html b/tests/text_processing/tickets_data/PHPBB3-3981.html
new file mode 100644
index 0000000000..e5f1b4561d
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-3981.html
@@ -0,0 +1 @@
+<a href="http://www.xn--ndaaa.com" class="postlink">http://www.ööö.com</a> \ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-3981.txt b/tests/text_processing/tickets_data/PHPBB3-3981.txt
new file mode 100644
index 0000000000..976823f1d1
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-3981.txt
@@ -0,0 +1 @@
+[url]http://www.ööö.com[/url] \ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-7187.html b/tests/text_processing/tickets_data/PHPBB3-7187.html
new file mode 100644
index 0000000000..9138779d29
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-7187.html
@@ -0,0 +1 @@
+<blockquote class="uncited"><div><img class="smilies" src="phpBB/images/smilies/icon_e_geek.gif" alt=":geek:" title="Geek"> <img class="smilies" src="phpBB/images/smilies/icon_e_ugeek.gif" alt=":ugeek:" title="Uber Geek"></div></blockquote> \ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-7187.txt b/tests/text_processing/tickets_data/PHPBB3-7187.txt
new file mode 100644
index 0000000000..584151a083
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-7187.txt
@@ -0,0 +1 @@
+[quote]:geek: :ugeek:[/quote] \ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-7187.xml b/tests/text_processing/tickets_data/PHPBB3-7187.xml
new file mode 100644
index 0000000000..d270b12619
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-7187.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_smilies">
+ <column>smiley_id</column>
+ <column>code</column>
+ <column>emotion</column>
+ <column>smiley_url</column>
+ <column>smiley_width</column>
+ <column>smiley_height</column>
+ <column>smiley_order</column>
+ <column>display_on_posting</column>
+ <row>
+ <value>41</value>
+ <value>:geek:</value>
+ <value>Geek</value>
+ <value>icon_e_geek.gif</value>
+ <value>17</value>
+ <value>17</value>
+ <value>41</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>42</value>
+ <value>:ugeek:</value>
+ <value>Uber Geek</value>
+ <value>icon_e_ugeek.gif</value>
+ <value>17</value>
+ <value>18</value>
+ <value>42</value>
+ <value>1</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/text_processing/tickets_data/PHPBB3-7275.after.php b/tests/text_processing/tickets_data/PHPBB3-7275.after.php
new file mode 100644
index 0000000000..a824cb9b84
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-7275.after.php
@@ -0,0 +1,15 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2013 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+function after_assert_phpbb3_7275($vars)
+{
+ extract($vars);
+ decode_message($parsed_text);
+ $test->assertSame($original, $parsed_text);
+}
diff --git a/tests/text_processing/tickets_data/PHPBB3-7275.html b/tests/text_processing/tickets_data/PHPBB3-7275.html
new file mode 100644
index 0000000000..12502833fd
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-7275.html
@@ -0,0 +1 @@
+<div align="center"><img class="smilies" src="phpBB/images/smilies/icon_e_smile.gif" alt=":)" title="Smile"></div> \ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-7275.txt b/tests/text_processing/tickets_data/PHPBB3-7275.txt
new file mode 100644
index 0000000000..8de97d67e0
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-7275.txt
@@ -0,0 +1 @@
+[center]:)[/center] \ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-7275.xml b/tests/text_processing/tickets_data/PHPBB3-7275.xml
new file mode 100644
index 0000000000..9e979afffb
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-7275.xml
@@ -0,0 +1,49 @@
+<?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>center</value>
+ <value></value>
+ <value>1</value>
+ <value>[center]{TEXT}[/center]</value>
+ <value><![CDATA[<div align="center">{TEXT}</div>]]></value>
+ <value>!\[center\](.*?)\[/center\]!ies</value>
+ <value><![CDATA['[center:$uid]'.str_replace(array("\r\n", '\"', '\'', '(', ')'), array("\n", '"', '&#39;', '&#40;', '&#41;'), trim('${1}')).'[/center:$uid]']]></value>
+ <value>!\[center:$uid\](.*?)\[/center:$uid\]!s</value>
+ <value><![CDATA[<div align="center">${1}</div>]]></value>
+ </row>
+ </table>
+
+ <table name="phpbb_smilies">
+ <column>smiley_id</column>
+ <column>code</column>
+ <column>emotion</column>
+ <column>smiley_url</column>
+ <column>smiley_width</column>
+ <column>smiley_height</column>
+ <column>smiley_order</column>
+ <column>display_on_posting</column>
+ <row>
+ <value>4</value>
+ <value>:)</value>
+ <value>Smile</value>
+ <value>icon_e_smile.gif</value>
+ <value>15</value>
+ <value>17</value>
+ <value>4</value>
+ <value>1</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/text_processing/tickets_data/PHPBB3-9377.html b/tests/text_processing/tickets_data/PHPBB3-9377.html
new file mode 100644
index 0000000000..dcfb79c173
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-9377.html
@@ -0,0 +1 @@
+<span style="color:red">red <span style="color:blue">blue</span> red</span> \ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-9377.txt b/tests/text_processing/tickets_data/PHPBB3-9377.txt
new file mode 100644
index 0000000000..dfd71492c5
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-9377.txt
@@ -0,0 +1 @@
+[red]red [blue]blue[/blue] red[/red] \ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-9377.xml b/tests/text_processing/tickets_data/PHPBB3-9377.xml
new file mode 100644
index 0000000000..1d8ee3d53f
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-9377.xml
@@ -0,0 +1,41 @@
+<?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>red</value>
+ <value></value>
+ <value>1</value>
+ <value>[red]{TEXT}[/red]</value>
+ <value>&lt;span style=&quot;color:red&quot;&gt;{TEXT}&lt;/span&gt;</value>
+ <value>!\[red\](.*?)\[/red\]!ies</value>
+ <value>'[red:$uid]'.str_replace(array(&quot;\r\n&quot;, '\&quot;', '\'', '(', ')'), array(&quot;\n&quot;, '&quot;', '&amp;#39;', '&amp;#40;', '&amp;#41;'), trim('${1}')).'[/red:$uid]'</value>
+ <value>!\[red:$uid\](.*?)\[/red:$uid\]!s</value>
+ <value>&lt;span style=&quot;color:red&quot;&gt;${1}&lt;/span&gt;</value>
+ </row>
+
+ <row>
+ <value>14</value>
+ <value>blue</value>
+ <value></value>
+ <value>1</value>
+ <value>[blue]{TEXT}[/blue]</value>
+ <value>&lt;span style=&quot;color:blue&quot;&gt;{TEXT}&lt;/span&gt;</value>
+ <value>!\[blue\](.*?)\[/blue\]!ies</value>
+ <value>'[blue:$uid]'.str_replace(array(&quot;\r\n&quot;, '\&quot;', '\'', '(', ')'), array(&quot;\n&quot;, '&quot;', '&amp;#39;', '&amp;#40;', '&amp;#41;'), trim('${1}')).'[/blue:$uid]'</value>
+ <value>!\[blue:$uid\](.*?)\[/blue:$uid\]!s</value>
+ <value>&lt;span style=&quot;color:blue&quot;&gt;${1}&lt;/span&gt;</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/text_processing/tickets_test.php b/tests/text_processing/tickets_test.php
new file mode 100644
index 0000000000..d2072a10f5
--- /dev/null
+++ b/tests/text_processing/tickets_test.php
@@ -0,0 +1,91 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2013 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once __DIR__ . '/../../phpBB/includes/functions.php';
+require_once __DIR__ . '/../../phpBB/includes/functions_content.php';
+require_once __DIR__ . '/../../phpBB/includes/utf/utf_tools.php';
+require_once __DIR__ . '/../mock/container_builder.php';
+
+class phpbb_text_processing_tickets_test extends phpbb_test_case
+{
+ /**
+ * @dataProvider get_tickets_data
+ */
+ public function test_tickets($ticket_id, $original, $expected, $fixture, $before_assert, $after_assert)
+ {
+ global $phpbb_container;
+
+ $phpbb_container = new phpbb_mock_container_builder;
+
+ $this->get_test_case_helpers()->set_s9e_services($phpbb_container, $fixture);
+
+ $parser = $phpbb_container->get('text_formatter.parser');
+ $renderer = $phpbb_container->get('text_formatter.renderer');
+
+ if (isset($before_assert))
+ {
+ $test = $this;
+ $before_assert(get_defined_vars());
+ }
+
+ $parsed_text = $parser->parse($original);
+
+ $this->assertSame($expected, $renderer->render($parsed_text));
+
+ if (isset($after_assert))
+ {
+ $test = $this;
+ $after_assert(get_defined_vars());
+ }
+ }
+
+ public function get_tickets_data()
+ {
+ $tests = array();
+
+ foreach (glob(__DIR__ . '/tickets_data/*.txt') as $txt_filename)
+ {
+ $ticket_id = basename($txt_filename, '.txt');
+ $html_filename = substr($txt_filename, 0, -3) . 'html';
+ $xml_filename = substr($txt_filename, 0, -3) . 'xml';
+ $before_filename = substr($txt_filename, 0, -3) . 'before.php';
+ $after_filename = substr($txt_filename, 0, -3) . 'after.php';
+
+ if (!file_exists($xml_filename))
+ {
+ $xml_filename = __DIR__ . '/../fixtures/empty.xml';
+ }
+
+ $before_assert = null;
+ if (file_exists($before_filename))
+ {
+ include($before_filename);
+ $before_assert = 'before_assert_' . strtolower(str_replace('-', '_', $ticket_id));
+ }
+
+ $after_assert = null;
+ if (file_exists($after_filename))
+ {
+ include($after_filename);
+ $after_assert = 'after_assert_' . strtolower(str_replace('-', '_', $ticket_id));
+ }
+
+ $tests[] = array(
+ $ticket_id,
+ file_get_contents($txt_filename),
+ file_get_contents($html_filename),
+ $xml_filename,
+ $before_assert,
+ $after_assert
+ );
+ }
+
+ return $tests;
+ }
+}