+
diff --git a/tests/text_processing/generate_text_for_display_test.php b/tests/text_processing/generate_text_for_display_test.php
index 057416da33..fe83938c0b 100644
--- a/tests/text_processing/generate_text_for_display_test.php
+++ b/tests/text_processing/generate_text_for_display_test.php
@@ -11,10 +11,8 @@
*
*/
-require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
-require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php';
-require_once dirname(__FILE__) . '/../mock/user.php';
-require_once dirname(__FILE__) . '/../mock/cache.php';
+require_once __DIR__ . '/../../phpBB/includes/functions.php';
+require_once __DIR__ . '/../../phpBB/includes/functions_content.php';
class phpbb_text_processing_generate_text_for_display_test extends phpbb_test_case
{
@@ -24,21 +22,175 @@ class phpbb_text_processing_generate_text_for_display_test extends phpbb_test_ca
parent::setUp();
- $cache = new phpbb_mock_cache;
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher;
+ $config = new \phpbb\config\config(array());
+ set_config(null, null, null, $config);
+ }
- $user = new phpbb_mock_user;
+ /**
+ * @dataProvider get_legacy_tests
+ */
+ public function test_legacy($original, $expected, $uid = '', $bitfield = '', $flags = 0, $censor_text = true)
+ {
+ global $cache, $user;
+
+ $cache = new phpbb_mock_cache;
+ $user = new \phpbb\user('\\phpbb\\datetime');
+ $user->optionset('viewcensors', true);
+ $user->optionset('viewflash', true);
+ $user->optionset('viewimg', true);
+ $user->optionset('viewsmilies', true);
+
+ $actual = generate_text_for_display($original, $uid, $bitfield, $flags, $censor_text);
+
+ $this->assertSame($expected, $actual);
+ }
+
+ public function get_legacy_tests()
+ {
+ return array(
+ array(
+ '',
+ ''
+ ),
+ array(
+ '0',
+ '0'
+ ),
+ );
+ }
+
+ public function test_censor_is_restored()
+ {
+ global $phpbb_container;
+
+ $phpbb_container = new phpbb_mock_container_builder;
+
+ $user = new \phpbb\user('\\phpbb\\datetime');
$user->optionset('viewcensors', false);
- $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+ $config = new \phpbb\config\config(array('allow_nocensors' => true));
+
+ $auth = $this->getMock('phpbb\\auth\\auth');
+ $auth->expects($this->any())
+ ->method('acl_get')
+ ->with('u_chgcensors')
+ ->will($this->returnValue(true));
+
+ $phpbb_container->set('user', $user);
+ $phpbb_container->set('config', $config);
+ $phpbb_container->set('auth', $auth);
+
+ $this->get_test_case_helpers()->set_s9e_services($phpbb_container);
+ $renderer = $phpbb_container->get('text_formatter.renderer');
+
+ $original = 'apple';
+
+ $renderer->set_viewcensors(false);
+ $this->assertSame('apple', $renderer->render($original));
+ $renderer->set_viewcensors(true);
+ $this->assertSame('banana', $renderer->render($original));
+ $this->assertSame('apple', generate_text_for_display($original, '', '', 0, false));
+ $this->assertSame('banana', $renderer->render($original), 'The original setting was not restored');
+
+ $renderer->set_viewcensors(false);
+ $this->assertSame('apple', $renderer->render($original));
+ $this->assertSame('banana', generate_text_for_display($original, '', '', 0, truee));
+ $this->assertSame('apple', $renderer->render($original), 'The original setting was not restored');
}
- public function test_empty_string()
+ /**
+ * @dataProvider get_text_formatter_tests
+ */
+ public function test_text_formatter($original, $expected, $censor_text = true, $setup = null)
{
- $this->assertSame('', generate_text_for_display('', '', '', 0));
+ global $phpbb_container;
+
+ $phpbb_container = new phpbb_mock_container_builder;
+
+ if (isset($setup))
+ {
+ $setup($phpbb_container, $this);
+ }
+
+ $this->get_test_case_helpers()->set_s9e_services($phpbb_container);
+
+ $this->assertSame($expected, generate_text_for_display($original, '', '', 0, $censor_text));
}
- public function test_zero_string()
+ public function get_text_formatter_tests()
{
- $this->assertSame('0', generate_text_for_display('0', '', '', 0));
+ return array(
+ array(
+ 'Plain text',
+ 'Plain text'
+ ),
+ array(
+ 'Hello [url=http://example.org]world[/url]',
+ 'Hello world'
+ ),
+ array(
+ '&<>"\'',
+ '&<>"\''
+ ),
+ array(
+ 'apple',
+ 'banana',
+ true
+ ),
+ array(
+ 'apple',
+ 'apple',
+ false
+ ),
+ array(
+ '[flash=123,456]http://localhost/foo.swf[/flash]',
+ ''
+ ),
+ array(
+ '[flash=123,456]http://localhost/foo.swf[/flash]',
+ 'http://localhost/foo.swf',
+ true,
+ function ($phpbb_container)
+ {
+ $user = new \phpbb\user('\\phpbb\\datetime');
+ $user->optionset('viewflash', false);
+
+ $phpbb_container->set('user', $user);
+ }
+ ),
+ array(
+ '[img]http://localhost/mrgreen.gif[/img]',
+ ''
+ ),
+ array(
+ '[img]http://localhost/mrgreen.gif[/img]',
+ 'http://localhost/mrgreen.gif',
+ true,
+ function ($phpbb_container)
+ {
+ $user = new \phpbb\user('\\phpbb\\datetime');
+ $user->optionset('viewimg', false);
+
+ $phpbb_container->set('user', $user);
+ }
+ ),
+ array(
+ ':)',
+ ''
+ ),
+ array(
+ ':)',
+ ':)',
+ true,
+ function ($phpbb_container)
+ {
+ $user = new \phpbb\user('\\phpbb\\datetime');
+ $user->optionset('smilies', false);
+
+ $phpbb_container->set('user', $user);
+ }
+ ),
+ );
}
}
diff --git a/tests/text_processing/generate_text_for_edit_test.php b/tests/text_processing/generate_text_for_edit_test.php
new file mode 100644
index 0000000000..105e8da86b
--- /dev/null
+++ b/tests/text_processing/generate_text_for_edit_test.php
@@ -0,0 +1,92 @@
+
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+require_once __DIR__ . '/../../phpBB/includes/functions.php';
+require_once __DIR__ . '/../../phpBB/includes/functions_content.php';
+
+class phpbb_text_processing_generate_text_for_edit_test extends phpbb_test_case
+{
+ /**
+ * @dataProvider get_legacy_tests
+ */
+ public function test_legacy($original, $expected, $uid = '', $flags = 0)
+ {
+ global $cache, $user, $phpbb_dispatcher;
+
+ $cache = new phpbb_mock_cache;
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher;
+
+ $user = new phpbb_mock_user;
+ $user->optionset('viewcensors', false);
+
+ $return = generate_text_for_edit($original, $uid, $flags);
+
+ $this->assertSame($expected, $return['text']);
+ }
+
+ public function get_legacy_tests()
+ {
+ return array(
+ array(
+ '',
+ ''
+ ),
+ array(
+ '0',
+ '0'
+ ),
+ array(
+ 'Hello [url=http://example.org:1f4coh9x]world[/url:1f4coh9x] ',
+ 'Hello [url=http://example.org]world[/url] :)',
+ '1f4coh9x',
+ 0
+ ),
+ array(
+ "&<>"'",
+ "&<>"'"
+ )
+ );
+ }
+
+ /**
+ * @dataProvider get_text_formatter_tests
+ */
+ public function test_text_formatter($original, $expected)
+ {
+ global $phpbb_dispatcher;
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher;
+ $this->get_test_case_helpers()->set_s9e_services();
+
+ $return = generate_text_for_edit($original, '', 0);
+
+ $this->assertSame($expected, $return['text']);
+ }
+
+ public function get_text_formatter_tests()
+ {
+ return array(
+ array(
+ 'Plain text',
+ 'Plain text'
+ ),
+ array(
+ 'Hello [url=http://example.org]world[/url]:)',
+ 'Hello [url=http://example.org]world[/url] :)'
+ ),
+ array(
+ '&<>"\'',
+ "&<>"'"
+ )
+ );
+ }
+}
diff --git a/tests/text_processing/generate_text_for_storage_test.php b/tests/text_processing/generate_text_for_storage_test.php
new file mode 100644
index 0000000000..ffa06e4e02
--- /dev/null
+++ b/tests/text_processing/generate_text_for_storage_test.php
@@ -0,0 +1,73 @@
+
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+require_once __DIR__ . '/../../phpBB/includes/functions.php';
+require_once __DIR__ . '/../../phpBB/includes/functions_content.php';
+require_once __DIR__ . '/../../phpBB/includes/utf/utf_tools.php';
+
+class phpbb_text_processing_generate_text_for_storage_test extends phpbb_test_case
+{
+ public function setUp()
+ {
+ global $config, $phpbb_container, $phpbb_dispatcher;
+
+ parent::setUp();
+
+ $config = new \phpbb\config\config(array());
+ set_config(null, null, null, $config);
+
+ $phpbb_container = new phpbb_mock_container_builder;
+ $phpbb_container->set('config', $config);
+ $this->get_test_case_helpers()->set_s9e_services($phpbb_container);
+
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher;
+ }
+
+ /**
+ * @dataProvider get_text_formatter_tests
+ */
+ public function test_text_formatter($original, $expected, $allow_bbcode = true, $allow_urls = true, $allow_smilies = true, $setup = null)
+ {
+ $actual = $original;
+ $uid = '';
+ $bitfield = '';
+ $flags = 0;
+
+ if (isset($setup))
+ {
+ $setup();
+ }
+
+ generate_text_for_storage($actual, $uid, $bitfield, $flags, $allow_bbcode, $allow_urls, $allow_smilies);
+
+ $this->assertSame($expected, $actual);
+ }
+
+ public function get_text_formatter_tests()
+ {
+ return array(
+ array(
+ 'Hello world',
+ 'Hello world'
+ ),
+ array(
+ 'Hello [url=http://example.org]world[/url] :)',
+ 'Hello [url=http://example.org]world[/url]:)'
+ ),
+ array(
+ '&<>"\'',
+ '&<>"\''
+ ),
+ );
+ }
+}
diff --git a/tests/text_processing/message_parser_test.php b/tests/text_processing/message_parser_test.php
new file mode 100644
index 0000000000..691c0d5b8a
--- /dev/null
+++ b/tests/text_processing/message_parser_test.php
@@ -0,0 +1,536 @@
+
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+require_once __DIR__ . '/../../phpBB/includes/bbcode.php';
+require_once __DIR__ . '/../../phpBB/includes/functions.php';
+require_once __DIR__ . '/../../phpBB/includes/functions_content.php';
+require_once __DIR__ . '/../../phpBB/includes/message_parser.php';
+require_once __DIR__ . '/../../phpBB/includes/utf/utf_tools.php';
+
+class phpbb_text_processing_message_parser_test extends phpbb_test_case
+{
+ public static function setUpBeforeClass()
+ {
+ parent::setUpBeforeClass();
+
+ // Set up an intercepting proxy for getimagesize() calls
+ stream_wrapper_unregister('http');
+ stream_wrapper_register('http', __CLASS__ . '_proxy');
+ }
+
+ public static function tearDownAfterClass()
+ {
+ parent::tearDownAfterClass();
+ stream_wrapper_restore('http');
+ }
+
+ protected function prepare_s9e_services($setup = null)
+ {
+ global $config, $phpbb_container, $user;
+
+ $config = new \phpbb\config\config(array('max_poll_options' => 999));
+
+ $map = array(
+ array('MAX_FLASH_HEIGHT_EXCEEDED', 123, 'Your flash files may only be up to 123 pixels high.'),
+ array('MAX_FLASH_WIDTH_EXCEEDED', 456, 'Your flash files may only be up to 456 pixels wide.'),
+ array('MAX_FONT_SIZE_EXCEEDED', 120, 'You may only use fonts up to size 120.'),
+ array('MAX_FONT_SIZE_EXCEEDED', 200, 'You may only use fonts up to size 200.'),
+ array('MAX_IMG_HEIGHT_EXCEEDED', 12, 'Your images may only be up to 12 pixels high.'),
+ array('MAX_IMG_WIDTH_EXCEEDED', 34, 'Your images may only be up to 34 pixels wide.'),
+ array('TOO_MANY_SMILIES', 3, 'Your message contains too many smilies. The maximum number of smilies allowed is 3.'),
+ array('TOO_MANY_URLS', 2, 'Your message contains too many URLs. The maximum number of URLs allowed is 2.'),
+ array('UNAUTHORISED_BBCODE', '[flash]', 'You cannot use certain BBCodes: [flash].'),
+ array('UNAUTHORISED_BBCODE', '[img]', 'You cannot use certain BBCodes: [img].'),
+ array('UNAUTHORISED_BBCODE', '[quote]', 'You cannot use certain BBCodes: [quote].'),
+ array('UNAUTHORISED_BBCODE', '[url]', 'You cannot use certain BBCodes: [url].'),
+ array('UNABLE_GET_IMAGE_SIZE', 'It was not possible to determine the dimensions of the image.'),
+ );
+
+ $user = $this->getMockBuilder('phpbb\\user')->disableOriginalConstructor()->getMock();
+ $user->expects($this->any())
+ ->method('lang')
+ ->will($this->returnValueMap($map));
+
+ $user->lang = array(
+ 'NO_POLL_TITLE' => 'You have to enter a poll title.',
+ 'POLL_TITLE_TOO_LONG' => 'The poll title must contain fewer than 100 characters.',
+ 'POLL_TITLE_COMP_TOO_LONG' => 'The parsed size of your poll title is too large, consider removing BBCodes or smilies.',
+ 'TOO_FEW_POLL_OPTIONS' => 'You must enter at least two poll options.',
+ 'TOO_MANY_POLL_OPTIONS' => 'You have tried to enter too many poll options.',
+ 'TOO_MANY_USER_OPTIONS' => 'You cannot specify more options per user than existing poll options.',
+ );
+
+ $phpbb_container = new phpbb_mock_container_builder;
+ $phpbb_container->set('user', $user);
+ $phpbb_container->set('config', $config);
+
+ if (isset($setup))
+ {
+ $setup($parser, $phpbb_container, $this);
+ }
+
+ $this->get_test_case_helpers()->set_s9e_services($phpbb_container);
+ }
+
+ /**
+ * @dataProvider get_test_polls
+ */
+ public function test_parse_poll($poll, $expected, $warn_msg = array())
+ {
+ $this->prepare_s9e_services();
+
+ $message_parser = new parse_message('Me[i]s[/i]sage');
+
+ // Add some default values
+ $poll += array(
+ 'poll_length' => 123,
+ 'poll_start' => 123,
+ 'poll_last_vote' => 123,
+ 'poll_vote_change' => true,
+ 'enable_bbcode' => true,
+ 'enable_urls' => true,
+ 'enable_smilies' => true,
+ 'img_status' => true
+ );
+
+ $message_parser->parse_poll($poll);
+ $this->assertSame($expected, array_intersect_key($poll, $expected));
+
+ $this->assertSame(
+ 'Me[i]s[/i]sage',
+ $message_parser->parse(true, true, true, true, true, true, true, false)
+ );
+
+ $this->assertSame($warn_msg, $message_parser->warn_msg);
+ }
+
+ public function get_test_polls()
+ {
+ return array(
+ array(
+ array(
+ 'poll_title' => 'foo [b]bar[/b] baz',
+ 'poll_option_text' => "[i]foo[/i]\nbar\n[i]baz[/i]",
+ 'poll_max_options' => 3,
+ 'poll_options_size' => 3
+ ),
+ array(
+ 'poll_title' => 'foo [b]bar[/b] baz',
+ 'poll_option_text' => "[i]foo[/i]\nbar\n[i]baz[/i]",
+ 'poll_options' => array(
+ '[i]foo[/i]',
+ 'bar',
+ '[i]baz[/i]'
+ )
+ )
+ ),
+ array(
+ array(
+ 'poll_title' => 'xxx',
+ 'poll_option_text' => "[quote]quote[/quote]\n:)",
+ 'poll_max_options' => 2,
+ 'poll_options_size' => 2
+ ),
+ array(
+ 'poll_title' => 'xxx',
+ 'poll_option_text' => "[quote]quote[/quote]\n:)",
+ 'poll_options' => array(
+ '[quote]quote[/quote]',
+ ':)'
+ )
+ ),
+ array('You cannot use certain BBCodes: [quote].')
+ ),
+ array(
+ array(
+ 'poll_title' => 'xxx',
+ 'poll_option_text' => "[flash=12,34]http://example.org/x.swf[/flash]\n:)",
+ 'poll_max_options' => 2,
+ 'poll_options_size' => 2
+ ),
+ array(
+ 'poll_title' => 'xxx',
+ 'poll_option_text' => "[flash=12,34]http://example.org/x.swf[/flash]\n:)",
+ 'poll_options' => array(
+ '[flash=12,34]http://example.org/x.swf[/flash]',
+ ':)'
+ )
+ ),
+ array('You cannot use certain BBCodes: [flash].')
+ ),
+ array(
+ array(
+ 'poll_title' => 'xxx',
+ 'poll_option_text' => "[b]x\ny[/b]",
+ 'poll_max_options' => 2,
+ 'poll_options_size' => 2
+ ),
+ array(
+ 'poll_title' => 'xxx',
+ 'poll_option_text' => "[b]x\ny[/b]",
+ 'poll_options' => array(
+ '[b]x',
+ 'y[/b]',
+ )
+ )
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider get_test_cases
+ */
+ public function test_options($original, $expected, array $args, $setup = null, $warn_msg = array())
+ {
+ $this->prepare_s9e_services($setup);
+
+ $message_parser = new parse_message($original);
+ call_user_func_array(array($message_parser, 'parse'), $args);
+
+ $this->assertSame($expected, $message_parser->message);
+ $this->assertSame($warn_msg, $message_parser->warn_msg);
+ }
+
+ public function get_test_cases()
+ {
+ return array(
+ array(
+ '[b]bold[/b]',
+ '[b]bold[/b]',
+ array(true, true, true, true, true, true, true)
+ ),
+ array(
+ '[b]bold[/b]',
+ '[b]bold[/b]',
+ array(false, true, true, true, true, true, true)
+ ),
+ array(
+ 'http://example.org',
+ 'http://example.org',
+ array(true, true, true, true, true, true, true)
+ ),
+ array(
+ 'http://example.org',
+ 'http://example.org',
+ array(true, false, true, true, true, true, true)
+ ),
+ array(
+ ':)',
+ ':)',
+ array(true, true, true, true, true, true, true)
+ ),
+ array(
+ ':)',
+ ':)',
+ array(true, true, false, true, true, true, true)
+ ),
+ array(
+ '[url=http://example.org][img]http://example.org/img.png[/img][/url]',
+ '[url=http://example.org][img]http://example.org/img.png[/img][/url]',
+ array(true, true, true, true, true, true, true)
+ ),
+ array(
+ '[url=http://example.org][img]http://example.org/img.png[/img][/url]',
+ '[url=http://example.org][img]http://example.org/img.png[/img][/url]',
+ array(true, true, true, false, true, true, true),
+ null,
+ array('You cannot use certain BBCodes: [img].')
+ ),
+ array(
+ '[flash=12,34]http://example.org/foo.swf[/flash]',
+ '[flash=12,34]http://example.org/foo.swf[/flash]',
+ array(true, true, true, true, true, true, true)
+ ),
+ array(
+ '[flash=12,34]http://example.org/foo.swf[/flash]',
+ '[flash=12,34]http://example.org/foo.swf[/flash]',
+ array(true, true, true, true, false, true, true),
+ null,
+ array('You cannot use certain BBCodes: [flash].')
+ ),
+ array(
+ '[quote="foo"]bar :)[/quote]',
+ '[quote="foo"]bar :)[/quote]',
+ array(true, true, true, true, true, true, true)
+ ),
+ array(
+ '[quote="foo"]bar :)[/quote]',
+ '[quote="foo"]bar :)[/quote]',
+ array(true, true, true, true, true, false, true),
+ null,
+ array('You cannot use certain BBCodes: [quote].')
+ ),
+ array(
+ '[url=http://example.org][img]http://example.org/img.png[/img][/url]',
+ '[url=http://example.org][img]http://example.org/img.png[/img][/url]',
+ array(true, true, true, true, true, true, true)
+ ),
+ array(
+ '[url=http://example.org][img]http://example.org/img.png[/img][/url]',
+ '[url=http://example.org][img]http://example.org/img.png[/img][/url]',
+ array(true, true, true, true, true, true, false),
+ null,
+ array('You cannot use certain BBCodes: [url].')
+ ),
+ array(
+ '[size=200]200[/size]',
+ '[size=200]200[/size]',
+ array(true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_post_font_size', 200);
+ }
+ ),
+ array(
+ '[size=200]200[/size]',
+ '[size=200]200[/size]',
+ array(true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_post_font_size', 0);
+ }
+ ),
+ array(
+ '[size=2000]2000[/size]',
+ '[size=2000]2000[/size]',
+ array(true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_post_font_size', 200);
+ },
+ array('You may only use fonts up to size 200.')
+ ),
+ array(
+ '[size=0]0[/size]',
+ '[size=0]0[/size]',
+ array(true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_post_font_size', 200);
+ }
+ ),
+ array(
+ '[size=200]200[/size]',
+ '[size=200]200[/size]',
+ array(true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_sig_font_size', 200);
+ }
+ ),
+ array(
+ '[size=200]200[/size]',
+ '[size=200]200[/size]',
+ array(true, true, true, true, true, true, true, true, 'sig'),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_sig_font_size', 120);
+ },
+ array('You may only use fonts up to size 120.')
+ ),
+ array(
+ '[img]http://example.org/100x100.png[/img]',
+ '[img]http://example.org/100x100.png[/img]',
+ array(true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_post_img_height', 12);
+ },
+ array('Your images may only be up to 12 pixels high.')
+ ),
+ array(
+ '[img]http://example.org/100x100.png[/img]',
+ '[img]http://example.org/100x100.png[/img]',
+ array(true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_post_img_width', 34);
+ },
+ array('Your images may only be up to 34 pixels wide.')
+ ),
+ array(
+ '[img]http://example.org/100x100.png[/img]',
+ '[img]http://example.org/100x100.png[/img]',
+ array(true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_post_img_height', 0);
+ $phpbb_container->get('config')->set('max_post_img_width', 0);
+ }
+ ),
+ array(
+ '[img]http://example.org/100x100.png[/img]',
+ '[img]http://example.org/100x100.png[/img]',
+ array(true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_post_img_height', 100);
+ $phpbb_container->get('config')->set('max_post_img_width', 100);
+ }
+ ),
+ array(
+ '[img]http://example.org/100x100.png[/img]',
+ '[img]http://example.org/100x100.png[/img]',
+ array(true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_sig_img_height', 12);
+ $phpbb_container->get('config')->set('max_sig_img_width', 34);
+ }
+ ),
+ array(
+ '[img]http://example.org/404.png[/img]',
+ '[img]http://example.org/404.png[/img]',
+ array(true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_post_img_height', 12);
+ },
+ array('It was not possible to determine the dimensions of the image.')
+ ),
+ array(
+ '[flash=999,999]http://example.org/foo.swf[/flash]',
+ '[flash=999,999]http://example.org/foo.swf[/flash]',
+ array(true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_post_img_height', 123);
+ },
+ array('Your flash files may only be up to 123 pixels high.')
+ ),
+ array(
+ '[flash=999,999]http://example.org/foo.swf[/flash]',
+ '[flash=999,999]http://example.org/foo.swf[/flash]',
+ array(true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_post_img_width', 456);
+ },
+ array('Your flash files may only be up to 456 pixels wide.')
+ ),
+ array(
+ ':) :) :)',
+ ':):):)',
+ array(true, true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_post_smilies', 3);
+ }
+ ),
+ array(
+ ':) :) :) :)',
+ ':):):) :)',
+ array(true, true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_post_smilies', 3);
+ },
+ array('Your message contains too many smilies. The maximum number of smilies allowed is 3.')
+ ),
+ array(
+ ':) :) :) :)',
+ ':):):):)',
+ array(true, true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_post_smilies', 0);
+ }
+ ),
+ array(
+ ':) :) :) :)',
+ ':):):):)',
+ array(true, true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_sig_smilies', 3);
+ }
+ ),
+ array(
+ ':) :) :) :)',
+ ':):):) :)',
+ array(true, true, true, true, true, true, true, true, 'sig'),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_sig_smilies', 3);
+ },
+ array('Your message contains too many smilies. The maximum number of smilies allowed is 3.')
+ ),
+ array(
+ 'http://example.org http://example.org http://example.org',
+ 'http://example.orghttp://example.org http://example.org',
+ array(true, true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_post_urls', 2);
+ },
+ array('Your message contains too many URLs. The maximum number of URLs allowed is 2.')
+ ),
+ array(
+ 'http://example.org http://example.org http://example.org',
+ 'http://example.orghttp://example.orghttp://example.org',
+ array(true, true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_post_urls', 0);
+ }
+ ),
+ array(
+ 'http://example.org http://example.org http://example.org',
+ 'http://example.orghttp://example.orghttp://example.org',
+ array(true, true, true, true, true, true, true, true),
+ function ($parser, $phpbb_container)
+ {
+ $phpbb_container->get('config')->set('max_sig_urls', 2);
+ }
+ ),
+ );
+ }
+}
+
+class phpbb_text_processing_message_parser_test_proxy
+{
+ protected $response;
+
+ public function stream_open($url)
+ {
+ if (strpos($url, '100x100'))
+ {
+ // Return a 100 x 100 PNG image
+ $this->response = base64_decode('iVBORw0KGgoAAAANSUhEUgAAAGQAAABkAQAAAABYmaj5AAAAE0lEQVR4AWOgKxgFo2AUjIJRAAAFeAABHs0ozQAAAABJRU5ErkJggg==');
+ }
+ else
+ {
+ $this->response = '404 not found';
+ }
+
+ return true;
+ }
+
+ public function stream_stat()
+ {
+ return false;
+ }
+
+ public function stream_read($len)
+ {
+ $chunk = substr($this->response, 0, $len);
+ $this->response = substr($this->response, $len);
+
+ return $chunk;
+ }
+
+ public function stream_eof()
+ {
+ return ($this->response === false);
+ }
+}
diff --git a/tests/text_processing/smilies_test.php b/tests/text_processing/smilies_test.php
new file mode 100644
index 0000000000..3bbe065d36
--- /dev/null
+++ b/tests/text_processing/smilies_test.php
@@ -0,0 +1,52 @@
+
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+require_once __DIR__ . '/../../phpBB/includes/functions.php';
+require_once __DIR__ . '/../../phpBB/includes/functions_content.php';
+
+class phpbb_text_processing_smilies_test extends phpbb_test_case
+{
+ /**
+ * @dataProvider get_text_formatter_tests
+ */
+ public function test_text_formatter($original, $expected)
+ {
+ $container = $this->get_test_case_helpers()->set_s9e_services(null, __DIR__ . '/fixtures/smilies.xml');
+ $parser = $container->get('text_formatter.parser');
+ $renderer = $container->get('text_formatter.renderer');
+
+ $this->assertSame($expected, $renderer->render($parser->parse($original)));
+ }
+
+ public function get_text_formatter_tests()
+ {
+ return array(
+ array(
+ ':) beginning',
+ ' beginning'
+ ),
+ array(
+ 'end :)',
+ 'end '
+ ),
+ array(
+ ':)',
+ ''
+ ),
+ array(
+ 'xx (18) 8) xx',
+ 'xx (18) xx'
+ ),
+ );
+ }
+}
diff --git a/tests/text_processing/strip_bbcode_test.php b/tests/text_processing/strip_bbcode_test.php
new file mode 100644
index 0000000000..827d8d4a52
--- /dev/null
+++ b/tests/text_processing/strip_bbcode_test.php
@@ -0,0 +1,42 @@
+
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php';
+
+class phpbb_text_processing_strip_bbcode_test extends phpbb_test_case
+{
+ public function test_legacy()
+ {
+ $original = '[b:20m4ill1]bold[/b:20m4ill1]';
+ $expected = ' bold ';
+
+ $actual = $original;
+ strip_bbcode($actual);
+
+ $this->assertSame($expected, $actual, '20m4ill1');
+ }
+
+ public function test_s9e()
+ {
+ $phpbb_container = $this->get_test_case_helpers()->set_s9e_services();
+
+ $original = '[b]bold[/b]';
+ $expected = ' bold ';
+
+ $actual = $original;
+ strip_bbcode($actual);
+
+ $this->assertSame($expected, $actual);
+ }
+}
diff --git a/tests/text_processing/tickets_data/PHPBB3-10002.html b/tests/text_processing/tickets_data/PHPBB3-10002.html
new file mode 100644
index 0000000000..82990b2253
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-10002.html
@@ -0,0 +1,2 @@
+
one
+
two
\ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-10002.txt b/tests/text_processing/tickets_data/PHPBB3-10002.txt
new file mode 100644
index 0000000000..fe2f29073f
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-10002.txt
@@ -0,0 +1,2 @@
+[quote][list][*]one
+[quote][list][*]two[/list][/quote]
\ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-10122.html b/tests/text_processing/tickets_data/PHPBB3-10122.html
new file mode 100644
index 0000000000..f0fb6115b2
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-10122.html
@@ -0,0 +1 @@
+
This is my indented text
\ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-10122.txt b/tests/text_processing/tickets_data/PHPBB3-10122.txt
new file mode 100644
index 0000000000..a5e059df66
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-10122.txt
@@ -0,0 +1 @@
+[list=none][*]This is my indented text[/list]
\ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-10425.html b/tests/text_processing/tickets_data/PHPBB3-10425.html
new file mode 100644
index 0000000000..522b2f8858
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-10425.html
@@ -0,0 +1,3 @@
+http://ar.wikipedia.org/wiki/الصفحة_الرئيسية
+http://ar.wikipedia.org/wiki/الصفحة_الرئيسية
+link
\ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-10425.txt b/tests/text_processing/tickets_data/PHPBB3-10425.txt
new file mode 100644
index 0000000000..d93c0446b6
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-10425.txt
@@ -0,0 +1,3 @@
+http://ar.wikipedia.org/wiki/الصفحة_الرئيسية
+[url]http://ar.wikipedia.org/wiki/الصفحة_الرئيسية[/url]
+[url=http://ar.wikipedia.org/wiki/الصفحة_الرئيسية]link[/url]
\ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-10587.html b/tests/text_processing/tickets_data/PHPBB3-10587.html
new file mode 100644
index 0000000000..dd0a483244
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-10587.html
@@ -0,0 +1,2 @@
+http://www.tx-gaming.net/warzone/tournament.php?tourney[id]=34&action=brackets
+link
\ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-10587.txt b/tests/text_processing/tickets_data/PHPBB3-10587.txt
new file mode 100644
index 0000000000..f81a35eb5f
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-10587.txt
@@ -0,0 +1,2 @@
+[url]http://www.tx-gaming.net/warzone/tournament.php?tourney[id]=34&action=brackets[/url]
+[url="http://www.tx-gaming.net/warzone/tournament.php?tourney[id]=34&action=brackets"]link[/url]
\ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-10922.html b/tests/text_processing/tickets_data/PHPBB3-10922.html
new file mode 100644
index 0000000000..cdf8316df0
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-10922.html
@@ -0,0 +1 @@
+user@example.org...
\ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-10922.txt b/tests/text_processing/tickets_data/PHPBB3-10922.txt
new file mode 100644
index 0000000000..348f8a1541
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-10922.txt
@@ -0,0 +1 @@
+[email]user@example.org[/email][email=user@example.org]...[/email]
\ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-10989.html b/tests/text_processing/tickets_data/PHPBB3-10989.html
new file mode 100644
index 0000000000..f003ad3dfa
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-10989.html
@@ -0,0 +1,8 @@
+
Lorem wrote:[quote="Lorem"
Suspendisse iaculis porta tempor. Nulla.
+ Nullam a tortor sit amet.
+ Proin ac mi eget magna.
+
+
Lorem wrote:Quisque fermentum tortor quis odio scelerisque consequat fermentum urna gravida. In semper vehicula condimentum. Donec suscipit ante imperdiet augue rhoncus.
+
+
+Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Maecenas quis odio orci, sit amet semper.
\ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-10989.txt b/tests/text_processing/tickets_data/PHPBB3-10989.txt
new file mode 100644
index 0000000000..dc2430f210
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-10989.txt
@@ -0,0 +1,8 @@
+[quote="Lorem"][quote="Lorem"[quote] Suspendisse iaculis porta tempor. Nulla.[/quote]
+ Nullam a tortor sit amet.[/quote]
+ Proin ac mi eget magna.
+
+[quote="Lorem"]Quisque fermentum tortor quis odio scelerisque consequat fermentum urna gravida. In semper vehicula condimentum. Donec suscipit ante imperdiet augue rhoncus.[/quote]
+
+
+Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Maecenas quis odio orci, sit amet semper.
\ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-11153.html b/tests/text_processing/tickets_data/PHPBB3-11153.html
new file mode 100644
index 0000000000..0f67ac4bc0
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-11153.html
@@ -0,0 +1 @@
+...
\ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-11153.txt b/tests/text_processing/tickets_data/PHPBB3-11153.txt
new file mode 100644
index 0000000000..d2794978d9
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-11153.txt
@@ -0,0 +1 @@
+[myemail=user@example.org]...[/myemail]
\ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-11153.xml b/tests/text_processing/tickets_data/PHPBB3-11153.xml
new file mode 100644
index 0000000000..a7fc69520b
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-11153.xml
@@ -0,0 +1,28 @@
+
+
+
+
diff --git a/tests/text_processing/tickets_data/PHPBB3-12195.html b/tests/text_processing/tickets_data/PHPBB3-12195.html
new file mode 100644
index 0000000000..d8e0f8d523
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-12195.html
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-12195.txt b/tests/text_processing/tickets_data/PHPBB3-12195.txt
new file mode 100644
index 0000000000..b66dbd5d96
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-12195.txt
@@ -0,0 +1 @@
+[url=//example.org/][img]//example.org/img.png[/img][/url]
\ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-3981.before.php b/tests/text_processing/tickets_data/PHPBB3-3981.before.php
new file mode 100644
index 0000000000..1c326b52af
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-3981.before.php
@@ -0,0 +1,21 @@
+
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+function before_assert_phpbb3_3981($vars)
+{
+ if (!function_exists('idn_to_ascii'))
+ {
+ extract($vars);
+ $test->markTestSkipped('International URLs need idn_to_ascii()');
+ }
+}
diff --git a/tests/text_processing/tickets_data/PHPBB3-3981.html b/tests/text_processing/tickets_data/PHPBB3-3981.html
new file mode 100644
index 0000000000..e5f1b4561d
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-3981.html
@@ -0,0 +1 @@
+http://www.ööö.com
\ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-3981.txt b/tests/text_processing/tickets_data/PHPBB3-3981.txt
new file mode 100644
index 0000000000..976823f1d1
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-3981.txt
@@ -0,0 +1 @@
+[url]http://www.ööö.com[/url]
\ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-7187.html b/tests/text_processing/tickets_data/PHPBB3-7187.html
new file mode 100644
index 0000000000..9138779d29
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-7187.html
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-7187.txt b/tests/text_processing/tickets_data/PHPBB3-7187.txt
new file mode 100644
index 0000000000..584151a083
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-7187.txt
@@ -0,0 +1 @@
+[quote]:geek: :ugeek:[/quote]
\ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-7187.xml b/tests/text_processing/tickets_data/PHPBB3-7187.xml
new file mode 100644
index 0000000000..d270b12619
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-7187.xml
@@ -0,0 +1,33 @@
+
+
+
+
diff --git a/tests/text_processing/tickets_data/PHPBB3-7275.after.php b/tests/text_processing/tickets_data/PHPBB3-7275.after.php
new file mode 100644
index 0000000000..99f41d7839
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-7275.after.php
@@ -0,0 +1,19 @@
+
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+function after_assert_phpbb3_7275($vars)
+{
+ extract($vars);
+ decode_message($parsed_text);
+ $test->assertSame($original, $parsed_text);
+}
diff --git a/tests/text_processing/tickets_data/PHPBB3-7275.html b/tests/text_processing/tickets_data/PHPBB3-7275.html
new file mode 100644
index 0000000000..12502833fd
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-7275.html
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-7275.txt b/tests/text_processing/tickets_data/PHPBB3-7275.txt
new file mode 100644
index 0000000000..8de97d67e0
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-7275.txt
@@ -0,0 +1 @@
+[center]:)[/center]
\ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-7275.xml b/tests/text_processing/tickets_data/PHPBB3-7275.xml
new file mode 100644
index 0000000000..9e979afffb
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-7275.xml
@@ -0,0 +1,49 @@
+
+
+
+
diff --git a/tests/text_processing/tickets_data/PHPBB3-9377.html b/tests/text_processing/tickets_data/PHPBB3-9377.html
new file mode 100644
index 0000000000..dcfb79c173
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-9377.html
@@ -0,0 +1 @@
+red blue red
\ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-9377.txt b/tests/text_processing/tickets_data/PHPBB3-9377.txt
new file mode 100644
index 0000000000..dfd71492c5
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-9377.txt
@@ -0,0 +1 @@
+[red]red [blue]blue[/blue] red[/red]
\ No newline at end of file
diff --git a/tests/text_processing/tickets_data/PHPBB3-9377.xml b/tests/text_processing/tickets_data/PHPBB3-9377.xml
new file mode 100644
index 0000000000..1d8ee3d53f
--- /dev/null
+++ b/tests/text_processing/tickets_data/PHPBB3-9377.xml
@@ -0,0 +1,41 @@
+
+
+