mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/13803] Added pm_text tests
PHPBB3-13803
This commit is contained in:
parent
ea445ffa47
commit
9bf0f794b5
4 changed files with 136 additions and 33 deletions
|
@ -29,6 +29,38 @@ abstract class base implements reparser_interface
|
||||||
*/
|
*/
|
||||||
abstract protected function get_records($min_id, $max_id);
|
abstract protected function get_records($min_id, $max_id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add fields to given record, 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 $record Original record
|
||||||
|
* @return array Complete record
|
||||||
|
*/
|
||||||
|
protected function add_missing_fields(array $record)
|
||||||
|
{
|
||||||
|
if (!isset($record['enable_bbcode'], $record['enable_smilies'], $record['enable_magic_url']))
|
||||||
|
{
|
||||||
|
$record += array(
|
||||||
|
'enable_bbcode' => !empty($record['bbcode_uid']),
|
||||||
|
'enable_smilies' => $this->guess_smilies($record),
|
||||||
|
'enable_magic_url' => $this->guess_magic_url($record),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Those BBCodes are disabled based on context and user permissions and that value is never
|
||||||
|
// stored in the database. Here we test whether they were used in the original text.
|
||||||
|
$bbcodes = array('flash', 'img', 'quote', 'url');
|
||||||
|
foreach ($bbcodes as $bbcode)
|
||||||
|
{
|
||||||
|
$field_name = 'enable_' . $bbcode . '_bbcode';
|
||||||
|
$record[$field_name] = $this->guess_bbcode($record, $bbcode);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $record;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Guess whether given BBCode is in use in given record
|
* Guess whether given BBCode is in use in given record
|
||||||
*
|
*
|
||||||
|
@ -120,7 +152,11 @@ abstract class base implements reparser_interface
|
||||||
$flags,
|
$flags,
|
||||||
$unparsed['enable_bbcode'],
|
$unparsed['enable_bbcode'],
|
||||||
$unparsed['enable_magic_url'],
|
$unparsed['enable_magic_url'],
|
||||||
$unparsed['enable_smilies']
|
$unparsed['enable_smilies'],
|
||||||
|
$unparsed['enable_img_bbcode'],
|
||||||
|
$unparsed['enable_flash_bbcode'],
|
||||||
|
$unparsed['enable_quote_bbcode'],
|
||||||
|
$unparsed['enable_url_bbcode']
|
||||||
);
|
);
|
||||||
|
|
||||||
// Save the new text if it has changed
|
// Save the new text if it has changed
|
||||||
|
|
|
@ -44,38 +44,6 @@ abstract class row_based_plugin extends base
|
||||||
*/
|
*/
|
||||||
abstract public function get_table_name();
|
abstract public 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' => $this->guess_smilies($row),
|
|
||||||
'enable_magic_url' => $this->guess_magic_url($row),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Those BBCodes are disabled based on context and user permissions and that value is never
|
|
||||||
// stored in the database. Here we test whether they were used in the original text.
|
|
||||||
$bbcodes = array('flash', 'img', 'quote', 'url');
|
|
||||||
foreach ($bbcodes as $bbcode)
|
|
||||||
{
|
|
||||||
$field_name = 'enable_' . $bbcode;
|
|
||||||
$row[$field_name] = $this->guess_bbcode($row, $bbcode);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $row;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|
73
tests/text_reparser/fixtures/privmsgs.xml
Normal file
73
tests/text_reparser/fixtures/privmsgs.xml
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<dataset>
|
||||||
|
<table name="phpbb_privmsgs">
|
||||||
|
<column>msg_id</column>
|
||||||
|
<column>enable_bbcode</column>
|
||||||
|
<column>enable_smilies</column>
|
||||||
|
<column>enable_magic_url</column>
|
||||||
|
<column>message_text</column>
|
||||||
|
<column>bbcode_uid</column>
|
||||||
|
<column>to_address</column>
|
||||||
|
<column>bcc_address</column>
|
||||||
|
<row>
|
||||||
|
<value>1</value>
|
||||||
|
<value>1</value>
|
||||||
|
<value>1</value>
|
||||||
|
<value>1</value>
|
||||||
|
<value>This row should be [b]ignored[/b]</value>
|
||||||
|
<value>abcd1234</value>
|
||||||
|
<value></value>
|
||||||
|
<value></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>
|
||||||
|
<value></value>
|
||||||
|
<value></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>
|
||||||
|
<value></value>
|
||||||
|
<value></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>
|
||||||
|
<value></value>
|
||||||
|
<value></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>
|
||||||
|
<value></value>
|
||||||
|
<value></value>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<value>1000</value>
|
||||||
|
<value>1</value>
|
||||||
|
<value>1</value>
|
||||||
|
<value>1</value>
|
||||||
|
<value>This row should be [b]ignored[/b]</value>
|
||||||
|
<value>abcd1234</value>
|
||||||
|
<value></value>
|
||||||
|
<value></value>
|
||||||
|
</row>
|
||||||
|
</table>
|
||||||
|
</dataset>
|
26
tests/text_reparser/pm_text_test.php
Normal file
26
tests/text_reparser/pm_text_test.php
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
<?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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
include_once __DIR__ . '/test_row_based_plugin.php';
|
||||||
|
|
||||||
|
class phpbb_textreparser_pm_text_test extends phpbb_textreparser_test_row_based_plugin
|
||||||
|
{
|
||||||
|
public function getDataSet()
|
||||||
|
{
|
||||||
|
return $this->createXMLDataSet(__DIR__ . '/fixtures/privmsgs.xml');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_reparser()
|
||||||
|
{
|
||||||
|
return new \phpbb\textreparser\plugins\pm_text($this->db);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue