diff options
Diffstat (limited to 'tests')
19 files changed, 1112 insertions, 1 deletions
diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 210cda9a94..cf530cc5be 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -315,7 +315,7 @@ class phpbb_test_case_helpers public function set_s9e_services(ContainerInterface $container = null, $fixture = null, $styles_path = null) { static $first_run; - global $phpbb_container, $phpbb_dispatcher, $phpbb_root_path, $phpEx; + global $phpbb_container, $phpbb_dispatcher, $phpbb_root_path, $phpEx, $user; $cache_dir = __DIR__ . '/../tmp/'; diff --git a/tests/text_reparser/plugins/contact_admin_info_test.php b/tests/text_reparser/plugins/contact_admin_info_test.php new file mode 100644 index 0000000000..e577d2fd3d --- /dev/null +++ b/tests/text_reparser/plugins/contact_admin_info_test.php @@ -0,0 +1,81 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @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__ . '/../../test_framework/phpbb_database_test_case.php'; + +class phpbb_textreparser_contact_admin_info_test extends phpbb_database_test_case +{ + protected $db; + + public function getDataSet() + { + return $this->createXMLDataSet(__DIR__ . '/fixtures/contact_admin_info.xml'); + } + + protected function get_reparser() + { + return new \phpbb\textreparser\plugins\contact_admin_info(new \phpbb\config\db_text($this->db, CONFIG_TEXT_TABLE)); + } + + public function setUp() + { + global $config; + if (!isset($config)) + { + $config = new \phpbb\config\config(array()); + } + $this->get_test_case_helpers()->set_s9e_services(); + $this->db = $this->new_dbal(); + parent::setUp(); + } + + public function test_get_max_id() + { + $reparser = $this->get_reparser(); + $this->assertEquals(1, $reparser->get_max_id()); + } + + public function testReparse() + { + $reparser = $this->get_reparser(); + $reparser->reparse_range(1, 1); + + $sql = 'SELECT config_name, config_value + FROM ' . CONFIG_TEXT_TABLE . ' + ORDER BY config_name'; + $result = $this->db->sql_query($sql); + $rows = $this->db->sql_fetchrowset($result); + $this->db->sql_freeresult($result); + + $expected = array( + array( + 'config_name' => 'contact_admin_info', + 'config_value' => '<r><EMAIL email="admin@example.org"><s>[email]</s>admin@example.org<e>[/email]</e></EMAIL></r>', + ), + array( + 'config_name' => 'contact_admin_info_bitfield', + 'config_value' => 'ACA=', + ), + array( + 'config_name' => 'contact_admin_info_flags', + 'config_value' => '7', + ), + array( + 'config_name' => 'contact_admin_info_uid', + 'config_value' => '1a2hbwf5', + ), + ); + $this->assertEquals($expected, $rows); + } +} diff --git a/tests/text_reparser/plugins/fixtures/contact_admin_info.xml b/tests/text_reparser/plugins/fixtures/contact_admin_info.xml new file mode 100644 index 0000000000..13cd82b1a4 --- /dev/null +++ b/tests/text_reparser/plugins/fixtures/contact_admin_info.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_config_text"> + <column>config_name</column> + <column>config_value</column> + <row> + <value>contact_admin_info</value> + <value>[email:1a2hbwf5]admin@example.org[/email:1a2hbwf5]</value> + </row> + <row> + <value>contact_admin_info_uid</value> + <value>1a2hbwf5</value> + </row> + <row> + <value>contact_admin_info_bitfield</value> + <value>ACA=</value> + </row> + <row> + <value>contact_admin_info_flags</value> + <value>7</value> + </row> + </table> +</dataset> diff --git a/tests/text_reparser/plugins/fixtures/forums.xml b/tests/text_reparser/plugins/fixtures/forums.xml new file mode 100644 index 0000000000..39c172c969 --- /dev/null +++ b/tests/text_reparser/plugins/fixtures/forums.xml @@ -0,0 +1,91 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_forums"> + <column>forum_id</column> + <column>forum_parents</column> + <column>forum_desc</column> + <column>forum_desc_uid</column> + <column>forum_rules</column> + <column>forum_rules_uid</column> + <row> + <value>1</value> + <value></value> + <value>This row should be [b]ignored[/b]</value> + <value>abcd1234</value> + <value>This row should be [b]ignored[/b]</value> + <value>abcd1234</value> + </row> + <row> + <value>2</value> + <value></value> + <value>[b]Not bold[/b] :) http://example.org</value> + <value>abcd1234</value> + <value>[b]Not bold[/b] :) http://example.org</value> + <value>abcd1234</value> + </row> + <row> + <value>3</value> + <value></value> + <value>[b:abcd1234]Bold[/b:abcd1234] :) http://example.org</value> + <value>abcd1234</value> + <value>[b:abcd1234]Bold[/b:abcd1234] :) http://example.org</value> + <value>abcd1234</value> + </row> + <row> + <value>4</value> + <value></value> + <value><![CDATA[[b]Not bold[/b] <!-- s:) --><img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile" /><!-- s:) --> http://example.org]]></value> + <value>abcd1234</value> + <value><![CDATA[[b]Not bold[/b] <!-- s:) --><img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile" /><!-- s:) --> http://example.org]]></value> + <value>abcd1234</value> + </row> + <row> + <value>5</value> + <value></value> + <value><![CDATA[[b]Not bold[/b] :) <!-- m --><a class="postlink" href="http://example.org">http://example.org</a><!-- m -->]]></value> + <value>abcd1234</value> + <value><![CDATA[[b]Not bold[/b] :) <!-- m --><a class="postlink" href="http://example.org">http://example.org</a><!-- m -->]]></value> + <value>abcd1234</value> + </row> + <row> + <value>6</value> + <value></value> + <value><![CDATA[[flash=123,345:abcd1234]http://example.org/flash.swf[/flash:abcd1234]]]></value> + <value>abcd1234</value> + <value><![CDATA[[flash=123,345:abcd1234]http://example.org/flash.swf[/flash:abcd1234]]]></value> + <value>abcd1234</value> + </row> + <row> + <value>7</value> + <value></value> + <value><![CDATA[[flash=123,345]http://example.org/flash.swf[/flash]]]></value> + <value>abcd1234</value> + <value><![CDATA[[flash=123,345]http://example.org/flash.swf[/flash]]]></value> + <value>abcd1234</value> + </row> + <row> + <value>8</value> + <value></value> + <value><![CDATA[[img:abcd1234]http://example.org/img.png[/img:abcd1234]]]></value> + <value>abcd1234</value> + <value><![CDATA[[img:abcd1234]http://example.org/img.png[/img:abcd1234]]]></value> + <value>abcd1234</value> + </row> + <row> + <value>9</value> + <value></value> + <value><![CDATA[[img]http://example.org/img.png[/img]]]></value> + <value>abcd1234</value> + <value><![CDATA[[img]http://example.org/img.png[/img]]]></value> + <value>abcd1234</value> + </row> + <row> + <value>1000</value> + <value></value> + <value>This row should be [b]ignored[/b]</value> + <value>abcd1234</value> + <value>This row should be [b]ignored[/b]</value> + <value>abcd1234</value> + </row> + </table> +</dataset> diff --git a/tests/text_reparser/plugins/fixtures/groups.xml b/tests/text_reparser/plugins/fixtures/groups.xml new file mode 100644 index 0000000000..d3df0131a3 --- /dev/null +++ b/tests/text_reparser/plugins/fixtures/groups.xml @@ -0,0 +1,69 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_groups"> + <column>group_id</column> + <column>group_desc</column> + <column>group_desc_options</column> + <column>group_desc_uid</column> + <row> + <value>1</value> + <value>This row should be [b]ignored[/b]</value> + <value>7</value> + <value>abcd1234</value> + </row> + <row> + <value>2</value> + <value>[b]Not bold[/b] :) http://example.org</value> + <value>0</value> + <value>abcd1234</value> + </row> + <row> + <value>3</value> + <value>[b:abcd1234]Bold[/b:abcd1234] :) http://example.org</value> + <value>1</value> + <value>abcd1234</value> + </row> + <row> + <value>4</value> + <value><![CDATA[[b]Not bold[/b] <!-- s:) --><img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile" /><!-- s:) --> http://example.org]]></value> + <value>2</value> + <value>abcd1234</value> + </row> + <row> + <value>5</value> + <value><![CDATA[[b]Not bold[/b] :) <!-- m --><a class="postlink" href="http://example.org">http://example.org</a><!-- m -->]]></value> + <value>4</value> + <value>abcd1234</value> + </row> + <row> + <value>6</value> + <value><![CDATA[[flash=123,345:abcd1234]http://example.org/flash.swf[/flash:abcd1234]]]></value> + <value>7</value> + <value>abcd1234</value> + </row> + <row> + <value>7</value> + <value><![CDATA[[flash=123,345]http://example.org/flash.swf[/flash]]]></value> + <value>7</value> + <value>abcd1234</value> + </row> + <row> + <value>8</value> + <value><![CDATA[[img:abcd1234]http://example.org/img.png[/img:abcd1234]]]></value> + <value>7</value> + <value>abcd1234</value> + </row> + <row> + <value>9</value> + <value><![CDATA[[img]http://example.org/img.png[/img]]]></value> + <value>7</value> + <value>abcd1234</value> + </row> + <row> + <value>1000</value> + <value>This row should be [b]ignored[/b]</value> + <value>7</value> + <value>abcd1234</value> + </row> + </table> +</dataset> diff --git a/tests/text_reparser/plugins/fixtures/poll_options.xml b/tests/text_reparser/plugins/fixtures/poll_options.xml new file mode 100644 index 0000000000..c2fad9f764 --- /dev/null +++ b/tests/text_reparser/plugins/fixtures/poll_options.xml @@ -0,0 +1,73 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_poll_options"> + <column>poll_option_id</column> + <column>topic_id</column> + <column>poll_option_text</column> + <row> + <value>1</value> + <value>1</value> + <value>This row should be [b]ignored[/b]</value> + </row> + <row> + <value>2</value> + <value>1</value> + <value>This row should be [b:abcd1234]ignored[/b:abcd1234]</value> + </row> + <row> + <value>1</value> + <value>2</value> + <value>[b:abcd1234]Bold[/b:abcd1234]</value> + </row> + <row> + <value>2</value> + <value>2</value> + <value><![CDATA[<!-- s:) --><img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile" /><!-- s:) -->]]></value> + </row> + <row> + <value>3</value> + <value>2</value> + <value><![CDATA[<!-- m --><a class="postlink" href="http://example.org">http://example.org</a><!-- m -->]]></value> + </row> + <row> + <value>1</value> + <value>123</value> + <value>This row should be [b]ignored[/b]</value> + </row> + <row> + <value>2</value> + <value>123</value> + <value>This row should be [b:abcd1234]ignored[/b:abcd1234]</value> + </row> + </table> + <table name="phpbb_posts"> + <column>post_id</column> + <column>post_text</column> + <column>bbcode_uid</column> + <row> + <value>1</value> + <value></value> + <value>abcd1234</value> + </row> + </table> + <table name="phpbb_topics"> + <column>topic_id</column> + <column>topic_first_post_id</column> + <column>poll_title</column> + <row> + <value>1</value> + <value>1</value> + <value>This row should be [b]ignored[/b]</value> + </row> + <row> + <value>2</value> + <value>1</value> + <value>This row should be [b]ignored[/b]</value> + </row> + <row> + <value>123</value> + <value>1</value> + <value>This row should be [b]ignored[/b]</value> + </row> + </table> +</dataset> diff --git a/tests/text_reparser/plugins/fixtures/polls.xml b/tests/text_reparser/plugins/fixtures/polls.xml new file mode 100644 index 0000000000..9baf813c97 --- /dev/null +++ b/tests/text_reparser/plugins/fixtures/polls.xml @@ -0,0 +1,68 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_posts"> + <column>post_id</column> + <column>post_text</column> + <column>bbcode_uid</column> + <row> + <value>1</value> + <value></value> + <value>abcd1234</value> + </row> + </table> + <table name="phpbb_topics"> + <column>topic_id</column> + <column>topic_first_post_id</column> + <column>poll_title</column> + <row> + <value>1</value> + <value>1</value> + <value>This row should be [b]ignored[/b]</value> + </row> + <row> + <value>2</value> + <value>1</value> + <value>[b]Not bold[/b] :) http://example.org</value> + </row> + <row> + <value>3</value> + <value>1</value> + <value>[b:abcd1234]Bold[/b:abcd1234] :) http://example.org</value> + </row> + <row> + <value>4</value> + <value>1</value> + <value><![CDATA[[b]Not bold[/b] <!-- s:) --><img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile" /><!-- s:) --> http://example.org]]></value> + </row> + <row> + <value>5</value> + <value>1</value> + <value><![CDATA[[b]Not bold[/b] :) <!-- m --><a class="postlink" href="http://example.org">http://example.org</a><!-- m -->]]></value> + </row> + <row> + <value>6</value> + <value>1</value> + <value><![CDATA[[flash=123,345:abcd1234]http://example.org/flash.swf[/flash:abcd1234]]]></value> + </row> + <row> + <value>7</value> + <value>1</value> + <value><![CDATA[[flash=123,345]http://example.org/flash.swf[/flash]]]></value> + </row> + <row> + <value>8</value> + <value>1</value> + <value><![CDATA[[img:abcd1234]http://example.org/img.png[/img:abcd1234]]]></value> + </row> + <row> + <value>9</value> + <value>1</value> + <value><![CDATA[[img]http://example.org/img.png[/img]]]></value> + </row> + <row> + <value>1000</value> + <value>1</value> + <value>This row should be [b]ignored[/b]</value> + </row> + </table> +</dataset> diff --git a/tests/text_reparser/plugins/fixtures/posts.xml b/tests/text_reparser/plugins/fixtures/posts.xml new file mode 100644 index 0000000000..ec31747ed9 --- /dev/null +++ b/tests/text_reparser/plugins/fixtures/posts.xml @@ -0,0 +1,91 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_posts"> + <column>post_id</column> + <column>enable_bbcode</column> + <column>enable_smilies</column> + <column>enable_magic_url</column> + <column>post_text</column> + <column>bbcode_uid</column> + <row> + <value>1</value> + <value>1</value> + <value>1</value> + <value>1</value> + <value>This row should be [b]ignored[/b]</value> + <value>abcd1234</value> + </row> + <row> + <value>2</value> + <value>0</value> + <value>0</value> + <value>0</value> + <value>[b]Not bold[/b] :) http://example.org</value> + <value>abcd1234</value> + </row> + <row> + <value>3</value> + <value>1</value> + <value>0</value> + <value>0</value> + <value>[b:abcd1234]Bold[/b:abcd1234] :) http://example.org</value> + <value>abcd1234</value> + </row> + <row> + <value>4</value> + <value>0</value> + <value>1</value> + <value>0</value> + <value><![CDATA[[b]Not bold[/b] <!-- s:) --><img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile" /><!-- s:) --> http://example.org]]></value> + <value>abcd1234</value> + </row> + <row> + <value>5</value> + <value>0</value> + <value>0</value> + <value>1</value> + <value><![CDATA[[b]Not bold[/b] :) <!-- m --><a class="postlink" href="http://example.org">http://example.org</a><!-- m -->]]></value> + <value>abcd1234</value> + </row> + <row> + <value>6</value> + <value>1</value> + <value>1</value> + <value>0</value> + <value><![CDATA[[flash=123,345:abcd1234]http://example.org/flash.swf[/flash:abcd1234]]]></value> + <value>abcd1234</value> + </row> + <row> + <value>7</value> + <value>1</value> + <value>1</value> + <value>0</value> + <value><![CDATA[[flash=123,345]http://example.org/flash.swf[/flash]]]></value> + <value>abcd1234</value> + </row> + <row> + <value>8</value> + <value>1</value> + <value>1</value> + <value>0</value> + <value><![CDATA[[img:abcd1234]http://example.org/img.png[/img:abcd1234]]]></value> + <value>abcd1234</value> + </row> + <row> + <value>9</value> + <value>1</value> + <value>1</value> + <value>0</value> + <value><![CDATA[[img]http://example.org/img.png[/img]]]></value> + <value>abcd1234</value> + </row> + <row> + <value>1000</value> + <value>1</value> + <value>1</value> + <value>1</value> + <value>This row should be [b]ignored[/b]</value> + <value>abcd1234</value> + </row> + </table> +</dataset> diff --git a/tests/text_reparser/plugins/fixtures/privmsgs.xml b/tests/text_reparser/plugins/fixtures/privmsgs.xml new file mode 100644 index 0000000000..4049b9890a --- /dev/null +++ b/tests/text_reparser/plugins/fixtures/privmsgs.xml @@ -0,0 +1,113 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_privmsgs"> + <column>msg_id</column> + <column>enable_bbcode</column> + <column>enable_smilies</column> + <column>enable_magic_url</column> + <column>message_text</column> + <column>bbcode_uid</column> + <column>to_address</column> + <column>bcc_address</column> + <row> + <value>1</value> + <value>1</value> + <value>1</value> + <value>1</value> + <value>This row should be [b]ignored[/b]</value> + <value>abcd1234</value> + <value></value> + <value></value> + </row> + <row> + <value>2</value> + <value>0</value> + <value>0</value> + <value>0</value> + <value>[b]Not bold[/b] :) http://example.org</value> + <value>abcd1234</value> + <value></value> + <value></value> + </row> + <row> + <value>3</value> + <value>1</value> + <value>0</value> + <value>0</value> + <value>[b:abcd1234]Bold[/b:abcd1234] :) http://example.org</value> + <value>abcd1234</value> + <value></value> + <value></value> + </row> + <row> + <value>4</value> + <value>0</value> + <value>1</value> + <value>0</value> + <value><![CDATA[[b]Not bold[/b] <!-- s:) --><img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile" /><!-- s:) --> http://example.org]]></value> + <value>abcd1234</value> + <value></value> + <value></value> + </row> + <row> + <value>5</value> + <value>0</value> + <value>0</value> + <value>1</value> + <value><![CDATA[[b]Not bold[/b] :) <!-- m --><a class="postlink" href="http://example.org">http://example.org</a><!-- m -->]]></value> + <value>abcd1234</value> + <value></value> + <value></value> + </row> + <row> + <value>6</value> + <value>1</value> + <value>1</value> + <value>0</value> + <value><![CDATA[[flash=123,345:abcd1234]http://example.org/flash.swf[/flash:abcd1234]]]></value> + <value>abcd1234</value> + <value></value> + <value></value> + </row> + <row> + <value>7</value> + <value>1</value> + <value>1</value> + <value>0</value> + <value><![CDATA[[flash=123,345]http://example.org/flash.swf[/flash]]]></value> + <value>abcd1234</value> + <value></value> + <value></value> + </row> + <row> + <value>8</value> + <value>1</value> + <value>1</value> + <value>0</value> + <value><![CDATA[[img:abcd1234]http://example.org/img.png[/img:abcd1234]]]></value> + <value>abcd1234</value> + <value></value> + <value></value> + </row> + <row> + <value>9</value> + <value>1</value> + <value>1</value> + <value>0</value> + <value><![CDATA[[img]http://example.org/img.png[/img]]]></value> + <value>abcd1234</value> + <value></value> + <value></value> + </row> + <row> + <value>1000</value> + <value>1</value> + <value>1</value> + <value>1</value> + <value>This row should be [b]ignored[/b]</value> + <value>abcd1234</value> + <value></value> + <value></value> + </row> + </table> +</dataset> diff --git a/tests/text_reparser/plugins/fixtures/users.xml b/tests/text_reparser/plugins/fixtures/users.xml new file mode 100644 index 0000000000..60c623b6b1 --- /dev/null +++ b/tests/text_reparser/plugins/fixtures/users.xml @@ -0,0 +1,91 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_users"> + <column>user_id</column> + <column>user_permissions</column> + <column>username_clean</column> + <column>user_options</column> + <column>user_sig</column> + <column>user_sig_bbcode_uid</column> + <row> + <value>1</value> + <value></value> + <value>user1</value> + <value>230271</value> + <value>This row should be [b]ignored[/b]</value> + <value>abcd1234</value> + </row> + <row> + <value>2</value> + <value></value> + <value>user2</value> + <value>895</value> + <value>[b]Not bold[/b] :) http://example.org</value> + <value>abcd1234</value> + </row> + <row> + <value>3</value> + <value></value> + <value>user3</value> + <value>33663</value> + <value>[b:abcd1234]Bold[/b:abcd1234] :) http://example.org</value> + <value>abcd1234</value> + </row> + <row> + <value>4</value> + <value></value> + <value>user4</value> + <value>66431</value> + <value><![CDATA[[b]Not bold[/b] <!-- s:) --><img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile" /><!-- s:) --> http://example.org]]></value> + <value>abcd1234</value> + </row> + <row> + <value>5</value> + <value></value> + <value>user5</value> + <value>131967</value> + <value><![CDATA[[b]Not bold[/b] :) <!-- m --><a class="postlink" href="http://example.org">http://example.org</a><!-- m -->]]></value> + <value>abcd1234</value> + </row> + <row> + <value>6</value> + <value></value> + <value>user6</value> + <value>99199</value> + <value><![CDATA[[flash=123,345:abcd1234]http://example.org/flash.swf[/flash:abcd1234]]]></value> + <value>abcd1234</value> + </row> + <row> + <value>7</value> + <value></value> + <value>user7</value> + <value>99199</value> + <value><![CDATA[[flash=123,345]http://example.org/flash.swf[/flash]]]></value> + <value>abcd1234</value> + </row> + <row> + <value>8</value> + <value></value> + <value>user8</value> + <value>99199</value> + <value><![CDATA[[img:abcd1234]http://example.org/img.png[/img:abcd1234]]]></value> + <value>abcd1234</value> + </row> + <row> + <value>9</value> + <value></value> + <value>user9</value> + <value>99199</value> + <value><![CDATA[[img]http://example.org/img.png[/img]]]></value> + <value>abcd1234</value> + </row> + <row> + <value>1000</value> + <value></value> + <value>user1000</value> + <value>230271</value> + <value>This row should be [b]ignored[/b]</value> + <value>abcd1234</value> + </row> + </table> +</dataset> diff --git a/tests/text_reparser/plugins/forum_description_test.php b/tests/text_reparser/plugins/forum_description_test.php new file mode 100644 index 0000000000..3b739353cd --- /dev/null +++ b/tests/text_reparser/plugins/forum_description_test.php @@ -0,0 +1,26 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ +include_once __DIR__ . '/test_row_based_plugin.php'; + +class phpbb_textreparser_forum_description_test extends phpbb_textreparser_test_row_based_plugin +{ + public function getDataSet() + { + return $this->createXMLDataSet(__DIR__ . '/fixtures/forums.xml'); + } + + protected function get_reparser() + { + return new \phpbb\textreparser\plugins\forum_description($this->db); + } +} diff --git a/tests/text_reparser/plugins/forum_rules_test.php b/tests/text_reparser/plugins/forum_rules_test.php new file mode 100644 index 0000000000..4c267c9014 --- /dev/null +++ b/tests/text_reparser/plugins/forum_rules_test.php @@ -0,0 +1,26 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ +include_once __DIR__ . '/test_row_based_plugin.php'; + +class phpbb_textreparser_forum_rules_test extends phpbb_textreparser_test_row_based_plugin +{ + public function getDataSet() + { + return $this->createXMLDataSet(__DIR__ . '/fixtures/forums.xml'); + } + + protected function get_reparser() + { + return new \phpbb\textreparser\plugins\forum_rules($this->db); + } +} diff --git a/tests/text_reparser/plugins/group_description_test.php b/tests/text_reparser/plugins/group_description_test.php new file mode 100644 index 0000000000..51035903e1 --- /dev/null +++ b/tests/text_reparser/plugins/group_description_test.php @@ -0,0 +1,26 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ +include_once __DIR__ . '/test_row_based_plugin.php'; + +class phpbb_textreparser_group_description_test extends phpbb_textreparser_test_row_based_plugin +{ + public function getDataSet() + { + return $this->createXMLDataSet(__DIR__ . '/fixtures/groups.xml'); + } + + protected function get_reparser() + { + return new \phpbb\textreparser\plugins\group_description($this->db); + } +} diff --git a/tests/text_reparser/plugins/pm_text_test.php b/tests/text_reparser/plugins/pm_text_test.php new file mode 100644 index 0000000000..3896a57e98 --- /dev/null +++ b/tests/text_reparser/plugins/pm_text_test.php @@ -0,0 +1,26 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ +include_once __DIR__ . '/test_row_based_plugin.php'; + +class phpbb_textreparser_pm_text_test extends phpbb_textreparser_test_row_based_plugin +{ + public function getDataSet() + { + return $this->createXMLDataSet(__DIR__ . '/fixtures/privmsgs.xml'); + } + + protected function get_reparser() + { + return new \phpbb\textreparser\plugins\pm_text($this->db); + } +} diff --git a/tests/text_reparser/plugins/poll_option_test.php b/tests/text_reparser/plugins/poll_option_test.php new file mode 100644 index 0000000000..e043858597 --- /dev/null +++ b/tests/text_reparser/plugins/poll_option_test.php @@ -0,0 +1,100 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @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__ . '/../../test_framework/phpbb_database_test_case.php'; + +class phpbb_textreparser_poll_option_test extends phpbb_database_test_case +{ + protected $db; + + public function getDataSet() + { + return $this->createXMLDataSet(__DIR__ . '/fixtures/poll_options.xml'); + } + + protected function get_reparser() + { + return new \phpbb\textreparser\plugins\poll_option($this->db); + } + + public function setUp() + { + global $config; + if (!isset($config)) + { + $config = new \phpbb\config\config(array()); + } + $this->get_test_case_helpers()->set_s9e_services(); + $this->db = $this->new_dbal(); + parent::setUp(); + } + + public function test_get_max_id() + { + $reparser = $this->get_reparser(); + $this->assertEquals(123, $reparser->get_max_id()); + } + + public function testReparse() + { + $reparser = $this->get_reparser(); + $reparser->reparse_range(2, 3); + + $sql = 'SELECT topic_id, poll_option_id, poll_option_text + FROM ' . POLL_OPTIONS_TABLE . ' + ORDER BY topic_id, poll_option_id'; + $result = $this->db->sql_query($sql); + $rows = $this->db->sql_fetchrowset($result); + $this->db->sql_freeresult($result); + + $expected = array( + array( + 'topic_id' => 1, + 'poll_option_id' => 1, + 'poll_option_text' => 'This row should be [b]ignored[/b]', + ), + array( + 'topic_id' => 1, + 'poll_option_id' => 2, + 'poll_option_text' => 'This row should be [b:abcd1234]ignored[/b:abcd1234]', + ), + array( + 'topic_id' => 2, + 'poll_option_id' => 1, + 'poll_option_text' => '<r><B><s>[b]</s>Bold<e>[/b]</e></B></r>', + ), + array( + 'topic_id' => 2, + 'poll_option_id' => 2, + 'poll_option_text' => '<r><E>:)</E></r>', + ), + array( + 'topic_id' => 2, + 'poll_option_id' => 3, + 'poll_option_text' => '<r><URL url="http://example.org">http://example.org</URL></r>', + ), + array( + 'topic_id' => 123, + 'poll_option_id' => 1, + 'poll_option_text' => 'This row should be [b]ignored[/b]', + ), + array( + 'topic_id' => 123, + 'poll_option_id' => 2, + 'poll_option_text' => 'This row should be [b:abcd1234]ignored[/b:abcd1234]', + ), + ); + $this->assertEquals($expected, $rows); + } +} diff --git a/tests/text_reparser/plugins/poll_title_test.php b/tests/text_reparser/plugins/poll_title_test.php new file mode 100644 index 0000000000..76ca2ee228 --- /dev/null +++ b/tests/text_reparser/plugins/poll_title_test.php @@ -0,0 +1,26 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ +include_once __DIR__ . '/test_row_based_plugin.php'; + +class phpbb_textreparser_poll_title_test extends phpbb_textreparser_test_row_based_plugin +{ + public function getDataSet() + { + return $this->createXMLDataSet(__DIR__ . '/fixtures/polls.xml'); + } + + protected function get_reparser() + { + return new \phpbb\textreparser\plugins\poll_title($this->db); + } +} diff --git a/tests/text_reparser/plugins/post_text_test.php b/tests/text_reparser/plugins/post_text_test.php new file mode 100644 index 0000000000..0f934a06ee --- /dev/null +++ b/tests/text_reparser/plugins/post_text_test.php @@ -0,0 +1,26 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ +include_once __DIR__ . '/test_row_based_plugin.php'; + +class phpbb_textreparser_post_text_test extends phpbb_textreparser_test_row_based_plugin +{ + public function getDataSet() + { + return $this->createXMLDataSet(__DIR__ . '/fixtures/posts.xml'); + } + + protected function get_reparser() + { + return new \phpbb\textreparser\plugins\post_text($this->db); + } +} diff --git a/tests/text_reparser/plugins/test_row_based_plugin.php b/tests/text_reparser/plugins/test_row_based_plugin.php new file mode 100644 index 0000000000..befcb48bda --- /dev/null +++ b/tests/text_reparser/plugins/test_row_based_plugin.php @@ -0,0 +1,129 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @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__ . '/../../test_framework/phpbb_database_test_case.php'; + +abstract class phpbb_textreparser_test_row_based_plugin extends phpbb_database_test_case +{ + protected $db; + + abstract protected function get_reparser(); + + public function setUp() + { + global $config; + if (!isset($config)) + { + $config = new \phpbb\config\config(array()); + } + $this->get_test_case_helpers()->set_s9e_services(); + $this->db = $this->new_dbal(); + parent::setUp(); + } + + public function test_get_max_id() + { + $reparser = $this->get_reparser(); + $this->assertEquals(1000, $reparser->get_max_id()); + } + + /** + * @dataProvider getReparseTests + */ + public function testReparse($min_id, $max_id, $expected) + { + $reparser = $this->get_reparser(); + $reparser->reparse_range($min_id, $max_id); + + $ids = array(); + foreach ($expected as $row) + { + $ids[] = $row['id']; + } + + $columns = $reparser->get_columns(); + $sql = 'SELECT ' . $columns['id'] . ' AS id, ' . $columns['text'] . ' AS text + FROM ' . $reparser->get_table_name() . ' + WHERE ' . $this->db->sql_in_set($columns['id'], $ids) . ' + ORDER BY id'; + $result = $this->db->sql_query($sql); + $rows = $this->db->sql_fetchrowset($result); + $this->db->sql_freeresult($result); + $this->assertEquals($expected, $rows); + } + + public function getReparseTests() + { + return array( + array( + 2, + 5, + array( + array( + 'id' => '1', + 'text' => 'This row should be [b]ignored[/b]', + ), + array( + 'id' => '2', + 'text' => '<t>[b]Not bold[/b] :) http://example.org</t>', + ), + array( + 'id' => '3', + 'text' => '<r><B><s>[b]</s>Bold<e>[/b]</e></B> :) http://example.org</r>', + ), + array( + 'id' => '4', + 'text' => '<r>[b]Not bold[/b] <E>:)</E> http://example.org</r>', + ), + array( + 'id' => '5', + 'text' => '<r>[b]Not bold[/b] :) <URL url="http://example.org">http://example.org</URL></r>', + ), + array( + 'id' => '1000', + 'text' => 'This row should be [b]ignored[/b]', + ), + ) + ), + array( + 6, + 7, + array( + array( + 'id' => '6', + 'text' => '<r><FLASH height="345" url="http://example.org/flash.swf" width="123"><s>[flash=123,345]</s>http://example.org/flash.swf<e>[/flash]</e></FLASH></r>', + ), + array( + 'id' => '7', + 'text' => '<t>[flash=123,345]http://example.org/flash.swf[/flash]</t>', + ), + ) + ), + array( + 8, + 9, + array( + array( + 'id' => '8', + 'text' => '<r><IMG src="http://example.org/img.png"><s>[img]</s>http://example.org/img.png<e>[/img]</e></IMG></r>', + ), + array( + 'id' => '9', + 'text' => '<t>[img]http://example.org/img.png[/img]</t>', + ), + ) + ), + ); + } +} diff --git a/tests/text_reparser/plugins/user_signature_test.php b/tests/text_reparser/plugins/user_signature_test.php new file mode 100644 index 0000000000..ab830a303d --- /dev/null +++ b/tests/text_reparser/plugins/user_signature_test.php @@ -0,0 +1,26 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ +include_once __DIR__ . '/test_row_based_plugin.php'; + +class phpbb_textreparser_user_signature_test extends phpbb_textreparser_test_row_based_plugin +{ + public function getDataSet() + { + return $this->createXMLDataSet(__DIR__ . '/fixtures/users.xml'); + } + + protected function get_reparser() + { + return new \phpbb\textreparser\plugins\user_signature($this->db); + } +} |