aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoshyPHP <s9e.dev@gmail.com>2015-05-01 19:21:01 +0200
committerJoshyPHP <s9e.dev@gmail.com>2015-05-30 17:26:00 +0200
commitb5911281ae175340817345e63ddbfaf43abb3cec (patch)
tree044e1fe16209c353e55689febe322096b5b1b6bc
parent986af43f37342953bff548630aa33904c21234f4 (diff)
downloadforums-b5911281ae175340817345e63ddbfaf43abb3cec.tar
forums-b5911281ae175340817345e63ddbfaf43abb3cec.tar.gz
forums-b5911281ae175340817345e63ddbfaf43abb3cec.tar.bz2
forums-b5911281ae175340817345e63ddbfaf43abb3cec.tar.xz
forums-b5911281ae175340817345e63ddbfaf43abb3cec.zip
[ticket/13803] Added tests, fixed param order in generate_text_for_storage()
PHPBB3-13803
-rw-r--r--phpBB/phpbb/textreparser/base.php4
-rw-r--r--phpBB/phpbb/textreparser/plugins/user_signature.php39
-rw-r--r--phpBB/phpbb/textreparser/row_based_plugin.php34
-rw-r--r--tests/text_reparser/fixtures/posts.xml42
-rw-r--r--tests/text_reparser/post_text_test.php38
5 files changed, 135 insertions, 22 deletions
diff --git a/phpBB/phpbb/textreparser/base.php b/phpBB/phpbb/textreparser/base.php
index 7d1e12c52d..f65745f6ab 100644
--- a/phpBB/phpbb/textreparser/base.php
+++ b/phpBB/phpbb/textreparser/base.php
@@ -63,8 +63,8 @@ abstract class base implements reparser_interface
$bitfield,
$flags,
$unparsed['enable_bbcode'],
- $unparsed['enable_smilies'],
- $unparsed['enable_magic_url']
+ $unparsed['enable_magic_url'],
+ $unparsed['enable_smilies']
);
// Save the new text if it has changed
diff --git a/phpBB/phpbb/textreparser/plugins/user_signature.php b/phpBB/phpbb/textreparser/plugins/user_signature.php
index 2beaaf98e5..7a66f39ab6 100644
--- a/phpBB/phpbb/textreparser/plugins/user_signature.php
+++ b/phpBB/phpbb/textreparser/plugins/user_signature.php
@@ -16,14 +16,47 @@ namespace phpbb\textreparser\plugins;
class user_signature extends \phpbb\textreparser\row_based_plugin
{
/**
+ * @var array Bit numbers used for user options
+ * @see \phpbb\user
+ */
+ protected $keyoptions;
+
+ /**
+ * Constructor
+ *
+ * Retrieves and saves the bit numbers used for user options
+ */
+ public function __construct()
+ {
+ $class_vars = get_class_vars('phpbb\\user');
+ $this->keyoptions = $class_vars['keyoptions'];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function add_missing_fields(array $row)
+ {
+ $options = $row['user_options'];
+ $row += array(
+ 'enable_bbcode' => phpbb_optionget($this->keyoptions['sig_bbcode'], $options),
+ 'enable_smilies' => phpbb_optionget($this->keyoptions['sig_smilies'], $options),
+ 'enable_magic_url' => phpbb_optionget($this->keyoptions['sig_links'], $options),
+ );
+
+ return $row;
+ }
+
+ /**
* {@inheritdoc}
*/
protected function get_columns()
{
return array(
- 'id' => 'user_id',
- 'text' => 'user_sig',
- 'bbcode_uid' => 'user_sig_bbcode_uid',
+ 'id' => 'user_id',
+ 'text' => 'user_sig',
+ 'bbcode_uid' => 'user_sig_bbcode_uid',
+ 'user_options' => 'user_options',
);
}
diff --git a/phpBB/phpbb/textreparser/row_based_plugin.php b/phpBB/phpbb/textreparser/row_based_plugin.php
index 2317c79e4f..b946d6532b 100644
--- a/phpBB/phpbb/textreparser/row_based_plugin.php
+++ b/phpBB/phpbb/textreparser/row_based_plugin.php
@@ -45,6 +45,29 @@ abstract class row_based_plugin extends base
abstract protected function get_table_name();
/**
+ * Add fields to given row, if applicable
+ *
+ * The enable_* fields are not always saved to the database. Sometimes we need to guess their
+ * original value based on the text content or possibly other fields
+ *
+ * @param array $row Original row
+ * @return array Complete row
+ */
+ protected function add_missing_fields(array $row)
+ {
+ if (!isset($row['enable_bbcode'], $row['enable_smilies'], $row['enable_magic_url']))
+ {
+ $row += array(
+ 'enable_bbcode' => !empty($row['bbcode_uid']),
+ 'enable_smilies' => (strpos($row['text'], '<!-- s') !== false),
+ 'enable_magic_url' => (strpos($row['text'], '<!-- m -->') !== false),
+ );
+ }
+
+ return $row;
+ }
+
+ /**
* {@inheritdoc}
*/
public function get_max_id()
@@ -67,16 +90,7 @@ abstract class row_based_plugin extends base
$result = $this->db->sql_query($this->get_records_query($min_id, $max_id));
while ($row = $this->db->sql_fetchrow($result))
{
- if (!isset($row['enable_bbcode'], $row['enable_smilies'], $row['enable_magic_url']))
- {
- // Those fields are not saved to the database, we need to guess their original value
- $row += array(
- 'enable_bbcode' => !empty($row['bbcode_uid']),
- 'enable_smilies' => (strpos($row['text'], '<!-- s') !== false),
- 'enable_magic_url' => (strpos($row['text'], '<!-- m -->') !== false)
- );
- }
- $records[] = $row;
+ $records[] = $this->add_missing_fields($row);
}
$this->db->sql_freeresult($result);
diff --git a/tests/text_reparser/fixtures/posts.xml b/tests/text_reparser/fixtures/posts.xml
index 6485293361..3cfbfd2e95 100644
--- a/tests/text_reparser/fixtures/posts.xml
+++ b/tests/text_reparser/fixtures/posts.xml
@@ -12,7 +12,47 @@
<value>1</value>
<value>1</value>
<value>1</value>
- <value>Plain text</value>
+ <value>This post should be [b]ignored[/b]</value>
+ <value>abcd1234</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>0</value>
+ <value>0</value>
+ <value>0</value>
+ <value>[b]Not bold[/b] :) http://example.org</value>
+ <value>abcd1234</value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>1</value>
+ <value>0</value>
+ <value>0</value>
+ <value>[b:abcd1234]Bold[/b:abcd1234] :) http://example.org</value>
+ <value>abcd1234</value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>0</value>
+ <value>1</value>
+ <value>0</value>
+ <value><![CDATA[[b]Not bold[/b] <!-- s:) --><img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile" /><!-- s:) --> http://example.org]]></value>
+ <value>abcd1234</value>
+ </row>
+ <row>
+ <value>5</value>
+ <value>0</value>
+ <value>0</value>
+ <value>1</value>
+ <value><![CDATA[[b]Not bold[/b] :) <!-- m --><a class="postlink" href="http://example.org">http://example.org</a><!-- m -->]]></value>
+ <value>abcd1234</value>
+ </row>
+ <row>
+ <value>1000</value>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>This post should be [b]ignored[/b]</value>
<value>abcd1234</value>
</row>
</table>
diff --git a/tests/text_reparser/post_text_test.php b/tests/text_reparser/post_text_test.php
index 9d9d689db9..19e9c37ecc 100644
--- a/tests/text_reparser/post_text_test.php
+++ b/tests/text_reparser/post_text_test.php
@@ -40,9 +40,15 @@ class phpbb_textreparser_post_text_test extends phpbb_database_test_case
$db = $this->new_dbal();
$reparser = new \phpbb\textreparser\plugins\post_text($db);
$reparser->reparse_range($min_id, $max_id);
+
+ $post_ids = array();
+ foreach ($expected as $row)
+ {
+ $post_ids[] = $row['post_id'];
+ }
$sql = 'SELECT post_id, post_text
- FROM ' . POSTS_TABLE . "
- WHERE post_id BETWEEN $min_id AND $max_id";
+ FROM ' . POSTS_TABLE . '
+ WHERE ' . $db->sql_in_set('post_id', $post_ids);
$result = $db->sql_query($sql);
$rows = $db->sql_fetchrowset($result);
$db->sql_freeresult($result);
@@ -53,13 +59,33 @@ class phpbb_textreparser_post_text_test extends phpbb_database_test_case
{
return array(
array(
- 1,
- 1,
+ 2,
+ 5,
array(
array(
'post_id' => 1,
- 'post_text' => '<t>Plain text</t>'
- )
+ 'post_text' => 'This post should be [b]ignored[/b]',
+ ),
+ array(
+ 'post_id' => 2,
+ 'post_text' => '<t>[b]Not bold[/b] :) http://example.org</t>',
+ ),
+ array(
+ 'post_id' => 3,
+ 'post_text' => '<r><B><s>[b]</s>Bold<e>[/b]</e></B> :) http://example.org</r>',
+ ),
+ array(
+ 'post_id' => 4,
+ 'post_text' => '<r>[b]Not bold[/b] <E>:)</E> http://example.org</r>',
+ ),
+ array(
+ 'post_id' => 5,
+ 'post_text' => '<r>[b]Not bold[/b] :) <URL url="http://example.org">http://example.org</URL></r>',
+ ),
+ array(
+ 'post_id' => 1000,
+ 'post_text' => 'This post should be [b]ignored[/b]',
+ ),
)
),
);