mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-27 21:58:52 +00:00
[ticket/11768] Updated the text_formatter.s9e.utils service
Made it use s9e\TextFormatter\Utils. Refactored some tests to make them more readable. PHPBB3-11768
This commit is contained in:
parent
5b2d3fddfd
commit
37fedc656f
2 changed files with 16 additions and 38 deletions
|
@ -26,7 +26,7 @@ class utils implements \phpbb\textformatter\utils_interface
|
||||||
// Insert a space before <s> and <e> then remove formatting
|
// Insert a space before <s> and <e> then remove formatting
|
||||||
$text = preg_replace('#<[es]>#', ' $0', $text);
|
$text = preg_replace('#<[es]>#', ' $0', $text);
|
||||||
|
|
||||||
return \s9e\TextFormatter\Unparser::removeFormatting($text);
|
return \s9e\TextFormatter\Utils::removeFormatting($text);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,18 +34,7 @@ class utils implements \phpbb\textformatter\utils_interface
|
||||||
*/
|
*/
|
||||||
public function remove_bbcode($text, $bbcode_name, $depth = 0)
|
public function remove_bbcode($text, $bbcode_name, $depth = 0)
|
||||||
{
|
{
|
||||||
$dom = new \DOMDocument;
|
return \s9e\TextFormatter\Utils::removeTag($text, strtoupper($bbcode_name), $depth);
|
||||||
$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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,7 +42,7 @@ class utils implements \phpbb\textformatter\utils_interface
|
||||||
*/
|
*/
|
||||||
public function remove_formatting($text)
|
public function remove_formatting($text)
|
||||||
{
|
{
|
||||||
return \s9e\TextFormatter\Unparser::removeFormatting($text);
|
return \s9e\TextFormatter\Utils::removeFormatting($text);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -109,52 +109,41 @@ class phpbb_textformatter_s9e_utils_test extends phpbb_test_case
|
||||||
public function test_remove_bbcode($original, $name, $depth, $expected)
|
public function test_remove_bbcode($original, $name, $depth, $expected)
|
||||||
{
|
{
|
||||||
$container = $this->get_test_case_helpers()->set_s9e_services();
|
$container = $this->get_test_case_helpers()->set_s9e_services();
|
||||||
|
$parser = $container->get('text_formatter.parser');
|
||||||
$utils = $container->get('text_formatter.utils');
|
$utils = $container->get('text_formatter.utils');
|
||||||
|
|
||||||
$this->assertSame($expected, $utils->remove_bbcode($original, $name, $depth));
|
$parsed = $parser->parse($original);
|
||||||
|
$actual = $utils->unparse($utils->remove_bbcode($parsed, $name, $depth));
|
||||||
|
|
||||||
|
$this->assertSame($expected, $actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_remove_bbcode_tests()
|
public function get_remove_bbcode_tests()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
array(
|
array(
|
||||||
'<t>Plain text</t>',
|
'Plain text',
|
||||||
'b',
|
'b',
|
||||||
1,
|
1,
|
||||||
'<t>Plain text</t>'
|
'Plain text'
|
||||||
),
|
),
|
||||||
array(
|
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>
|
'[quote="u0"][quote="u1"][quote="u2"]q2[/quote]q1[/quote]q0[/quote][b]bold[/b]',
|
||||||
q1<e>[/quote]</e></QUOTE>
|
|
||||||
q0<e>[/quote]</e></QUOTE>
|
|
||||||
<B><s>[b]</s>bold<e>[/b]</e></B></r>',
|
|
||||||
'quote',
|
'quote',
|
||||||
0,
|
0,
|
||||||
'<r>
|
'[b]bold[/b]',
|
||||||
<B><s>[b]</s>bold<e>[/b]</e></B></r>'
|
|
||||||
),
|
),
|
||||||
array(
|
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>
|
'[quote="u0"][quote="u1"][quote="u2"]q2[/quote]q1[/quote]q0[/quote][b]bold[/b]',
|
||||||
q1<e>[/quote]</e></QUOTE>
|
|
||||||
q0<e>[/quote]</e></QUOTE>
|
|
||||||
<B><s>[b]</s>bold<e>[/b]</e></B></r>',
|
|
||||||
'quote',
|
'quote',
|
||||||
1,
|
1,
|
||||||
'<r><QUOTE author="u0"><s>[quote="u0"]</s>
|
'[quote="u0"]q0[/quote][b]bold[/b]',
|
||||||
q0<e>[/quote]</e></QUOTE>
|
|
||||||
<B><s>[b]</s>bold<e>[/b]</e></B></r>'
|
|
||||||
),
|
),
|
||||||
array(
|
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>
|
'[quote="u0"][quote="u1"][quote="u2"]q2[/quote]q1[/quote]q0[/quote][b]bold[/b]',
|
||||||
q1<e>[/quote]</e></QUOTE>
|
|
||||||
q0<e>[/quote]</e></QUOTE>
|
|
||||||
<B><s>[b]</s>bold<e>[/b]</e></B></r>',
|
|
||||||
'quote',
|
'quote',
|
||||||
2,
|
2,
|
||||||
'<r><QUOTE author="u0"><s>[quote="u0"]</s><QUOTE author="u1"><s>[quote="u1"]</s>
|
'[quote="u0"][quote="u1"]q1[/quote]q0[/quote][b]bold[/b]',
|
||||||
q1<e>[/quote]</e></QUOTE>
|
|
||||||
q0<e>[/quote]</e></QUOTE>
|
|
||||||
<B><s>[b]</s>bold<e>[/b]</e></B></r>'
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue