* @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_default_formatting_test extends phpbb_test_case { public function test_bbcode_code_lang_is_saved() { $container = $this->get_test_case_helpers()->set_s9e_services(); $parser = $container->get('text_formatter.parser'); $original = '[code]...[/code][code=php]...[/code]'; $expected = '[code]...[/code][code=php]...[/code]'; $this->assertXmlStringEqualsXmlString($expected, $parser->parse($original)); } /** * @dataProvider get_default_formatting_tests */ public function test_default_formatting($original, $expected, $setup = null) { $fixture = __DIR__ . '/fixtures/default_formatting.xml'; $container = $this->get_test_case_helpers()->set_s9e_services(null, $fixture); $parser = $container->get('text_formatter.parser'); $renderer = $container->get('text_formatter.renderer'); if (isset($setup)) { call_user_func($setup, $container); } $parsed_text = $parser->parse($original); $this->assertSame($expected, $renderer->render($parsed_text)); } public function get_default_formatting_tests() { return array( array( '[b]bold[/b]', 'bold' ), array( '[u]underlined[/u]', 'underlined' ), array( '[i]italic[/i]', 'italic' ), array( '[color=#FF0000]colored[/color]', 'colored' ), array( '[color=red]colored[/color]', 'colored' ), array( '[size=75]smaller[/size]', 'smaller' ), array( '[quote]quoted[/quote]', '
quoted
' ), array( '[quote="username"]quoted[/quote]', '
username wrote:quoted
' ), array( '[code]unparsed code[/code]', '

CODE: Select all

unparsed code
' ), array( '[list]no item[/list]', '' ), array( '[*]unparsed', '[*]unparsed' ), array( '[list][*]item[/list]', '' ), array( '[list][*]item[/*][/list]', '' ), array( '[list=1][*]item[/list]', '
  1. item
' ), array( '[list=a][*]item[/list]', '
  1. item
' ), array( '[list=i][*]item[/list]', '
  1. item
' ), array( '[list=I][*]item[/list]', '
  1. item
' ), array( '[list=disc][*]item[/list]', '' ), array( '[list=circle][*]item[/list]', '' ), array( '[list=square][*]item[/list]', '' ), array( '[img]https://area51.phpbb.com/images/area51.png[/img]', 'Image' ), array( '[url]https://area51.phpbb.com/[/url]', 'https://area51.phpbb.com/' ), array( '[url=https://area51.phpbb.com/]Area51[/url]', 'Area51' ), array( '[email]bbcode-test@phpbb.com[/email]', 'bbcode-test@phpbb.com' ), array( '[email=bbcode-test@phpbb.com]Email[/email]', 'Email' ), array( '[attachment=0]filename[/attachment]', '
filename
' ), array( // PHPBB3-1401 - correct: parsed '[quote="[test]test"]test [ test[/quote]', '
[test]test wrote:test [ test
' ), array( // PHPBB3-6117 - correct: parsed '[quote]test[/quote] test ] and [ test [quote]test[/quote]', '
test
test ] and [ test
test
' ), array( // PHPBB3-6200 - correct: parsed '[quote="["]test[/quote]', '
[ wrote:test
' ), array( // PHPBB3-9364 - quoted: "test[/[/b]quote] test" / non-quoted: "[/quote] test" - also failed if layout distorted '[quote]test[/[/b]quote] test [/quote][/quote] test', '
test[/[/b]quote] test
[/quote] test' ), array( // PHPBB3-8096 - first quote tag parsed, second quote tag unparsed '[quote="a"]a[/quote][quote="a]a[/quote]', '
a wrote:a
[quote="a]a[/quote]' ), array( // Allow textual bbcodes in textual bbcodes '[b]bold [i]bold + italic[/i][/b]', 'bold bold + italic' ), array( // Allow textual bbcodes in url with description '[url=https://area51.phpbb.com/]Area51 [i]italic[/i][/url]', 'Area51 italic' ), array( // Allow url with description in textual bbcodes '[i]italic [url=https://area51.phpbb.com/]Area51[/url][/i]', 'italic Area51' ), array( // Do not parse textual bbcodes in code '[code]unparsed code [b]bold [i]bold + italic[/i][/b][/code]', '

CODE: Select all

unparsed code [b]bold [i]bold + italic[/i][/b]
' ), array( // Do not parse quote bbcodes in code '[code]unparsed code [quote="username"]quoted[/quote][/code]', '

CODE: Select all

unparsed code [quote="username"]quoted[/quote]
' ), array( // Textual bbcode nesting into textual bbcode '[b]bold [i]bold + italic[/b] italic[/i]', 'bold bold + italic italic' ), array( "[code]\tline1\n line2[/code]", '

CODE: Select all

' . "\tline1\n  line2
" ), array( "[code]\n\tline1\n line2[/code]", '

CODE: Select all

' . "\tline1\n  line2
" ), array( '... http://example.org ...', '... http://example.org ...' ), array( '... www.example.org ...', '... www.example.org ...' ), array( // From make_clickable_test.php 'www.phpbb.com/community/?', 'www.phpbb.com/community/?' ), array( // From make_clickable_test.php 'http://www.phpbb.com/community/path/to/long/url/file.ext#section', 'http://www.phpbb.com/community/path/to/ ... xt#section' ), array( 'http://localhost/ http://localhost/phpbb/ http://localhost/phpbb/viewforum.php?f=1', 'http://localhost/ http://localhost/phpbb/ viewforum.php?f=1' ), array( 'http://localhost/phpbb/viewforum.php?f=1#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'viewforum.php?f=1#xxxxxxxxxxxxxxxxxxxxx ... xxxxxxxxxx' ), array( '[url]http://example.org/0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0[/url]', 'http://example.org/0xxxxxxxxxxxxxxxxxxx ... xxxxxxxxx0' ), array( '[URL]http://example.org/0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0[/url]', 'http://example.org/0xxxxxxxxxxxxxxxxxxx ... xxxxxxxxx0' ), array( '[url=http://example.org/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx]xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx[/url]', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' ), array( '[url=http://example.org/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx]http://example.org/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx[/url]', 'http://example.org/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' ), array( '[quote="[url=http://example.org]xxx[/url]"]...[/quote]', '
xxx wrote:...
' ), array( '[quote="[url]http://example.org[/url]"]...[/quote]', '
http://example.org wrote:...
' ), array( '[quote=http://example.org]...[/quote]', '
http://example.org wrote:...
' ), array( "[quote]\nThis is a long quote that is definitely going to exceed 80 characters\n[/quote]\n\nFollowed by a reply", "
\nThis is a long quote that is definitely going to exceed 80 characters\n
\n\nFollowed by a reply" ), array( '[quote=Username post_id=123]...[/quote]', '
Username wrote: ...
' ), array( // Users are not allowed to submit their own URL for the post '[quote="Username" post_url="http://fake.example.org"]...[/quote]', '
Username wrote:...
' ), array( '[quote=Username time=58705871]...[/quote]', '
Username wrote:
1971-11-11 11:11:11
...
' ), array( '[quote=Username user_id=123]...[/quote]', '
Username wrote:...
' ), array( // Users are not allowed to submit their own URL for the profile '[quote=Username profile_url=http://fake.example.org]...[/quote]', '
Username wrote:...
' ), array( // From phpbb_textformatter_s9e_utils_test::test_generate_quote() '[quote=\'[quote="foo"]\']...[/quote]', '
[quote="foo"] wrote:...
' ), array( "Emoji: \xF0\x9F\x98\x80", 'Emoji: ' . ' ), array( "Emoji: \xF0\x9F\x98\x80", "Emoji: \xF0\x9F\x98\x80", function ($container) { $container->get('text_formatter.renderer')->set_viewsmilies(false); } ), ); } }