From 75e7e7b293c812645942427fd8156a160225d0d5 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 27 Nov 2017 21:12:19 +0100 Subject: [ticket/15468] Add a service to merge duplicate BBCodes PHPBB3-15468 --- tests/text_formatter/s9e/bbcode_merger_test.php | 280 ++++++++++++++++++++++++ 1 file changed, 280 insertions(+) create mode 100644 tests/text_formatter/s9e/bbcode_merger_test.php (limited to 'tests/text_formatter/s9e/bbcode_merger_test.php') diff --git a/tests/text_formatter/s9e/bbcode_merger_test.php b/tests/text_formatter/s9e/bbcode_merger_test.php new file mode 100644 index 0000000000..815539056b --- /dev/null +++ b/tests/text_formatter/s9e/bbcode_merger_test.php @@ -0,0 +1,280 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +class phpbb_textformatter_s9e_bbcode_merger_test extends phpbb_test_case +{ + /** + * @dataProvider get_merge_bbcodes_tests + */ + public function test_merge_bbcodes($usage_without, $template_without, $usage_with, $template_with, $expected_usage, $expected_template) + { + $container = $this->get_test_case_helpers()->set_s9e_services(); + $factory = $container->get('text_formatter.s9e.factory'); + $bbcode_merger = new \phpbb\textformatter\s9e\bbcode_merger($factory); + + $without = ['usage' => $usage_without, 'template' => $template_without]; + $with = ['usage' => $usage_with, 'template' => $template_with]; + $merged = $bbcode_merger->merge_bbcodes($without, $with); + + // Normalize the expected template's whitespace to match the default indentation + $expected_template = str_replace("\n\t\t\t\t", "\n", $expected_template); + $expected_template = str_replace("\t", ' ', $expected_template); + + $this->assertSame($expected_usage, $merged['usage']); + $this->assertSame($expected_template, $merged['template']); + } + + public function get_merge_bbcodes_tests() + { + return [ + [ + '[x]{TEXT}[/x]', + '{TEXT}', + + '[x={TEXT1}]{TEXT}[/x]', + '{TEXT}', + + '[x={TEXT1?}]{TEXT}[/x]', + ' + + + + + + + ' + ], + [ + // The tokens' numbering differs between versions + '[x]{TEXT}[/x]', + '{TEXT}', + + '[x={TEXT1}]{TEXT2}[/x]', + '{TEXT2}', + + '[x={TEXT1?}]{TEXT2}[/x]', + ' + + + + + + + ' + ], + [ + '[x]{URL}[/x]', + '{URL}', + + '[x={URL}]{TEXT}[/x]', + '{TEXT}', + + '[x={URL;useContent}]{TEXT}[/x]', + ' + + ' + ], + [ + '[x]{URL}[/x]', + '{L_GO_TO}: {URL}', + + '[x={URL}]{TEXT}[/x]', + '{L_GO_TO}: {TEXT}', + + '[x={URL;useContent}]{TEXT}[/x]', + '{L_GO_TO}: ' + ], + [ + // Test that unsafe BBCodes can still be merged + '[script]{TEXT}[/script]', + '', + + '[script={TEXT1}]{TEXT2}[/script]', + '', + + '[script={TEXT1?}]{TEXT2}[/script]', + '' + ], + [ + // https://www.phpbb.com/community/viewtopic.php?p=14848281#p14848281 + '[note]{TEXT}[/note]', + '{TEXT}', + + '[note={TEXT1}]{TEXT2}[/note]', + '{TEXT1}{TEXT2}', + + '[note={TEXT1?}]{TEXT2}[/note]', + ' + + + + + + + + ' + ], + [ + // https://www.phpbb.com/community/viewtopic.php?p=14768441#p14768441 + '[MI]{TEXT}[/MI]', + 'MI: {TEXT}', + + '[MI={TEXT2}]{TEXT1}[/MI]', + 'MI for: "{TEXT2}": {TEXT1}', + + '[MI={TEXT2?}]{TEXT1}[/MI]', + 'MI for: "": + + + + ' + ], + [ + // https://www.phpbb.com/community/viewtopic.php?p=14700506#p14700506 + '[spoiler]{TEXT}[/spoiler]', + ' {TEXT}', + + '[spoiler={TEXT1}]{TEXT2}[/spoiler]', + '
{TEXT1}{TEXT2}
', + + '[spoiler={TEXT1?}]{TEXT2}[/spoiler]', + ' + +
+ + + + + +
+
+ + + + + + +
' + ], + [ + // https://www.phpbb.com/community/viewtopic.php?p=14859676#p14859676 + '[AE]{TEXT}[/AE]', + ' + +
+ + + + +
+ + + + + + + + +
+  ACTIVE EFFECTS & CONDITIONS  
+ + + + +
+ {TEXT} +
+
+
+
+

 

', + + '[AE={TEXT1}]{TEXT2}[/AE]', + ' + +
+ + + + +
+ + + + + + + + +
+   {TEXT1}  
+ + + + +
+ {TEXT2} +
+
+
+
+

 

', + + '[AE={TEXT1?}]{TEXT2}[/AE]', + ' + + + +
+ + + + +
+ + + + + + + + +
+ + +   ACTIVE EFFECTS & CONDITIONS  + + +  
+ + + + +
+ +
+
+
+
+

 

' + ], + ]; + } +} -- cgit v1.2.1 From d6f5b5ef6cd052d43f4bf75af423eaafd8ba9b07 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 25 Nov 2019 18:34:04 +0100 Subject: [ticket/16228] Fix BBCodes merging PHPBB3-16228 --- tests/text_formatter/s9e/bbcode_merger_test.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests/text_formatter/s9e/bbcode_merger_test.php') diff --git a/tests/text_formatter/s9e/bbcode_merger_test.php b/tests/text_formatter/s9e/bbcode_merger_test.php index 815539056b..5ec0c91971 100644 --- a/tests/text_formatter/s9e/bbcode_merger_test.php +++ b/tests/text_formatter/s9e/bbcode_merger_test.php @@ -275,6 +275,22 @@ class phpbb_textformatter_s9e_bbcode_merger_test extends phpbb_test_case

 

' ], + [ + // https://www.phpbb.com/community/viewtopic.php?f=438&t=2530451 + '[issue]{NUMBER}[/issue]', + ' Issue #{NUMBER}', + + '[issue={SIMPLETEXT}]{NUMBER}[/issue]', + ' Issue #{NUMBER} ({SIMPLETEXT})', + + '[issue={SIMPLETEXT?}]{NUMBER}[/issue]', + ' + + //issues/ Issue # () + /default/issues/ Issue # + + ' + ], ]; } } -- cgit v1.2.1