diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/functional/posting_test.php | 81 | ||||
-rw-r--r-- | tests/notification/base.php | 9 | ||||
-rw-r--r-- | tests/notification/manager_helper.php | 5 | ||||
-rw-r--r-- | tests/notification/submit_post_base.php | 5 | ||||
-rw-r--r-- | tests/notification/submit_post_type_quote_test.php | 38 | ||||
-rw-r--r-- | tests/regex/censor_test.php | 12 | ||||
-rw-r--r-- | tests/test_framework/phpbb_test_case_helpers.php | 2 | ||||
-rw-r--r-- | tests/text_formatter/s9e/parser_test.php | 10 | ||||
-rw-r--r-- | tests/text_formatter/s9e/utils_test.php | 34 | ||||
-rw-r--r-- | tests/text_processing/tickets_data/PHPBB3-13641.html | 1 | ||||
-rw-r--r-- | tests/text_processing/tickets_data/PHPBB3-13641.txt | 1 | ||||
-rw-r--r-- | tests/text_processing/tickets_data/PHPBB3-13641.xml | 28 | ||||
-rw-r--r-- | tests/text_processing/tickets_data/PHPBB3-8419.html | 1 | ||||
-rw-r--r-- | tests/text_processing/tickets_data/PHPBB3-8419.txt | 1 | ||||
-rw-r--r-- | tests/text_processing/tickets_data/PHPBB3-8419.xml | 28 |
15 files changed, 215 insertions, 41 deletions
diff --git a/tests/functional/posting_test.php b/tests/functional/posting_test.php index 7acf375c5d..5c083aef37 100644 --- a/tests/functional/posting_test.php +++ b/tests/functional/posting_test.php @@ -71,4 +71,85 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}"); $this->assertContains('😀', $crawler->text()); } + + /** + * @testdox max_quote_depth is applied to the text populating the posting form + */ + public function test_quote_depth_form() + { + $text = '0[quote]1[quote]2[/quote]1[/quote]0'; + $expected = array( + 0 => '[quote="admin"]0[quote]1[quote]2[/quote]1[/quote]0[/quote]', + 1 => '[quote="admin"]00[/quote]', + 2 => '[quote="admin"]0[quote]11[/quote]0[/quote]', + 3 => '[quote="admin"]0[quote]1[quote]2[/quote]1[/quote]0[/quote]', + ); + + $this->login(); + $topic = $this->create_topic(2, 'Test Topic 1', 'Test topic'); + $post = $this->create_post(2, $topic['topic_id'], 'Re: Test Topic 1', $text); + $quote_url = "posting.php?mode=quote&f=2&t={$post['topic_id']}&p={$post['post_id']}&sid={$this->sid}"; + + $this->admin_login(); + foreach ($expected as $quote_depth => $expected_text) + { + $this->set_quote_depth($quote_depth); + $crawler = self::request('GET', $quote_url); + $this->assertContains($expected_text, $crawler->filter('textarea#message')->text()); + } + } + + /** + * @testdox max_quote_depth is applied to the submitted text + */ + public function test_quote_depth_submit() + { + $text = 'depth:0[quote]depth:1[quote]depth:2[quote]depth:3[/quote][/quote][/quote]'; + $contains = array( + 0 => array('depth:0', 'depth:1', 'depth:2', 'depth:3'), + 1 => array('depth:0', 'depth:1'), + 2 => array('depth:0', 'depth:1', 'depth:2'), + 3 => array('depth:0', 'depth:1', 'depth:2', 'depth:3'), + ); + $not_contains = array( + 0 => array(), + 1 => array('depth:2', 'depth:3'), + 2 => array('depth:3'), + 3 => array(), + ); + + $this->login(); + $this->admin_login(); + $topic = $this->create_topic(2, 'Test Topic 1', 'Test topic'); + + for ($quote_depth = 0; $quote_depth <= 2; ++$quote_depth) + { + $this->set_quote_depth($quote_depth); + + $post = $this->create_post(2, $topic['topic_id'], 'Re: Test Topic 1', $text); + $url = "viewtopic.php?p={$post['post_id']}&sid={$this->sid}"; + + $crawler = self::request('GET', $url); + $text_content = $crawler->filter('#p' . $post['post_id'])->text(); + foreach ($contains[$quote_depth] as $contains_text) + { + $this->assertContains($contains_text, $text_content); + } + foreach ($not_contains[$quote_depth] as $not_contains_text) + { + $this->assertNotContains($not_contains_text, $text_content); + } + } + } + + protected function set_quote_depth($depth) + { + $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_board&mode=post'); + $form = $crawler->selectButton('Submit')->form(); + $values = $form->getValues(); + $values['config[max_quote_depth]'] = $depth; + $form->setValues($values); + $crawler = self::submit($form); + $this->assertEquals(1, $crawler->filter('.successbox')->count()); + } } diff --git a/tests/notification/base.php b/tests/notification/base.php index a1ebecd6f9..45b0b6f179 100644 --- a/tests/notification/base.php +++ b/tests/notification/base.php @@ -116,7 +116,14 @@ abstract class phpbb_tests_notification_base extends phpbb_database_test_case { global $phpbb_root_path, $phpEx; - return new $type($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config, $phpbb_root_path, $phpEx, 'phpbb_notification_types', 'phpbb_notifications', 'phpbb_user_notifications'); + $instance = new $type($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config, $phpbb_root_path, $phpEx, 'phpbb_notification_types', 'phpbb_notifications', 'phpbb_user_notifications'); + + if ($type === 'phpbb\\notification\\type\\quote') + { + $instance->set_utils(new \phpbb\textformatter\s9e\utils); + } + + return $instance; } protected function assert_notifications($expected, $options = array()) diff --git a/tests/notification/manager_helper.php b/tests/notification/manager_helper.php index 75b7275d3a..48bf5b177b 100644 --- a/tests/notification/manager_helper.php +++ b/tests/notification/manager_helper.php @@ -48,6 +48,11 @@ class phpbb_notification_manager_helper extends \phpbb\notification\manager $item = new $item_type($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notification_types_table, $this->notifications_table, $this->user_notifications_table); + if ($item_type === 'phpbb\\notification\\type\\quote') + { + $item->set_utils(new \phpbb\textformatter\s9e\utils); + } + $item->set_notification_manager($this); $item->set_initial_data($data); diff --git a/tests/notification/submit_post_base.php b/tests/notification/submit_post_base.php index d7a711e007..04fb6658c3 100644 --- a/tests/notification/submit_post_base.php +++ b/tests/notification/submit_post_base.php @@ -117,6 +117,11 @@ abstract class phpbb_notification_submit_post_base extends phpbb_database_test_c $phpbb_root_path, $phpEx, NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE); + if ($type === 'quote') + { + $class->set_utils(new \phpbb\textformatter\s9e\utils); + } + $phpbb_container->set('notification.type.' . $type, $class); $notification_types_array['notification.type.' . $type] = $class; diff --git a/tests/notification/submit_post_type_quote_test.php b/tests/notification/submit_post_type_quote_test.php index 61e3840773..8ad6a62b09 100644 --- a/tests/notification/submit_post_type_quote_test.php +++ b/tests/notification/submit_post_type_quote_test.php @@ -51,6 +51,8 @@ class phpbb_notification_submit_post_type_quote_test extends phpbb_notification_ */ public function submit_post_data() { + $parser = $this->get_test_case_helpers()->set_s9e_services()->get('text_formatter.parser'); + return array( /** * Normal post @@ -65,15 +67,15 @@ class phpbb_notification_submit_post_type_quote_test extends phpbb_notification_ */ array( array( - 'message' => implode(' ', array( - '[quote="poster":uid]poster should not be notified[/quote:uid]', - '[quote="test":uid]test should be notified[/quote:uid]', - '[quote="unauthorized":uid]unauthorized to read, should not receive a notification[/quote:uid]', - '[quote="notified":uid]already notified, should not receive a new notification[/quote:uid]', - '[quote="disabled":uid]option disabled, should not receive a notification[/quote:uid]', - '[quote="default":uid]option set to default, should receive a notification[/quote:uid]', - '[quote="doesn\'t exist":uid]user does not exist, should not receive a notification[/quote:uid]', - )), + 'message' => $parser->parse(implode(' ', array( + '[quote="poster"]poster should not be notified[/quote]', + '[quote="test"]test should be notified[/quote]', + '[quote="unauthorized"]unauthorized to read, should not receive a notification[/quote]', + '[quote="notified"]already notified, should not receive a new notification[/quote]', + '[quote="disabled"]option disabled, should not receive a notification[/quote]', + '[quote="default"]option set to default, should receive a notification[/quote]', + '[quote="doesn\'t exist"]user does not exist, should not receive a notification[/quote]', + ))), 'bbcode_uid' => 'uid', ), array( @@ -94,15 +96,15 @@ class phpbb_notification_submit_post_type_quote_test extends phpbb_notification_ */ array( array( - 'message' => implode(' ', array( - '[quote="poster":uid]poster should not be notified[/quote:uid]', - '[quote="test":uid]test should be notified[/quote:uid]', - '[quote="unauthorized":uid]unauthorized to read, should not receive a notification[/quote:uid]', - '[quote="notified":uid]already notified, should not receive a new notification[/quote:uid]', - '[quote="disabled":uid]option disabled, should not receive a notification[/quote:uid]', - '[quote="default":uid]option set to default, should receive a notification[/quote:uid]', - '[quote="doesn\'t exist":uid]user does not exist, should not receive a notification[/quote:uid]', - )), + 'message' => $parser->parse(implode(' ', array( + '[quote="poster"]poster should not be notified[/quote]', + '[quote="test"]test should be notified[/quote]', + '[quote="unauthorized"]unauthorized to read, should not receive a notification[/quote]', + '[quote="notified"]already notified, should not receive a new notification[/quote]', + '[quote="disabled"]option disabled, should not receive a notification[/quote]', + '[quote="default"]option set to default, should receive a notification[/quote]', + '[quote="doesn\'t exist"]user does not exist, should not receive a notification[/quote]', + ))), 'bbcode_uid' => 'uid', 'force_approved_state' => false, ), diff --git a/tests/regex/censor_test.php b/tests/regex/censor_test.php index 50c6778c8c..5625b0020b 100644 --- a/tests/regex/censor_test.php +++ b/tests/regex/censor_test.php @@ -37,17 +37,7 @@ class phpbb_regex_censor_test extends phpbb_test_case */ public function test_censor_unicode($pattern, $subject) { - $regex = get_censor_preg_expression($pattern, true); - - $this->assertRegExp($regex, $subject); - } - - /** - * @dataProvider censor_test_data - */ - public function test_censor_no_unicode($pattern, $subject) - { - $regex = get_censor_preg_expression($pattern, false); + $regex = get_censor_preg_expression($pattern); $this->assertRegExp($regex, $subject); } diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 685014d3e4..210cda9a94 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -494,11 +494,9 @@ class phpbb_test_case_helpers $parser = new \phpbb\textformatter\s9e\parser( $cache, $cache_key_parser, - $user, $factory, $dispatcher ); - $container->set('text_formatter.parser', $parser); $container->set('text_formatter.s9e.parser', $parser); diff --git a/tests/text_formatter/s9e/parser_test.php b/tests/text_formatter/s9e/parser_test.php index 71966f9d36..3b72e713e1 100644 --- a/tests/text_formatter/s9e/parser_test.php +++ b/tests/text_formatter/s9e/parser_test.php @@ -35,7 +35,6 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case $parser = new \phpbb\textformatter\s9e\parser( $cache, '_foo_parser', - $this->getMockBuilder('phpbb\\user')->disableOriginalConstructor()->getMock(), $factory, new phpbb_mock_event_dispatcher ); @@ -63,7 +62,6 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case $parser = new \phpbb\textformatter\s9e\parser( $cache, '_foo_parser', - $this->getMockBuilder('phpbb\\user')->disableOriginalConstructor()->getMock(), $factory, new phpbb_mock_event_dispatcher ); @@ -92,7 +90,6 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case $parser = new \phpbb\textformatter\s9e\parser( new phpbb_mock_cache, '_foo_parser', - $this->getMockBuilder('phpbb\\user')->disableOriginalConstructor()->getMock(), $factory, new phpbb_mock_event_dispatcher ); @@ -126,7 +123,6 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case $parser = new \phpbb\textformatter\s9e\parser( $cache, '_foo_parser', - $this->getMockBuilder('phpbb\\user')->disableOriginalConstructor()->getMock(), $factory, new phpbb_mock_event_dispatcher ); @@ -191,7 +187,6 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case new \phpbb\textformatter\s9e\parser( $container->get('cache.driver'), '_foo_parser', - $container->get('user'), $container->get('text_formatter.s9e.factory'), $dispatcher ); @@ -200,9 +195,7 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case public function setup_event_callback($vars) { return isset($vars['parser']) - && $vars['parser'] instanceof \phpbb\textformatter\s9e\parser - && isset($vars['user']) - && $vars['user'] instanceof \phpbb\user; + && $vars['parser'] instanceof \phpbb\textformatter\s9e\parser; } /** @@ -236,7 +229,6 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case $parser = new \phpbb\textformatter\s9e\parser( $container->get('cache.driver'), '_foo_parser', - $container->get('user'), $container->get('text_formatter.s9e.factory'), $dispatcher ); diff --git a/tests/text_formatter/s9e/utils_test.php b/tests/text_formatter/s9e/utils_test.php index 69f8682cac..b1b937709c 100644 --- a/tests/text_formatter/s9e/utils_test.php +++ b/tests/text_formatter/s9e/utils_test.php @@ -75,6 +75,40 @@ class phpbb_textformatter_s9e_utils_test extends phpbb_test_case } /** + * @dataProvider get_outermost_quote_authors_tests + */ + public function test_get_outermost_quote_authors($original, $expected) + { + $container = $this->get_test_case_helpers()->set_s9e_services(); + $utils = $container->get('text_formatter.utils'); + $parser = $container->get('text_formatter.parser'); + + $this->assertSame($expected, $utils->get_outermost_quote_authors($parser->parse($original))); + } + + public function get_outermost_quote_authors_tests() + { + return array( + array( + 'No quotes here', + array() + ), + array( + '[quote="foo"]..[/quote] [quote]..[/quote]', + array('foo') + ), + array( + '[quote="foo"]..[/quote] [quote="bar"]..[/quote]', + array('foo', 'bar') + ), + array( + '[quote="foo"].[quote="baz"]..[/quote].[/quote] [quote="bar"]..[/quote]', + array('foo', 'bar') + ), + ); + } + + /** * @dataProvider get_remove_bbcode_tests */ public function test_remove_bbcode($original, $name, $depth, $expected) diff --git a/tests/text_processing/tickets_data/PHPBB3-13641.html b/tests/text_processing/tickets_data/PHPBB3-13641.html new file mode 100644 index 0000000000..1bd1c06dbb --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-13641.html @@ -0,0 +1 @@ +<code>[color=#FF0000]</code> - <span style="color: #FF0000">red</span>
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-13641.txt b/tests/text_processing/tickets_data/PHPBB3-13641.txt new file mode 100644 index 0000000000..58f324715e --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-13641.txt @@ -0,0 +1 @@ +[c][color=#FF0000][/c] - [color=#FF0000]red[/color]
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-13641.xml b/tests/text_processing/tickets_data/PHPBB3-13641.xml new file mode 100644 index 0000000000..451c5c69cd --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-13641.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_bbcodes"> + <column>bbcode_id</column> + <column>bbcode_tag</column> + <column>bbcode_helpline</column> + <column>display_on_posting</column> + <column>bbcode_match</column> + <column>bbcode_tpl</column> + <column>first_pass_match</column> + <column>first_pass_replace</column> + <column>second_pass_match</column> + <column>second_pass_replace</column> + + <row> + <value>13</value> + <value>c</value> + <value></value> + <value>1</value> + <value>[c]{TEXT}[/c]</value> + <value><![CDATA[<code>{TEXT}</code>]]></value> + <value><\[/c\]!ies]]></value> + <value><![CDATA['[c:$uid]'.str_replace(array("\r\n", '\"', '\'', '(', ')'), array("\n", '"', ''', '(', ')'), trim('${1}')).'[/c:$uid]']]></value> + <value><\[/c:$uid\]!s]]></value> + <value><![CDATA[<code>${1}</code>]]></value> + </row> + </table> +</dataset> diff --git a/tests/text_processing/tickets_data/PHPBB3-8419.html b/tests/text_processing/tickets_data/PHPBB3-8419.html new file mode 100644 index 0000000000..38df626a94 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-8419.html @@ -0,0 +1 @@ +<span style="font-style: italic"><span style="font-weight: bold"><span style="color: #FF0000">tę </span></span></span>przykład
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-8419.txt b/tests/text_processing/tickets_data/PHPBB3-8419.txt new file mode 100644 index 0000000000..dac47823b6 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-8419.txt @@ -0,0 +1 @@ +[ort]tę [/ort]przykład
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-8419.xml b/tests/text_processing/tickets_data/PHPBB3-8419.xml new file mode 100644 index 0000000000..2f1df345f9 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-8419.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_bbcodes"> + <column>bbcode_id</column> + <column>bbcode_tag</column> + <column>bbcode_helpline</column> + <column>display_on_posting</column> + <column>bbcode_match</column> + <column>bbcode_tpl</column> + <column>first_pass_match</column> + <column>first_pass_replace</column> + <column>second_pass_match</column> + <column>second_pass_replace</column> + + <row> + <value>13</value> + <value>myemail</value> + <value></value> + <value>1</value> + <value>[ort]{TEXT}[/ort]</value> + <value><![CDATA[<span style="font-style: italic"><span style="font-weight: bold"><span style="color: #FF0000">{TEXT}</span></span></span>]]></value> + <value><\[/ort\]!ies]]></value> + <value><![CDATA['[ort:$uid]'.str_replace(array("\r\n", '\"', '\'', '(', ')'), array("\n", '"', ''', '(', ')'), trim('${1}')).'[/ort:$uid]']]></value> + <value><\[/ort:$uid\]!s]]></value> + <value><![CDATA[<span style="font-style: italic"><span style="font-weight: bold"><span style="color: #FF0000">${1}</span></span></span>]]></value> + </row> + </table> +</dataset> |