* @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   

 

' ], ]; } }