diff options
-rw-r--r-- | phpBB/phpbb/textformatter/s9e/utils.php | 41 | ||||
-rw-r--r-- | phpBB/phpbb/textformatter/utils_interface.php | 22 | ||||
-rw-r--r-- | tests/text_formatter/s9e/utils_test.php | 29 |
3 files changed, 29 insertions, 63 deletions
diff --git a/phpBB/phpbb/textformatter/s9e/utils.php b/phpBB/phpbb/textformatter/s9e/utils.php index 29dcfcdf58..2018bbf519 100644 --- a/phpBB/phpbb/textformatter/s9e/utils.php +++ b/phpBB/phpbb/textformatter/s9e/utils.php @@ -19,37 +19,42 @@ namespace phpbb\textformatter\s9e; class utils implements \phpbb\textformatter\utils_interface { /** - * {@inheritdoc} + * Replace BBCodes and other formatting elements with whitespace + * + * NOTE: preserves smilies as text + * + * @param string $xml Parsed text + * @return string Plain text */ - public function clean_formatting($text) + public function clean_formatting($xml) { // Insert a space before <s> and <e> then remove formatting - $text = preg_replace('#<[es]>#', ' $0', $text); + $xml = preg_replace('#<[es]>#', ' $0', $xml); - return \s9e\TextFormatter\Utils::removeFormatting($text); + return \s9e\TextFormatter\Utils::removeFormatting($xml); } /** - * {@inheritdoc} + * Remove given BBCode and its content, at given nesting depth + * + * @param string $xml Parsed text + * @param string $bbcode_name BBCode's name + * @param integer $depth Minimum nesting depth (number of parents of the same name) + * @return string Parsed text */ - public function remove_bbcode($text, $bbcode_name, $depth = 0) + public function remove_bbcode($xml, $bbcode_name, $depth = 0) { - return \s9e\TextFormatter\Utils::removeTag($text, strtoupper($bbcode_name), $depth); + return \s9e\TextFormatter\Utils::removeTag($xml, strtoupper($bbcode_name), $depth); } /** - * {@inheritdoc} + * Return a parsed text to its original form + * + * @param string $xml Parsed text + * @return string Original plain text */ - public function remove_formatting($text) + public function unparse($xml) { - return \s9e\TextFormatter\Utils::removeFormatting($text); - } - - /** - * {@inheritdoc} - */ - public function unparse($text) - { - return \s9e\TextFormatter\Unparser::unparse($text); + return \s9e\TextFormatter\Unparser::unparse($xml); } } diff --git a/phpBB/phpbb/textformatter/utils_interface.php b/phpBB/phpbb/textformatter/utils_interface.php index 45610f7ecb..132dc8ece4 100644 --- a/phpBB/phpbb/textformatter/utils_interface.php +++ b/phpBB/phpbb/textformatter/utils_interface.php @@ -23,36 +23,26 @@ interface utils_interface * * NOTE: preserves smilies as text * - * @param string $text - * @return string + * @param string $text Parsed text + * @return string Plain text */ public function clean_formatting($text); /** - * Remove given BBCode at given nesting depth + * Remove given BBCode and its content, 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 + * @return string Parsed text */ 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 - */ - public function remove_formatting($text); - - /** * Return a parsed text to its original form * - * @param string $text - * @return string + * @param string $text Parsed text + * @return string Original plain text */ public function unparse($text); } diff --git a/tests/text_formatter/s9e/utils_test.php b/tests/text_formatter/s9e/utils_test.php index 6f0ef54182..69f8682cac 100644 --- a/tests/text_formatter/s9e/utils_test.php +++ b/tests/text_formatter/s9e/utils_test.php @@ -46,35 +46,6 @@ class phpbb_textformatter_s9e_utils_test extends phpbb_test_case } /** - * @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) |